MOD = 10**9 + 7 def main(): import sys from collections import defaultdict N, R, G, B = map(int, sys.stdin.readline().split()) total = R + G + B if total > N: print(0) return # Initialize DP with (prev_color, streak, r_remain, g_remain, b_remain) # prev_color: 0=R, 1=G, 2=B, 3=blank dp = defaultdict(int) initial_state = (3, 0, R, G, B) dp[initial_state] = 1 for _ in range(N): next_dp = defaultdict(int) for (prev_color, streak, r, g, b), cnt in dp.items(): # Option 1: Place blank new_streak = 0 new_pc = 3 key = (new_pc, new_streak, r, g, b) next_dp[key] = (next_dp[key] + cnt) % MOD # Option 2: Place Red if r > 0 and prev_color != 0: if streak < 2: new_r = r - 1 new_streak = streak + 1 if prev_color != 3 else 1 new_pc = 0 if new_streak <= 2 and new_r >= 0: key = (new_pc, new_streak, new_r, g, b) next_dp[key] = (next_dp[key] + cnt) % MOD # Option 3: Place Green if g > 0 and prev_color != 1: if streak < 2: new_g = g - 1 new_streak = streak + 1 if prev_color != 3 else 1 new_pc = 1 if new_streak <= 2 and new_g >= 0: key = (new_pc, new_streak, r, new_g, b) next_dp[key] = (next_dp[key] + cnt) % MOD # Option 4: Place Blue if b > 0 and prev_color != 2: if streak < 2: new_b = b - 1 new_streak = streak + 1 if prev_color != 3 else 1 new_pc = 2 if new_streak <= 2 and new_b >= 0: key = (new_pc, new_streak, r, g, new_b) next_dp[key] = (next_dp[key] + cnt) % MOD dp = next_dp result = 0 for (pc, s, r, g, b), cnt in dp.items(): if r == 0 and g == 0 and b == 0: result = (result + cnt) % MOD print(result) if __name__ == "__main__": main()