#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 300005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps(); // no space at end of line
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...); // print w/ spaces
    }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    modular(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }

    friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }
    friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular pow(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    } // equivalent to return exp(b,MOD-2) if MOD is prime
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;
typedef pair<mi,mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// base and base_digits must be consistent
constexpr int base = 1000000000;
constexpr int base_digits = 9;

struct bigint {
    // value == 0 is represented by empty z
    vector<int> z; // digits

    // sign == 1 <==> value >= 0
    // sign == -1 <==> value < 0
    int sign;

    bigint() : sign(1) {}
    bigint(long long v) { *this = v; }

    bigint &operator=(long long v) {
        sign = v < 0 ? -1 : 1; v *= sign;
        z.clear(); for (; v > 0; v = v / base) z.push_back((int) (v % base));
        return *this;
    }

    bigint(const string &s) { read(s); }

    bigint &operator+=(const bigint &other) {
        if (sign == other.sign) {
            for (int i = 0, carry = 0; i < other.z.size() || carry; ++i) {
                if (i == z.size())
                    z.push_back(0);
                z[i] += carry + (i < other.z.size() ? other.z[i] : 0);
                carry = z[i] >= base;
                if (carry)
                    z[i] -= base;
            }
        } else if (other != 0 /* prevent infinite loop */) {
            *this -= -other;
        }
        return *this;
    }

    friend bigint operator+(bigint a, const bigint &b) { return a += b; }

    bigint &operator-=(const bigint &other) {
        if (sign == other.sign) {
            if (sign == 1 && *this >= other || sign == -1 && *this <= other) {
                for (int i = 0, carry = 0; i < other.z.size() || carry; ++i) {
                    z[i] -= carry + (i < other.z.size() ? other.z[i] : 0);
                    carry = z[i] < 0;
                    if (carry)
                        z[i] += base;
                }
                trim();
            } else {
                *this = other - *this;
                this->sign = -this->sign;
            }
        } else {
            *this += -other;
        }
        return *this;
    }

    friend bigint operator-(bigint a, const bigint &b) { return a -= b; }

    bigint &operator*=(int v) {
        if (v < 0) sign = -sign, v = -v;
        for (int i = 0, carry = 0; i < z.size() || carry; ++i) {
            if (i == z.size())
                z.push_back(0);
            long long cur = (long long) z[i] * v + carry;
            carry = (int) (cur / base);
            z[i] = (int) (cur % base);
        }
        trim();
        return *this;
    }

    bigint operator*(int v) const { return bigint(*this) *= v; }

    friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
        int norm = base / (b1.z.back() + 1);
        bigint a = a1.abs() * norm;
        bigint b = b1.abs() * norm;
        bigint q, r;
        q.z.resize(a.z.size());

        for (int i = (int) a.z.size() - 1; i >= 0; i--) {
            r *= base;
            r += a.z[i];
            int s1 = b.z.size() < r.z.size() ? r.z[b.z.size()] : 0;
            int s2 = b.z.size() - 1 < r.z.size() ? r.z[b.z.size() - 1] : 0;
            int d = (int) (((long long) s1 * base + s2) / b.z.back());
            r -= b * d;
            while (r < 0)
                r += b, --d;
            q.z[i] = d;
        }

        q.sign = a1.sign * b1.sign;
        r.sign = a1.sign;
        q.trim();
        r.trim();
        return {q, r / norm};
    }

    friend bigint sqrt(const bigint &a1) {
        bigint a = a1;
        while (a.z.empty() || a.z.size() % 2 == 1)
            a.z.push_back(0);

        int n = a.z.size();

        int firstDigit = (int) ::sqrt((double) a.z[n - 1] * base + a.z[n - 2]);
        int norm = base / (firstDigit + 1);
        a *= norm;
        a *= norm;
        while (a.z.empty() || a.z.size() % 2 == 1)
            a.z.push_back(0);

        bigint r = (long long) a.z[n - 1] * base + a.z[n - 2];
        firstDigit = (int) ::sqrt((double) a.z[n - 1] * base + a.z[n - 2]);
        int q = firstDigit;
        bigint res;

        for (int j = n / 2 - 1; j >= 0; j--) {
            for (;; --q) {
                bigint r1 = (r - (res * 2 * base + q) * q) * base * base +
                            (j > 0 ? (long long) a.z[2 * j - 1] * base + a.z[2 * j - 2] : 0);
                if (r1 >= 0) {
                    r = r1;
                    break;
                }
            }
            res *= base;
            res += q;

            if (j > 0) {
                int d1 = res.z.size() + 2 < r.z.size() ? r.z[res.z.size() + 2] : 0;
                int d2 = res.z.size() + 1 < r.z.size() ? r.z[res.z.size() + 1] : 0;
                int d3 = res.z.size() < r.z.size() ? r.z[res.z.size()] : 0;
                q = (int) (((long long) d1 * base * base + (long long) d2 * base + d3) / (firstDigit * 2));
            }
        }

        res.trim();
        return res / norm;
    }

    bigint operator/(const bigint &v) const { return divmod(*this, v).first; }

    bigint operator%(const bigint &v) const { return divmod(*this, v).second; }

    bigint &operator/=(int v) {
        if (v < 0) sign = -sign, v = -v;
        for (int i = (int) z.size() - 1, rem = 0; i >= 0; --i) {
            long long cur = z[i] + rem * (long long) base;
            z[i] = (int) (cur / v);
            rem = (int) (cur % v);
        }
        trim();
        return *this;
    }

    bigint operator/(int v) const { return bigint(*this) /= v; }

    int operator%(int v) const {
        if (v < 0) v = -v;
        int m = 0;
        for (int i = (int) z.size() - 1; i >= 0; --i)
            m = (int) ((z[i] + m * (long long) base) % v);
        return m * sign;
    }

    bigint &operator*=(const bigint &v) { return *this = *this * v; }
    bigint &operator/=(const bigint &v) { return *this = *this / v; }

    bool operator<(const bigint &v) const {
        if (sign != v.sign)
            return sign < v.sign;
        if (z.size() != v.z.size())
            return z.size() * sign < v.z.size() * v.sign;
        for (int i = (int) z.size() - 1; i >= 0; i--)
            if (z[i] != v.z[i])
                return z[i] * sign < v.z[i] * sign;
        return false;
    }

    bool operator>(const bigint &v) const { return v < *this; }
    bool operator<=(const bigint &v) const { return !(v < *this); }
    bool operator>=(const bigint &v) const { return !(*this < v); }

    bool operator==(const bigint &v) const { return !(*this < v) && !(v < *this); }

    bool operator!=(const bigint &v) const { return *this < v || v < *this; }

    void trim() {
        while (!z.empty() && z.back() == 0) z.pop_back();
        if (z.empty()) sign = 1;
    }

    bool isZero() const { return z.empty(); }

    friend bigint operator-(bigint v) {
        if (!v.z.empty()) v.sign = -v.sign;
        return v;
    }

    bigint abs() const {
        return sign == 1 ? *this : -*this;
    }

    long long longValue() const {
        long long res = 0;
        for (int i = (int) z.size() - 1; i >= 0; i--)
            res = res * base + z[i];
        return res * sign;
    }

    friend bigint gcd(const bigint &a, const bigint &b) {
        return b.isZero() ? a : gcd(b, a % b);
    }

    friend bigint lcm(const bigint &a, const bigint &b) {
        return a / gcd(a, b) * b;
    }

    void read(const string &s) {
        sign = 1;
        z.clear();
        int pos = 0;
        while (pos < s.size() && (s[pos] == '-' || s[pos] == '+')) {
            if (s[pos] == '-')
                sign = -sign;
            ++pos;
        }
        for (int i = (int) s.size() - 1; i >= pos; i -= base_digits) {
            int x = 0;
            for (int j = max(pos, i - base_digits + 1); j <= i; j++)
                x = x * 10 + s[j] - '0';
            z.push_back(x);
        }
        trim();
    }

    friend istream &operator>>(istream &stream, bigint &v) {
        string s; stream >> s;
        v.read(s);
        return stream;
    }

    friend ostream &operator<<(ostream &stream, const bigint &v) {
        if (v.sign == -1)
            stream << '-';
        stream << (v.z.empty() ? 0 : v.z.back());
        for (int i = (int) v.z.size() - 2; i >= 0; --i)
            stream << setw(base_digits) << setfill('0') << v.z[i];
        return stream;
    }

    static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
        vector<long long> p(max(old_digits, new_digits) + 1);
        p[0] = 1;
        for (int i = 1; i < p.size(); i++)
            p[i] = p[i - 1] * 10;
        vector<int> res;
        long long cur = 0;
        int cur_digits = 0;
        for (int v : a) {
            cur += v * p[cur_digits];
            cur_digits += old_digits;
            while (cur_digits >= new_digits) {
                res.push_back(int(cur % p[new_digits]));
                cur /= p[new_digits];
                cur_digits -= new_digits;
            }
        }
        res.push_back((int) cur);
        while (!res.empty() && res.back() == 0)
            res.pop_back();
        return res;
    }

    typedef vector<long long> vll;

    static vll karatsubaMultiply(const vll &a, const vll &b) {
        int n = a.size();
        vll res(n + n);
        if (n <= 32) {
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    res[i + j] += a[i] * b[j];
            return res;
        }

        int k = n >> 1;
        vll a1(a.begin(), a.begin() + k);
        vll a2(a.begin() + k, a.end());
        vll b1(b.begin(), b.begin() + k);
        vll b2(b.begin() + k, b.end());

        vll a1b1 = karatsubaMultiply(a1, b1);
        vll a2b2 = karatsubaMultiply(a2, b2);

        for (int i = 0; i < k; i++)
            a2[i] += a1[i];
        for (int i = 0; i < k; i++)
            b2[i] += b1[i];

        vll r = karatsubaMultiply(a2, b2);
        for (int i = 0; i < a1b1.size(); i++)
            r[i] -= a1b1[i];
        for (int i = 0; i < a2b2.size(); i++)
            r[i] -= a2b2[i];

        for (int i = 0; i < r.size(); i++)
            res[i + k] += r[i];
        for (int i = 0; i < a1b1.size(); i++)
            res[i] += a1b1[i];
        for (int i = 0; i < a2b2.size(); i++)
            res[i + n] += a2b2[i];
        return res;
    }

    bigint operator*(const bigint &v) const {
        vector<int> a6 = convert_base(this->z, base_digits, 6);
        vector<int> b6 = convert_base(v.z, base_digits, 6);
        vll a(a6.begin(), a6.end());
        vll b(b6.begin(), b6.end());
        while (a.size() < b.size())
            a.push_back(0);
        while (b.size() < a.size())
            b.push_back(0);
        while (a.size() & (a.size() - 1))
            a.push_back(0), b.push_back(0);
        vll c = karatsubaMultiply(a, b);
        bigint res;
        res.sign = sign * v.sign;
        for (int i = 0, carry = 0; i < c.size(); i++) {
            long long cur = c[i] + carry;
            res.z.push_back((int) (cur % 1000000));
            carry = (int) (cur / 1000000);
        }
        res.z = convert_base(res.z, 6, base_digits);
        res.trim();
        return res;
    }

};

bigint random_bigint(int n) {
    string s;
    for (int i = 0; i < n; i++) {
        s += rand() % 10 + '0';
    }
    return bigint(s);
}

// random tests
void bigintTest() {
    bigint x = bigint("120");
    bigint y = bigint("5");
    cout << x / y << endl;

    for (int i = 0; i < 1000; i++) {
        int n = rand() % 100 + 1;
        bigint a = random_bigint(n);
        bigint res = sqrt(a);
        bigint xx = res * res;
        bigint yy = (res + 1) * (res + 1);

        if (xx > a || yy <= a) {
            cout << i << endl;
            cout << a << " " << res << endl;
            break;
        }

        int m = rand() % n + 1;
        bigint b = random_bigint(m) + 1;
        res = a / b;
        xx = res * b;
        yy = b * (res + 1);

        if (xx > a || yy <= a) {
            cout << i << endl;
            cout << a << " " << b << " " << res << endl;
            break;
        }
    }

    bigint a = random_bigint(10000);
    bigint b = random_bigint(2000);
    clock_t start = clock();
    bigint c = a / b;
    printf("time=%.3lfsec\n", (clock() - start) * 1. / CLOCKS_PER_SEC);
}

int n,rem[MX];
vector<pair<int,vi>> groups;
bigint B;
vmi dp = {1};

