stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<iostream>

#include<set>

#include<queue>

using namespace std;

int n;

int z;

int sum[1100000];

void dfs(int a,int b,int c,int num,int fl)

{

    if(num>1e9)

    {

        return ;

    }

    if(fl>9)

        return ;

    if(a&&b&&c)

    {

        sum[z++]=num;

        dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }

    else

    {

           dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }



}

int main()

{

    z=0;

    dfs(0,0,0,0,0);

    sort(sum,sum+z);

    int key;

    while(cin>>key)

    {



    int left = 0;

    int right =z-1;

    while (left <= right) {

        int mid = (left + right) / 2;

        if (sum[mid] > key) {

            right = mid - 1;

        }

        else {

            left = mid + 1;

        }

    }

    cout<<right+1<<endl;

    }



}




// Optimized solution to the same problem (faster):
/*#include<cstdio>

#include<iostream>

using namespace std;



bool judge(int x){

    int ans3 = 0,ans5 = 0,ans7 = 0,num=0;

    do{

       if(x % 10 == 3) ans3++;

       if(x % 10 == 5) ans5++;

       if(x % 10 == 7) ans7++;

       num++;

       x = x/10;



    }while(x != 0);

    if(ans3 > 0 && ans5 > 0 && ans7 > 0 && ans3+ans5+ans7 == num){

        return true;

    }else{

        return false;

    }

}



int main(){

    int t;

    cin>>t;

    int ans = 0;

    for(int i = 1;i <= t;){

        if(judge(i)){

            ans++;

            i+=18;

        }else{

            i++;

        }

    }

    cout<<ans;

}

*/

#include<cstdio>

int count = 0;

int t;



void DFS(long long x,bool three,bool five,bool seven){

    if(x <= t){

        if(three && five && seven) count++;

    DFS(x*10+3,true,five,seven);

    DFS(x*10+5,three,true,seven);

    DFS(x*10+7,three,five,true);

    }



}



int main(){

    scanf("%d",&t);

    DFS(0,false,false,false);

    printf("%d",count);

}
















































// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int N,count=0;

void dfs(long long,unsigned char);

int main()

{

    cin>>N;

    dfs(0,0);

    cout<<count<<endl;

    return 0;

}

void dfs(long long nextNum,unsigned char flag357)

{

    if(nextNum<=N)

    {

        if(flag357==07)    // 07 is BIN 111

            count++;

        dfs(nextNum*10+3,flag357|01); // BIN 001

        dfs(nextNum*10+5,flag357|02); // BIN 010

        dfs(nextNum*10+7,flag357|04); // BIN 100

    }

}

	

// Optimized solution to the same problem (faster):
/*#include<cstdio>

#include<iostream>

using namespace std;



bool judge(int x){

    int ans3 = 0,ans5 = 0,ans7 = 0,num=0;

    do{

       if(x % 10 == 3) ans3++;

       if(x % 10 == 5) ans5++;

       if(x % 10 == 7) ans7++;

       num++;

       x = x/10;



    }while(x != 0);

    if(ans3 > 0 && ans5 > 0 && ans7 > 0 && ans3+ans5+ans7 == num){

        return true;

    }else{

        return false;

    }

}



int main(){

    int t;

    cin>>t;

    int ans = 0;

    for(int i = 1;i <= t;){

        if(judge(i)){

            ans++;

            i+=18;

        }else{

            i++;

        }

    }

    cout<<ans;

}

*/

#include<cstdio>

int count = 0;

int t;



void DFS(long long x,bool three,bool five,bool seven){

    if(x <= t){

        if(three && five && seven) count++;

    DFS(x*10+3,true,five,seven);

    DFS(x*10+5,three,true,seven);

    DFS(x*10+7,three,five,true);

    }



}



int main(){

    scanf("%d",&t);

    DFS(0,false,false,false);

    printf("%d",count);

}
















































// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

using namespace std;



long long int ans=0,t;



void f(long long int k,bool r3,bool r5,bool r7){

    if(t<k)

        return ;

    else if(r3&&r5&&r7)

        ans++;

    f(10*k+3,true,r5,r7);

    f(10*k+5,r3,true,r7);

    f(10*k+7,r3,r5,true);

}



