MOD = 10**9 + 7 def main(): import sys from collections import defaultdict N, R, G, B = map(int, sys.stdin.readline().split()) K = R + G + B # 颜色编码:0=空白,1=红,2=绿,3=蓝 # 状态:dp[i][pp][p][r][g][b] # 由于空间限制,使用字典存储状态 dp = [defaultdict(int) for _ in range(N+1)] dp[0][(0, 0, 0, 0, 0)] = 1 # (pp_color, p_color, r, g, b) for i in range(N): current_dp = dp[i] next_dp = defaultdict(int) for state in current_dp: pp_color, p_color, r, g, b = state count = current_dp[state] for c in [0, 1, 2, 3]: # 当前涂的颜色选项(0=空白) if c == 1: if p_color == 1 or (pp_color != 0 and p_color != 0): continue if r + 1 > R: continue new_r = r + 1 new_g = g new_b = b elif c == 2: if p_color == 2 or (pp_color != 0 and p_color != 0): continue if g + 1 > G: continue new_r = r new_g = g + 1 new_b = b elif c == 3: if p_color == 3 or (pp_color != 0 and p_color != 0): continue if b + 1 > B: continue new_r = r new_g = g new_b = b + 1 else: # c=0,空白 new_r = r new_g = g new_b = b # 检查三个连续的涂色情况 if pp_color != 0 and p_color != 0 and c != 0: continue # 三个连续涂色,不允许 new_pp_color = p_color new_p_color = c next_state = (new_pp_color, new_p_color, new_r, new_g, new_b) next_dp[next_state] = (next_dp[next_state] + count) % MOD dp[i+1] = next_dp # 最后,检查所有状态,其中r=R, g=G, b=B,并且i=N total = 0 for state in dp[N]: pp_color, p_color, r, g, b = state if r == R and g == G and b == B: total = (total + dp[N][state]) % MOD print(total % MOD) if __name__ == '__main__': main()