void init() {
    setIO(); re(n);
    vi a(n-1), b(n);
    re(a,b);
    // F0R(i,n-1) a[i] = 2;
    // F0R(i,n) b[i] = 1;
    string m;
    re(m);
    // F0R(i,10000) m += '9';
    B = bigint(m);
    for (int i = 0; i < n; ) {
    	vi v;
    	while (i < n-1 && a[i] == 1) v.pb(b[i++]);
    	v.pb(b[i]);
    	groups.pb({i==n-1?MOD:a[i],v});
    	i ++;
    }
}

ll toint(bigint b) {
	stringstream ss; ss << b;
	ll res; ss >> res;
	return res;
}

int main() {
	init();
	F0R(i,sz(groups)) rem[i] = -1;
	// exit(0);
	for (int i = 0; i < sz(groups); ) {
		int I = i; ll mul = 1;
		while (i < sz(groups) && mul < MOD) mul *= groups[i++].f;
		auto BB = divmod(B,mul);
		//ps("HA",mul,BB.f,BB.s);
		ll r = toint(BB.s);
		FOR(j,I,i) {
			rem[j] = r%groups[j].f;
			r /= groups[j].f;
		}
		B = BB.f;
	}
	if (B != 0) {
		ps(0);
		exit(0);
	}
	//F0R(i,sz(groups)) ps(i,rem[i]); exit(0);
	F0R(i,sz(groups)) if (rem[i] == -1) {
		ps("HUH",i,rem[i]);
		exit(0);
	}
	// exit(0);
	F0R(i,sz(groups)) {
		auto t = groups[i];
		// ps(t); continue;
		trav(z,t.s) {
			vmi DP(sz(dp)+z);
			mi tot = 0; int l = 0, r = -1;
			F0R(j,sz(DP)) {
				while (r < j && r+1 < sz(dp)) tot += dp[++r];
				while (l < j-z) tot -= dp[l++];
				DP[j] = tot;
			}
			swap(dp,DP);
		}
		assert(rem[i] != -1);
		vmi DP; F0R(j,sz(dp)) if (j%t.f == rem[i]) DP.pb(dp[j]);
		swap(dp,DP); if (!sz(dp)) break;
	}
	ps(dp[0]);
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<iostream>
#include<vector>
#include<string>
using namespace std;

struct Modint {
	static const int MOD = 1000000007;
	int val;

	Modint(int nval = 0) {
		val = nval;
	}

	Modint& operator+=(Modint r) {
		val = (val + r.val) % MOD;
		return *this;
	}
	Modint operator+(Modint r) {return Modint(*this) += r;}

	Modint& operator-=(Modint r) {
		val = (val + MOD - r.val) % MOD;
		return *this;
	}
	Modint operator-(Modint r) {return Modint(*this) -= r;}

	Modint& operator*=(Modint r) {
		val = 1LL * val * r.val % MOD;
		return *this;
	}
	Modint operator*(Modint r) {return Modint(*this) *= r;}
};

struct Bignum {
	static const int MOD = 1000000000;
	vector<int> data;

	Bignum(string s) {
		while(s.size() > 0) {
			int l = max((int)s.size()-9, 0);
			data.push_back(stoi(s.substr(l, 9)) );
			s.resize(l);
		}
	}

	Bignum() = default;

	//And the division operation
	pair<Bignum, int> div(int val) {
		Bignum d;
		d.data.resize(data.size(), 0);
		long long r = 0;

		for(int i=(int)data.size()-1;i>=0;i--) {
			r *= MOD;
			r += data[i];

			d.data[i] = r/val;
			r = r%val;
		}
		while(d.data.back() == 0)
			d.data.pop_back();
		return {d, int(r)};
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;

	vector<int> a(n-1);
	for(int i=0;i<n-1;i++)
		cin >> a[i];
	vector<int> b(n);
	for(int i=0;i<n;i++)
		cin >> b[i];

	string m;
	cin >> m;

	//Now calculate the effective limits
	vector<int> lim(n, 0);
	for(int i=0;i<n;i++) {
		lim[i] += b[i];

		if(i < n-1)
			lim[i+1] += lim[i] / a[i];
	}

	//Calculate the remainders
	vector<int> r(n, 0);

	{
		Bignum val(m);
		int l = 0, d = 1;

		for(int i=0;i<n;i++) {
			if(i == n-1 || d > 1000000000/a[i]) {
				pair<Bignum, int> ret = val.div(d);
				r[l] = ret.second;
				val = ret.first;
				l = i;
				d = 1;
			}

			if(i < n-1)
				d *= a[i];
		}

		if(val.data.size() > 1 || val.data[0] > lim[n-1]+1) {
			cout << "0\n";
			return 0;
		}
		r[n-1] = val.data[0];

		//Next move up the remainders
		for(int i=0;i<n-1;i++) {
			r[i+1] += r[i]/a[i];
			r[i] = r[i]%a[i];
		}
	}

	//Finally do the dp calculation
	vector<Modint> dp(lim[n-1]+1, 0);
	dp[r[n-1]] = 1;

	for(int lvl = n-1; lvl > 0; lvl--) {
		vector<Modint> ndp(lim[lvl-1]+1, 0), add(lim[lvl-1]+1, 0);

		for(int x=0;x<=lim[lvl];x++) if(dp[x].val != 0) {
			int right = min(x, b[lvl]);

			int addl = (x-right)*a[lvl-1] + r[lvl-1];
			int addr = (x+1)*a[lvl-1] + r[lvl-1];

			if(addl <= lim[lvl-1])
				add[addl]+=dp[x];
			if(addr <= lim[lvl-1])
				add[addr]-=dp[x];
		}

		//And now add them up
		Modint cadd = 0;
		for(int i=r[lvl-1]; i <= lim[lvl-1]; i+=a[lvl-1]) {
			cadd += add[i];
			ndp[i] += cadd;
		}

		swap(dp, ndp);
	}

	Modint result = 0;
	for(int i=0;i<=b[0];i++)
		result += dp[i];

	cout << result.val << '\n';

	return 0;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

// {{{
// clang-format off
#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define irep(i, a, b) for (int i = int(a); i >= int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define popcount __builtin_popcount
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
template <class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os << "(" << v.first << ", " << v.second << ")"; }
template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; repn(i, sz(v)) { if(i) os << ", "; os << v[i]; } return os << "]"; }
template <class T> bool setmax(T& _a, T _b) { if(_a < _b) { _a = _b; return true; } return false; }
template <class T> bool setmin(T& _a, T _b) { if(_b < _a) { _a = _b; return true; } return false; }
template <class T> T gcd(T _a, T _b) { return _b == 0 ? _a : gcd(_b, _a % _b); }
// clang-format on
// }}}

const LL MOD = LL(1e9) + 7;
const LL B = LL(1e8);

VL read_bigint() {
    static char s[10010];
    scanf("%s", s);
    int len = (int)strlen(s);

    VL ans;
    LL cur = 0, p = 1;
    irepn(i, len) {
        cur += LL(s[i] - '0') * p;
        p *= 10;
        if(p == B) {
            ans.pb(cur);
            cur = 0, p = 1;
        }
    }
    if(cur > 0) ans.pb(cur);
    return ans;
}

LL div(VL& a, LL b) {
    LL r = 0;
    irepn(i, sz(a)) {
        a[i] += r * B;
        r = a[i] % b, a[i] /= b;
    }
    while(!a.empty() && a.back() == 0) {
        a.pop_back();
    }
    return r;
}

bool parse_to_int(VL a, LL* ans) {
    if(sz(a) >= 2) return false;
    *ans = a[0];
    if(*ans > 300010) return false;
    return true;
}

bool check(VL ratio, VL a, VL b) {
    const int n = sz(a);
    LL spare = 0;
    repn(i, n) {
        LL d = max(a[i] - b[i], 0ll);
        if(spare < d) return false;
        spare -= d, a[i] -= d;
        if(i + 1 < n) {
            spare = (spare + b[i] - a[i]) / ratio[i];
        }
    }
    return true;
}

LL solve(VL ratio, VL a, VL b) {
    const int n = sz(a);
    if(b[0] - a[0] < 0) return 0;
    if(n == 1) return 1;
    if(!check(ratio, a, b)) return 0;

    VL f(b[0] - a[0] + 1);
    for(LL cur = 0; a[0] + ratio[0] * cur <= b[0]; ++cur) {
        f[cur] = 1;
    }
    replr(i, 1, n - 1) {
        VL s(sz(f) + 1);
        repn(k, sz(f)) s[k + 1] = (s[k] + f[k]) % MOD;
        f.clear();
        for(LL cur = 0;; ++cur) {
            LL l = a[i] + ratio[i] * cur - b[i];
            LL r = a[i] + ratio[i] * cur;
            if(l >= sz(s)) break;
            l = max(l, 0ll), r = min(r, sz(s) - 2ll);
            if(l > r) {
                f.pb(0);
            } else {
                if(l < 0 || l >= sz(s) || r + 1 < 0 || r + 1 >= sz(s))
                    return -1;
                f.pb((s[r + 1] - s[l] + MOD) % MOD);
            }
            if(cur > 500000) return -1;
        }
    }
    LL ans = 0;
    repn(cur, sz(f)) {
        if(a[n - 1] - cur >= 0 && a[n - 1] - cur <= b[n - 1]) {
            (ans += f[cur]) %= MOD;
        }
    }
    return ans;
}

void test() {
    VL ratio(100000 - 1, 2);
    VL a(100000, 1);
    VL b(100000, 3);
    cout << solve(ratio, a, b) << endl;
}

int main() {
    // test();
    int n;
    scanf("%d", &n);
    VL ratio(n - 1);
    repn(i, n - 1) scanf("%lld", &ratio[i]);
    VL b(n);
    repn(i, n) scanf("%lld", &b[i]);
    VL m = read_bigint();

    VL a(n);
    repn(i, n - 1) { a[i] = div(m, ratio[i]); }
    if(!parse_to_int(m, &a[n - 1])) {
        printf("0\n");
        return 0;
    }
    printf("%lld\n", solve(ratio, a, b));

    return 0;
}


#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define forg(i,gu) for (int i=gu;~i;i=e[i].next)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
//const ll inf=0x3f3f3f3f3f3f3f3fll;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
const int mo=1e9+7;
int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}

int n;
int a[333333];
int b[333333];
int r[333333];
char str[33333];

int num[33333];int len;
int dv(int m){
	ll cur=0;
	for (int i=len-1;i>=0;i--){
		cur=cur*10+num[i];
		num[i]=cur/m;
		cur=cur%m;
	}
	return cur;
}

int f[3333333];//f[0..len-1]
int fne[3333333];
int tmpf[3333333];

void mulpo(int d){//mul (1+x+..+x^d)
	rep(i,len,len+d)f[i]=0;
	rep(i,1,len)upmo(f[i],f[i-1]);
	for (int i=len+d-1;i>=0;i--){
		int su=f[i]-(i-d-1<0?0:f[i-d-1]);
		f[i]=su;
		upmo(f[i],0);
	}
	len+=d;
}
int main()
{
#ifdef JCVB
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int _time_jc=clock();
#endif
	gn(n);
	rep(i,1,n)gn(a[i]);
	a[n]=2e9;
	rep(i,1,n+1)gn(b[i]);

	gs(str);
	len=strlen(str);
	rep(i,0,len)num[i]=str[len-i-1]-'0';

	rep(i,1,n+1){
		r[i]=dv(a[i]);
	}
	f[0]=1;
	len=1;
	rep(i,1,n+1)if(i==1 || a[i-1]!=1){
		int j=i+1;
		while(j<=n && a[j-1]==1)j++;
		j--;
		//[i,j]

		rep(k,i,j+1)mulpo(b[k]);

		for (t=r[j],tt=0;t<len;t+=a[j],tt++){
			fne[tt]=tmpf[t];
		}
		len=tt;
		rep(k,0,len)f[k]=fne[k];
	}
	printf("%d\n",f[0]);
#ifdef JCVB
	debug("time: %d\n",int(clock()-_time_jc));
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long ans,i,j,l,r;
int main()
{
    cin>>l>>r;
    for(i=0;i<=32;i++)
    {
      for(j=0;j<=26;j++)
      if(pow(2,i)*pow(3,j)<=r and pow(2,i)*pow(3,j)>=l)
      ans++;
    }
  cout<<ans;
}
.


#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include "ctime"
using namespace std;

int main()
{
	int r, l, q, cnt = 0, i;
	cin >> l;
	cin >> r;
	for (i = l; i <= r; i++)
	{
		q = i;
		while (q > 1)
		{
			if (q % 2 == 0)
				q /= 2;
			else if (q % 3 == 0)
				q /= 2;
			else break;
		}
		if (q == 1)
			cnt++;
	}
	cout << cnt;
}


// Java program to count the elements
// in the range [L, R] whose prime
// factors are only 2 and 3.
import java.util.*;
public class GFG{

// Function which will calculate the
// elements in the given range
static void calc_ans(int l, int r)
{

	Vector<Integer> power2 = new Vector<Integer>(),
					power3 = new Vector<Integer>();

	// Store the current power of 2
	int mul2 = 1;
	while (mul2 <= r)
	{
		power2.add(mul2);
		mul2 *= 2;
	}

	// Store the current power of 3
	int mul3 = 1;
	while (mul3 <= r)
	{
		power3.add(mul3);
		mul3 *= 3;
	}

	// power23[] will store pairwise product of
	// elements of power2 and power3 that are <=r
	Vector<Integer> power23 = new Vector<Integer>();

	for (int x = 0; x < power2.size(); x++)
	{
		for (int y = 0; y < power3.size(); y++)
		{
			int mul = power2.get(x) *
					power3.get(y);
			if (mul == 1)
				continue;

			// Insert in power23][]
			// only if mul<=r
			if (mul <= r)
				power23.add(mul);
		}
	}

	// Store the required answer
	int ans = 0;
	for (int x : power23)
	{
		if (x >= l && x <= r)
			ans++;
	}

	// Print the result
	System.out.print(ans + "\n");
}

// Driver code
public static void main(String[] args)
{
	Scanner sc = new Scanner(System.in);
	int l = sc.nextInt();
	int r = sc.nextInt();

	calc_ans(l, r);
}
}

// This code is contributed by 29AjayKumar


#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = INF + 7;
const ld PI = acos(-1.0);

int32_t main(){
	fast;
    int n
}


#include <iostream>
#include <algorithm>
#include <iterator>
#include <deque>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <valarray>
#include <list>
#include <stack>
#include <array>
#include <iomanip>
#include <map>
#include <string>
#include <queue>
#include <sstream>
#include <iomanip>
#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{
	vector<int> v(5);
	for (auto& x : v)
		cin >> x;

	auto S = accumulate(v.begin(), v.end(), 0);

	if (S == 0 || S % 5 != 0)
		cout << -1 <<< endl;

	cout << S / 5 << endl;

	return 0;
}


