#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

template <uint_fast64_t Modulus> 
struct ModInt {
    using u64 = uint_fast64_t;

    u64 a;

    constexpr ModInt(const long long x = 0) noexcept : a(x >= 0 ? x % Modulus : (Modulus - (-x) % Modulus) % Modulus) {}
    constexpr u64 &value() noexcept {return a;}
    constexpr const u64 &value() const noexcept {return a;}
    constexpr ModInt operator+(const ModInt rhs) const noexcept {return ModInt(*this) += rhs;}
    constexpr ModInt operator-(const ModInt rhs) const noexcept {return ModInt(*this) -= rhs;}
    constexpr ModInt operator*(const ModInt rhs) const noexcept {return ModInt(*this) *= rhs;}
    constexpr ModInt operator/(const ModInt rhs) const noexcept {return ModInt(*this) /= rhs;}
    constexpr ModInt operator^(const long long rhs) const noexcept {return ModInt(*this) ^= rhs;}
    constexpr bool operator==(const ModInt &rhs) const noexcept {return a == rhs.a;}
    constexpr bool operator!=(const ModInt &rhs) const noexcept {return a != rhs.a;}
    constexpr ModInt &operator+=(const ModInt rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr ModInt &operator/=(ModInt rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }
    constexpr ModInt &operator^=(long long exp) noexcept {
        ModInt rhs = a;
        a = 1;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }

    friend ostream &operator<<(ostream& os, const ModInt& rhs) noexcept {return os << rhs.a;}
    friend istream &operator>>(istream& is, ModInt& rhs) noexcept {long long a; is >> a; rhs = a; return is;}
};

using mint = ModInt<MOD>;

template<class C>
struct AhoCorasick{
	struct Node{
		map<C,int>nex;
		int link;
		int len;
		int par;
		Node():link(0),len(0),par(0){}
	};
	vector<Node>nds;
	AhoCorasick(){
		nds.emplace_back();
		nds[0].link=-1;
		nds[0].par=-1;
	}

	int process(int k,const C &c){
		while(k!=-1&&nds[k].nex.find(c)==nds[k].nex.end())k=nds[k].link;
        if(k==-1)return 0;
        return nds[k].nex[c];
	}

    inline int addChar(int k,const C &c){
        if(nds[k].nex.find(c)==nds[k].nex.end()){
            nds[k].nex[c]=nds.size();
            nds.emplace_back();
            nds.back().len=nds[k].len+1;
			nds.back().par=k;
        }
        return nds[k].nex[c];
    }

    template<class T>
	int addString(const T &s){
		int k=0;
        for(const C& c:s)k=addChar(k,c);
        return k;
	}

	void build(){
		queue<int>que;
		for(auto &p:nds[0].nex)que.push(p.second);
		while(que.size()){
			int k=que.front();
			que.pop();
			for(auto &p:nds[k].nex){
				C c=p.first;
				int nx=p.second;
				nds[nx].link=process(nds[k].link,c);
				que.push(nx);
			}
		}
	}

	Node& operator[](int k){return nds[k];}
	inline int size(){return nds.size();}
};


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,X,Y,Z; cin >> N >> X >> Y >> Z;

    auto func=[](auto&& self, int x)->vector<vector<int>> {
        if (x==0) {
            vector<vector<int>> ret(1);
            return ret;
        }
        vector<vector<int>> ret;
        for (int i = 1; i <= x; i++) {
            auto arr = self(self,x-i);
            for (auto &j : arr) j.emplace_back(i);
            copy(arr.begin(), arr.end(), back_inserter(ret)); 
        }
        return ret;
    };

    auto AX = func(func,X);
    auto AY = func(func,Y);
    auto AZ = func(func,Z);

    AhoCorasick<int> AHO;
    set<int> dic;
    for (auto &x : AX) {
        for (auto &y : AY) {
            for (auto &z : AZ) {
                vector<int> arr;
                copy(x.begin(), x.end(), back_inserter(arr));
                copy(y.begin(), y.end(), back_inserter(arr));
                copy(z.begin(), z.end(), back_inserter(arr));
                int k = AHO.addString<vector<int>>(arr);
                dic.emplace(k);
            }
        }
    }
    AHO.build();
    int sz = AHO.size();
    vector<vector<int>> nex(sz, vector<int>(11,-1));
    rep(i,sz) {
        if (dic.count(i)) continue;
        for (int j = 1; j <= 10; j++) {
            int cur = i;
            while (true) {
                if (AHO.nds[cur].nex.count(j)) {
                    if (!dic.count(AHO.nds[cur].nex[j])) nex[i][j] = AHO.nds[cur].nex[j];
                    break;
                } else {
                    if (cur==0) {
                        nex[i][j] = 0;
                        break;
                    } else cur = AHO.nds[cur].link;
                }
            }
        }
    }

    vector<vector<mint>> dp(N+1, vector<mint>(sz));
    dp[0][0] = 1;
    rep(i,N) {
        rep(j,sz) {
            for (int k = 1; k <= 10; k++) {
                if (nex[j][k] != -1) dp[i+1][nex[j][k]] += dp[i][j];
            }
        }
    }

    mint ans = 10;
    ans ^= N;
    rep(j,sz) ans -= dp[N][j];

    cout << ans << ln;
}

Measured memory_bytes: 20076