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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<map>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//////////////////////

int const N = 41;
int const M = 18;
int const MOD = 1e9 + 7;

int n, x, y, z;
int ans;

void add(int &a, int b){
	a += b;
	if(a >= MOD) a -= MOD;
}

int mul(int a, int b){
	return (ll) a * b % MOD;
}

bool bit(int m, int i){
	return (m & (1 << i));
}

void removeleast(int &m){
	fi(1, 11){
		if(bit(m, i)){
			m >>= i;
			return;
		}
	}
}

int getnewmask(int m, int o){
	fdi(M, 0){
		if(bit(m, i)){
			m |= (1 << (o + i));
			break;
		}
	}	
	//cerr << m <<  " " << o << endl;
	while(m >= (1 << M)){
		removeleast(m);
		//cerr << "getnewmask " << m << endl;
	}
	return m;
}

int hm[(1<<M)];

bool have(int m){
	if(hm[m] != -1) return hm[m];
	vector<int> v;
	fi(0, M){
		if(bit(m, i)) v.pb(i);
	}
	fdi(sz(v), 1) v[i] -= v[i-1];
	fi(0, sz(v)){
		int sx = x, sy = y, sz = z;
		fj(i, sz(v)){
			if(sx > 0){
				sx -= v[j];
			}else if(sy > 0){
				sy -= v[j];
			}else if(sz > 0){
				sz -= v[j];
			}
		}
		if(sx == sy && sy == sz && sz == 0) return hm[m] = 1;
	}
	return hm[m] = 0;
}

int d[N][(1 << M)];

void solve(){
	memset(hm, 255, sizeof(hm));
	int ten[4141];
	ten[0] = 1;
	fi(1, 4141) ten[i] = mul(10, ten[i-1]);

	d[0][1] = 1;
	fi(0, n){
		cerr << i << endl;
		/*int cur = (i&1);
		int nxt = (1 ^ cur);*/
		int cur = i;
		int nxt = i + 1;
		//memset(d[nxt], 0, sizeof(d[nxt]));
		fj(0, (1<<M)){ 
			if(d[cur][j]){
				fo(1, 11){
					//cerr << i << " " << j << " " << o << endl;
					int nj = getnewmask(j, o);
					if(have(nj)){
						add(ans, mul(ten[n-1-i], d[cur][j]));
					}else{
						add(d[nxt][nj], d[cur][j]);
					}
				}
			}
		}
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d %d %d %d",&n,&x,&y,&z);

	solve();

	printf("%d\n",ans);

	return 0;
}