#include "pch.h"
#include <iostream>
#include <algorithm>

int main()
{
	int inputArray[5], result = -1, temp = 0;
	for (int i = 0; i < 5; i++)
		std::cin >> inputArray[i];
	std::sort(inputArray, inputArray + 5); //Отсортировали массив по возрастанию

	for (int i = 0; i < 2; i++)
	{
		if (inputArray[4-i] - inputArray[i] > 1 && (inputArray[4-i] - inputArray[i]) % 2 == 0)
		{
			temp = inputArray[4-i];
			inputArray[4-i] -= (temp - inputArray[i]) / 2;
			inputArray[i] += (temp - inputArray[i]) / 2;
		}
		else if (inputArray[4-i] - inputArray[i] >= 1 && (inputArray[4-i] - inputArray[i]) % 2 != 0)
		{
			temp = inputArray[4-i];
			inputArray[4-i] -= (temp - inputArray[i]) / 2;
			inputArray[i] += (temp - inputArray[i]) / 2;
		}
	}

	//Ищем моду числового ряда
	int moda = inputArray[0], cmax = 0, rmax = 0;
	for (int i = 0; i < 5; i++) {
		if (cmax > rmax) {
			rmax = cmax;
			moda = inputArray[i - 1];
		}
		cmax = 0;
		for (int j = i; j < 5; j++)
			if (inputArray[j] == inputArray[i])
				cmax++;
	}
	//В итоге в moda у нас получится мода, а в rmax сколько раз она встречается

	int temp_i1 = 0, temp_i2 = 0;
	for (int i = 0; i < 5; i++)
	{
		if (inputArray[i] != moda && temp_i1 == 0)
			temp_i1 = i;
		else if (inputArray[i] != moda)
			temp_i2 = i;
		else if (temp_i1 * temp_i2 != 0)
			break;
	}

	if (inputArray[temp_i1] > inputArray[temp_i2])
	{
		temp = inputArray[temp_i1];
		inputArray[temp_i1] -= (temp - inputArray[temp_i2]) / 2;
		inputArray[temp_i2] += (temp - inputArray[temp_i2]) / 2;
	}
	else
	{
		temp = inputArray[temp_i2];
		inputArray[temp_i2] -= (temp - inputArray[temp_i1]) / 2;
		inputArray[temp_i1] += (temp - inputArray[temp_i1]) / 2;
	}

	if (inputArray[0] == inputArray[1] && inputArray[1] == inputArray[2] && inputArray[2] == inputArray[3] && inputArray[3] == inputArray[4])
		std::cout << inputArray[0];
	else
		std::cout << -1;
	std::cin >> temp;

	return 0;
}


#include <iostream>
using namespace std;
int ar[10];
int main(){
  int n=5,sum=0;
  for(int i=0; i<n; ++i){
    cin>>ar[i];
    sum=sum+ar[i];
  }
  if(sum%5==0 && sum!=0)cout<<sum/5<<endl;
  else cout<<"-1"<<endl;
  return 0;
}


a#include <iostream>

using namespace std;
int getcol(char c){
    if(c=='B')return 0;
    if(c=='R')return 1;
    if(c=='G')return 2;
    if(c=='Y')return 3;
    if(c=='W')return 4;
}
int getval(char c){
    return c-'1';
}

char str[1111][5];
int main()
{
    int n;

    cin>>n;
    int ans=10;
    for(int i=0;i<n;i++){
            cin>>str[i];
            //cout<<getcol(str[i][0])<<getval(str[i][1])endl;
           // cout<<str[i]<<endl;
    }
    for(int i=0;i<(1<<5);i++){
        for(int j=0;j<(1<<5);j++){

            int noval=-1,nocol=-1;
            int col[11]={100};
            int val[11]={100};
            bool ok =true;
            for(int k=0;k<n;k++){
                    int cl=getcol(str[k][0]);
                    int vl=getval(str[k][1]);
                  //  cout<<cl<<" "<<vl<<" "<<i<<" "<<j<<" "<<col[cl]<<col[vl]<<endl;

                if( ( (1<<cl) & i) && ( (1<<vl) &j ) ){
                    continue;
                }
                else if(( (1<<cl) &i)){
                    if(col[cl]!= 0 && (col[cl]!= vl+1) )ok=false;
                    else {
                        col[cl]= vl+1;
                    }
                }
                else if(( (1<<vl) &j)){
                    if(val[vl]!= 0 && (val[vl]!= cl+1) )ok=false;
                    else {
                        val[vl]= cl+1;
                    }
                }
                else {
                    if(nocol!=-1 && nocol !=cl)ok=false;
                    else nocol=cl;
                    if(noval!=-1 && noval !=vl)ok=false;
                    else noval=vl;
                }
            }
            if(ok==true){
                    ans=min(__builtin_popcount(i)+__builtin_popcount(j),ans);

                   // cout<<i<<" "<<j<<" "<<__builtin_popcount(i)+__builtin_popcount(j)<<endl;
            }

        }
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 103;
int n, cnt[7][7], tmp[7][7];

int f_min(int a, int b) {return a < b ? a : b;}

int get(char ch) {
    if(ch >= '1' && ch <= '5')
        return ch - '1';
    if(ch == 'R') return 0;
    if(ch == 'G') return 1;
    if(ch == 'B') return 2;
    if(ch == 'Y') return 3;
    return 4;
}

void get_data() {
    char cd[3];
    cin >> n;
    memset(cnt, 0, sizeof(cnt));
    for(int i = 0; i < n; ++i) {
        cin >> cd;
        cnt[get(cd[0])][get(cd[1])]++;
    }
}

bool check(int x) {
    int i, j, k, t, tt;
    memset(tmp, 0, sizeof(tmp));
    for(k = 0; k < 10; ++k) {
        if(x & (1 << k)) {
            if(k < 5) {
                i = k;
                for(j = 0; j < 5; ++j) {
                    if(cnt[i][j]) {
                        if(tmp[i][j] == 0) tmp[i][j] = 1;// color
                        else tmp[i][j] = 3;// all
                    }
                }
            }
            else {
                j = k - 5;
                for(i = 0; i < 5; ++i) {
                    if(cnt[i][j]) {
                        if(tmp[i][j] == 0) tmp[i][j] = 2;// number
                        else tmp[i][j] = 3;// all
                    }
                }
            }
        }
    }
    for(i = 0; i < 5; ++i) {
        for(j = t = tt = 0; j < 5; ++j) {
            if(cnt[i][j]) {
                if(tmp[i][j] == 1) tt++;
                if(tmp[i][j] == 0) t++;
            }
        }
        if(tt > 1 || t > 1) return false;
    }
    for(j = 0; j < 5; ++j) {
        for(i = t = tt = 0; i < 5; ++i) {
            if(cnt[i][j]) {
                if(tmp[i][j] == 2) tt++;
                if(tmp[i][j] == 0) t++;
            }
        }
        if(tt > 1 || t > 1) return false;
    }
    return true;
}

int count(int x) {
    int res = 0;
    while(x) {
        if(x & 1) res++;
        x >>= 1;
    }
    return res;
}

void solve() {
    int i, ans = 10000000;
    for(i = 0; i < 1024; ++i) {
        if(check(i)) ans = f_min(ans, count(i));
    }
    cout << ans << endl;
}

int main() {
    get_data();
    solve();
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <exception>
using namespace std;
typedef pair<int,int> Pii;
typedef long long ll;
typedef unsigned long long ull;
const int INFI = 1<<28;
const long long int INFL = 1LL<<60;
const double INFD = 1e+300;
const double EPS = 1e-8;
//→ ↑ ← ↓
//int dx[] = {1,0,-1,0};
//int dy[] = {0,-1,0,1};
//struct P {
//    int id, cost;
//    P () {}
//    P (int i, int c) : id(i), cost(c) {}
//    bool operator < (const P &p) const { return cost > p.cost; }
//};

bool f (const vector<string> & cards, const vector<string> & hand) {
    int L = cards.size();
    vector<bool> h_used(L, false);
    vector<bool> c_used(L, false);
    int cnt = 0;
    while (true) {
        bool update = false;
        for (int i = 0; i < L; i++) {
            if (h_used[i]) continue;
            set<string> candidate;
            int idx = 0;
            for (int j = 0; j < L; j++) {
                if (c_used[j]) continue;
                if ((hand[i][0] == '*' || hand[i][0] == cards[j][0]) &&
                    (hand[i][1] == '*' || hand[i][1] == cards[j][1])) {
                    candidate.insert(cards[j]);
                    idx = j;
                    break;
                }
            }
            if (candidate.size() == 1) {
                update = true;
                c_used[idx] = true;
                h_used[i] = true;
                cnt++;
                break;
            }

        }
        if (!update) break;
    }
    return cnt == L;
}
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int L;
    cin >> L;
    vector<string> cards(L);
    for (int i = 0; i < L; i++) {
        cin >> cards[i];
    }
    const char *M = "RGBYW";
    const char *N = "12345";
    int ans = 1<<28;
    for (int m = 0; m < (1<<5); m++) {
        for (int n = 0; n < (1<<5); n++) {
            vector<string> tmp(L, string("**"));
            for (int i = 0; i < L; i++) {
                for (int j = 0; j < 5; j++) {
                    if ((m & (1<<j)) && M[j] == cards[i][0]) tmp[i][0] = M[j];
                    if ((n & (1<<j)) && N[j] == cards[i][1]) tmp[i][1] = N[j];
                }
            }
            int mbit = __builtin_popcount(m);
            int nbit = __builtin_popcount(n);
            if (f(cards, tmp, mbit, nbit)) {
                ans = min(ans, mbit + nbit);
                /*
                for (int i = 0; i < L; i++) {
                    cout << tmp[i] << " ";
                }
                cout << "cost:" << mbit+nbit << endl;
                */
            }
        }
    }
    cout << ans << endl;
    return 0;
}


include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 105;

int n, l[N], r[N];

inline int cal (char ch) {
    if (ch == 'B')
        return 0;
    else if (ch == 'Y')
        return 1;
    else if (ch == 'W')
        return 2;
    else if (ch == 'G')
        return 3;
    else if (ch == 'R')
        return 4;
    return -1;
}

int bit (int i) {
    return 1<<i;
}

int bitCount (int x) {
    return x == 0 ? 0 : bitCount(x/2) + (x&1);
}

bool judge (int s) {

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

            if (l[i] == l[j]) {

                if (r[i] != r[j] && (s&bit(r[i]+5)) == 0 && (s&bit(r[j]+5)) == 0)
                    return false;

            } else {

                if ((s&bit(l[i])) || (s&bit(l[j])))
                    continue;

                if (r[i] != r[j] && ( (s&bit(r[i]+5)) || (s&bit(r[j]+5)) ))
                    continue;

                return false;
            }
        }
    }
    return true;
}

int main () {
    char str[N];
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%s", str);
        l[i] = cal(str[0]);
        r[i] = str[1] - '1';
    }

    int ans = 10;
    for (int i = 0; i < (1<<10); i++) {
        int cnt = bitCount(i);

        if (cnt >= ans)
            continue;

        if (judge(i))
            ans = cnt;
    }
    printf("%d\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>

#include <string>

using namespace std;

typedef long long ll;
#define tc(x) static_cast<char>(x)

const int MAXN = 200 + 10;
const int MAXM = 200 + 10;

int N, M;
ll K, t;

int z[MAXM];
int As[MAXM][2];
ll v[MAXM][MAXM];
int Af[MAXM][MAXM];
void build(const string& s, bool output = false) {
    z[0] = 0;
    for(int i = 1;i < s.size();i++) {
        z[i] = z[i - 1];
        while(z[i] != 0 and s[i] != s[z[i]]) z[i] = z[z[i] - 1];
        if(s[z[i]] == s[i]) z[i]++;
    }
    //for(int i = 0;i < s.size();i++) printf("%d\n", z[i]);
    for(int i = 0;i <= s.size();i++) {
        for(int j = 0;j < 2;j++) {
            As[i][j] = i;
            while(As[i][j] != 0 and tc(j + 48) != s[As[i][j]]) As[i][j] = z[As[i][j] - 1];
            if(s[As[i][j]] == tc(j + 48)) As[i][j]++;
        }
    }
    //for(int i = 0;i <= s.size();i++) printf("%d: %d %d\n", i, As[i][0], As[i][1]);
    for(int i = 0;i <= 1;i++) {
        for(int j = 0;j <= s.size();j++) {
            Af[i][j] = As[j][i];
            if(Af[i][j] == s.size()) v[i][j] = 1; else v[i][j] = 0;
        }
    }
    for(int i = 2;i <= N;i++) {
        for(int j = 0;j <= s.size();j++) {
            Af[i][j] = Af[i - 1][Af[i - 2][j]];
            v[i][j] = v[i - 2][j] + v[i - 1][Af[i - 2][j]];
        }
    }
    if(output) for(int i = 0;i <= N;i++, printf("\n")) for(int j = 0;j <= s.size();j++) printf("%lld ", static_cast<ll>(v[i][j]));
}

int main() {
    scanf("%d%lld%d", &N, &K, &M);      //reduce K to 1

    string ans = "";
    for(int i = 0;i < M;i++) {
        if(i) {
            build(ans);
            if(Af[N][0] == i) {
                assert(K >= 1);
                if(K == 1) break;
                else K--;
            }
        }

        build(ans + '0');

        if(K > v[N][0]) {
            K -= v[N][0];
            ans += '1';
        } else ans += '0';

        //cerr << i << " " << K << "\n";
    }
    printf("%s\n", ans.c_str());

    //build("10", true);

    return 0;
}


#include <cstring>
#include <iostream>
#include<stdlib.h>
#include<vector>
using namespace std;
int COUNT_KMP(const char *S, const char *T, int s_len, int t_len){
    int next[t_len];
    next[0] = -1;
    for (int i = 1; i<t_len; i++){
        int j = next[i - 1];
        while (j >= 0 && T[i - 1] != T[j]) j = next[j];
        if (j >= 0 &&  T[i - 1] == T[j]) next[i] = j + 1;
        else next[i] = 0;
    }
    int index, count = 0;
    for (index = 0; index<s_len; ++index){
        int pos = 0;
        int iter = index;
        while (pos<t_len && iter<s_len){
            if (S[iter] == T[pos]){ ++iter; ++pos; }
            else{
                if (pos == 0) ++iter;
                else pos = next[pos - 1] + 1;
            }
        }
        if (pos == t_len && (iter - index) == t_len) ++count;
    }
    return count;
}
int my_substr (char *s,char *t,int pos,int len) {
	int i;
	for (i=0;i<len;++i) {

		if (t[i+pos] == '\0') {
			break;
		}
		s[i] = t[i+pos];
	}
	s[i] = '\0';
	return i;
}
long long cal (const char *s, int n, long long k) {
	long long sum[100000];
	memset (sum,0,sizeof(sum));
	char f[100000][100000*10+1];
	int len[100000];
	memset (len,0,sizeof(len));
	int s_len = strlen(s);
	sprintf (f[0],"0");
	sprintf (f[1],"1");
	len[0] = len[1] = 1;
	if (s_len ==1) {
		if (s[0] == '0') {
			sum[0] ++;
		}
		else if (s[0] == '1') {
			sum[1] ++;
		}
	}
	int max_len = s_len - 1;
	char tmp_str[100000*10+1];
	for (int i = 2; i<=n; ++i) {
		len[i] = len[i-2] + len[i-1];
		sprintf (f[i],"%s%s",f[i-2],f[i-1]);
		int start = 0;
		if (len[i-2] > max_len) {
			start = len[i-2] - max_len;
		}
		int my_len = my_substr (tmp_str,f[i-2],start,max_len);
		my_len += my_substr (tmp_str+my_len,f[i-1],0,max_len);

		long long result = COUNT_KMP (tmp_str,s,my_len,s_len);

		sum[i] = sum[i-2] + sum[i-1] + result;
		if (sum[i] > k) {
			return sum[i];
		}

		if (len[i] > max_len * 2) {
			int del_num = len[i] - (max_len * 2);
			for (int pos=max_len + del_num;pos<len[i];++pos) {
				f[i][pos-del_num] = f[i][pos];
			}
			len[i] = max_len * 2;
			f[i][len[i]] = '\0';
		}
	}
	return sum[n];
}
int main(){
	int n,m;
	long long k;
	char suffix[] = "11010110101101101011010110110101101101011010110110101101101011010110110101101011011010110110101101011011010110101101101011011010110101101101011011010110101101101011010110110101101101011010110110101101";
	int suffix_len = strlen (suffix);
	cin>>n>>k>>m;
	char s[100000];
	memset (s,'\0',sizeof(s));
	for (int i = 0; i < m; ++i) {
		int pos = suffix_len - i;
		int s_pos = 0;
		while (pos < suffix_len) {
			if (s[s_pos] != suffix[pos]) {
				break;
			}
			s_pos++;
			pos++;
		}
		if (pos == suffix_len && i>0) {
			if (k == 1) {
				break;
			}
			k --;
		}

		if (i >0 && s[i-1] == '0') {
			s[i] = '1';
			s[i+1] = '\0';
			continue;
		}

		if (i > 1 && s[i-1] == '1' && s[i-2] == '1') {
			s[i] = '0';
			s[i+1] = '\0';
			continue;
		}

		s[i] = '0';
		s[i+1] = '\0';

		long long count = cal (s,n,k);
		if (count < k) {
			k = k - count;
			s[i] = '1';
		}

	}
	cout<<s;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k,tmp[509];
string ret,Fib[15];
inline bool is_pre(int f_pos,string&s,int s_start,unsigned cmp_len){
	if(f_pos>14)f_pos=12|(f_pos&1);
	return cmp_len<=Fib[f_pos].size()&&Fib[f_pos].substr(0,cmp_len)==s.substr(s_start,cmp_len);
}
inline bool is_suf(int f_pos,string&s,int s_start,unsigned cmp_len){
	if(f_pos>14)f_pos=14;
	return cmp_len<=Fib[f_pos].size()&&Fib[f_pos].substr(Fib[f_pos].size()-cmp_len)==s.substr(s_start,cmp_len);
}
signed main(){
	Fib[0]="0",Fib[1]="1";
	for(int i=2;i<=14;++i)Fib[i]=Fib[i-2]+Fib[i-1];
	scanf("%lld%lld%lld",&n,&k,&m);
	for(int i=1;i<=m;++i){
		int Tag=(i==1?0:is_suf(n,ret,0,ret.size()));
		if(k<=Tag)return puts(ret.c_str()),0;
		int cnt=Tag+({
			string test0=ret+'0';
			tmp[0]=(test0=="0"),tmp[1]=(test0=="1");
			unsigned len=test0.size();
			for(int i=2;i<=n;++i){
				tmp[i]=tmp[i-1]+tmp[i-2];
				for(unsigned j=1;j<len;++j)if(is_suf(i-2,test0,0,j)&&is_pre(i-1,test0,j,len-j))++tmp[i];
				if(tmp[i]+Tag>=k){
				    tmp[n]=k;
				    break;
				}
			}
			return tmp[n];
		});
		if(k<=cnt){
			k-=Tag;
			ret+='0';
		}
		else{
			k-=cnt;
			ret+='1';
		}
	}
	puts(ret.c_str());
	return 0;
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;
const int N=210;
int n,m;
ll k,f[N],d[N],h[N],qy[2][2];
string pre[2],nxt[2],str[17],suf[N*10],ans;

inline bool cmp(string a,string b){
    for(int i=0;i<min(a.length(),b.length());i++){
        if(a[i]==b[i]) continue;
        if(a[i]<b[i]) return 1;
        else return 0;
    }
    return a.length()<b.length();
}

int Try(string a){
    int res=0;
    for(int i=0;i<a.length();i++){
        if(i+ans.length()-1>=a.length()) break;
        bool flag=1;
        for(int j=0;j<ans.length();j++)
            if(a[i+j]!=annxt[j]) flag=0;
        res+=flag;
    }
    return res;
}

ll solve(){
    int len=ans.length();
    pre[0].clear();pre[1].clear();nxt[0].clear();nxt[1].clear();
    d[14]=h[14]=0; d[15]=h[15]=1;
    for(int i=0;i<len-1;i++) pre[0].push_back(str[14][i]),pre[1].push_back(str[15][i]);
    for(int i=1;i<=len-1;i++) nxt[0].push_back(str[14][str[14].length()-len+i]);
    for(int i=1;i<=len-1;i++) nxt[1].push_back(str[15][str[15].length()-len+i]);
    for(int i=0;i<2;i++)
        for(int j=0;j<2;j++)
            qy[i][j]=Try(pre[i]+nxt[j]);
    f[14]=Try(str[14]); f[15]=Try(str[15]);
    for(int i=16;i<=n;i++){
        h[i]=h[i-1];
        d[i]=d[i-2];
        f[i]=f[i-1]+f[i-2];
        f[i]+=qy[d[i]][h[i]];
        if(f[i]>1e18) return f[i];
    }
    return f[n];
}

int main(){
    scanf("%d%lld%d",&n,&k,&m);
    str[0]="0"; str[1]="1";
    for(int i=2;i<=15;i++) str[i]=str[i-2]+str[i-1];
    if(n<=15){
        for(int i=0;i<str[n].length();i++)
            for(int j=i;j<str[n].length();j++)
                suf[i+1].push_back(str[n][j]);
        sort(suf+1,suf+str[n].length()+1,cmp);
        for(int i=0;i<min(m,(int)suf[k].length());i++) printf("%c",suf[k][i]);
        return 0;
    }
    for(int i=1;i<=m;i++){
        ans.push_back('0');
        ll z=solve();
        if(z<k){
            k-=z;
            ans.pop_back(); ans.push_back('1');
        }
        int flag=1;
        for(int i=suf[n].length()-ans.length(),j=0;j<suf[n].length();i++){
            if(annxt[j]!=suf[n][i]) flag=false;
            j++;
        }
        k-=flag;
        if(k==0){
            for(int i=0;i<ans.length();i++) printf("%c",annxt[i]);
            return 0;
        }
    }
    for(int i=0;i<ans.length();i++)
        printf("%c",annxt[i]);
    return 0;
}


//============================================================================
// Name        : AC{M.cpp
// Author      : Moment
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
/*
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

long long cal(long long w,long long m,long long k)
{
	long long sum = 0;
	long long c,x,j;
	c = 0,x = m,j = 1;
	while(x)
	{
		x /= 10;
		c++,j *= 10;
	}
	while(1)
	{
		long long rest = j - m;
		//cout << "rest: " << rest << endl;
		//cout << "w: " << w << endl;
		if(rest * k * c <= w)
		{
			sum += rest;
			w -= rest * k * c;
			m = j;
		}
		else
		{
			sum += w / (k * c);
			break;
		}
		j *= 10,c++;
	}
	return sum;
}

int main()
{
	long long w,m,k;
	while(cin >> w >> m >> k)
		cout << cal(w,m,k) << endl;
	return 0;
}
*/

#include<iostream>
#include<string>
#include<cstring>
using namespace std;

struct Num
{
	int id;
	int sum;
}num[10];

bool check(int k,string str[])
{
	bool flag = true;
	int sum[10] = {0},t;
	for(int i = 0;i < 4;i++)
		for(int j = 0;j < 4;j++)
			if(str[i][j] != '.')
				sum[str[i][j] - '0']++;
	t = 0;
	for(int i = 0;i < 10;i++)
		if(sum[i])
		{
			num[t].id = i,num[t].sum = sum[i];
			t++;
		}
	int step = 1;
	for(int i = 0;i < t;i++,step++)
	{
		if(!num[i].sum)
			continue;
		if(k * 2 >= num[i].sum)
		{
			int tmp,j;
			tmp = 2 * k,j = i;
			while(tmp && j < t)
			{
				if(tmp >= num[j].sum)
				{
					tmp -= num[j].sum;
					num[j].sum = 0;
				}
				else
					num[j].sum -= tmp;
				j++;
			}
		}
		else
		{
			flag = false;
			break;
		}
	}
	return flag;
}

int main()
{
	int k;
	string str[4];
	while(cin >> k)
	{
		for(int i = 0;i < 4;i++)
			cin >> str[i];
		puts(check(k,str) ? "YES" : "NO");
	}
	return 0;
}


#include "pch.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()

{
	int k;
	cin >> k;
	vector <int> a;
	for (int i = 0; i < 9; i++) {
		a.push_back(0);
	}
	for (int i = 0; i < 4; i++) {
		string x;
		cin >> x;
		for (int j = 0; j < 4; j++) {
			if (x[j] != '.') {
				int y = static_cast<int>(x[j]) - 48;
				a[y - 1] ++;
			}
		}
	}
	int m = a[0];
	for (int i = 1; i < 9; i++) {
		if (a[i] > m) {
			m = a[i];
		}
	}
	if (m > 2 * k) {
		cout << "NO";
	}
	else {
		cout << "YES";
	}

	return 0;
}
/* Mon Aug 12 2019 22:04:03 GMT+0300 (MSK) */


#include <iostream>
#include <string>
#include <vector>

using namespace std;
 int num1(int a[20],int sized)
{
    int l=0;
    for(int i=0;i<sized;i++)
        if(a[i]==1) l++;
    return l;
}
 void minim( int &  a[20],int sized)
{
    for(int i=0;i<sized;i++)
        if(a[i]!=0)a[i]--;
}
int main(){
    int k,z=0,a[20];
    char s;
    cin>>k;
    for(int i=0;i<4;i++)
       for(int j=0;j<4;j++)
    {
        cin>>s;
        if(s!='.') {a[z]=int(s);z++;}

    }
    if(z<=2*k) {cout<<"YES";return 0;}
    else
    {for(int j=0;j<z;j++)
        if(num1(a,z)<=2*k) minim(a,z);
        else {cout<<"NO";return 0;}
    }

      cout<<"YES";

    return 0;
}


#include<iostream>

int main()
{

 int n,k,max,min;
 std::cin>>n>k;

 if(n=k)
 {min=max=0;}

if (k=0)
 {min=max=0;
   goto label;}

if (n>k)
{
      if (k>=(n/2))
      { max=n-k;
          min=1;  }

      if (k<n/2)
      { max=k+1;
          min=1;}

}

 label:
std::cout<<min<<max;

return(0);

}


#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <sstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <unordered_set>
#include <set>

using namespace std;

#define pb push_back
#define sz(a) (int)a.size()
#define vi vector <int>
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < n; ++i)
#define F first
#define S second

typedef long long int;
// typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

// const ll inf = 1e9;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int SZ = 55555;

int get1(int n, int k) {
	int l = -1, r = k;
	while (r - l > 1) {
		int mid = (r + l)/2;
		if ((n - mid) >= 2*(k - mid))
			r = mid;
		else
			l = mid;
	}
	return r;
}
int get2(int n, int k) {
	int l = -1, r = k;
	while (r - l > 1) {
		int mid = (r + l)/2;
		if ((n - 2*mid - 1) >= 3*(k - mid))
			r = mid;
		else
			l = mid;
	}
	return r;
}

int solve() {
	int n, k, ans = 0;
	cin >> n >> k;
	int diff = get1(n, k);
	n -= diff;
	k-= diff;
	int diff2 = get2(n, k);
	ans += diff2;
	n -= 2*diff2 - 1;
	ans += (2*(n/3) + (n % 3 == 1 ? 0 : 1));
	cout << 1 << " "<< ans << endl;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	// int t;
	// cin >> t;
	// while (t--) {
		solve();
	// }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k;
    cin>>n>>k;
    if(n==k)
    {
        cout<<0<<" "<<0<<endl;
    }
    else if(k==0)
    {
        cout<<0<<" "<<0<<endl;
    }
    else
    {
        if(k>=((n/2)-1)
        {
            cout<<1<<" "<<min((n-k),k)<<endl;
        }
        else
        {
            cout<<1<<" "<<2*k<<endl;
        }
    }
}


#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <map>
#include <string.h>
#include <queue>
using namespace std;
*
bool arr[N];
void getprim(){ arr[0]=1;arr[1]=1;int i;long long j;for(i=2;i<N;i++){if(arr[i]==0){ for(j=i,j=j*i;j<N;j+=i){arr[j]=1;}}}}
*/
//priority_queue
//lower_bound,upper_bound

//struct stu //�����
//{
//	int x,y;
//	bool operator <(const stu &t)const
//	{
//		return y<t.y;
//	}
//}w;

int main()
{
	double a,b,c,d,e,f;
	double gold;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF)
	{
		double ans=0;;
		if(a==0)
		{
			if(b==0)ans=0;
			else ans=100000000;
		}
		else ans=b;
		if(c==0)
		{
			if(d==0)ans=0;
			else ans=100000000;
		}
		else ans=ans/c *d;
		if(e==0)
		{
			if(f==0)ans=0;
			else ans=100000000;
		}
		else ans=ans/e*f;
		if(gold>d || (ans>a))
		{
			printf("Ron\n");
		}
		else printf("Hermione");
	}
	return 0;
}
////100 10 200 20 300 30
//#include <iostream>
//using namespace std;
//typedef long long ll;
//int main(){        ll a,b,c,d,e,f;        cin>>a>>b>>c>>d>>e>>f;        cout<<(b*d*f > a*c*e || (d && (!c || (!a && b))) ? "Ron" : "Hermione")<<'\n';}


#include<iostream>
#include<cstdio>
#include<cassert>

using namespace std;

long long gcd(long long a,long long b){
  if(b==0)return a;
  else {
    long long ret;
    assert(ret=gcd(b,a%b));
    return ret;
  }
}

long long lcm(long long a,long long b){
  return a/gcd(a,b)*b;
}

int main(){

  long long a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;

  if(b==0||d==0||f==0){
    puts("Hermione"); return 0;
  }else if(c==0||e==0||a==0){
    puts("Ron"); return 0;
  }

  long long aa,bb;
  aa=lcm(b,c))
  bb=lcm(d,e);
  long long p22=bb/d,p21=bb/e,p2=lcm(p21,p22);
  long long p1=p2*c/b,p3=p2*d/e;

  /*
  prlong longf("%d %d : %d\n",p1*a,p1*b,p1);
  prlong longf("%d %d : %d\n",p2*c,p2*d,p2);
  prlong longf("%d %d : %d\n",p3*e,p3*f,p3);
  */
  long long make_d;
  assert(make_d=(p2*c)/(p1*b)*(p2*d));
  long long ans;
  assert(ans=make_d/(p3*e)*(p3*f));

  if(ans>p1*a)puts("Ron");
  else puts("Hermione");

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	double a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	double last=a;

	if(a==0)
	{
		a=0.000001;
	}
	if(c==0)
	{
		c=0.000001;
	}
	if(e==0)
	{
		e=0.000001;
	}
	if(d/c>100000)
	{
		cout<<"Ron";
		return 0;
	}
	else if
	if(b*d/c/a>100000)
	{
		cout<<"Ron";
		return 0;
	}
	last=b*d*f/c/a/e;
	if(last>a)
	{
		cout<<"Ron";
	}
	else
	{
		cout<<"Hermione";
	}
	return 0;
}


#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...) 0
#define debug() 0
#endif
using namespace std;
#define df(b, e) ((b) > (e))
#define fore(i, b, e) \
  for (__typeof(e) i = (b)-df(b, e); i != e - df(b, e); i += 1 - 2 * df(b, e))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define pb push_back
typedef long long lli;
typedef long double ld;
typedef pair<int, int> ii;

const int N = 16;
const int T = 226;
const int G = 3;
const int mod = 1e9 + 7;

int mem[N][T][1 << N];
int done[N][T][1 << N];
int t[N], g[N];
int n, len;

int dp(int i, int maxTime, int mask) {
  if (maxTime < 0)
    return 0;
  if (maxTime == 0) {
    debug() << deb(i) << deb(maxTime) << deb(mask);
    return 1;
  }

  int &ans = mem[i][maxTime][mask];
  if (!done[i][maxTime][mask]) {
    ans = 0;
    done[i][maxTime][mask] = 1;
    fore (j, 0, n) {
      if (!((mask >> j) & 1) && g[i] != g[j]) {
        ans += dp(j, maxTime - t[j], mask | (1 << j));
        ans %= mod;
      }
    }
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> len;
  fore(i, 0, n) cin >> t[i] >> g[i];
  g[n] = 5;
  int sum = dp(n, len, 0);
  cout << sum << '\n';
  return 0;
}


//1
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#define int long long int
#define ld long double
#define pb push_back
#define F first
#define S second
#define MOD 1000000007
#define mod1 1187278649
#define mod2 1149736019
#define ioi cout<<"\n------------ioi------------\n"
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

const ld PI=3.14159265358979323;
lint linf=(lint)2e18;
const int inf=1011111111;
const int N = 40000;
// global variables...
int n, t, nx;
int dp[40000][4];
vector <int> pow2;
vector < pair <int,int> > vec1;

//functions...
void input(){
	vec1.clear();
	memset(dp, 0, sizeof dp);
    cin>>n>>t;
    // vec1.pb({0, 4});
   	for(int i=0;i<n;i++){
   		int q1, q2;
   		cin>>q1>>q2;
   		vec1.pb({q1, q2});
   	}
}

int32_t main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("inputf.txt", "r", stdin);
    //     freopen("outputf.txt", "w", stdout);
    // #endif

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int q1 = 1;
    for(int i=0;i<=20;i++){
    	pow2.pb(q1);
    	q1*=2;
    }
    int test=1;
    // cin>>test;
    while(test--){
        input();
        nx = pow2[n];
        // cout<<nx<<" ";
        // ioi;
        // filling the dp in bottom up manner.
        dp[0][3] = 1;

        for(int i=0;i<=nx;i++){
        	for(int j=0;j<=3;j++){
        		if(dp[i][j]==0)
        			continue;
        		int mask = i;
        		int last = j;
        		for(int k=0;k<n;k++){
        			if(mask&pow2[k])
        				continue;
        			int nmask = (mask | pow2[k]);
        			int nlast = vec1[k].S-1;
        			if(nlast==last)
        				continue;
        			dp[nmask][nlast] += dp[mask][last];
        			dp[nmask][nlast] %= MOD;
        		}
        	}
        }
        // for(int i=0;i<=nx;i++){
        // 	for(int j=0;j<=3;j++){
        // 		cout<<dp[i][j]<<" ";
        // 	}
        // 	cout<<"\n";
        // }
        // ioi;
        int ans = 0;
        for(int i=0;i<nx;i++){
        	for(int j=0;j<3;j++){
        		bool ok = false;
        		int sum = 0;
        		for(int k=0;k<n;k++){
        			if(i&pow2[k])
        				sum += vec1[k].F;
        		}
        		if(sum==t)
        			ok = true;
        		if(ok)
        			ans = (ans + dp[i][j])%MOD;

        	}
        }
        cout<<ans<<"\n";
    }
    cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
}


#include <bits/stdc++.h>  // This will work only for g++ compiler.

#define loop(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define floop(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define rloop(i, l, r) for (int i = (int)(l); i >= (int)(r); --i)

//short hand for usual tokens
#define pb push_back

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

using namespace std;

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int n,t;
int id[16];
int tm[226];
int dp[16][1<<15];

ll fact(ll n) {
    if (n==1) return 1;
    else return n*fact(n-1);
}

// ll solve(int n,int mask) {
//     // cout<<n<<" "<<mask<<'\n';
//     int len=0;
//     int tmp = mask;
//     int count = 1;
//     while(tmp>0) {
//         if (tmp&1) {
//             len += tm[count];
//         }
//         count++;
//         tmp/=2;
//     }
//     if (len==t) {
//         return fact(__builtin_popcount(mask));
//     }
//     if (n==0) {
//         return 0;
//     }
//     if (dp[n][mask] != -1) {
//         return dp[n][mask];
//     }
//     ll ans = solve(n-1,mask);
//     // loop(i,0,n) {
//     //     if (len + tm[n] <=t && !(mask & 1<<i)) {

//     //     }
//     // }

//     if (len+tm[n] <=t && !(mask & 1<<(n-1))) {
//         ans += solve(n-1,(mask | 1<<(n-1)));
//     }
//     return dp[n][mask] = ans;
// }

ll solve1(int prev,int mask) {
    int len=0;
    int tmp = mask;
    int count = 1;
    while(tmp>0) {
        if (tmp&1) {
            len += tm[count];
        }
        count++;
        tmp/=2;
    }
    len = t-len;
    if (len == 0 ) {
        return 1;
    }

    if (dp[prev][mask] != -1) {
        return dp[prev][mask];
    }
    ll ans = 0;
    floop(i,1,n) {
        if (id[i]!=prev && tm[i]<=len && !(mask & 1<<(i-1)))
        ans += solve1(id[i],mask | (1<<(i-1)));
    }
    return dp[prev][mask] = ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    cin>>n>>t;
    floop(i,1,n) {
        cin>>tm[i]>>id[i];
    }
    memset(dp,-1,sizeof(int) *16 * (1<<15));
    cout<<solve1(0,0);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <iomanip>
#include <string>
#include <cstdio>

using namespace std;
#define ll long long
#define mod 1000000007

int n, t;
vector<pair<int, int>> s;
ll dp[16][16][16][3];

ll cal(int c1, int c2, int c3, int last) {
    if (c1 < 0 || c2 < 0 || c3 < 0) return 0;

    if (!c1 && !c2 && !c3) {
        return 1;
    }

    if (last != -1 && dp[c1][c2][c3][last] != -1) {
        return dp[c1][c2][c3][last];
    }

    ll ans = 0;

    if (last != 0) {
        ans = (ans + cal(c1 - 1, c2, c3, 0)) % mod;
    }

    if (last != 1) {
        ans = (ans + cal(c1, c2 - 1, c3, 1)) % mod;
    }

    if (last != 2) {
        ans = (ans + cal(c1, c2, c3 - 1, 2)) % mod;
    }

    dp[c1][c2][c3][last] = ans;
    return ans;
}

int main() {
    cin >> n >> t;
    s.resize(n);

    for (auto &p : s) {
        cin >> p.first >> p.second;
    }

    wmemset(dp, -1, sizeof(dp));
    vector<int> fact(16);
    fact[0] = fact[1] = 1;
    for (int i = 2; i < 16; i++) {
        fact[i] = fact[i - 1] * i;
    }

    ll ans = 0;

    vector<int> chosen;
    for (int i = 0; i < (1 << n); i++) {
        chosen.clear();
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) chosen.push_back(j);
        }
        int sum = 0;
        vector<int> c(3, 0);
        for (auto j : chosen) {
            sum += s[j].first;
            c[s[j].second - 1]++;
        }
        if (sum != t) continue;
        ll r = cal(c[0], c[1], c[2], -1);
        r = r * fact[c[0]] % mod;
        r = r * fact[c[1]] % mod;
        r = r * fact[c[2]] % mod;
        ans = (ans + r) % mod;
    }

    cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

int main(){

	 int a,b,c,x,y;
	 cin>>a>>b>>c;
	 if(a>=b && a>=c) swap(a,c);
	 if(b>=a && b>=c) swap(a,c);

	 if(c<=b && c<=a) swap(a,c);
	 if(b<=c && b<=a) swap(b,a);

	  	cout<<b-a+c-b;;
	 }

	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
}

