#include <bits/stdc++.h>
#include <omp.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;


#define int ll
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());


typedef pair<int, int> pii;
typedef pair<string, string> pst;
typedef pair<pii, pii> piii;
typedef vector<piii> vpii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<pii> vpi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef pair<pld, pld> pldd;
typedef vector<pld> vpd;
typedef complex<double> base;


#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define my_abs(a) (((a) >= 0) ? (a) : -(a))
#define mp(a, b) make_pair(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define MODIK(a) (a >= M ? a - M : a)
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cout << (#x) << " = " << x << endl;
#ifdef ART_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif


const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

istream &operator >> (istream &in, pii &a)
{
    in >> a.first >> a.second;
    return in;
}


ostream &operator << (ostream &out, pii &a)
{
    out << a.first << ' ' << a.second;
    return out;
}


istream &operator >> (istream &in, pld &a)
{
    in >> a.first >> a.second;
    return in;
}


ostream &operator << (ostream &out, pld &a)
{
    out << a.first << ' ' << a.second;
    return out;
}


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) <<
               ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void print(int a, int b, int n, vi h)
{
    ofstream cout("output.txt");
    cout << SZ(h) << ' ' << a << ' ' << b << '\n';
    for (int i = 0; i < SZ(h); ++i) {
        cout << h[i]  << ' ';
    }
    cout.close();
    exit(0);
}


inline bool break_time(ld time)
{
    return clock() > CLOCKS_PER_SEC * time;
}


void bonds()
{
    ld price, nkd, kd, year;
    int cnt;
    cout << "price nkd kd cnt year\n";
    cout << endl;
    cin >> price >> nkd >> kd >> cnt >> year;
    cout << 100 * ((1000 + kd * cnt - price * 10 - nkd) / (price * 10) / year);
}


ld get_rand_ld(ld l, ld r)
{
    uniform_real_distribution<double> gen(l, r);
    return gen(rng);
}


bool may(int E, ld T)
{
    if (E < 0)
        return 1;

    double eps = get_rand_ld(0, 1);
    return eps < exp(-E / T);
}


void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

#ifdef ART_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(2) << fixed;
    smain();
#ifdef ART_HOME
    cout << "\nTOTAL EXECUTIOn TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}


const int N = 8, N1 = 6, NN = 33900, NNN = 45, K = 2e3 + 10, B = 100, oo = 1e14, M = 1e9 + 7, LOG = 20;
const int M1 = 1000000093, x1 = 27162;
const int M2 = 1000000087, x2 = 241;
const ld pi = atan2(1, 0) * 2, EPS = 1e-9;


vvi flex[N];
vvi flex2[N];
int to[NN][11], pw[NNN], label[NN], links[NN], par[NN], num[NN];
int dp[NNN][NN];


const int root = 1;
int fre = 2;


inline int MOD(int v, int M)
{
    v %= M;
    if (v < 0)
        v += M;

    return v;
}


void add_word(vi s)
{
    int cur = 1;
    for (int v : s) {

        if (!to[cur][v])
            to[cur][v] = fre,
            num[fre] = v,
            par[fre++] = cur;

        cur = to[cur][v];
    }

    label[cur] = 1;
}


void build_suffix_links()
{
    queue<int> flex;
    flex.push(root);

    while (SZ(flex))
    {
        int v = flex.front();
        flex.pop();

        links[v] = root;
        for (int nm = 1; nm <= 10; ++nm)
            if (to[v][nm])
                flex.push(to[v][nm]);

        if (v != root && par[v] != root)
        {
            int pr = links[par[v]];
            int c = num[v];

            while (pr != root && !to[pr][c])
                pr = links[pr];

            if (to[pr][c])
                pr = to[pr][c];

            links[v] = pr;
        }
    }
}


int go(int v, int c)
{
    while (v != root && !to[v][c])
        v = links[v];

    if (to[v][c])
        v = to[v][c];

    return v;
}


void smain()
{
    pw[0] = 1;
    for (int i = 1; i < NNN; ++i)
        pw[i] = MOD(pw[i - 1] * 10, M);

    for (int _1 = 1; _1 < N; ++_1)
        for (int _2 = _1; _2 < N; ++_2)
            for (int _3 = _2; _3 < N; ++_3)
                for (int _4 = _3; _4 < N; ++_4)
                    for (int _5 = _4; _5 < N; ++_5)
                        for (int _6 = _5; _6 < N; ++_6)
                            for (int _7 = _6; _7 < N; ++_7)
                            {
                                int v;
                                vi hui;

                                hui.clear();
                                v = _1;

                                if (v < N) {
                                    hui.push_back(_1);
                                    flex[v].push_back(hui);
                                }


                                hui.clear();
                                v = _1 + _2;

                                if (v < N) {
                                    hui.push_back(_1);
                                    hui.push_back(_2);
                                    flex[v].push_back(hui);
                                }


                                hui.clear();
                                v = _1 + _2 + _3;

                                if (v < N) {
                                    hui.push_back(_1);
                                    hui.push_back(_2);
                                    hui.push_back(_3);
                                    flex[v].push_back(hui);
                                }



                                hui.clear();
                                v = _1 + _2 + _3 + _4;

                                if (v < N) {
                                    hui.push_back(_1);
                                    hui.push_back(_2);
                                    hui.push_back(_3);
                                    hui.push_back(_4);
                                    flex[v].push_back(hui);
                                }


                                hui.clear();
                                v = _1 + _2 + _3 + _4 + _5;

                                if (v < N) {
                                    hui.push_back(_1);
                                    hui.push_back(_2);
                                    hui.push_back(_3);
                                    hui.push_back(_4);
                                    hui.push_back(_5);
                                    flex[v].push_back(hui);
                                }


                                hui.clear();
                                v = _1 + _2 + _3 + _4 + _5 + _6;

                                if (v < N) {
                                    hui.push_back(_1);
                                    hui.push_back(_2);
                                    hui.push_back(_3);
                                    hui.push_back(_4);
                                    hui.push_back(_5);
                                    hui.push_back(_6);
                                    flex[v].push_back(hui);
                                }


                                hui.clear();
                                v = _1 + _2 + _3 + _4 + _5 + _6 + _7;

                                if (v < N) {
                                    hui.push_back(_1);
                                    hui.push_back(_2);
                                    hui.push_back(_3);
                                    hui.push_back(_4);
                                    hui.push_back(_5);
                                    hui.push_back(_6);
                                    hui.push_back(_7);
                                    flex[v].push_back(hui);
                                }
                            }

    for (int i = 1; i < N; ++i)
    {
        for (vi p : flex[i])
        {
            do
            {
                if (!count(ALL(flex2[i]), p))
                    flex2[i].push_back(p);
            } while(next_permutation(ALL(p)));
        }
    }


    int n, x, y, z;
    cin >> n >> x >> y >> z;

    vi hui;
    set<vi> h;


    for (vi p1 : flex2[x])
    {
        for (int i = 0; i < SZ(p1); ++i)
            hui.push_back(p1[i]);

        for (vi p2 : flex2[y])
        {

            for (int i = 0; i < SZ(p2); ++i)
                hui.push_back(p2[i]);

            for (vi p3 : flex2[z])
            {
                for (int i = 0; i < SZ(p3); ++i)
                    hui.push_back(p3[i]);

                if (!h.count(hui))
                    h.insert(hui);

                for (int i = 0; i < SZ(p3); ++i)
                    hui.pop_back();
            }

            for (int i = 0; i < SZ(p2); ++i)
                hui.pop_back();
        }

        for (int i = 0; i < SZ(p1); ++i)
            hui.pop_back();
    }

    vvi her;
    her.push_back(vi());
    for (vi v : h)
        add_word(v),
        her.push_back(v);

    build_suffix_links();
    dp[0][root] = 1;
//    cout << fre << endl;

    int ans = 0;
    for (int i = 0; i <= n; ++i)
    {
        for (int j = root; j < fre; ++j)
        {
            if (!dp[i][j])
                continue;

            if (label[j])
            {
                ans = MOD(ans + dp[i][j] * pw[n - i], M);
                continue;
            }

            for (int c = 1; c <= 10; ++c)
                dp[i + 1][go(j, c)] = MOD(dp[i + 1][go(j, c)] + dp[i][j], M);
        }
    }

    cout << ans;
}


Measured memory_bytes: 22132