Problem:
Score : 700 points

Problem Statement

Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.

Iroha is looking for X,Y,Z-Haiku (defined below) in integer sequences.

Consider all integer sequences of length N whose elements are between 1 and 10, inclusive. Out of those 10^N sequences, how many contain an X,Y,Z-Haiku?

Here, an integer sequence a_0, a_1, ..., a_{N-1} is said to contain an X,Y,Z-Haiku if and only if there exist four indices x, y, z, w (0 ≦ x < y < z < w ≦ N) such that all of the following are satisfied:

a_x + a_{x+1} + ... + a_{y-1} = X

a_y + a_{y+1} + ... + a_{z-1} = Y

a_z + a_{z+1} + ... + a_{w-1} = Z

Since the answer can be extremely large, print the number modulo 10^9+7.

Constraints

3 ≦ N ≦ 40

1 ≦ X ≦ 5

1 ≦ Y ≦ 7

1 ≦ Z ≦ 5

Input

The input is given from Standard Input in the following format:

N X Y Z

Output

Print the number of the sequences that contain an X,Y,Z-Haiku, modulo 10^9+7.

Sample Input 1

3 5 7 5

Sample Output 1

1

Here, the only sequence that contains a 5,7,5-Haiku is [5, 7, 5].

Sample Input 2

4 5 7 5

Sample Output 2

34

Sample Input 3

37 4 2 3

Sample Output 3

863912418

Sample Input 4

40 5 7 5

Sample Output 4

562805100

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long[][][] dp = new long[N+1][][];
		for(int i=0;i<N+1;i++){
			dp[i] = new long[4][];
			dp[i][0] = new long[X];
			dp[i][1] = new long[Y];
			dp[i][2] = new long[Z];
			dp[i][3] = new long[1];
		}
		
		long mod = (long)1e9+7;
		dp[0][0][0] = 1;
		for(int i=0;i<N;i++){
			for(int j=1;j<=10;j++){
				// before X
				for(int k=0;k<X;k++){
					if(j+k < X){
						dp[i+1][0][j+k] += dp[i][0][k];
						if(dp[i+1][0][j+k] >= mod) dp[i+1][0][j+k] -= mod;
					}
					if(j+k == X){
						dp[i+1][1][0] += dp[i][0][k];
						if(dp[i+1][1][0] >= mod) dp[i+1][1][0] -= mod;
					}
					dp[i+1][0][0] += dp[i][0][k];
					if(dp[i+1][0][0] >= mod) dp[i+1][0][0] -= mod;
				}				// before Y (X comp)
				for(int k=0;k<Y;k++){
					if(j+k < Y){
						dp[i+1][1][j+k] += dp[i][1][k];
						if(dp[i+1][1][j+k] >= mod) dp[i+1][1][j+k] -= mod;
					}
					if(j+k == Y){
						dp[i+1][2][0] += dp[i][1][k];
						if(dp[i+1][2][0] >= mod) dp[i+1][2][0] -= mod;
					}
					dp[i+1][0][0] += dp[i][1][k];
					if(dp[i+1][0][0] >= mod) dp[i+1][0][0] -= mod;
				}
				// before Z (Y comp)
				for(int k=0;k<Z;k++){
					if(j+k < Z){
						dp[i+1][2][j+k] += dp[i][2][k];
						if(dp[i+1][2][j+k] >= mod) dp[i+1][2][j+k] -= mod;
					}
					if(j+k == Z){
						dp[i+1][3][0] += dp[i][2][k];
						if(dp[i+1][3][0] >= mod) dp[i+1][3][0] -= mod;
					}
					dp[i+1][0][0] += dp[i][2][k];
					if(dp[i+1][0][0] >= mod) dp[i+1][0][0] -= mod;
				}
				// comp;
				dp[i+1][3][0] += dp[i][3][0];
				if(dp[i+1][3][0] >= mod) dp[i+1][3][0] -= mod;
				
				
			}
		}
		
		Console.WriteLine(dp[N][3][0]);
	}
	int N,X,Y,Z;
	public Sol(){
		var d = ria();
		N = d[0];
		X = d[1];
		Y = d[2];
		Z = d[3];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}