int x1,x2,x3;

cin>>x1>>x2>>x3;

int d1= abs(x1-x2) + abs(x1-x30);

int d2=abs(x2-x1) + abs(x2-x3);

int d3=abs(x3-x1) +abs(x3-x2) ;

cout<<min(min(d1,d2),d3);

return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int a(0),b(0),c(0),p,ans;
cin>>a>>b>>c;
p=(max(a,b,c)+min(a,b,c))/2;
ans=abs(p-a)+abs(p-b)+abs(p-c);
cout<<ans<<endl;
return 0;
}


#include<iostream>
#include<cstdlib>
#include<math.h>
using namespace std;
int main()
{

	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int x, y, z;
	x=sqrt((double)(a*c/b));
	y=a/x;
    z=b*x/a;
	printf("%d",4*x+4*y+4*z);
	system("pause");
	return 0;
}


#include<bits/stdc++.h>
using namepsace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<4*(sqrt(a)+sqrt(b)+sqrt(c));
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <sstream>
using namespace std;
int main()
{
	int x,y,z,a=1,b=1,c=1;
	cin>>x>>y>>z;
	for(int i=1;i<x;i++)
	{
		if(x%i==0)
		{
			a=x/i; b=x/a;
			if(y%a==0&&z%b==0&&(y/a)==(z/b))
			{
				c=z/b;
				break;
			}
			else if(y%b==0&&z%a==0&&(y/b)==(z/a))
			{
				c=z/a;
				break;
			}
		}
	}
	cout<<a*4+b*4+c*4<<endl;
	system("pause");
	return 0;
}#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <sstream>
using namespace std;
int main()
{
	int x,y,z,a=1,b=1,c=1;
	cin>>x>>y>>z;
	for(int i=1;i<x;i++)
	{
		if(x%i==0)
		{
			a=x/i; b=x/a;
			if(y%a==0&&z%b==0&&(y/a)==(z/b))
			{
				c=z/b;
				break;
			}
			else if(y%b==0&&z%a==0&&(y/b)==(z/a))
			{
				c=z/a;
				break;
			}
		}
	}
	cout<<a*4+b*4+c*4<<endl;
//	system("pause");
	return 0;
}