int main()

{

    scanf("%lld",&t);

    f(3,true,false,false);

    f(5,false,true,false);

    f(7,false,false,true);

    printf("%lld",ans);

}


// Optimized solution to the same problem (faster):
#include<cstdio>



using namespace std;

int t,count=0;

void dfs(long long num,int flag357){

    if(num <= t){

        if(flag357==07)

            count++;

        dfs(num*10+3,flag357|01);

        dfs(num*10+5,flag357|02);

        dfs(num*10+7,flag357|04);

    }

}

int main()

{

    scanf("%d",&t);

    dfs(0,0);

    printf("%d",count);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int N,count=0;

void dfs(long long,unsigned char);

int main(){

    cin>>N;

    dfs(0,0);

    cout<<count;

    return 0;

}

void dfs(long long nextNum,unsigned char flag357){

    if(nextNum<=N){

        if(flag357==07)    // 07 is BIN 111

            count++;

        dfs(nextNum*10+3,flag357|01); // BIN 001

        dfs(nextNum*10+5,flag357|02); // BIN 010

        dfs(nextNum*10+7,flag357|04); // BIN 100

    }

}

// Optimized solution to the same problem (faster):
#include<cstdio>



using namespace std;

int t,count=0;

void dfs(long long num,int flag357){

    if(num <= t){

        if(flag357==07)

            count++;

        dfs(num*10+3,flag357|01);

        dfs(num*10+5,flag357|02);

        dfs(num*10+7,flag357|04);

    }

}

int main()

{

    scanf("%d",&t);

    dfs(0,0);

    printf("%d",count);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#include<iostream>

#include<algorithm>

#include<string>

#include<map>

#include<set>

#define maxn 1005

using namespace std;

typedef long long  LL;

int cnt=0;

LL n;

void f(LL num,int flag1,int flag2,int flag3)

{

    if(num<=n)

    {

        if(flag1&&flag2&&flag3)

            cnt++;

        f(num*10+3,1,flag2,flag3);

        f(num*10+5,flag1,1,flag3);

        f(num*10+7,flag1,flag2,1);

    }

    return ;

}

int main()

{



    scanf("%lld",&n);

    f(0,0,0,0);

    cout<<cnt<<endl;







    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>



using namespace std;

int t,count=0;

void dfs(long long num,int flag357){

    if(num <= t){

        if(flag357==07)

            count++;

        dfs(num*10+3,flag357|01);

        dfs(num*10+5,flag357|02);

        dfs(num*10+7,flag357|04);

    }

}

int main()

{

    scanf("%d",&t);

    dfs(0,0);

    printf("%d",count);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

using namespace std;



typedef long long LL;



int Total = 0;

int n;





void DPS(LL abc)

{

	if (abc > n)

		return;



	string check = to_string(abc);

	if (check.find('5') != string::npos && check.find('3') != string::npos&& check.find('7') != string::npos)

		Total++;

	DPS(abc * 10 + 5);

	DPS(abc * 10 + 3);

	DPS(abc * 10 + 7);

}



int main()

{

	cin >> n;

	DPS(0);

	cout << Total << endl;

}

// Optimized solution to the same problem (faster):
#include<cstdio>



using namespace std;

int t,count=0;

void dfs(long long num,int flag357){

    if(num <= t){

        if(flag357==07)

            count++;

        dfs(num*10+3,flag357|01);

        dfs(num*10+5,flag357|02);

        dfs(num*10+7,flag357|04);

    }

}

int main()

{

    scanf("%d",&t);

    dfs(0,0);

    printf("%d",count);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int n, nn;

set<string> res;

void f(string s) {

	if(s.length() > 0 && stoi(s) <= nn){

		set<char> st;

		for(int i=0; i<s.length(); ++i) {

			st.insert(s[i]);

		}

		if(st.size() == 3)

		  res.insert(s);

	} 

	if(s.length() == n) {

		return;

	}

	f(s + '3');

	f(s + '5');

	f(s + '7');

}



int main() {

	cin >> nn;

	n = to_string(nn).length();

	f("");

	cout << res.size() << "\n";

	return 0;

}

// Optimized solution to the same problem (faster):
/*

ID: espr1t

TASK: 

KEYWORDS: 

*/



#include <cstdio>

#include <cstring>

#include <algorithm>

#include <vector>

#include <string>



using namespace std;



const int MAX = 1024;



int ans;

int limit;



void recurse(long long num, int mask) {

    if (num > limit)

        return;

    if ((mask & 7) == 7)

        ans++;

    recurse(num * 10 + 3, mask | 1);

    recurse(num * 10 + 5, mask | 2);

    recurse(num * 10 + 7, mask | 4);

}



int main(void) {

	// in = fopen("C.in", "rt");

	

	scanf("%d", &limit);

	

	recurse(0, 0);

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

	

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



typedef long long lint;

typedef pair<int, int> P;

#define REP(i, x, n) for(int i = x ; i < n ; ++i)

#define rep(i, n) REP(i, 0, n)

#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)

#define ALL(x) (x).begin(), (x).end()

#define SORT(x) sort(ALL(x))



const int IINF = 1e9 + 10;

const lint LLINF = (lint)1e18 + 10;

const lint MOD = (lint)1e9 + 7;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};

const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};



int main(){

    const int shichigosan[] = {3, 5, 7};

    vector<int> v;

    REP(i, 1, 8){

        REP(j, 1, 9 - i){

            REP(k, 1, 10 - i - j){

                vector<int> tmp;

                int cnt = 0;

                while(cnt < i){

                    tmp.push_back(shichigosan[0]);

                    ++cnt;

                }

                cnt = 0;

                while(cnt < j){

                    tmp.push_back(shichigosan[1]);

                    ++cnt;

                }

                cnt = 0;

                while(cnt < k){

                    tmp.push_back(shichigosan[2]);

                    ++cnt;

                }

                do{

                    int now = 0;

                    rep(l, tmp.size()){

                        now *= 10;

                        now += tmp[l];

                    }

                    v.push_back(now);

                }while(next_permutation(ALL(tmp)));

            }

        }

    }

    SORT(v);

    int n;

    cin >> n;

    int ans = upper_bound(ALL(v), n) - v.begin();

    cout << ans << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;



typedef long long lint;

typedef pair<int, int> P;

#define REP(i, x, n) for(int i = x ; i < n ; ++i)

#define rep(i, n) for(int i = 0 ; i < n ; ++i)

#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)

#define ALL(x) (x).begin(), (x).end()

#define SORT(x) sort((x).begin(), (x).end())



const int IINF = 1e9 + 10;

const long long LLINF = (long long)1e18 + 10;

const long long MOD = (long long)1e9 + 7;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};

const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

const double EPS = 1e-8;



int n, ans = 0;



void solve(lint now, bool shichi, bool go, bool san){

    if(now > n){

        return;

    }

    if(shichi && go && san){

        ++ans;

    }

    solve(now * 10LL + 7LL, true, go, san);

    solve(now * 10LL + 5LL, shichi, true, san);

    solve(now * 10LL + 3LL, shichi, go, true);

    return;

}



int main(){

    cin >> n;

    solve(0, false, false, false);

    cout << ans << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstring>

#include <iostream>

#include <string>

#include <cmath>

#include <bitset>

#include <vector>

#include <map>

#include <set>

#include <queue>

#include <deque>

#include <algorithm>

#include <complex>

#include <unordered_map>

#include <random>

using namespace std;

typedef long long int ll;

typedef pair<int, int> P;

vector<int> v;

int m;

void solve(int i){

	if(i==10) return;

	m*=10;

	m+=3;

	v.push_back(m);

	solve(i+1);

	m+=2;

	v.push_back(m);

	solve(i+1);

	m+=2;

	v.push_back(m);

	solve(i+1);

  m/=10;

}



int main()

{

	solve(1);

	sort(v.begin(), v.end());

	int n; cin>>n;

	int ans=0;

	for(int i=0; i<v.size(); i++){

		if(v[i]>n) break;

		int c[10]={};

		int n0=v[i];

		while(n0>0){

			c[n0%10]++;

			n0/=10;

		}

		if(c[3] && c[5] && c[7]) ans++;

	}

	cout<<ans<<endl;

  return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <string>

#include <iostream>

#include <cmath>

#include <bitset>

#include <vector>

#include <map>

#include <set>

#include <queue>

#include <deque>

#include <algorithm>

#include <unordered_map>

#include <unordered_set>

using namespace std;

typedef long long int ll;

typedef pair<int, int> P;



int main()

{

	string s;

	cin>>s;

	int d=s.size();

	int c=0, p3=1;

	for(int i=1; i<d; i++){

		p3*=3;

		c+=p3;

	}

	int dp[2][2][2][2][10]={};

	dp[0][0][0][0][0]=1;

	for(int i=0; i<d; i++){

		for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][1][k][l][i+1]+=(dp[1][1][k][l][i]+dp[1][0][k][l][i]);

		for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][k][1][l][i+1]+=(dp[1][k][1][l][i]+dp[1][k][0][l][i]);

		for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][k][l][1][i+1]+=(dp[1][k][l][1][i]+dp[1][k][l][0][i]);

		if(3<s[i]-'0'){

			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][1][k][l][i+1]+=(dp[0][1][k][l][i]+dp[0][0][k][l][i]);

		}else if(3==s[i]-'0'){

			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[0][1][k][l][i+1]+=(dp[0][1][k][l][i]+dp[0][0][k][l][i]);

		}

		if(5<s[i]-'0'){

			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][k][1][l][i+1]+=(dp[0][k][1][l][i]+dp[0][k][0][l][i]);

		}else if(5==s[i]-'0'){

			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[0][k][1][l][i+1]+=(dp[0][k][1][l][i]+dp[0][k][0][l][i]);

		}

		if(7<s[i]-'0'){

			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[1][k][l][1][i+1]+=(dp[0][k][l][1][i]+dp[0][k][l][0][i]);

		}else if(7==s[i]-'0'){

			for(int k=0; k<2; k++) for(int l=0; l<2; l++) dp[0][k][l][1][i+1]+=(dp[0][k][l][1][i]+dp[0][k][l][0][i]);

		}

	}

	cout<<dp[0][1][1][1][d]+dp[1][1][1][1][d]+c-3*((1<<d)-2)+3*(d-1)<<endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<stdio.h>

#include<iostream>

#include<algorithm>

using namespace std;

const int Mod = 1e9+7;

int S,dp[45][1<<17],ans=1;

int main()

{

    int n,x,y,z,now;

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

    for(int i=1;i<=n;i++) ans=1LL*ans*10%Mod;

    now=(1<<(x-1))|(1<<(x+y-1))|(1<<(x+y+z-1));

    S=(1<<x+y+z)-1;

    dp[0][0]=1;

    for(int i=1;i<=n;i++)

    {

        for(int j=0;j<=S;j++)

        {

            for(int k=1;k<=10;k++)

            {

                int T=(j<<k)|(1<<k-1);

                T&=S;

                if((T&now)!=now) dp[i][T]=(dp[i][T]+dp[i-1][j])%Mod;

            }

        }

    }

    for(int i=0;i<=S;i++) ans=(ans-dp[n][i]+Mod)%Mod;

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

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



const int MAXN = 40;

const int P = 1e9 + 7;



inline int add(int a, int b) { return a + b >= P ? a + b - P : a + b; }

inline int sub(int a, int b) { return a - b < 0 ? a - b + P : a - b; }

inline int mul(int a, int b) { return 1LL * a * b % P; }

inline void inc(int &a, int b) { a = add(a, b); }

inline void dec(int &a, int b) { a = sub(a, b); }

inline void mlt(int &a, int b) { a = mul(a, b); }



int ans = 1;

int n, X, Y, Z, mask, valid;

int dp[MAXN + 9][1 << 17];



int main() {

  scanf("%d%d%d%d", &n, &X, &Y, &Z);

  mask = (1 << X + Y + Z) - 1;



  valid = (1 << X + Y + Z - 1) | (1 << Y + Z - 1) | (1 << Z - 1);

  // 满足要求的最小状态



  for (int i = 1; i <= n; ++i) mlt(ans, 10);



  dp[0][0] = 1;

  for (int i = 1; i <= n; ++i) 

    for (int s = 0; s <= mask; ++s) {

      if (!dp[i - 1][s]) continue;

      for (int j = 1; j <= 10; ++j) {

        int now = ((s << j) | (1 << j - 1)) & mask;

        if ((now & valid) != valid) inc(dp[i][now], dp[i - 1][s]);

      }

    }



  for (int s = 0; s <= mask; ++s) dec(ans, dp[n][s]);



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



  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _CRT_SECURE_NO_WARNINGS

#include<sstream>

#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<climits>

#include<cmath>

#include<string>

#include<vector>

#include<set>

#include<map>

#include<queue>

#include<numeric>

#include<functional>

#include<algorithm>

#include<bitset>

#include<tuple>

#include<unordered_set>

#include<random>

using namespace std;

#define INF (1<<29)

#define rep(i,n) for(int i=0;i<(int)(n);i++)

#define all(v) v.begin(),v.end()

#define uniq(v) v.erase(unique(all(v)),v.end())





#define MOD 1000000007









int dp[2][1 << 16];





int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);

	int n, x, y, z;

	cin >> n >> x >> y >> z;



	long long ans = 1;

	rep(i, n)(ans *= 10) %= MOD;



	int(*cur)=dp[0], (*nxt)=dp[1];

	cur[0] = 1;

	rep(i,n) {

		memset(nxt, 0, sizeof(dp[0]));

		rep(j,1<<x+y+z-1) if(cur[j]){

			for (int a = 1; a <= 10;a++) {

				int b = j << a;

				b |= 1 << a - 1;

				if ((b & 1 << x - 1) == 0 || (b & 1 << x + y - 1) == 0 || (b & 1 << x + y + z - 1) == 0) {

					(nxt[b&((1 << x + y + z - 1) - 1)] += cur[j]) %= MOD;

				}

			}

		}

		swap(cur, nxt);

	}

	rep(i,1<<x+y+z-1) {

		ans -= cur[i];

	}

	ans %= MOD;

	ans += MOD;

	ans %= MOD;

	cout << ans << endl;



	return 0;

}

// Optimized solution to the same problem (faster):
#define _CRT_SECURE_NO_WARNINGS

#include<sstream>

#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<climits>

#include<cmath>

#include<string>

#include<vector>

#include<set>

#include<map>

#include<queue>

#include<numeric>

#include<functional>

#include<algorithm>

#include<bitset>

#include<tuple>

#include<unordered_set>

#include<random>

using namespace std;

#define INF (1<<29)

#define rep(i,n) for(int i=0;i<(int)(n);i++)

#define all(v) v.begin(),v.end()

#define uniq(v) v.erase(unique(all(v)),v.end())





#define MOD 1000000007







long long dp[41][1 << 16];



int trash[1 << 16];







int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);

	int n, x, y, z;

	cin >> n >> x >> y >> z;

	const int haiku = (1 << x - 1) | (1 << x + y - 1) | (1 << x + y + z - 1);



	for (int i = 1; i < (1 << x + y + z - 1); i++) {

		int a = i;

		int n = x + y + z - 1;

		while ((a & 1 << x + y + z - 1) == 0) {

			a = a << 1 | 1;

			n--;

		}

		if ((a&haiku) != haiku) trash[i] = trash[i&~(1 << n)];

		else trash[i] = i;

	}



	const int mask = ((1 << x + y + z - 1) - 1);

	dp[0][0] = 1;

	rep(i, n) {

		rep(j, 1 << x + y + z - 1) if (dp[i][j]) {

			dp[i][j] %= MOD;

			for (int a = 1; a <= 10; a++) {

				int b = j << a | 1 << a - 1;

				if ((b&haiku) != haiku) {

					dp[i + 1][trash[b&mask]] += dp[i][j];

				}

			}

		}

	}



	long long ans = 1;

	rep(i, n)(ans *= 10) %= MOD;

	rep(i, 1 << x + y + z - 1) {

		(ans -= dp[n][i]) %= MOD;

	}

	ans += MOD;

	ans %= MOD;

	cout << ans << endl;



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define int long long

#define rg register

#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);

using namespace std;

const int mod=1e9+7;

int read(){

    int x=0,f=1;char c=getchar();

    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();

    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();

    return f*x;

}

int f[41][262143+10];

int ksm(int a,int b){

	int ans=1;

	while(b){

		if(b&1) ans=ans*a%mod;

		a=a*a%mod;

		b>>=1;

	}

	return ans;

}

main(){

    //file("");

	int n=read(),x=read(),y=read(),z=read(),len=(1<<(x+y+z))-1,res=1<<(x+y+z-1)|(1<<(y+z-1))|(1<<(z-1)),ans=0;

	f[0][0]=1;

	for(int i=1;i<=n;i++)

		for(int j=0;j<=len;j++)

			for(int k=1;k<=10;k++){

				int z=(j<<k)|(1<<(k-1));

				z&=len;

				if((z&res)==res) continue;

				f[i][z]=(f[i-1][j]+f[i][z])%mod;

		}

	for(int i=0;i<=len;i++)

		ans=(ans+f[n][i])%mod;

	cout<<(ksm(10,n)-ans+mod)%mod;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cmath>

#include <cstdio>

#include <cstring>

#include <algorithm>

using std::min; using std::max;

using std::swap; using std::sort;

typedef long long ll;



template<typename T>

void read(T &x) {

	int flag = 1; x = 0; char ch = getchar();

	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }

	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();

	x *= flag;

}



const int _ = 42, __ = 1.5e5 + 10, P = 1e9 + 7;

int n, x, y, z, f[_][__], lim, Q;



int main () {

	read(n), read(x), read(y), read(z);

	lim = (1 << (x + y + z)) - 1;

	Q = 1 << (z - 1) | 1 << (y + z - 1) | 1 << (x + y + z - 1);

	f[0][0] = 1; int ret = 1;

	for(int i = 0; i < n; ++i) {

		ret = 1ll * ret * 10 % P;

		for(int s = 0; s <= lim; ++s)

			for(int j = 1; j <= 10; ++j) {

				int t = (s << j | (1 << (j - 1))) & lim;

				if(!f[i][s] || (t & Q) == Q) continue;

				(f[i + 1][t] += f[i][s]) %= P;

			}

	}

	for(int s = 0; s <= lim; ++s) (ret += P - f[n][s]) %= P;

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

	return 0;

} 


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

#define int long long

#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)

using namespace std;



inline int read(){

	int sum=0,f=1;char ch=getchar();

	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}

	return f*sum;

}



