MOD = 10**9 + 7 n, R, G, B = map(int, input().split()) from collections import defaultdict current_dp = defaultdict(lambda: defaultdict(int)) current_dp[(None, 0)][(0, 0, 0)] = 1 for _ in range(n): next_dp = defaultdict(lambda: defaultdict(int)) for (prev_color, streak), color_counts in current_dp.items(): for (r, g, b), cnt in color_counts.items(): # Option 1: leave blank key = (None, 0) next_dp[key][(r, g, b)] = (next_dp[key][(r, g, b)] + cnt) % MOD # Option 2: paint with color 'R', 'G', or 'B' for color in ['R', 'G', 'B']: if prev_color == color: continue # Calculate new_streak if prev_color is None: new_streak = 1 else: new_streak = streak + 1 if new_streak > 2: continue # Update color counts dr = 1 if color == 'R' else 0 dg = 1 if color == 'G' else 0 db = 1 if color == 'B' else 0 nr = r + dr ng = g + dg nb = b + db if nr > R or ng > G or nb > B: continue key_new = (color, new_streak) next_dp[key_new][(nr, ng, nb)] = (next_dp[key_new][(nr, ng, nb)] + cnt) % MOD current_dp = next_dp result = 0 for (prev_color, streak), color_counts in current_dp.items(): for (r, g, b), cnt in color_counts.items(): if r == R and g == G and b == B: result = (result + cnt) % MOD print(result)