#include <iostream>
using namespace std;
int a,b,c,s;
main(){
    cin>>a>>b>>c;
    s=sqrt(a*a+b*b+c*c);
    cout<<4*(s/a+s/b+s/c);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+1000;
int a[maxn];
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	kk=k;
	k=(k%2)?k/2+1:k/2;
	int p,q;
	p=(k%m==0)?(k/m):(k/m+1);
	q=(k%m==0)?m:(k%m);
	cout<<p<<" "<<q<<" ";
	if(kk%2) cout<<"L";
	else cout<<"R";
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<queue>
using namespace std;
int a[20000][20000];
int main()
{
    int n,m,k,b=1,f=0;
    cin>>n>>m>>k;
    int x,y;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            a[j][f]=b;
            b++;
            a[j][f+1]=b;
            b++;
        }
        f+=2;
    }
    for(int i=0; i<m; i++)
    {
        for(int j=0; j<2*n; j++)
            if(a[i][j]==k)
            {
                x=i,y=j;
            }
    }
    if(k%2==0)
        cout<<y/2+1<<" "<<x+1<<" "<<"R"<<endl;
    else
        cout<<y/2+1<<" "<<x+1<<" "<<"L"<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n, m, k, buff = 0;
		cin >> n >> m >> k;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			buff++;
			if (buff == k) {
				cout << i + 1 << " " << j + 1 << " L" << endl;
				break;
			}
			buff++;
			if (buff == k) {
				cout << i + 1 << " " << j + 1 << " R" << endl;
				break;
			}
		}
		if (buff == k) break;
	}
	return 0;


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,m; long long k;

	cin >>n >> m >> k;

	char c = k & 1 ? 'L' : 'R';

	k = (k + 1) >> 1;

	cout << (k - 1) / m + 1 << "\n" << !(k % m) ? m : (k % m) << "\n" << c;
	return 0;
}


#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#include <cmath>
using namespace std;

int main(){
	long long int x,i;
	cin >> x;
	i=sqrt(x);
	while(x%i){ i--; }
		cout << i<< " "<< (x/i);
}


#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int ans;
int main()
{
	int n,i,j;
	cin>>n;
	for( i*i=n;i>=1;i--)
		for( j*j=n;j<=n;j++){
			if(i*j==n&&i<=j){
				cout<<i<<' '<<j<<endl;
				return 0;
			}
		}
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
 int n;
 cin>>n;
 vector<int>a;
if(n==1)cout<<cout<<n<<" "<<n; return 0;}
      for(int i=1;i<=n;i++){
              if(n%i==0) a.push_back(i);
          }

       int medio=(a.size()/2)-1;
         for(int i=1;i<=a.size();i++){
           if(a[i]*a[i]==n){cout<<a[i]<<" "<<a[i]; return 0;}
             }
       cout<<a[medio]<<" "<<a[medio+1];

}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a*b / gcd(a, b); }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

int n;

int main() {
	//file_put();

	scanf("%d", &n);
	for (int i=(int)sqrt(n); i>=1; i--)
		if (n % i == 0) {
			printf("%d %d\n", i, n / i);
			break;
		}

	return 0;
}


#include<iostream>
#include<cmath>

using namespace std;

int a[1000][1000];