const int N=43;

const int M=1<<17;

const int Mod=1000000007;

int n,X,Y,Z,ans=1,lim,st;

int f[N][M];



signed main(){

	n=read();

	X=read();Y=read();Z=read();

	st|=1<<(Z-1);

	st|=1<<(Y+Z-1);

	st|=1<<(X+Y+Z-1);

	lim=(1<<(X+Y+Z))-1;

	f[0][0]=1;

	for(int i=1;i<=n;i++){

		ans=ans*10%Mod;

		for(int j=0;j<lim;j++){

			for(int k=1;k<=10;k++){

				int ret=((j<<k)|(1<<(k-1)))&lim;

				if((ret&st)!=st) f[i][ret]=(f[i][ret]+f[i-1][j])%Mod;

			}

		}	   

	}

	for(int j=0;j<lim;j++) ans=(ans-f[n][j])%Mod;

	printf("%lld\n",(ans+Mod)%Mod);

	return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>



const int N(45), Mod(1e9 + 7);

int n, X, Y, Z, ans = 1, f[N][1 << 17];



int main()

{

	scanf("%d%d%d%d", &n, &X, &Y, &Z); int S = (1 << (X + Y + Z)) - 1;

	int H = (1 << (Z - 1)) | (1 << (Y + Z - 1)) | (1 << (X + Y + Z - 1));

	for (int i = 1; i <= n; i++) ans = 10ll * ans % Mod;

	for (int i = (f[0][0] = 1, 0); i < n; i++)

		for (int T = 0; T <= S; T++) if (f[i][T])

			for (int j = 1, s; j <= 10; j++)

				if (((s = ((T << j) | (1 << (j - 1))) & S) & H) != H)

					f[i + 1][s] = (f[i + 1][s] + f[i][T]) % Mod;

	for (int i = 0; i <= S; i++) ans = (ans - f[n][i] + Mod) % Mod;

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

	return 0;

}


// Fastest known solution for this problem: