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: Accepted)

using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N,X,Y,Z;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long[,] dp = new long[N,1 << (X+Y+Z)];
        int l = 0;
        int g = 0;
        long count = 1;
        g += 1 << X+Y+Z-1;
        g += 1 << Y+Z-1;
        g += 1 << Z-1;
        for(int i=0;i<X+Y+Z;i++){
            l += 1 << i;
        }
        for(int i=0;i<N;i++){
            for(int j=0;j<1 << (X+Y+Z);j++){
                dp[i,j] = 0;
            }
        }
        for(int i=0;i<10;i++){
            dp[0,l & (1 << i)] ++;
        }
        for(int i=0;i<N-1;i++){
            for(int j=0;j<1 << (X+Y+Z);j++){
                for(int k = 1;k <= 10;k++){
                    int t = (j << k) + (1 << (k-1));
                    if((t & g) != g){
                        dp[i+1,t & l] = (dp[i+1,t & l] + dp[i,j]) % Define.mod; 
                    }
                }
            }
        }
        for(int i=0;i<N;i++){
            count = (count * 10) % Define.mod;
        }
        for(int i=0;i< 1 << (X+Y+Z);i++){
            count = (count - dp[N-1,i] + Define.mod) % Define.mod;
        }
        sb.Append(count+"\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        X = int.Parse(str[1]);
        Y = int.Parse(str[2]);
        Z = int.Parse(str[3]);
    }    
}
public static class Define{
    public const long mod = 1000000007;
}