int main(){   // freopen("input.cpp","r",stdin);
    string s;cin>>s;
    int si=500,flag=0, d,sj=500; d=1;
    a[si][sj]=1; int ii,jj; ii=si; jj=sj;
    for(int i=0;i<s.size();i++){
       if( s[i]=='L' ){
          if(d==1 ){
            d=2; si--;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else if( d==2 ){
            d=3; sj--;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else if(d==3 ){
            d=4; si++;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else {
           d=1; sj++;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
       }
       else if( s[i]=='R' ){
          if(d==1 ){
            d=4; si++;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else if( d==2 ){
           d=1; sj++;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else if(d==3 ){
           d=2; si--;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else {
           d=3; sj--;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
       }
       else if( s[i]=='D' ){
          if(d==1 ){
            d=3; sj--;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else if( d==2 ){
            d=4; si++;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else if(d==3 ){
           d=1; sj++;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else {
           d=2; si--;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
       }
       else if( s[i]=='U' ){
          if(d==1 ){
             sj++;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else if( d==2 ){
            si--;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else if(d==3 ){
            sj--;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
          else {
            si++;
            if( a[si][sj]==1 ){ cout<<"BUG"<<endl; flag=1; break; }
            a[si][sj]=1;
          }
       }
    }
    if( abs(si-ii)+abs(sj-jj) != s.size() ) cout<<"BUG"<<endl;else
    if( flag==0 ) cout<<"OK"<<endl;

   // cout<<"\nTime take :: "<<clock()<<" ::ms"<<endl;while(true);
    return 0;
}


/*JANVI PATEL, DAIICT ,INDIA  */
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define dob double
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ff first
#define ss second
#define forr(z,y) for(ll i=z;i<y;i++)
#define rfor(z,y) for(ll i=z;i>=y;i--)
#define  Vp vector<pair<ll,ll>>
#define V vector
#define sort(a) sort(a.begin(),a.end())
#define unique(a) unique(a.begin(),a.end())
ll i,j,x,y,k=0,l;
const int MOD=1e9+7;
ll m1 = LLONG_MAX;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
V<ll> g[1000001];
ll n;
ll v[101];
ll s[101];

ll m2 = LLONG_MIN;
int32_t main()
{       FAST
        string s;
        cin>>s;
        ll l=0,r=0,u=0,d=0;

        for(i=0;i<s.length();i++)
        {
            if(s[i]=='L')
            l++;
            else if(s[i]=='R')
            r++;
            else if(s[i]=='U')
            u++;
            else
            d++;

        }
        //cout<<l<<"  "<<r<<"  "<<u<<"  "<<d<<endl;

        if((l!=0 && r!=0 && l==r) ||(u!=0 && d!=0 && u==d))
        cout<<"BUG"<<endl;*/
        else
        cout<<"OK"<<endl;

}


#include <bits/stdc++.h>
using namespace std;
static const int MAXN=100;
struct Node{
    int x,y;
}point[MAXN+10];

int main()
{
    string s;
    cin>>s;
    point[0]={0,0};
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='L')
            point[i+1]={point[i].x,point[i].y-1};
        else if(s[i]=='R')
            point[i+1]={point[i].x,point[i].y+1};
        else if(s[i]=='U')
            point[i+1]={point[i].x-1,point[i].y};
        else
            point[i+1]={point[i].x+1,point[i].y};
    }
    for(int i=0;i<=s.size();i++)
        for(int j=i+2;j<=s.size();j++)
            if(abs(point[i].x-point[j].x)+abs(point[i].y-point[j].y)<=1)
            {
                cout<<"BUG"<<endl;
                return 0;
            }
    cout<<"OK"<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int x,y,z,t,num,bond1,bond2,bond3, f;
    bool flag=true;

    cin>>x;
    cin>>y;
    cin>>z;
    if (x>y)
    {
        t=x;
        x=y;
        y=t;
    }
    if (y>z)
    {
        t=y;
        y=z;
        z=t;
    }
    if (x>y)
    {
        t=x;
        x=y;
        y=t;
    }
    f=x+y+z;

    num=f/2;
    if ((x==y)&&(y==z))
    {
        if (x%2!=0)
        cout<<x/2<<" "<<x/2<<" "<<x/2<<endl;
        else
            cout<<"Impossible";

    }
    else

            if (x+y<z)
                cout<<"Impossible";
            else
                if (x+y==z)
                    cout<<0<<" "<<y<<" "<<x<<" "<<endl;
                else
                {
                    bond3=x-1;
                    num=num-bond3;
                    bond2=y-1;
                    num=num-bond2;
                    bond1=num;
                    num=num-bond1;
                    if ((bond1<0)||(num>0))
                        cout<<"Impossible"<<endl;
                    else
                        cout<<bond1<<" "<<bond2<<" "<<bond3<<endl;
                }
    }

    return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    long long x, y, z;
    cin >> x >> y >> z;
    long long chack = x + y + z;
    if ((chack) % 2 == 1)
        cout << "Impossible" << endl;
    //ba gnerate number my be in between
    else
    {
        for (int i = 0; i <= x; i++)
        {
            //cout << x - z - i << "    " << y - i << endl;
            if (abs(x - z - i) == abs(y - i))
            {
                x = abs(i);
                y = y - x;
                z = z - y;
                break;
            }
        }
        if (x >= 0 && y >= 0 && z >= 0)
            cout << x << " " << y << " " << z << endl;
        else
            cout << "Impossible" << endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long int a,b,c,x,y,z;
    cin >>a>>b>>c;
    if((a+b+c)%2==0)
    {x=a;
    z=a;
    y=c;
    for(int i=0;i<a;i++)
    {
        if((x+z==a) && (y+z==c) )
            cout<<x<<" "y<<" "<<z;
        else {x--;y--;z--;}
    }}else cout<<"Impossible";
    return 0;
}


#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define F first
#define S second

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

string tos(int x){

ostringstream out;

out << x;

return out.str();

}

int toi(string s){

istringstream in(s);

int a; in >> a;

return a;

}

int main(){

ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int a, b, c;
cin >> a >> b >> c;

if(a==b && b==c){
    if(a%2) { cout << "Impossible"; return 0; }

    cout << a/2 <<' '<<a/2<<' '<<a/2; return 0;
}

int Max = max(a, max(b,c)), sum = a+b+c;

if(Max > sum-Max){ cout << "Impossible"; return 0; }

if((sum- Max - Max)%2) { cout << "Impossible"; return 0; }

int ab, bc, ac;

if(a>=b && a>=c){

     bc  = (sum-Max-Max)/2, ab = b-bc, ac = c-bc;

} else if(b>=c){

     ac = (sum-Max-Max)/2,  ab = a-ac, bc = c-ac;

} else {
    ab = (sum-Max-Max)/2, bc = b - ab, ac = a - ab;
}

cout << ab <<' '<<bc<<' '<<ac;

return 0;


#include<iostream>
#include<cmath>

using namespace std;

pair<int,int> pto(int mx,int x,int st,int T){
    if(x<=mx)return make_pair(mx-x,0);
    if(st+(x-mx)<=T)return make_pair(0,x-mx);
    int d=(st+(x-mx)-T);
    return make_pair(d,x-mx-d);

}

int cerc(int x,int st,int T){
    int mst2=st/2,mst1=(st+1)/2;
    pair<int,int> p1=pto(mst1,x,st,T),p2=pto(mst2,x,st,T);
    if(p1.first<=p2.first)return p1.second;
    return p2.second;
}

int main(){
    int x,y,n,m,a,b;
    cin>>n>>m>>x>>y>>a>>b;
    int g=__gcd(a,b);
    a/=g,b/=g;
    int na,nb;
    int ra=n/a,rb=m/b;
    if(ra*b<=m)na=ra*a,nb=ra*b;
    else na=rb*a,nb=rb*b;
    //cout<<na<<" "<<nb<<endl;
    int xa=cerc(x,na,n),yb=cerc(y,nb,m);
    cout<<xa<<" "<<yb<<" "<<xa+na<<" "<<yb+nb<<endl;
}


/*
Night is falling
Brothers in blood
Invincible in their faith

Deceiver, believer,
Stronger than steel
Insanity is what I feel

Here I stand
Take my hand
Let us flee
To be free

I'm a liar
I'm a sinner
I feel pain
Running through my veins

I'm a liar
I'm a sinner
I feel pain
Of my own destiny

Fighting, dying,
Revenge in blood
Listen to the tongues of hate

Destroyer, betrayer,
Witness of love
Sadness is my lonley fate

Here I stand
Take my hand
Let us flee
To be free

I'm a liar
I'm a sinner
I feel pain
Running through my veins

I'm a liar
I'm a sinner
I feel pain
Of my own destiny
*/
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

using namespace std;

#define ll long long
#define pb push_back
#define ppb pop_back

#define y1 aasdfasdfasdf

const ll N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const ll inf = -1e18;
const ll M = 5 * 1e8;

long long l, w, gd, k, t, n, m, a, b;
double dis, mn, mx, my, x1, x2, y1, y2, a1, a2, b1, b2, x, y;

ll gcd(ll a, ll b) {
	if (b == 0)
	{
		return a;
	}
	else
	{
		return gcd(b, a % b);
	}
}

int main()
{
	cin >> n >> m >> x >> y >> a >> b;
	gd = gcd(a, b);
	a /= gd;
	b /= gd;
	ll r = min(n / a, m / b);
	for (int i = r; i >= 1; i--)
	{
		l = r * a;
		w = r * b;
		if (l <= n && w <= m)
		{
			break;
		}
	}
	mn = INF;
	k = max(0 * 1ll, ll(x - l) - 1 * 1ll);
	t = max(0 * 1ll, ll(y - w) - 1 * 1ll);
	for (int i = k; i <= ll(x); i++)
	{
		if (i + l > n)
		{
			break;
		}
		for (int j = t; j <= ll(y); j++)
		{
			if (j + w > m)
			{
				break;
			}
			x1 = i;
			y1 = j;
			x2 = i + l;
			y2 = j + w;
			if (x < x1 || x > x2 || y < y1 || y > y2)
			{
				continue;
			}
			mx = (x1 + x2) / 2.0;
			my = (y1 + y2) / 2.0;
			dis = sqrt((x - mx)*(x - mx) + (y - my)*(y - my));
			if (dis < mn)
			{
				mn = dis;
				a1 = x1, a2 = x2, b1 = y1, b2 = y2;
			}
		}
	}
	cout << a1 << " " << b1 << " " << a2 << " " << b2;
	cin.get(), cin.get();
	return 0;
}


// Solution by Mukai Yersin
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>

#define sz 2000000
#define mp make_pair
#define pb push_back
#define eps 1e-5
#define inf 1<<30
#define INF (long long)(1ll<<62)
#define F first
#define S second

typedef long long ll;

using namespace std;

int x, y, a, b, n, m, k, K, l, r, X, Y

int main()
{
	cin>>n>>m>>x>>y>>a>>b;
	l=0; r=max(n, m)+1;
	int g=__gcd(a, b);
	a/=g;
	b/=g;
	while (l<r)
	{
	 	K=(l+r)/2+(l+r)%2;
	 	if (a*1ll*K<=n&&b*1ll*K<=m) l=K;
	 	else r=K-1;
	}
	k=(int)(l+5);
	while (!(a*1ll*k<=n&&b*1ll*k<=m)) k=k-1;
	X=max(0, x-(a*1ll*k)/2-(a*1ll*k)%2);
	Y=max(0, y-(b*1ll*k)/2-(b*1ll*k)%2);
	if (X+a*1ll*k>n) X=n-a*1ll*k;
	if (Y+b*1ll*k>m) Y=m-b*1ll*k;
	cout<<X<<' '<<Y<<' '<<X+a*1ll*k<<' '<<Y+b*1ll*k<<endl;
	return 0;
}


#include <cstdlib>
#include <cstring>
#include <memory>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>

#define DEBUG
#ifdef DEBUG
#define DBG(...) cerr << #__VA_ARGS__ << ": " << __VA_ARGS__ << endl
#define DV(...) cerr << __VA_ARGS__ << endl
#define _D(fmt, ...) printf("%10s %3d : " fmt,__FUNCTION__,__LINE__,__VA_ARGS__)
#define _DE(fmt, ...) fprintf(stderr, "%10s %3d : " fmt,__FUNCTION__,__LINE__,__VA_ARGS__)
#else
#define DBG(...)
#define DV(...)
#define _D(fmt, ...)
#define _DE(fmt, ...)
#endif

typedef signed long long ll;
typedef unsigned long long u64;

#define _PE(...) printf(__VA_ARGS__); fprintf(stderr, __VA_ARGS__);
#define _E(...) fprintf(stderr, __VA_ARGS__)
#undef _P
#define _P(...) printf(__VA_ARGS__)

#define FOR(x,to) for(x=0;x<to;x++)
#define FOR2(x,from,to) for(x=from;x<to;x++)
#define ZERO(a) memset(a,0,sizeof(a))
void _fill_int(int* p,int val,int rep) {int i;  FOR(i,rep) p[i]=val;}
#define FILL_INT(a,val) _fill_int((int*)a,val,sizeof(a)/4)
#define ZERO2(a,b) memset(a,0,b)
#define MINUS(a) _fill_int((int*)a,-1,sizeof(a)/4)
#define GETs(x) scanf("%s",x);
int GETi() { int i;scanf("%d",&i); return i;}
#define GET1(x) scanf("%d",x);
#define GET2(x,y) scanf("%d%d",x,y);
#define GET3(x,y,z) scanf("%d%d%d",x,y,z);

#define EPS (1e-11)
template <class T> T sqr(T val){ return val*val;}

//-------------------------------------------------------

ll N,M,X,Y,A,B;

ll gcd(ll a, ll b) { return (b==0)?a:gcd(b,a%b);}

void solve() {
    int f,r,i,j,k,l,x,y;

    cin>>N>>M>>X>>Y>>A>>B;
    ll g=gcd(A,B);
    A/=g;
    B/=g;

    ll MD=min(N/A,M/B);
    N*=2;M*=2;X*=2;Y*=2;

    ll x1=min(max(X,MD*A),N-MD*A)-MD*A;
    ll y1=min(max(Y,MD*B),M-MD*B)-MD*B;
    _P("%lld %lld %lld %lld\n",x1/2,y1/2,x2/2+MD*A,y2/2+MD*B);

    return;
}

int main(int argc,char** argv){
    if(argc>1) freopen(argv[1], "r", stdin);
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long p=1e9+7;
map<long long,long long> m;

long long pow(long long a, long long b){
    long long ans=1;
    while(b>0){
        if(b&1)
            ans=(ans*a)%p;
        b/=2;
        a=(a*a)%p;
    }
    return ans;
}

long long f(long long b){
    if(m[b])
        return m[b];
    long long r=pow(2,b-1),l=sqrt(b),i;
    for(i=2;i<=l;i++)
        if(n%i==0)
            r-=f(i),r-=f(n/i),r+=2*p,r%=p;
    if(l*l==b)
        r+=f(l),r%=p;
    return m[b]=(r-1+p)%p;
}

int main(){
    ios_base::sync_with_stdio (false);cin.tie(0);cout.tie(0);
    long long a,b;
    cin>>a>>b;
    if(b%a){
        cout<<"0\n";
        return 0;
    }
    b/=a;
    m[1]=1;
    cout<<f(b)<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

typedef long long ll;
const ll MOD = 1000000007;
int x, y;
map<int, ll> memo;

ll pow(ll n, ll exp = MOD - 2) {
	ll ret = 1;
	while (exp)
	{
		ret = ret*((exp & 1) ? n : 1) % MOD, n = n*n%MOD, exp >>= 1;
	}
	return ret;
}

static inline int sum(int q)
{
	if (q == 1) return 1;
	if (memo.count(q)) return memo[q];

	ll& ret = memo[q];
	ret = pow(2, q - 1);
	for (int i = 2; i*i <= q; i++)
	{
		if (q%i == 0)
		{
			ret -= sum(q / i);
			if (q / i != i) ret -= sum(i);
		}
	}

	return ret = (ret - 1 + MOD)%MOD;
}

static inline int solve()
{
	if (y % x) return 0;
	return sum(y / x);
}

int main()
{
	//freopen("input.txt", "r", stdin);

	cin.sync_with_stdio(false);
	cin >> x >> y;
	cout << solve() << endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

typedef long long uint;
const uint MOD = 1000000007;
int x, y;
map<int, uint> memo;

uint pow(uint n, uint exp = MOD - 2) {
	uint ret = 1;
	while (exp)
	{
		ret = ret*((exp & 1) ? n : 1) % MOD, n = n*n%MOD, exp >>= 1;
	}
	return ret;
}

static inline int sum(int q)
{
	if (q == 1) return 1;
	if (memo.count(q)) return memo[q];

	uint& ret = memo[q];
	ret = pow(2, q - 1);
	for (int i = 2; i*i <= q; i++)
	{
		if (q%i == 0)
		{
			ret -= sum(q / i);
			if (q / i != i) ret -= sum(i);
		}
	}

	return ret = (ret - 1 + MOD)%MOD;
}

static inline int solve()
{
	if (y % x) return 0;
	return sum(y / x);
}

int main()
{
	//freopen("input.txt", "r", stdin);

	cin.sync_with_stdio(false);
	cin >> x >> y;
	cout << solve() << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int N = 5e5 + 10, MOD = 1e9 + 7;
map <int , int> ans;

int Pow(int n, int i)
{
    int x = pow(n , i / 2);
    return ( ((x * x) % MOD) * (i % 2 ? x : 1) ) % MOD;
}

int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int x, y; cin >> x >> y;
    if (y % x != 0) return cout << 0, 0;
    int n = y / x;
    vector <int> v;
    for (int i = 1; i * i <= n; i ++) {
        if (n % i == 0) {
            v.push_back(i);
            if (i * i != n) v.push_back(n / i);
        }
    }
    sort(v.begin(), v.end());
    for (int i : v) {
        int Ans = pow(2, i - 1);
        for (int j = 1; j * j <= i; j ++) {
            if (i % j == 0) {Ans -= ans[j]; Ans = (Ans + Mod) % Mod;}
            if (j * j != i) {Ans -= ans[i / j]; Ans = (Ans + Mod) % Mod;}
        }
        ans[i] = Ans;
    }
    cout << ans[n] << "\n";
}


#include <bits/stdc++.h>
using namespace std;
const int N=100100;
int n,K,P;
int ny[N],jc[N],f[27][N];
int ksm(int x,int k)
{
	int res=1;
	while(k)
	{
		if(k&1)	res=1ll*res*x%P;
		k>>=1;x=1ll*x*x%P;
	}
	return res;
}
inline int lowbit(int x)
{
	return x&(-x);
}
int dfs(int now,int S)
{
	if(f[now][S]!=-1) return f[now][S];
	if(!S)
	{
		f[now][S]=jc[n];
		for(int i=0;i<now;i++) f[now][S]=1ll*f[now][S]*(K-i)%P;
		return f[now][S];
	}
	int res=0,s=S^lowbit(S);
	for(int i=s;i;i=(i-1)&s)
		 (res+=1ll*ny[S^i]*dfs(now+1,i)%P)%=P;
	(res+=1ll*ny[S]*dfs(now+1,0)%P)%=P;
	return f[now][S]=res;
}
int main()
{
	memset(f,-1,sizeof(f));
	scanf("%d%d%d",&n,&K,&P);
	jc[0]=1;
	for(int i=1;i<=n;i++) jc[i]=1ll*jc[i-1]*i%P;
	ny[n]=ksm(jc[n],P-2);
	for(int i=n-1;i>=0;i--) ny[i]=1ll*ny[i+1]*(i+1)%P;
	int ans=ksm(K,n);
	if(n&1) printf("%d\n",ans);
	else printf("%d\n",(ans-dfs(0,n)+P)%P);
	return 0;
}


#include<bits/stdc++.h>
#define N 250005
using namespace std;
int n,k,mo,ans;
int hr[N],fac[N],inv[N],f[27][N];
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int main(){
	scanf("%d%d%d",&n,&k,&mo);
	inv[0]=inv[1]=fac[0]=1;
	for (int i=2;i<=n;i++)
		inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
	for (int i=1;i/2<=n;i*=2)
		for (int j=i/2;j<i&&j<=n;j++)
			hr[j]=i;
	for (int i=1;i<=n;i++){
		fac[i]=1ll*fac[i-1]*i%mo;
		inv[i]=1ll*inv[i-1]*inv[i]%mo;
	}
	ans=power(k,n);4
	if (n%2==0){
		f[0][0]=1;
		for (int i=0;i<26;i++)
			for (int j=0;j<=n;j++)
				if (f[i][j]&&(j&n)==j)
					for (int k=j+hr[j];k<=n;k=(k+1)|j)
						if ((k&n)==k)
							f[i+1][k]=(f[i+1][k]+1ll*f[i][j]*inv[k-j]%mo);
		int tmp=0;
		for (int i=1;i<=26;i++)
			tmp=(tmp+1ll*f[i][n]*inv[k-i])%mo;
		ans=(ans+mo-1ll*tmp*fac[n]%mo*fac[k]%mo)%mo;
	}
	printf("%d",ans);
}


#include<iostream>
#include<cstdio>
using namespace std;

long n,k,p,bobwin;
long f[250010][30];

long power(long x, long y, long p);
long F(long n,long k,long p);
void lists(long a[], long max, long i, long num, long n, long k, long p);

long power(long x, long y, long p){
	if(y==0){
		return 1;
	}
	else{
		long long t = power(x, y/2, p);
		if(y%2==0){
			return (t*t)%p;
		}
		else{
			return ((t*t)%p)*x%p;
		}
	}
}

void lists(long a[], long max, long i, long num, long n, long k, long p){
	if(i==max){
		f[n][k] = (f[n][k]+F(num, k-1, p))%p;
		return;
	}
	if(a[i]==1){
		lists(a, max, i+1, num, n, k, p);
		lists(a, max, i+1, num+(1<<i), n, k, p);
	}
	else{
		lists(a, max, i+1, num, n, k, p);
	}
	return;
}

long F(long n,long k,long p){
	//cout<<n<<" "<<k<<endl;
	if ((n==0)||(k==1)){
		return 1;
	}
	if(f[n][k]!=0){
		return f[n][k];
	}
	long a[20];
	for(int i=0;i<20;i++){
		if ((n>>i)%2==1){
			a[i] = 1;
		}else{
			a[i] = 0;
		}
	}
	f[n][k] = 0;
	lists(a, 18, 0, 0, n, k, p);
	//cout<<"f["<<n<<"]["<<k<<"]="<<f[n][k]<<endl;
	return f[n][k];
}

int main(){
	memset(f, 0, sizeof(f));
	cin>>n>>k>>p;
	long total = power(k,n,p);
	if(n%2==1){
		cout<<total<<endl;
	}
	else{
		bobwin = F(n, k, p);
		cout<<(total-bobwin+p)%p<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int Maxn = 1 << 19 | 5;
int n, k, p, maxi, ct[Maxn], f[Maxn];
long long pp;
long long tmp1[20][Maxn], tmp2[20][Maxn], tmp3[20][Maxn];
long long fac[Maxn], inv[Maxn];
long long fast_pow(long long x, long long y)
{
    long long ans = 1, now = x;
    while (y)
    {
        if (y & 1) ans = ans * now % p;
        now = now * now % p;
        y >>= 1;
    }
    return ans;
}
void init(void)
{
    fac[0] = 1;
    for (int i = 1; i <= maxi; i++)
        fac[i] = fac[i - 1] * i % p;
    inv[maxi] = fast_pow(fac[maxi], p - 2);
    for (int i = maxi - 1; i >= 0; i--)
        inv[i] = inv[i + 1] * (i + 1) % p;
}
int lower(int x)
{
    int tmp = 1;
    for (; tmp < x; tmp <<= 1);
    return tmp;
}
void FWT(long long *now, int len, bool type = false)
{
	if (type)
		for (int i = 1; i < len; i <<= 1)
			for (int j = 0; j < len; j += (i << 1))
				for (int k = j; k < i + j; k++)
					now[i + k] -= now[k];
	else
		for (int i = 1; i < len; i <<= 1)
			for (int j = 0; j < len; j += (i << 1))
				for (int k = j; k < i + j; k++)
					now[i + k] += now[k];
	for (int i = 0; i < len; i ++) {
		now[i] %= p;
		if (now[i] < 0) now[i] += p;
	}
}
inline void __a (long long &x) { x >= pp ? x -= pp : x; }
void multi(void)
{
    for (int j = 0; j <= 19; j++)
    {
        memset(tmp1[j], 0, sizeof(long long[maxi + 1]));
        memset(tmp3[j], 0, sizeof(long long[maxi + 1]));
    }
    for (int j = 0; j <= maxi; j++)
        tmp1[ct[j]][j] = f[j];
    for (int j = 0; j <= 19; j++)
        FWT(tmp1[j], maxi + 1);
    for (int q = 0; q <= 19; q++)
        for (int l = 0; q + l <= 19; l++)
            for (int s = 0; s <= maxi; s++)
                __a(tmp3[q + l][s] += tmp1[q][s] * tmp2[l][s]);
    for (int q = 0; q <= 19; q++)
		for (int s = 0; s <= maxi; s++)
			tmp3[q][s] %= p;
    for (int j = 0; j <= 19; j++)
        FWT(tmp3[j], maxi + 1, true);
    for (int j = 0; j <= maxi; j++)
        f[j] = tmp3[ct[j]][j];
}
void multi2(void)
{
    static long long tmp[20][Maxn];
    for (int i = 0; i <= 19; i++)
        memset(tmp[i], 0, sizeof(long long[maxi + 1]));
    for (int q = 0; q <= 19; q++)
        for (int l = 0; q + l <= 19; l++)
            for (int s = 0; s <= maxi; s++)
                __a(tmp[q + l][s] += tmp2[q][s] * tmp2[l][s]);
    for (int q = 0; q <= 19; q++)
		for (int s = 0; s <= maxi; s++)
			tmp[q][s] %= p;
    for (int i = 0; i <= 19; i++)
        FWT(tmp[i], maxi + 1, true);
    for (int i = 0; i <= 19; i++)
        memset(tmp2[i], 0, sizeof(long long[maxi + 1]));
    for (int i = 0; i <= maxi; i++)
        tmp2[ct[i]][i] = tmp[ct[i]][i];
    for (int i = 0; i <= 19; i++)
        FWT(tmp2[i], maxi + 1);
}
int main()
{
    scanf("%d%d%d", &n, &k, &p);
	pp = 1ll * p * p;
    if (n & 1)
    {
        printf("%lld", fast_pow(k, n));
        return 0;
    }
    f[0] = 1;
    maxi = lower(n + 1) - 1;
    init();
    for (int i = 0; i <= maxi; i++)
        ct[i] = __builtin_popcount(i);
    for (int i = 0; i <= maxi; i++)
        tmp2[ct[i]][i] = inv[i];
    for (int i = 0; i <= 19; i++)
        FWT(tmp2[i], maxi + 1);
    int res_k = k;
    while (k)
    {
        cerr << k << endl;
        if (k & 1) multi();
        k >>= 1;
        if (k) multi2();
    }
    printf("%lld", (fast_pow(res_k, n) - fac[n] * f[n] % p + p) % p);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <memory.h>
using namespace std;
const int N=1e5+10;
int num[N];
int n,m,mindis,t,lower,upper,ans;
void dfs(int sum,int d,int x,int minn)
{
if(sum>=lower&&sum<=upper&&d>=mindis) ans++;
if(sum>upper) return;
for(int i=x;i<=n;++i)
{
dfs(sum+num[i],num[i]‐minn,i+1,minn);
}
} i
nt main()
{
while(cin>>n>>lower>>upper>>mindis)
{
ans=0;
memset(num,0,sizeof(num));
for(int i=1; i<=n; ++i) scanf("%d",&num[i]);
sort(num+1,num+1+n);
for(int i=1; i<=n; ++i)
{
dfs(num[i],0,i+1,num[i]);
} p
rintf("%d\n",ans);
} r
eturn 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> v;
int n, l, r, x;

int ric(int i, int s, int ma, int mi)
{
    if(i == 0 && s <= r &&  s >= l && ma - mi >= x) return 1;
    if(i < 0) return 0;

    return ric(i-1, s+v[i], max(ma, v[i]), min(mi, v[i])) + ric(i-1, s, ma, mi)+ c;
}

int main()
{

    cin>>n>>l>>r>>x;

    v.resize(n);

    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }

    cout<<ric(n-1, 0, -1, 2e9);

}