#pragma region Macros
#pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2")
// #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ll long long
using ld = long double;
#define rep2(i, a, b) for(ll i = (a); i <= (b); i++)
#define rep3(i, a, b) for(ll i = (a); i >= (b); --i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)                                                                                \
    vector<type> name(size);                                                                                \
    IN(name)
#define VEC2(type, name1, name2, size)                                                                                \
    vector<type> name1(size), name2(size);                                                                                \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i])
#define VEC3(type, name1, name2, name3, size)                                                                                \
    vector<type> name1(size), name2(size), name3(size);                                                                                \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i])
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)                                                                                \
    vector<vector<type>> name(h, vector<type>(w));                                                                                \
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)                                                                                \
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
#define mt make_tuple
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define SORT(v) sort(all(v))
#define REV(v) reverse(all(v))
template <class T = ll, class S> T SUM(const std::vector<S> &v) { return accumulate(all(v), T(0)); }
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using namespace std;
constexpr pii dx4[4] = {pii{1, 0}, pii{0, 1}, pii{-1, 0}, pii{0, -1}};
constexpr pii dx8[8] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { cout << yesno[t] << endl; }
void no(bool t = 1) { yes(!t); }
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
template <class T> using vvvc = vector<vvc<T>>;
template <class T> using vvvvc = vector<vvvc<T>>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define si(c) (int)(c).size()
#define INT(...)                                                                                \
    int __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
#define LL(...)                                                                                \
    ll __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
#define STR(...)                                                                                \
    string __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
#define CHR(...)                                                                                \
    char __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
#define DBL(...)                                                                                \
    double __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {
    scan(head);
    IN(tail...);
}

template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
vi iota(int n) {
    vi a(n);
    iota(all(a), 0);
    return a;
}
template <typename T> vi iota(vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(all(res), 0);
    sort(all(res), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())

template <class T> T ceil(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? (x + y - 1) / y : x / y);
}

template <class T> T floor(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? x / y : (x + y - 1) / y);
}
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
template <class T> T POW(T x, ll n, const ll &mod) {
    T res = 1;
    for(; n; n >>= 1, x = x * x % mod)
        if(n & 1) res = res * x % mod;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    UNIQUE(y);
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
template <class S> void fold_in(vector<S> &v) {}
template <typename Head, typename... Tail, class S> void fold_in(vector<S> &v, Head &&a, Tail &&...tail) {
    for(auto e : a) v.emplace_back(e);
    fold_in(v, tail...);
}
template <class S> void renumber(vector<S> &v) {}
template <typename Head, typename... Tail, class S> void renumber(vector<S> &v, Head &&a, Tail &&...tail) {
    for(auto &&e : a) e = lb(v, e);
    renumber(v, tail...);
}
template <class S, class... Args> vector<S> zip(vector<S> &head, Args &&...args) {
    vector<S> v;
    fold_in(v, head, args...);
    sort(all(v)), v.erase(unique(all(v)), v.end());
    renumber(v, head, args...);
    return v;
}

// x in [l, r)
template <class T, class S> bool inc(const T &x, const S &l, const S &r) { return l <= x and x < r; }
// (a, b) in [lx, rx) * [ly, ry)
template <class T, class S> bool inc(const pair<T, T> &x, const S &lx, const S &ly, const S &rx, const S &ry) { return inc(x.fi, lx, rx) && inc(x.se, ly, ry); }

constexpr ll ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; }
// bit 演算系
ll pow2(int i) { return 1LL << i; }
int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
int lowbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
int lowbit(ll a) { return a == 0 ? 64 : __builtin_ctzll(a); }
// int allbit(int n) { return (1 << n) - 1; }
ll allbit(ll n) { return (1LL << n) - 1; }
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }

ll rnd(ll l, ll r) { //[l, r]
#ifdef _LOCAL
    static mt19937_64 gen;
#else
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
#endif
    return uniform_int_distribution<ll>(l, r)(gen);
}

template <class t> void random_shuffle(vc<t> &a) { rep(i, si(a)) swap(a[i], a[rnd(0, i)]); }

int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}

template <class T, class S> pair<T, S> operator-(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi - y.fi, x.se - y.se); }
template <class T, class S> pair<T, S> operator+(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi + y.fi, x.se + y.se); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.fi, r.fi), min(l.se, r.se)); }
template <class T, class S> pair<T, S> operator+=(pair<T, S> &l, const pair<T, S> &r) { return l = l + r; }
template <class T, class S> pair<T, S> operator-=(pair<T, S> &l, const pair<T, S> &r) { return l = l - r; }

template <class T> ll operator*(const pair<T, T> &x, const pair<T, T> &y) { return (ll)x.fi * y.fi + (ll)x.se * y.se; }

template <typename T> struct edge {
    int from, to;
    T cost;
    int id;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {}
    constexpr bool operator<(const edge<T> &rhs) const noexcept { return cost < rhs.cost; }
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;

using Tree = vector<vector<int>>;
using Graph = vector<vector<int>>;
template <class T> using Wgraph = vector<vector<edge<T>>>;
Graph getG(int n, int m = -1, bool directed = false, int margin = 1) {
    Tree res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        cin >> a >> b;
        a -= margin, b -= margin;
        res[a].emplace_back(b);
        if(!directed) res[b].emplace_back(a);
    }
    return res;
}
template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) {
    Wgraph<T> res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        T c;
        cin >> a >> b >> c;
        a -= margin, b -= margin;
        res[a].emplace_back(b, c);
        if(!directed) res[b].emplace_back(a, c);
    }
    return res;
}
void add(Graph &G, int x, int y) { G[x].eb(y), G[y].eb(x); }
template <class S> void add(Wgraph<S> &G, int x, int y, S c) { G[x].eb(y, c), G[y].eb(x, c); }

#define i128 __int128_t
#define ull unsigned long long int
#define TEST                                                                                \
    INT(testcases);                                                                                \
    while(testcases--)
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    for(auto it = begin(v); it != end(v); ++it) {
        if(it == begin(v))
            os << *it;
        else
            os << " " << *it;
    }
    return os;
}
template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p) {
    os << p.first << " " << p.second;
    return os;
}
template <class S, class T> string to_string(pair<S, T> p) { return "(" + to_string(p.first) + "," + to_string(p.second) + ")"; }
string to_string(string s) { return "\"" + s + "\""; }
string to_string(char c) { return string(1, c); }
template <class T> string to_string(vector<T> s) {
    string res = "{";
    for(auto it = s.begin(); it != s.end(); it++) res += to_string(*it) + (next(it) == s.end() ? "" : ", ");
    return res + "}";
}
template <class T> string to_string(set<T> s) {
    string res = "{";
    for(auto it = s.begin(); it != s.end(); it++) res += to_string(*it), res += (next(it) == end(s) ? "" : ", ");
    return res + "}";
}

#define endl '\n'

#ifdef _LOCAL
void dump() { cerr << endl; }
template <class Head, class... Tail> void dump(Head head, Tail... tail) {
    cerr << to_string(head) << " ";
    dump(tail...);
}
#undef endl
#define debug(x)                                                                                \
    cout << #x << ": ";                                                                                \
    dump(x)
#else
void dump() {}
template <class Head, class... Tail> void dump(Head head, Tail... tail) {}
#define debug(x)
#endif
template <class T> void print(const T &a) { cout << a; }
void OUT() { cout << endl; }
template <class Head, class... Tail> void OUT(const Head &head, const Tail &...tail) {
    print(head);
    if(sizeof...(tail)) cout << ' ';
    OUT(tail...);
}

template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(15);
    }
} setup_io;
#define drop(s) cout << #s << endl, exit(0)

template <int N> struct ndFORarray {
    std::array<int, N> v;
    ndFORarray(std::array<int, N> v_) : v(v_) {}
    struct ndFORitr {
        const std::array<int, N> &v;
        std::array<int, N> tmp;
        bool is_end;
        ndFORitr(const std::array<int, N> &v_) : v(v_), tmp(), is_end(false) {}
        bool operator!=(const ndFORitr &) const { return !is_end; }
        void operator++() {
            int pos = N - 1;
            while(pos != -1) {
                tmp[pos] += 1;
                if(tmp[pos] == v[pos]) {
                    tmp[pos] = 0;
                    pos -= 1;
                } else {
                    break;
                }
            }
            if(pos == -1) { is_end = true; }
        }
        const std::array<int, N> &operator*() const { return tmp; }
    };
    ndFORitr begin() const { return ndFORitr(v); }
    ndFORitr end() const { return ndFORitr(v); }
};

struct ndFORvector {
    std::vector<int> v;
    ndFORvector(std::vector<int> v_) : v(v_) {}
    struct ndFORitr {
        const std::vector<int> &v;
        std::vector<int> tmp;
        bool is_end;
        ndFORitr(const std::vector<int> &v_) : v(v_), tmp(v.size(), 0), is_end(false) {}
        bool operator!=(const ndFORitr &) const { return !is_end; }
        void operator++() {
            int pos = v.size() - 1;
            while(pos != -1) {
                tmp[pos] += 1;
                if(tmp[pos] == v[pos]) {
                    tmp[pos] = 0;
                    pos -= 1;
                } else {
                    break;
                }
            }
            if(pos == -1) { is_end = true; }
        }
        const std::vector<int> &operator*() const { return tmp; }
    };
    ndFORitr begin() const { return ndFORitr(v); }
    ndFORitr end() const { return ndFORitr(v); }
};

auto ndFOR(std::vector<int> v) { return ndFORvector(v); }
template <class... Ts> auto ndFOR(Ts... v) { return ndFORarray<std::tuple_size<std::tuple<Ts...>>::value>({v...}); }
template <class F> struct REC {
    F f;
    REC(F &&f_) : f(std::forward<F>(f_)) {}
    template <class... Args> auto operator()(Args &&...args) const { return f(*this, std::forward<Args>(args)...); }
};

template <class S> vector<pair<S, int>> runLength(const vector<S> &v) {
    vector<pair<S, int>> res;
    for(auto &e : v) {
        if(res.empty() or res.back().fi != e)
            res.eb(e, 1);
        else
            res.back().se++;
    }
    return res;
}
vector<pair<char, int>> runLength(const string &v) {
    vector<pair<char, int>> res;
    for(auto &e : v) {
        if(res.empty() or res.back().fi != e)
            res.eb(e, 1);
        else
            res.back().se++;
    }
    return res;
}

template <class T, class F> T bin_search(T ok, T ng, const F &f) {
    while(abs(ok - ng) > 1) {
        T mid = ok + ng >> 1;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#pragma endregion

namespace modular {
ll MOD = 1;

const int MAXN = 1100000;
class modint {
    using u64 = ll;
    ll Modulus;

  public:
    u64 a;

    modint(const u64 x = 0) noexcept : Modulus(MOD), a(((x % MOD) + MOD) % MOD) {}
    u64 &value() noexcept { return a; }
    modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
    modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
    modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
    template <typename T> modint operator^(T rhs) const noexcept { return modint(*this) ^= rhs; }
    modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if(a >= Modulus) { a -= Modulus; }
        return *this;
    }
    modint &operator-=(const modint rhs) noexcept {
        if(a < rhs.a) { a += Modulus; }
        a -= rhs.a;
        return *this;
    }
    modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    template <typename T> modint &operator^=(T n) noexcept {
        modint res = 1;
        modint x = a;
        while(n) {
            if(n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        a = res.a;
        return *this;
    }
};
#define mint modint
#define vmint vector<mint>
vmint Inv, Prd, Invprd;
void setmod(ll x) {
    MOD = x;
    Inv = {0, 1}, Prd = Invprd = {1, 1};
}
mint inv(int n) {
    if(Inv.size() > n)
        return Inv[n];
    else {
        for(int i = Inv.size(); i <= n; ++i) Inv.emplace_back(Inv[MOD % i] * (-MOD / i));
        return Inv[n];
    }
}
mint prd(int n) {
    if(Prd.size() > n)
        return Prd[n];
    else
        for(int i = Prd.size(); i <= n; ++i) Prd.emplace_back(Prd[i - 1] * i);
    return Prd[n];
}
mint invprd(int n) {
    if(Invprd.size() > n)
        return Invprd[n];
    else
        for(int i = Invprd.size(); i <= n; ++i) Invprd.emplace_back(Invprd[i - 1] * inv(i));
    return Invprd[n];
}
mint modpow(ll a, ll n) {
    mint x = a;
    return x ^= n;
}
template <ll T> modint operator/(modint l, modint r) {
    if(r.a < MAXN) return l * inv(r.a);
    return l * (r ^ (MOD - 2));
}
template <typename T> modint operator/(T l, modint r) { return modint(l) / r; }
template <ll T> modint operator/=(modint &l, modint r) { return l = l / r; }
mint cmb(int a, int b) {
    if(a < b) return 0;
    if(a < 0 || b < 0) return 0;
    return prd(a) * invprd(b) * invprd(a - b);
}
ostream &operator<<(ostream &os, mint a) {
    os << a.a;
    return os;
}
istream &operator>>(istream &is, mint &a) {
    ll x;
    is >> x;
    a = x;
    return is;
}
} // namespace modular

using namespace modular;

int main() {
    INT(n, m);
    setmod(m);
    vmint dp(n + 2);
    dp[1] = 1;
    dp[2] = -1;
    rep2(i, 1, n - 1) {
        dp[i + 1] += 2*dp[i];
        for(int j = 2; i * j <= n; j++) {
            dp[i * j] += dp[i];
            if((i + 1) * j <= n) dp[i * j + j] -= dp[i];
        }
    }
    // OUT(dp);
    OUT(dp[n]);
}


#include <iostream>
#include <algorithm>

//once again

using namespace std;
int m, n;
long long d;
struct dd{
	long long c;
	long long  w;

};
bool cmp(dd a, dd b) { return a.c > b.c || (a.c == b.c && a.w < b.w); }
dd n1[1000001],n2[1000001];

long long sum, sum1, ss;

int main()
{
	cin >> n >> m >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> n1[i].c >> n1[i].w;

	}
	for (int i = 0; i < m ; i++)
	{
		cin >> n2[i].c >> n2[i].w;

	}
	sort(n1,n1+n,cmp);
	sort(n2, n2+ m , cmp);
	for (int i = 1; i < n; i++)
	{

		(n1[i].w)+=n1[i-1].w;
		(n1[i].c)+=n1[i-1].c;

	}
	cout << endl;
	for (int i = 1; i < m; i++)
	{

		(n2[i].w)+=n2[i-1].w;
		(n2[i].c)+=n2[i-1].c;

	}
	long long k = 0;

		for (int i = 0; i < n; i++)
		{
			if (n1[i].wid > d) break;

			ss = d - n1[i].w;
			int l = 0, r = m;
			while (l < r) {
				int mid = (l + r >> 1) + 1;
				if (n2[mid].w <= ss) l = mid;
				else r = mid - 1;
			}
			if (n2[l].w>ss)
				continue;
			sum = max(sum, (n1[i].c + n2[l].c));

		}
		l:
		cout << sum;

	return 0;

}


#include <iostream>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int N = 2000 + 5, MOD = 1000 * 1000 * 1000 + 7;
int dp[N][N], C[2 * N][2 * N];

int main() {
    ios::sync_with_stdio(false);
    C[0][0] = 1;
    for(int i = 1;i < 2 * N;++i) {
        C[i][0] = 1;
        for(int j = 1;j <= i;++j)
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j],
            C[i][j] %= MOD;
    }
    int n, m;
    cin >> n >> m;
    for(int i = 0;i <= n;++i)
        dp[0][i] = dp[1][i] = 1;
    for(int i = 2;i <= m;++i) {
        dp[i][0] = 1;
        for(int j = 1;j <= n;++j)
            dp[i][j] = dp[i][j - 1] + C[2 * j + i - 2][i - 2],
            dp[i][j] %= MOD;
    }
    int ans = 0;
    for(int i = 1;i <= n;++i) {
        for(int j = 2;j <= m;++j) {
            ll M = (ll)(m - j + 1) * dp[j][n - i];
            M %= MOD;
            M *= 2 * dp[j - 1][i - 1] - dp[j - 2][i - 1];
//          M %= MOD;
//          M += MOD;
            ans += M % MOD;
            ans %= MOD;
        }
    }
    ans %= MOD;
    ans += MOD;
    cout << ans % MOD << endl;
    return 0;
}


#include<iostream>
using namespace std;

int i,j,k,n,l,ans,temp;
char c;
char expr[2000000];

int gettype(int p, int q)
{
    int x,left,right;
    if (p==q)
    {
        if (expr[p]=='0') return 0;
        if (expr[p]=='1') return 1;
        if (expr[p]=='?') return 4;
    }
    k=0;
    for (i=p+1; i<=q-1; i++)
    {
        if (expr[i]=='(') k++;
        if (expr[i]==')') k--;
        if (expr[i]=='|'||expr[i]=='&'||expr[i]=='^')
            if (k==0) x=i;
    }
    left=gettype(p+1,x-1);
    right=gettype(x+1,q-1);
    if (left>right)
    {
        temp=left;
        left=right;
        right=temp;
    }
    if (expr[x]=='|')
    {
        if (left==0) return right;
        if (left==1) return 1;
        if (left==2&&right==2) return 2;
        return 3;
    }
    if (expr[x]=='&')
    {
        if (left==0) return 0;
        if (left==1) return right;
        if (left==2&&right==2) return 2;
        return 3;
    }
    if (expr[x]=='^')
    {
        if (left==0||left==2) return right;
        if (left==1)
            if (right==1) return 0; else return right;
        if (left==3) return 3;
        if (left==4) return 2;
    }
}

main()
{
    scanf("%d",&n);
    l=0;
    scanf("%c",&c);
    while (c=='\n') scanf("%c",&c);
    while (c!='\n')
    {
        l++;
        expr[l]=c;
        scanf("%c",&c);
    }
    ans=gettype(1,l);
    if (ans>=3) printf("yes\n"); else printf("no\n");
    //system("pause");
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std ;
const int maxn=1000000+15 ;
const ll mod=1e9+7 ;
typedef long long ll ;
ll ans ;
ll dp[maxn],inv[maxn],sum[maxn] ;
ll f[maxn] ;
ll N,K ;
inline ll ksm(ll a,ll b){
	ll ans=1 ;
	while(b){
		if(b&1) ans=(ans*a)%mod ;
		a=(a*a)%mod ;
		b>>=1 ;
	}
	return ans ;
}
int main(){
	scanf("%lld%lld",&N,&K) ;
	f[0]=1 ;
	for(ll i=1;i<=N;i++) f[i]=(f[i-1]*i)%mod ;
	for(ll i=1;i<=N;i++) inv[i]=ksm(f[i],mod-2) ;
	for(ll i=K+2;i<=N;i++){
		dp[i]=(((ll)(i-K-1)*(f[i-2])%mod+(sum[i-1]-sum[i-K-1])*(f[i-2])%mod))%mod ;
		sum[i]=(sum[i-1]+(1ll*dp[i]*inv[i-1])%mod)%mod ;
	}
	for(int i=1;i<=N;i++) ans=(ans+(1ll*dp[i]*f[N-1]%mod)*(inv[i-1]))%mod ;
	printf("%lld\n",ans) ;
	return 0 ;
}


#include<bits/stdc++.h>
#define maxn 50004
#define LL __int128
using namespace std;

int n;
int ft[maxn];
int fa[maxn],ch[maxn][2];
LL sz[maxn],sx[maxn],sx2[maxn],a[maxn],ans[maxn],sr[maxn],xans[maxn];
LL sqr(LL a){ return a * a; }
#define pa fa[x]
int inr(int x){ return ch[pa][1] == x; }
int isr(int x){ return ch[pa][0] != x && ch[pa][1] != x; }
void upd(int u){
	if(!u) return;
	int lc = ch[u][0] , rc = ch[u][1];
	sz[u] = sz[lc] + sz[rc] + sx[u];
	sr[u] = sr[lc] + sr[rc] + a[u] * sx[u];
	ans[u] = ans[lc] + ans[rc] + xans[u]
		+ a[u] * (sqr(sx[u]) - sx2[u])
		+ 2 * a[u] * sx[u] * sz[rc]
		+ 2 * sr[lc] * (sz[u] - sz[lc]);
}
void rot(int x){
	int y = fa[x] , z = fa[y] , c = inr(x);
	if(!isr(y)) ch[z][inr(y)] = x;
	(ch[y][c] = ch[x][!c]) && (fa[ch[y][c]] = y);
	fa[fa[ch[x][!c] = y]=x]=z;
	upd(y);
}
void splay(int x){
	for(;!isr(x);rot(x))
		if(!isr(pa))
			rot(inr(pa) ^ inr(x) ? x : pa);
	upd(x);
}
int access(int x){
	int y=0;
	for(;x;x=fa[y=x]){
		splay(x);
		sx[x] += sz[ch[x][1]];
		sx2[x] += sqr(sz[ch[x][1]]);
		xans[x] += ans[ch[x][1]];

		ch[x][1] = y;
		sx[x] -= sz[y];
		sx2[x] -= sqr(sz[y]);
		xans[x] -= ans[y];
		upd(x);
	}
	return y;
}

int main(){
	ios :: sync_with_stdio(0);
	cin >> n;
	for(int i=2;i<=n;i++){
		cin >> ft[i];
		fa[i] = ft[i];
	}
	for(int i=1;i<=n;i++){
		access(i),splay(i);
		int x;
		cin >> x;
		a[i] = x;
		sx[i] = 1;
		upd(i);
	}
	splay(1);
	printf("%.10lf\n",ans[1] * 1.0 / n / n);
	int m;cin >> m;
	string s;
	for(int u,v;m--;){
		cin >> s >> u >> v;
		if(s[0] == 'P'){
			access(u);int lca = access(v);
			if(lca == u) swap(u,v);
			int p = ft[u];
			access(p),splay(p);
			splay(u);

			sx[p] -= sz[u];
			sx2[p] -= sqr(sz[u]);
			xans[p] -= ans[u];
			upd(p);

			access(v),splay(v);
			sx[v] += sz[u];
			sx2[v] += sqr(sz[u]);
			xans[v] += ans[u];

			ft[u] = fa[u] = v;
			upd(v);
		}
		else{
			access(u),splay(u);
			a[u] = v;
			upd(u);
		}
		splay(1);
	printf("%.10lf\n",ans[1] * 1.0 / n / n);
	}
}


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

#define int long long

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int pri[maxn],phi[maxn],vis[maxn],tot;

void sieve() {
    phi[1]=1;
    for(int i=2;i<maxn;i++) {
        if(!vis[i]) pri[++tot]=i,phi[i]=i-1;
        for(int j=1;j<=tot&&i*pri[j]<maxn;j++) {
            vis[i*pri[j]]=1;
            if(i%pri[j]==0) {phi[i*pri[j]]=phi[i]*pri[j];break;}
            phi[i*pri[j]]=phi[i]*phi[pri[j]];
        }
    }
    // for(int i=1;i<=6;i++) write(phi[i]);
}

signed main() {
    int n,k;read(n),read(k);sieve();
    if(k==1) return write(3),void();
    sort(phi+1,phi+n+1);int ans=0;
    for(int i=2;i<=k+2;i++) ans+=phi[i];
    write(ans+1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 5e4+8;
#define eps 1e-4
const double pi = acos(-1.0);
const double inf = 1e6;
int cnt;
int segcnt = 0;
double curang;
struct Point{
    double x,y;
    double corss(Point b)const{
        return x * b.y - b.x * y;
    }
    Point operator - (const Point& b)const{
        return (Point){x-b.x,y-b.y};
    }
    double len(){return sqrt(x*x+y*y);}
};
Point segcross(Point a,Point b,Point c,Point d,bool& ok){
    double u = (b-a).corss(c-a) , v = (a-b).corss(d-b);
    if( fabs(u+v) < eps){
        ok = 0;
        Point tem = {-1,-1};
        return tem;
    }
    ok = 1;
    return (Point){ (c.x*v + d.x*u)/(u+v) , (c.y*v + d.y*u)/(u+v) };
}
struct Seg{
    Point a,b;
    int id;
    bool operator < (const Seg& s)const{
        bool ok1 ,ok2;
        Point c = (Point){inf*cos(curang) , inf * sin(curang)};
        Point o = (Point){0,0};
        Point cr1 = segcross(a,b,o,c,ok1);
        Point cr2 = segcross(s.a,s.b,o,c,ok2);
        assert(ok1 && ok2);
        if( fabs( cr1.len() - cr2.len() ) < eps ) return id < s.id;
        return cr1.len() < cr2.len();
    }
};
vector<Point> pol[N];
double ang[N];
vector<int> add[N],del[N];
Seg seg[N];

void add_seg(Point a,Point b){
    double anga = atan2(a.y,a.x) , angb = atan2(b.y,b.x);
    if( fabs(anga - angb) < eps ) return;
    if( anga > angb + eps ){
        swap(anga,angb);
        swap(a,b);
    }
    int pa = lower_bound(ang+1,ang+1+cnt,anga) - ang;
    int pb = lower_bound(ang+1,ang+1+cnt,angb) - ang;

    ++segcnt;
    seg[segcnt] = (Seg){a,b,segcnt};
    if( angb - anga > pi + eps ){
        // Point c = segcross(a,b,(Point){-inf,0},(Point){inf,0});
        if( fabs(anga + pi) > eps){
            // ++segcnt;
            // seg[segcnt] = (Seg){c,a,segcnt};
            add[1].push_back(segcnt);
            del[pa].push_back(segcnt);
        }

        if( fabs( angb - pi ) > eps){
            // ++segcnt;
            // seg[segcnt] = (Seg){b,c,segcnt};
            add[pb].push_back(segcnt);
            del[cnt].push_back(segcnt);
        }
    }
    else{
        add[pa].push_back(segcnt);
        del[pb].push_back(segcnt);
    }
}
double area(Point a,Point b,Point c,Point d){
    double res = 0;
    res += (b-a).corss(c-a);
    res += (c-a).corss(d-a);
    if(res < -eps ) res = -res;
    return res * 0.5;
}
void solve(){
    set<Seg> st;
    double ans = 0;
    curang = 0;
    for(int i = 1;i<cnt;++i){
        for(auto it : del[i] )  st.erase(seg[it]);
        curang = ( ang[i] + ang[i+1] ) / 2.0;
        for(auto it : add[i])  st.insert(seg[it]);
        if(st.size()>=2){
            Seg s1,s2;
            auto it = st.begin();  s1 = (*it);
            ++it; s2 = (*it);
            Point c1 = (Point){inf*cos(ang[i]) , inf * sin(ang[i])};
            Point c2 = (Point){inf*cos(ang[i+1]) , inf * sin(ang[i+1])};
            Point o = (Point){0,0};
            Point a1 = segcross(o,c1,s1.a,s1.b);
            Point a2 = segcross(o,c1,s2.a,s2.b);
            Point a3 = segcross(o,c2,s2.a,s2.b);
            Point a4 = segcross(o,c2,s1.a,s1.b);
            ans += area(a1,a2,a3,a4);
        }
    }
    printf("%.12f",ans);
}
int main(){
    int n; scanf("%d",&n);
    for(int i = 1;i<=n;++i){
        int m; scanf("%d",&m);
        Point tem;
        for(int j = 1;j<=m;++j){
            scanf("%lf %lf",&tem.x,&tem.y);
            pol[i].push_back(tem);
            ang[++cnt] = atan2(tem.y,tem.x);
        }
        pol[i].push_back(pol[i][0]);
    }
    ang[++cnt] = -pi; ang[++cnt] = pi;
    sort(ang+1,ang+1+cnt);
    cnt = unique(ang+1,ang+1+cnt) - ang - 1;

    for(int i = 1;i<=n;++i){
        for(int k = 0;k<pol[i].size()-1;++k){
            add_seg(pol[i][k],pol[i][k+1]);
        }
    }

    solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;

#define MAX_N 200000

int n;
int numbers[MAX_N];
int exists[MAX_N + 1];

struct Node {
    int l, r, sum;
    Node *left, *right;
    int first, last;
};

deque<Node> nodes;

Node *root;

Node* newNode() {
    nodes.emplace_back();
    return &nodes.back();
}

Node* fillNode(int first, int last) {
    if (first >= last) {
        return nullptr;
    }
    int mid = (first + (last - first) / 2);
    Node * result = newNode();
    result->first = first;
    result->last = last;
    result->l = first;
    result->r = last - 1;
    result->left = fillNode(l, mid);
    result->right = fillNode(mid + 1, r);
    result->sum = 0;
    if (!result->left && !result->right) {
        result->sum = l;
    } else {
        if (result->left) {
            result->sum += result->left->sum;
        }
        if (result->right) {
            result->sum += result->right->sum;
        }
    }
    return result;
}

void fixup(Node * node, Node * parent) {
    if (node->r < parent->l) {
        node->sum = (node->last - node->first) * parent->l;
        node->l = node->r = parent->l;
    }
}

int update(Node *node, int first, int last, int size, Node * parent) {
    if (first >= node->last || last <= node->first) return 0;
    if (parent)
        fixup(node, parent);
    if (node->l >= size) return 0;

    if (first <= node->first) {
        node->l = size;
    }
    if (node->last <= last) {
        node->r = max(node->r, size);
    }

    if (first <= node->first && node->last <= last && node->r <= size) {
        int new_sum = (node->last - node->first) * size;
        int result = new_sum - node->sum;
        node->sum = new_sum;
        return result;
    }

    int sum_from_child = 0;
    if (node->left) {
        sum_from_child += update(node->left, first, last, size, node);
    }
    if (node->right) {
        sum_from_child += update(node->right, first, last, size, node);
    }

    node->sum += sum_from_child;
    return sum_from_child;
}

int set_from(int first, int last) {
    if (first >= last) return 0;
    int barSize = last;
    int barIdx = first;
    return update(root, barIdx, n, barSize, nullptr);
}

int main() {
    std::ios_base::sync_with_stdio(false);
    cin >> n;
    root = fillNode(0, n);
    fill(begin(exists), end(exists), -1);
    for (int i = 0; i < n; ++i) {
        cin >> numbers[i];
        exists[numbers[i]] = i;
    }

    int64_t result = 0;
    for (int gcd = MAX_N; gcd >= 1; --gcd) {
        std::vector<int> idxs;
        for (int i = gcd; i <= MAX_N; i += gcd) {
            if (exists[i] >= 0)
                idxs.push_back(exists[i]);
        }
        if (idxs.size() < 2) continue;
        nth_element(begin(idxs), begin(idxs) + 2, end(idxs));
        int x1 = idxs[0];
        int x2 = idxs[1];
        nth_element(begin(idxs), begin(idxs) + idxs.size() - 2, end(idxs));
        int x3 = idxs[idxs.size() - 2];
        int x4 = idxs[idxs.size() - 1];

        result += gcd * set_from(0, x3);
        result += gcd * set_from(x2, idxs.size());
        result += gcd * set_from(x1 + 1, x4);
    }
}


#include<bits/stdc++.h>
using namespace std;
char A[200004];
char B[200004];
int n,m;
bool check(int l,int r)
{
    int j=0;
    for(int i=0;i<n;){
        if(i==l)i=r+1;
        if(A[i]===B[j]){
            i++;j++;
            if(j==m)return true;
        }else{
         i++;
        }
    }
    return false;
}
int main()
{
    scanf("%s",A);
    scanf("%s",B);
    n=strlen(A);
    m=strlen(B);
    int ans=0;
    for(int i=0;i<=n;i++){
        for(int j=i;j<=n;j++){
            if(check(i,j))ans=max(ans,j-i+1);
        }
    }
    cout<<ans<<'\n';

}


#include <bits/stdc++.h>
#define REP(i,n) for (long long i = 1; i <= n; i++)
using namespace std;

long long K;
typedef long long ll;
typedef vector<vector<long long> > matrix;
const long long MOD = 2000000001;
long long no=MOD;
long long n;
matrix mul(matrix A, matrix B)
{
    K=2*n;
    matrix C(K+1, vector<long long>(K+1));

    for (long long i=0;i<=K;i++)
        for (long long j=0;j<=K;j++)
            C[i][j]=MOD;

    for (long long k=0;k<=K;k++)
    {
        for (long long i=0;i<=K;i++)
        {
            for (long long j=0;j<=K;j++)
            {
                    C[i][j] = min(C[i][j] , A[i][k] + B[k][j]);
            }
        }
    }
    return C;
}

// computes A ^ p
matrix pow(matrix A, long long p)
{
    if (p == 1)
        return A;
    if (p % 2)
        return mul(A, pow(A, p-1));
    matrix X = pow(A, p/2);
    return mul(X, X);
}
long long down[30][30];
long long m;
long long up[30][30];
long long a[1000];
long long b[1000];
long long nope[1001]=MOD;
void calc_cost(long long x)
{
    long long mn=0,c=0;
    long long cost=0;
    for (long long i=0;i<n;i++)
    {
        if ((1<<i)&x)
            cost+=b[i],c--;
        else
            cost+=a[i],c++;
        mn=min(mn,c);
    }
    if (c<0)
        down[-mn][-c]=min(down[-mn][-c],cost);
    else if (c==0)
        nope[-mn]=min(nope[-mn],cost);
    else
        up[-mn][c]=min(up[-mn][c],cost);
}
long long solve()
{
    // create vector F1
    long long K=2*n;
    vector<ll> F1(K+1);
    matrix T(K+1, vector<long long>(K+1));
    for (long long i=0;i<=K;i++)
    {
        for (long long j=0;j<=K;j++)
        {
            T[i][j]=no;
            if (abs(i-j)>n)continue;
            if (i==j)
                for (long long x=i;x>=0;x--)
                    T[i][j]=min(T[i][j],nope[x]);
            else if (i<j)
            {
                for (long long x=i;x>=0;x--)
                    T[i][j]=min(T[i][j],up[x][(j-i)]);
            }
            else
            {
                for (long long x=i;x>=0;x--)
                    T[i][j]=min(T[i][j],down[x][(i-j)]);
            }
        }
    }

    T = pow(T, m);

    return T[0][0];
}
int main()
{
    cin>>n>>m;
    for (long long i=0;i<n;i++)cin>>a[i];
    for (long long i=0;i<n;i++)cin>>b[i];
    for (long long i=0;i<=20;i++)
        for (long long j=0;j<=20;j++)
            up[i][j]=down[i][j]=no;
    for (int i=0;i<=20;i++)
        nope[i]=MOD;
    for (long long i=0;i<(1<<n);i++)
        calc_cost(i);
    cout<<solve()<<endl;
}


#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
struct point{
    int x, y;
    bool operator <(const point &p)const{
        return x!=p.x?x<p.x:y<p.y;
    }
}P[260];
struct point2{
    int x, y;
    bool operator <(const point2 &p)const{
        return 1ll*y*p.x < 1ll*p.y*x;
    }
}w[260];
int ccw(point2 &a, point2 &b, point2 &c){
    long long t = 1ll*(b.x-a.x)*(c.y-a.y) - 1ll*(b.y-a.y)*(c.x-a.x);
    return t>0?1:t<0?-1:0;
}
int Pos[260][260], K;
long long res;
long long D[260][260][60], Area[260][260], R[260];
long long Calc(point2 a, point2 b){
    long long t = 1ll*a.x*b.y - 1ll*a.y*b.x;
    if(t<0)t=-t;
    return t;
}
int chk1[260], chk2[260];
void UDT(int x, int y){
    int i;
    for(i=1;i<=K;i++){
        R[i] = max(R[i], D[x][y][i]);
    }
}
void Do(int n){
    if(n+1<K)return;
    int i, j, k;
    sort(w+1,w+n+1);
    for(i=0;i<=n;i++)for(j=i;j<=n;j++)for(k=0;k<=K;k++)D[i][j][k]=-1e18;
    for(i=1;i<=n;i++)D[0][i][2] = 0;
    for(i=1;i<=n;i++){
/*        int pv = -1;
        for(j=i+1;j<=n;j++){
            if(pv == -1 || ccw(w[i], w[pv], w[j]) > 0)pv = j, Pos[i][j] = 1;
            else Pos[i][j] = 0;
            Area[i][j] = Calc(w[i],w[j]);
        }*/
        for(j=i+1;j<=n;j++){
            Area[i][j] = Calc(w[i],w[j]);
            Pos[i][j]=1;
            for(k=i+1;k<j;k++){
                if(ccw(w[i],w[j],w[k]) == ccw(w[j],w[0],w[k]) && ccw(w[j],w[0],w[k]) == ccw(w[0],w[i],w[k]))Pos[i][j]=0;
            }
        }
    }
    for(i=1;i<n;i++){
/*        for(j=1;j<=K;j++)R[j] = -1e9;
        for(j=0;j<=n;j++)chk1[j]=chk2[j]=0;
        while(1){
            int pv = -1;
            for(j=i+1;j<=n;j++){
                if(!chk1[j] && Pos[i][j] && (pv==-1 || ccw(w[i], w[pv],w[j]) < 0))pv = j;
            }
            if(pv==-1)break;
            while(1){
                int pp= -1;
                if(!chk2[0]){
                    UDT(0,i);
                    chk2[0] = 1;
                    continue;
                }
                for(j=1;j<i;j++){
                    if(!chk2[j] && Pos[j][i] && (pp==-1 || ccw(w[i],w[pp],w[j]) < 0))pp = j;
                }
                if(pp == -1 || ccw(w[i],w[pp],w[pv]) > 0)break;
                UDT(pp,i);
                chk2[pp] = 1;
            }
            for(j=1;j<K;j++){
                D[i][pv][j+1] = max(D[i][pv][j+1], R[j] + Area[i][pv]);
            }
            chk1[pv] = 1;
        }*/
        vector<int>T1, T2;
        T1.push_back(0);
        for(j=1;j<i;j++){
            if(Pos[j][i])T1.push_back(j);
        }
        for(j=i+1;j<=n;j++)if(Pos[i][j])T2.push_back(j);
        for(j=0;j<T1.size();j++)for(k=0;k<T2.size();k++)if(ccw(w[T1[j]],w[i],w[T2[k]])>0){
            for(int ii=2;ii<K;ii++)D[i][T2[k]][ii+1] = max(D[i][T2[k]][ii+1], D[T1[j]][i][ii] + Area[i][T2[k]]);
        }
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(ccw(w[i],w[j],w[0]) > 0)res = max(res, D[i][j][K]);
        }
    }
}
int main(){
    int n;
    int i, j;
    scanf("%d%d",&n,&K);
    for(i=1;i<=n;i++){
        scanf("%d%d",&P[i].x,&P[i].y);
    }
    sort(P+1,P+n+1);
    for(i=1;i<=n;i++){
        for(j=i;j<=n;j++){
            w[j-i] = {P[j].x-P[i].x, P[j].y-P[i].y};
        }
        Do(n-i);
    }
    printf("%lld.%02d",res/2,res%2*50);
}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdlib>
#include<utility>
#include<map>
#include<set>
#include<fstream>
#include<iomanip>
#include<cstdio>
#define D double
#define PB push_back
#define F first
#define S second
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector< vector<int> > VV;
const int MOD = 12345;

vector<int> v[40],help;
vector< vector<int> > A;
vector<int> kmm;
int M = 1,esh[30];

int asl_code(vector<int> &a){
	int ans = 0;
	for(int i = a.size()-1;i >= 0;i--){
		ans *= kmm[i];
		ans += a[i];
	}
	return ans;
}
vector<int> code_asl(int x){
	vector<int> ans;
	for(int i = 0; i < (int)kmm.size(); i++){
		ans.PB(x % kmm[i]);
		x /= kmm[i];
	}
	return ans;
}

VV MUL(VV &x, VV &y){
	VV ans(M);
	for (int i = 0; i < M; i++)
		ans[i].resize(M);
	for(int i = 0;i < M; i++)
		for(int j = 0;j < M; j++)
			for(int k = 0;k < M;k++)
				ans[i][j] = (ans[i][j] + x[i][k]*y[k][j]) % MOD;
	return ans;
}

VV PW(long long w){ // w != 0
	if(w == 1)
		return A;
	VV tmp = PW(w/2);
	if(w % 2 == 0)
		return MUL( tmp, tmp);
	return MUL(MUL(tmp,tmp),A);
}

int main(){
	ios::sync_with_stdio(false);
	long long n,m;cin >> n >> m;
	for(int i = 0;i < m;i++){
		char c;int x;cin >> c >> x;
		v[c-'A'].PB(x);
	}
	if(n == 0){
		cout << 1 <<endl;
		return 0;
	}
	for(int  i = 0;i < 30;i++){
		sort(v[i].begin(),v[i].end());
		unique(v[i].begin(),v[i].end());
	}
	for(int i = 0;i < 26;i++){
		if(v[i].size() == 0)
			continue;
		esh[kmm.size()] = i;
		int q = 1;
		for(int j = 0;j <(int)v[i].size();j++)
			q *= v[i][j];
		kmm.PB(q);
		M *= q;
	}
	A.resize(M);
	for(int i = 0;i < M; i++)
		A[i].resize(M);
	for(int i = 0;i < M;i++){
		vector<int> q = code_asl(i);
		for(int j = 0;j < (int)q.size();j++){
			q[j] = (q[j]-1+kmm[j])%kmm[j];
			int carr = asl_code(q);
			A[carr][i] = 1;
			q[j] = (q[j]+1)%kmm[j];
		}
	}
	VV qq = PW(n);
	long long res = 0;
	for(int i = 0;i < M;i++){
		vector<int> r = code_asl(i);
		bool ok = true;
		for(int j = 0;j < (int)r.size(); j++){
			bool help = false;
			for(int k = 0;k < (int)v[ esh[j] ].size();k++)
				if(r[j] % v[esh[j]][k] == 0)
					help = true;
			if(!help){
				ok = false;
				break;
			}
		}
		if(!ok)
			continue;
		res = (res+qq[i][0])%MOD;
	}
	cout << res <<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int k;
    cin>>k;
    int arr[10];
    for(int i=0;i<10;i++)
    {
        arr[i]=0;
    }
    for(int i=0;i<4;i++)
    {
        for(int j=0;j<4;j++)
        {
            int a;
            cin>>a;
            int r=a-48;
            arr[r]++;
        }
    }
    int res=0;
    for(int i=0;<10;i++)
    {
        res=max(res,arr[i]);
    }
    if(res>2*k)
      cout<<"NO"<<endl;
    else
     cout<<"YES"<<endl;
     return 0;
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#define sz(a) int((a).size())
#define pb push_back
#define rep(i,j,k) for (int i=j; i<=k; i++)
#define online1
#define sqr(x) (x)*(x)
using namespace std;
typedef long long LL;

#ifdef online
const int maxn=100;
#else
const int maxn=1000;
#endif

const double eps=1e-15;

int n,m;

int sign(double x){
    if (x<-eps) return -1; return x>eps;
}

struct point_3d{
    double x,y,z;
    point_3d(double _x,double _y,double _z):x(_x),y(_y),z(_z){
    }
    point_3d(){
    }
    point_3d operator+(point_3d &a){
        return point_3d(a.x+x, a.y+y, a.z+z);
    }
    point_3d operator-(point_3d &a){
        return point_3d(x-a.x, y-a.y, z-a.z);
    }
    point_3d operator/(double f){
        return point_3d(x/f, y/f, z/f);
    }
    double len(){
        return sqrt(x*x+y*y+z*z);
    }
};

double dis(point_3d &a, point_3d &b){
    return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)+sqr(a.z-b.z));
}

point_3d project(double A,double B,double C,double x1,double y1,double z1){
    double lambda=(A*x1+B*y1+C*z1)/(A*A+B*B+C*C);
    return point_3d(x1-lambda*A,y1-lambda*B,z1-lambda*C);
}

void calc2(double a,double b,double c,double d,double e,double f,double &x,double &y){
    if (sign(a)==0) {calc2(d,e,f,a,b,c,x,y); return;}
    e+=(-b/a*d); f+=(c/a*d);
    y=-f/e;
    x=(-b*y+c)/a;
}

point_3d cir_cen(point_3d &a, point_3d& b, point_3d& c, double A3, double B3, double C3){
    double x,y,z,A1,B1,C1,D1,A2,B2,C2,D2,D3=0;

    A1=-2*a.x+2*b.x;
    B1=-2*a.y+2*b.y;
    C1=-2*a.z+2*b.z;
    D1=-(b.x*b.x+b.y*b.y+b.z*b.z-a.x*a.x-a.y*a.y-a.z*a.z);

    A2=-2*c.x+2*b.x;
    B2=-2*c.y+2*b.y;
    C2=-2*c.z+2*b.z;
    D2=-(b.x*b.x+b.y*b.y+b.z*b.z-c.x*c.x-c.y*c.y-c.z*c.z);

    if (sign(A2)!=0) swap(A2,A1),swap(B2,B1),swap(C2,C1);
    if (sign(A3)!=0) swap(A3,A1),swap(B3,B1),swap(C3,C1);

    B2+=(-B1/A1*A2); C2+=(-C1/A1*A2); D2+=(+D1/A1*A2);
    B3+=(-B1/A1*A3); C3+=(-C1/A1*A3); D3+=(+D1/A1*A3);

    calc2(B2,C2,D2,B3,C3,D3,y,z);

    return point_3d((-B1*y-C1*z+D1)/A1,y,z);
}

point_3d p[maxn],a[maxn],o;
double r;

int main(){
    scanf("%d%d",&n,&m);
    rep(i,1,n) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);

    rep(mm,1,m){
        double A,B,C;
        scanf("%lf%lf%lf",&A,&B,&C);

        rep(i,1,n) a[i]=project(A,B,C,p[i].x,p[i].y,p[i].z);

        random_shuffle(a+1,a+n+1);
        o=point_3d(0.00,0.00,0.00); r=0;
        rep(i,1,n)
            if ( sign( dis(o,a[i])-r )==1 ){
                o=a[i]; r=0;
                rep(j,1,i-1)
                    if ( sign( dis(o,a[j])-r )==1 ){
                        o=(a[i]+a[j])/2; r=(o-a[i]).len();
                        rep(k,1,j-1)
                            if ( sign( dis(o,a[k])-r )==1 ){
                                o=cir_cen(a[i],a[j],a[k],A,B,C);  r=(o-a[i]).len();
                            }
                    }
            }

        printf("%.9lf\n",r);
    }

    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100009
#define EPS 10e-12
using namespace std;
int n,m,h;
int w[N],v[N],od[N];
int ans[N];
bool cmp(const int &a,const int &b){
    if(w[a]==w[b]) return v[a]<v[b];
    return w[a]<w[b];
}
bool isok(long double t){
    int cnt=1;
    for(int i=1;i<=n&&cnt<=m;i++)
        if(t*v[od[i]]>1.0*one*h-EPS){
            ans[cnt++]=od[i];
        }
    if(cnt>m) return true;
    else return false;
}
int main(){
    //freopen("in","r",stdin);
    scanf("%d%d%d",&n,&m,&h);
    for(int i=1;i<=n;i++)
        od[i]=i,scanf("%d",w+i);
    for(int i=1;i<=n;i++)
        scanf("%d",v+i);
    sort(od+1,od+n+1,cmp);
    long double s=0,e=10e10+9,mid;
    for(int i=1;i<=200;i++){
        mid=(s+e)/2;
        if(isok(mid)) e=mid;
        else s=mid;
    }
    //printf("%lf\n",res);
    printf("%d",ans[1]);
    for(int i=2;i<=m;i++) printf(" %d",ans[i]);
    puts("");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
LL a[1100000],x,y,P,D,sum;
int i,n;
int main()
{
	scanf("%d%I64d%I64d%I64d",&n,&x,&y,&P);
	sum=0;
	for(i=0;i<n;i++)
	{scanf("%I64d",&a[i]);sum+=a[i];}
	if(n==1){printf("%I64d\n",a[0]%P);return 0;}
	LL D=a[0]+a[n-1];
	sum*=2;LL te=3,BS=1;
	LL EE=x;
	while(x>0)
	{
		if(x%2==1)BS=(BS*te)%P;
		te=(te*te)%P;
		x/=2;
	}
	LL S=(((sum-D)*BS+D+2*P)%(2*P))/2;
//	cout<<S<<endl;
	S*=2;
	D=(a[0]+EE*a[n-1]+a[n-2])%P;
	te=3,BS=1;
	while(y>0)
	{
		if(y%2==1)BS=(BS*te)%P;
		te=(te*te)%P;
		y/=2;
	}
	S=(((S-D)*BS+D+2*P)%(2*P))/2;
	cout<<S<<endl;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll nc2(ll n)
{
    ll ans = (n*(n-1))/2;
    return ans;
}

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
	a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}

ll norm(ll a)
{
    a%=mod;
    if(a<0)
        a+=mod;
    return a;
}

ll add(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a+b);
}

ll mul(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a*b);
}

ll div(ll a, ll b)
{
    a = norm(a);
    b = powa(norm(b),mod-2,mod);
    return mul(a,b);
}

ll sub(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a-b);
}

#define N 101

void mul(ll res[N][N], ll m1[N][N], ll m2[N][N])
{
    ll temp[N][N];
    memset(temp,0,sizeof(temp));
    for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            for(ll k=0;k<N;k++)
            {
                temp[i][j]+=(m1[i][k]*m2[k][j])%mod;
                temp[i][j]%=mod;
            }
    for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            res[i][j] = temp[i][j];

}

void powam(ll mat[N][N], ll n)
{
   ll res[N][N];
   memset(res,0,sizeof(res));
   for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            if(i == j)
                res[i][j] = 1;

   while(n>0)
   {
       if(n%2 == 1)
           mul(res,res,mat);

       n>>=1;
       mul(mat,mat,mat);
   }

   for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            mat[i][j] = res[i][j];

}

int main()
{
  FAST/**/

   ll n,k;
   cin>>n>>k;

   ll arr[n];
   rep(n)
        cin>>arr[i];
   ll p = 0;
   rep(n)
        if(arr[i] == 0)
            p++;
   if(p == 0 || p == n)
   {
       cout<<1;
       return 0;
   }

   ll mat[N][N];
   memset(mat,0,sizeof(mat));

   ll den = powa((n*(n-1))/2,mod-2,mod);

   for(ll i=0;i<=p;i++)
   {
       if(i-1>-1)
            mat[i-1][i] = mul(i*i,den);
       mat[i][i] = mul(norm(nc2(p) + nc2(n-p) + i*(n-p-i) + i*(p-i)),den);
       if(i<p)
            mat[i+1][i] = mul(mul(p-i,n-p-i),den);
   }

   ll init = 0;
   rep(p)
        if(arr[i] == 1)
            init++;

   powam(mat,k);
   cout<<mat[0][init];

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1100;

struct PT{
	int x, y, c, id;
} p[N];

int vect(PT p, PT p1, PT p2) {
	return (p1.x - p.x) * (p2.y - p.y) - (p2.x - p.x) * (p1.y - p.y);
}

vector<int> convex_Hull(vector<int> ps) {
	if (ps.size() <= 1) return ps;
	int n = ps.size(), k = 0;
	vector<int> ch(2 * n);
	for (int i = 0; i < n; ch[k++] = ps[i++]) {
		while (k >= 2 && vect(p[ch[k-2]], p[ch[k-1]], p[ps[i]]) <= 0) --k;
	}
	for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) {
		while (k >= t && vect(p[ch[k-2]], p[ch[k-1]], p[ps[i]]) <= 0) --k;
	}
	ch.resize(k - 1);
	return ch;
}

bool valid(vector<int> ps) {
	vector<int> convex = convex_Hull(ps);
	int m = convex.size();
	convex.push_back(convex[0]);
	int changes = 0;
	int cnt[2] = {0};
	for (int i = 0; i < m; i++) {
		if (p[convex[i]].c != p[convex[i+1]].c) {
			changes++;
		}
	}
	return changes <= 2;
}

bool select[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i].x >> p[i].y >> p[i].c;
 		p[i].id = i;
	}
	sort(p, p + n, [](PT a, PT b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); });
	vector<int> ans;
	for (int i = 0; i < n; i++) {
		select[i] = 1;
	}
	int flg = 0;
	while (1) {
		vector<int> tmp;
		for (int i = 0; i < n; i++) {
			if (select[i]) tmp.push_back(i);
		}
		vector<int> convex = convex_Hull(tmp);
		int m = convex.size();
		convex.push_back(convex[0]);
		int changes = 0;
		vector<int> CHS;
		int cnt[2] = {0};
		for (int i = 0; i < m; i++) {
			cnt[p[convex[i]].c]++;
			if (p[convex[i]].c != p[convex[i+1]].c) {
				changes++;
			}
		}
		if (cnt[0] <= 1 && cnt[1] <= 1) break;
		if (changes > 2) {
			flg = 1;
			break;
		}
		if (!changes) {
			ans.push_back(convex[0]);
			ans.push_back(convex[1]);
			select[convex[0]] = 0;
			continue;
		} else {
			int which = 0;
			if (cnt[0] <= 1) which = 1;
			int fff = 0;
			for (int i = 0; i < m; i++) {
				if (p[convex[i]].c == which && p[convex[i+1]].c != p[convex[(i-1+m)%m]].c) {
					select[convex[i]] = 0;
					vector<int> vvv;
					for(int l = 0; l < n; l++) if (select[l])
					{
						vvv.push_back(l);
					}
					if (!valid(vvv))
					{
						select[convex[i]].c = 1;
						continue;
					}
					int j = (i+1)%m;
					if (p[convex[j]].c != which) j = (i-1+m)%m;
					ans.push_back(convex[i]);
					ans.push_back(convex[j]);
					fff = 1;
					break;
				}
			}
			if (!fff)
			{
				flg = 1;
				break;
			}
		}
	}
	if (flg) return puts("Impossible"), 0;
	cout << ans.size() / 2 << endl;
	for (int i = 0; i < ans.size(); i+=2) {
		cout << p[ans[i]].id << ' ' << p[ans[i+1]].id << endl;
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <cassert>
#include <climits>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(a) (a).begin(), (a).end()
#define iter(c) __typeof(c.begin())
#define tr(c, i) for (iter(c) i = c.begin(); i != c.end(); ++i)
#define pb push_back
#define mp make_pair

typedef long long ll;

ll fib[210];

int main() {
  fib[0] = fib[1] = 1;
  for (int i = 2; i <= 200; ++i) fib[i] = fib[i - 1] + fib[i - 2];

  string S;
  while (cin >> S) {
    vector<string> ss;

    string tmp = "";
    rep (i, S.length()) {
      if (tmp == "" || tmp[tmp.length() - 1] != S[i]) {
	tmp += S[i];
      } else {
	ss.pb(tmp);
	tmp = string() + S[i];
      }
    }
    if (!ss.empty() && ss[0][0] != tmp[tmp.length() - 1]) ss[0] = tmp + ss[0];
    else ss.pb(tmp);

    size_t len_sum = 0;
    rep (i, ss.size()) len_sum += ss[i].length();
    assert(len_sum == S.length());

    // rep (i, ss.size()) cout << i << ": " << ss[i] << endl; puts("");

    ll ans = 1;
    if (ss.size() == 1 && S.length() % 2 == 0) {
      int chain = ss[0].length() / 2;
      ans = fib[chain] + fib[chain - 2];
    } else {
      rep (i, ss.size()) {
	string s = ss[i];
	cerr << s << endl;
	if (s.length() == 1) continue;

	if (s[0] == 'A') {
	  if (s.length() < 3) { ans = 0; continue; }
	  s = s.substr(3);
	  if (s.empty()) continue;
	}

	if (s[s.length() - 1] == 'B') {
	  if (s.length() < 3) { ans = 0; continue; }
	  s = s.substr(0, s.length() - 3);
	  if (s.empty()) continue;
	}

	assert(s.length() % 2 == 0);
	int chain = s.length() / 2;

	cerr << s << ": " << fib[chain + 1] << endl;

	ans *= fib[chain + 1];
      }
    }

    cout << ans << endl;
  }
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#define int64 long long

using namespace std;
const int64 Maxn = (int64)1 << 50;
int n,v[550],a[550];
int64 f[550],g[550][550],g2[550][550][3],g3[550][550];
bool vis[550][550],vis2[550][550][3],vis3[550][550];

int64 solve2(int ,int ,int );
int64 solve(int ,int );
int64 work(int ,int );

int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++)   scanf("%d",&v[i]);
    for (int i = 1;i <= n;i++)   scanf("%d",&a[i]);
    for (int i = 1;i <= n;i++)  {
        f[i] = -Maxn;
        for (int j = 0;j < i;j++)
            f[i] = max(f[j] + solve(j + 1,i),f[i]);
    }
    cout << f[n];
}

int64 work(int l,int r)
{
    if (l > r)    return 0;
    if (l == r)   return v[1];
    if (vis3[l][r])   return g3[l][r];
    vis3[l][r] = 1;   int64 &ans = g3[l][r];
    ans = solve(l,r);
    for (int i = l;i < r;i++)
        ans = max(work(l,i) + work(i + 1,r),ans);
    return ans;
}
int64 solve2(int l,int r,int sign)
{
    if (l == r)    return 0;
    if (vis2[l][r][sign + 1])    return g2[l][r][sign + 1];
    vis2[l][r][sign + 1] = 1;
    int64 &ans = g2[l][r][sign + 1];   ans = -Maxn;
    for (int i = l;i <= r;i++)
        if (a[i] == a[l] + sign)
            ans = max(ans,solve2(i,r,sign) + work(l + 1,i - 1));
    return ans;
}
int64 solve(int l,int r)
{
    if (abs(a[r] - a[l]) + 1 > r - l + 1)   return -Maxn;
    if (l == r)   return v[1];
    if (vis[l][r])    return g[l][r];
    vis[l][r] = 1;   int64 &ans = g[l][r];
    ans = -Maxn;
    for (int i = l;i <= r;i++)
        {
            if (!(a[i] >= a[l] && a[i] >= a[r]))   continue ;
            if (a[i] - a[l] + a[i] - a[r] + 1 > r - l + 1)   continue ;
            ans = max(solve2(l,i,1) + solve2(i,r,-1) + v[2 * a[i] - a[l] - a[r] + 1],ans);
        }
    return ans;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#define int64 long long

using namespace std;
const int64 Maxn = (int64)1 << 50;
int n,v[550],a[550];
int64 f[550],g[550][550],g2[550][550][2],g3[550][550];
bool vis[550][550],vis2[550][550][2],vis3[550][550];

int64 solve2(int ,int ,int );
int64 solve(int ,int );
int64 work(int ,int );

int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++)   scanf("%d",&v[i]);
    for (int i = 1;i <= n;i++)   scanf("%d",&a[i]);
    for (int i = 1;i <= n;i++)  {
        f[i] = -Maxn;
        for (int j = 0;j < i;j++)
            f[i] = max(f[j] + solve(j + 1,i),f[i]);
    }
    cout << f[n];
}

int64 work(int l,int r)
{
    if (l > r)    return 0;
    if (vis3[l][r])   return g3[l][r];
    vis3[l][r] = 1;   int64 &ans = g3[l][r];
    ans = solve(l,r);
    for (int i = l;i <= r;i++)
        ans = max(work(l,i) + work(i + 1,r),ans);
    return ans;
}
int64 solve2(int l,int r,int sign)
{
    if (l == r)    return 0;
    if (vis2[l][r][sign + 1])    return g2[l][r][sign + 1];
    vis2[l][r][sign + 1] = 1;
    int64 &ans = g2[l][r][sign + 1];   ans = -Maxn;
    for (int i = l;i <= r;i++)
        if (a[i] == a[l] + sign)
            ans = max(ans,solve2(i,r,sign) + work(i + 1,r - 1));
    return ans;
}
int64 solve(int l,int r)
{
    if (abs(a[r] - a[l]) > r - l + 1)   return -Maxn;
    if (l == r)   return v[1];
    if (vis[l][r])    return g[l][r];
    vis[l][r] = 1;   int64 &ans = g[l][r];
    ans = -Maxn;
    for (int i = l;i <= r;i++)
        {
            if (!(a[i] >= a[l] && a[i] >= a[r]))   continue ;
            if (a[i] - a[l] + a[i] - a[r] + 1 > r - l + 1)   continue ;
            ans = max(solve2(l,i,1) + solve2(i,r,-1) + v[2 * a[i] - a[l] - a[r] + 1],ans);
        }
    return ans;
}


#include <bits/stdc++.h>
//
using namespace std;
const int INF = 1e9+7;
const int maxn = 100015;
const int maxm = 1000005;
int g[105][105];
int num[maxn];
int cnt;
void floyed(int n){
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
            }
        }
    }
};
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
struct Edge{
    int to,next,cap,flow;
}edge[maxm];
int tol,head[maxn];
void init()
{
    tol=2;
    memset(head,-1,sizeof(head));
}
void addedge(int u,int v,int w,int rw=0)
{
    edge[tol].to=v;edge[tol].cap=w;edge[tol].flow=0;
    edge[tol].next=head[u];head[u]=tol++;
    edge[tol].to=u;edge[tol].cap=rw;edge[tol].flow=0;
    edge[tol].next=head[v];head[v]=tol++;
}
int Q[maxn];
int dep[maxn],cur[maxn],sta[maxn];
bool bfs(int s,int t,int n)
{
    int front=0,tail=0;
    memset(dep,-1,sizeof(dep[0])*(n+1));
    dep[s]=0;
    Q[tail++]=s;
    while(front<tail){
        int u=Q[front++];
        for(int i=head[u];i!=-1;i=edge[i].next){
            int v=edge[i].to;
            if(edge[i].cap>edge[i].flow&&dep[v]==-1){
                dep[v]=dep[u]+1;
                if(v==t){
                    return true;
                }
                Q[tail++]=v;
            }
        }
    }
    return false;
}
long long dinic(int s,int t,int n)
{
    long long maxflow=0;
    while(bfs(s,t,n)){
        for(int i=0;i<n;i++){
            cur[i]=head[i];
        }
        int u=s,tail=0;
        while(cur[s]!=-1){
            if(u==t){
                int tp=INF;
                for(int i=tail-1;i>=0;i--){
                    tp=min(tp,edge[sta[i]].cap-edge[sta[i]].flow);
                }
                maxflow+=tp;
                for(int i=tail-1;i>=0;i--){
                    edge[sta[i]].flow+=tp;
                    edge[sta[i]^1].flow-=tp;
                    if(edge[sta[i]].cap-edge[sta[i]].flow==0){
                        tail=i;
                    }
                }
                u=edge[sta[tail]^1].to;
            }else if(cur[u]!=-1&&edge[cur[u]].cap>edge[cur[u]].flow&&dep[u]+1==dep[edge[cur[u]].to]){
                sta[tail++]=cur[u];
                u=edge[cur[u]].to;
            }else{
                while(u!=s&&cur[u]==-1){
                    u=edge[sta[--tail]^1].to;
                }
                cur[u]=edge[cur[u]].next;
            }
        }
    }
    return maxflow;
}
//vector<int>fuck[100005];
int fuckacm[100005];
int ps[105];
int in[maxn], out[maxn], shipos[maxn], atk[maxn], f[maxn], p[maxn], baspos[maxn], d[maxn], gold[maxn], val[maxn];
bool svis[maxn];
#define pii pair<int,int>
vector<pii> v1[105];
int main(){
    int n, m, u, v, s, b, k;
    n = read(), m = read();
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(i==j) g[i][j] = 0;
            else g[i][j] = g[j][i] = INF;
        }
    }
    for(int i = 1; i <= m; i++){
        u = read(), v = read();
        g[u][v] = g[v][u] = 1;
    }
    floyed(n);
    s = read(), b = read(), k = read();
    for(int i = 1; i <= s; i++){
        shipos[i] = read(), atk[i] = read(), f[i] = read(), p[i] = read();
    }
    for(int i = 1; i <= b; i++){
        baspos[i] = read(), d[i] = read(), gold[i] = read();
        v1[baspos[i]].emplace_back(pii(d[i], gold[i]));
    }
    for(int i = 1; i <= k; i++){
        int tmp1, tmp2;
        tmp1 = read(), tmp2 = read();
        fuckacm[tmp1] = tmp2;
        in[tmp2]++, out[tmp1]++;
    }
    for(int i = 1; i <= n; i++){
        sort(v1[i].begin(), v1[i].end()); ps[i] = 0;
        for(int j = 1; j < v1[i].size(); j++){
            v1[i][j].second = max(v1[i][j].second, v1[i][j-1].second);
        }
    }
    for(int i = 1; i <= s; i++){
        int ma = -INF;
        for(int j = 1; j <= n; j++){
            if(g[shipos[i]][j] <= f[i]){
                if(v1[j].empty()) continue;
                while(ps[j] < v1[j].size()-1 && v1[j][ps[j]+1].first <= atk[i]) ps[j]++;
                if(v1[j][ps[j]].first <= atk[i]) ma = max(ma, v1[j][ps[j]].second;
            }
        }
        val[i] = ma-p[i];
    }
    long long ans = 0;
    for(int i = 1; i <= s; i++){
        if(in[i] == 0 && out[i] > 0 && !svis[i]){
            if(val[i] <= 0){
                svis[i] = true;
            }
        }
        if(in[i] == 0 && out[i] == 0 && val[i]>0 && !svis[i]){
            ans += val[i];
            svis[i] = true;
        }
        if(in[i] == 0 && out[i] == 0 && val[i] < 0 && !svis[i]){
            svis[i] = true;
        }
    }
    int S = 2015+1, T = S+1;
    init();
    for(int i = 1; i <= s; i++){
        if(!svis[i]){
            if(val[i] > 0){
                num[i] = ++cnt;
                addedge(S, cnt, val[i]);
                ans += val[i];
            }
            else{
                num[i] = ++cnt;
                addedge(cnt, T, -val[i]);
            }
        }
    }
    for(int i = 1; i <= s; i++){
        if(!svis[i] && val[i] > 0)
            addedge(num[i], num[fuckacm[i]], INF);
    }
    ans -= dinic(S, T, T+1);
    cout << ans;
    return 0;
}


#include<iostream>
#include<algorithm>
#include <cstdlib>

using namespace std;

int n, totalSum, size;
int res[20], a[20];
bool mark[20];
int sum;
int n2;

inline bool check()
{
	sum = 0;
	for (int j = 0; j < n; j++)
		sum += res[n2 - n + j];
	if (sum != totalSum)
		return false;

	sum = 0;
	for (int i = 0; i < n2; i += n + 1)
		sum += res[i];
	if (sum != totalSum)
		return false;

	for (int i = 0; i < n2; i++)
	{
		cout << res[i] << " ";
		if (i % n == n - 1)
			cout << endl;
	}
	exit(0);
}

void backTrack(int x)
{
	if(x == 3 && res[2] > res[1])
		return;
	if(x == n && res[n - 1] > res[0])
		return;
	if(x > 0 && x % n == 0)
	{
		sum = 0;
		for (int i = 0; i < n; i++)
			sum += res[x - n + i];
		if (sum != totalSum)
			return;
	}
	else if(x > n2 - n)
	{
		if(x == n2 - n + 1)
		{
			sum = 0;
			for (int i = n - 1; i < n2 - 1; i += n - 1)
				sum += res[i];
			if (sum != totalSum)
				return;
		}
		sum = 0;
		for (int i = 0; i < n; i++)
			sum += res[x - n2 + n - 1 + i * n];
		if (sum != totalSum)
			return;
	}
	if (x == n2)
		return check();
	for (int i = 0; i < n2; i++)
		if (!mark[i])
		{
			mark[i] = true;
			res[x] = a[i];
			backTrack(x + 1);
			mark[i] = false;
		}
}

bool check3()
{
	// ROWS
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < n; j++)
			sum += res[i * n + j];
		if (sum != totalSum)
			return false;
	}
	// COLUMNS
	for (int j = 0; j < n; j++)
	{
		int sum = 0;
		for (int i = 0; i < n; i++)
			sum += res[i * n + j];
		if (sum != totalSum)
			return false;
	}
	// MAIN DIAG
	int mdsum = 0;
	for (int i = 0; i < n * n; i += n + 1)
		mdsum += res[i];
	// SEC DIAG
	int sdsum = 0;
	for (int i = n - 1; i < n * n - 1; i += n - 1)
		sdsum += res[i];
	if (mdsum != totalSum || sdsum != totalSum)
		return false;
	// OUTPUT
	for (int i = 0; i < n * n; i++)
	{
		cout << res[i] << " ";
		if (i % n == n - 1)
			cout << endl;
	}
	exit(0);
}

bool backTrack3(int x)
{
	//	cout << x << endl;
	if (x == n * n)
		return check();
	for (int i = 0; i < n * n; i++)
		if (!mark[i])
		{
			mark[i] = true;
			res[x] = a[i];
			backTrack(x + 1);
			mark[i] = false;
		}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	n2 = n * n;
	for (int i = 0; i < n * n; i++)
	{
		cin >> a[i];
		totalSum += a[i];
	}
	totalSum /= n;
	cout << totalSum << endl;
	if(n == 1)
		cout << a[0] << endl;
	else if(n < 4)
		backTrack3(0);
	else
		backTrack(0);

	return 0;
}


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

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename Node, size_t LIM>
struct LinkCutTreeBase{
  static array<Node, LIM> pool;
  size_t ptr;

  LinkCutTreeBase():ptr(0){}

  inline Node* create(){
    return &pool[ptr++];
  }

  inline Node* create(Node v){
    return &(pool[ptr++]=v);
  }

  inline size_t idx(Node *t){
    return t-&pool[0];
  }

  Node* operator[](size_t k){
    return &(pool[k]);
  }

  virtual void toggle(Node *t) = 0;
  virtual void eval(Node *t) = 0;
  virtual void pushup(Node *t) = 0;

  void rotR(Node *t){
    Node *x=t->p,*y=x->p;
    if((x->l=t->r)) t->r->p=x;
    t->r=x;x->p=t;
    pushup(x);pushup(t);
    if((t->p=y)){
      if(y->l==x) y->l=t;
      if(y->r==x) y->r=t;
      pushup(y);
    }
  }

  void rotL(Node *t){
    Node *x=t->p,*y=x->p;
    if((x->r=t->l)) t->l->p=x;
    t->l=x;x->p=t;
    pushup(x);pushup(t);
    if((t->p=y)){
      if(y->l==x) y->l=t;
      if(y->r==x) y->r=t;
      pushup(y);
    }
  }

  bool is_root(Node *t){
    return !t->p||(t->p->l!=t&&t->p->r!=t);
  }

  void splay(Node *t){
    eval(t);
    while(!is_root(t)){
      Node *q=t->p;
      if(is_root(q)){
        eval(q);eval(t);
        if(q->l==t) rotR(t);
        else rotL(t);
      }else{
        auto *r=q->p;
        eval(r);eval(q);eval(t);
        if(r->l==q){
          if(q->l==t) rotR(q),rotR(t);
          else rotL(t),rotR(t);
        }else{
          if(q->r==t) rotL(q),rotL(t);
          else rotR(t),rotL(t);
        }
      }
    }
  }

  virtual Node* expose(Node *t){
    Node *rp=nullptr;
    for(Node *c=t;c;c=c->p){
      splay(c);
      c->r=rp;
      pushup(c);
      rp=c;
    }
    splay(t);
    return rp;
  }

  void link(Node *par,Node *c){
    expose(c);
    expose(par);
    c->p=par;
    par->r=c;
    pushup(par);
  }

  void cut(Node *c){
    expose(c);
    Node *par=c->l;
    c->l=nullptr;
    pushup(c);
    par->p=nullptr;
  }

  void evert(Node *t){
    expose(t);
    toggle(t);
    eval(t);
  }

  Node *parent(Node *t){
    expose(t);
    t=t->l;
    while(t&&t->r) t=t->r;
    if(t) splay(t);
    return t;
  }

  Node *root(Node *t){
    expose(t);
    while(t->l) t=t->l;
    splay(t);
    return t;
  }

  bool is_connected(Node *a,Node *b){
    return root(a)==root(b);
  }

  Node *lca(Node *a,Node *b){
    expose(a);
    return expose(b);
  }
};
template<typename Node, size_t LIM>
array<Node, LIM> LinkCutTreeBase<Node, LIM>::pool;
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
  return 0;
}
#endif

#undef call_from_test

#endif
//BEGIN CUT HERE
template<typename Ap>
struct NodeBase{
  using A = Ap;
  NodeBase *l,*r,*p;
  bool rev;
  A val,dat,sum;
  NodeBase(){}
  NodeBase(A val,A dat,A sum):
    rev(0),val(val),dat(dat),sum(sum){
    l=r=p=nullptr;}
};

template<typename Np, size_t LIM>
struct SubTree : LinkCutTreeBase<Np, LIM>{
  using super = LinkCutTreeBase<Np, LIM>;
  using Node = Np;
  using A = typename Node::A;

  SubTree():super(){}

  Node* create(A val){
    return super::create(Node(val,A(),val));
  }

  inline void toggle(Node *t){
    swap(t->l,t->r);
    t->rev^=1;
  }

  inline void eval(Node *t){
    if(t->rev){
      if(t->l) toggle(t->l);
      if(t->r) toggle(t->r);
      t->rev=false;
    }
  }

  inline A resolve(Node *t){
    return t?t->sum:A();
  }

  inline void pushup(Node *t){
    if(t==nullptr) return;
    t->sum=t->val+t->dat;
    t->sum+=resolve(t->l);
    t->sum+=resolve(t->r);
  }

  using super::splay;

  Node* expose(Node *t){
    Node *rp=nullptr;
    for(Node *c=t;c;c=c->p){
      splay(c);
      c->dat+=resolve(c->r);
      c->r=rp;
      c->dat-=resolve(c->r);
      pushup(c);
      rp=c;
    }
    splay(t);
    return rp;
  }

  A query(Node *t){
    expose(t);
    return t->sum;
  }

  void set_val(Node *t,A a){
    expose(t);
    t->val=a;
    pushup(t);
  }
};
//END CUT HERE
#ifndef call_from_test

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#undef call_from_test

//INSERT ABOVE HERE

// sum of square
signed CFR564_E(){
  int n,m;
  cin>>n>>m;
  vector<vector<int>> modv(n),modt(n);
  vector<int> cs(n);

  for(int i=0;i<n;i++){
    cin>>cs[i];
    cs[i]--;
    modv[cs[i]].emplace_back(i);
    modt[cs[i]].emplace_back(0);
  }

  vector<vector<int> > G(n+1);
  for(int i=1;i<n;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  G[n].emplace_back(0);

  for(int i=1;i<=m;i++){
    int v,x;
    cin>>v>>x;
    v--;x--;
    modv[cs[v]].emplace_back(v);
    modt[cs[v]].emplace_back(i);
    cs[v]=x;
    modv[cs[v]].emplace_back(v);
    modt[cs[v]].emplace_back(i);
  }

  using ll = long long;
  struct A{
    ll sz1,sz2;
    A():sz1(0),sz2(){}
    A(ll sz1,ll sz2):sz1(sz1),sz2(sz2){}
    A operator+(const A &a)const{
      return A(sz1+a.sz1,sz2+a.sz2);
    };
    A& operator+=(const A &a){
      sz1+=a.sz1;
      sz2+=a.sz1*a.sz1;
      return (*this);
    }
    A& operator-=(const A &a){
      sz1-=a.sz1;
      sz2-=a.sz1*a.sz1;
      return (*this);
    }
  };

  using Node = NodeBase<A>;
  constexpr size_t LIM = 1e6;
  using LCT = SubTree<Node, LIM>;
  LCT lct;

  for(int i=0;i<n+1;i++) lct.create(A(1,0));

  vector<int> par(n+1,0);
  {
    using P = pair<int, int>;
    queue<P> q;
    q.emplace(n,-1);
    while(!q.empty()){
      int v,p;
      tie(v,p)=q.front();q.pop();
      par[v]=p;
      if(~p) lct.link(lct[p],lct[v]);
      for(int u:G[v])
        if(u!=p) q.emplace(u,v);
    }
  }

  vector<ll> delta(m+1,0);
  vector<int> color(n+1,0);

  for(int c=0;c<n;c++){
    ll lst=(ll)n*n,cur=(ll)n*n;
    delta[0]+=lst;

    if(modv[c].empty()) continue;
    for(int i=0;i<(int)modv[c].size();i++){
      int v=modv[c][i];
      color[v]^=1;
      if(color[v]){
        cur-=lct.query(lct.root(lct[v])).sz2;
        lct.cut(lct[v]);
        cur+=lct.query(lct.root(lct[par[v]])).sz2;
        cur+=lct.query(lct[v]).sz2;
      }else{
        cur-=lct.query(lct.root(lct[par[v]])).sz2;
        cur-=lct.query(lct[v]).sz2;
        lct.link(lct[par[v]],lct[v]);
        cur+=lct.query(lct.root(lct[v])).sz2;
      }
      if(i+1==(int)modv[c].size()||modt[c][i]!=modt[c][i+1]){
        delta[modt[c][i]]+=cur-lst;
        lst=cur;
      }
    }

    for(int i=0;i<(int)modv[c].size();i++){
      int v=modv[c][i];
      if(!color[v]) continue;
      color[v]^=1;
      lct.link(lct[par[v]],lct[v]);
    }
  }

  ll ans=(ll)n*n*n;
  for(int i=0;i<=m;i++){
    ans-=delta[i];
    cout<<ans<<"\n";
  }
  cout<<flush;
  return 0;
}
/*
  verified on 2019/12/27
  https://codeforces.com/contest/1172/problem/E
*/

// test root
signed NIKKEI2019_QUAL_E(){
  int n,m;
  cin>>n>>m;
  vector<int> xs(n);
  for(int i=0;i<n;i++) cin>>xs[i];
  using T = tuple<int, int, int>;
  vector<T> vt;
  for(int i=0;i<m;i++){
    int a,b,y;
    cin>>a>>b>>y;
    a--;b--;
    vt.emplace_back(y,a,b);
  }
  sort(vt.begin(),vt.end());

  using ll = long long;
  using Node = NodeBase<ll>;
  constexpr size_t LIM = 1e6;
  using LCT = SubTree<Node, LIM>;
  LCT lct;

  for(int i=0;i<n;i++) lct.create(xs[i]);

  using P = pair<int, int>;
  set<P> es;
  for(auto t:vt){
    int a,b;
    tie(ignore,a,b)=t;
    if(lct.is_connected(lct[a],lct[b])) continue;
    lct.evert(lct[b]);
    lct.link(lct[a],lct[b]);
    es.emplace(a,b);
  }

  int ans=0;
  reverse(vt.begin(),vt.end());
  for(auto t:vt){
    int y,a,b;
    tie(y,a,b)=t;
    auto rt=lct.root(lct[a]);
    ll sum=lct.query(rt);
    if(sum>=y) continue;
    ans++;
    if(es.count(P(a,b))){
      lct.evert(lct[a]);
      lct.cut(lct[b]);
    }
  }

  cout<<ans<<endl;
  return 0;
}
/*
  verified on 2019/12/27
  https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_e
*/

signed main(){
  CFR564_E();
  //NIKKEI2019_QUAL_E();
  return 0;
}
#endif


#include <bits/stdc++.h>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#define PER(i,a,b) for(int i = a; i>=b; --i)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second

const int inf=INT_MAX;
const int maxn=1e5 + 1;
const int N=2e3 + 5;
const int mod = 998244353;
int n,a[105],cnt=0;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    REP(i,1,n)
    cin >> a[i];
    sort(a+1,a+n+1);
    for(int i=1; i<=n; i+=2)
    cnt+=abs(a[i]-a[i+1]);
    cout << cnt;
}


// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <tr1/unordered_map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-5
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
using namespace std;
using namespace std::tr1;
// mylittledoge

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	int l1,r1,l2,r2;
	cin >> l1 >> r1 >> l2 >> r2;
	int ans =0;
	for(int i =1; i <= 30; i++)
        {

		int k1l =l1/(1<<i), k1r =r1/(1<<i);

		if(k1l*(1<<i) == l1) k1l--;

		if(k1r*(1<<i) == r1) k1r--;

		int k2l =l2/(1<<i), k2r =r2/(1<<i);

		if(k2l*(1<<i) >= l2) k2l--;

		if(k2r*(1<<i) == r2) k2r--;

		if(k2r-k2+1 > 2 && k1l-k1r+1 > 2) {
			ans =max(ans,(1<<i)-1);
			continue;}
		vector< pair<int,int> > p1,p2;
		for(int k =k1l; k < k1r; k++) {
			int x =0, y =(1<<i)-2;
			if(k == k1l) x =max(x,(l1%(1<<i) == 0)?((1<<i)-1):(l1%(1<<i)-1));
			if(k == k1r-1) y =min(y,r1%(1<<i)-1);
			p1.push_back(make_pair(x,y));
			if(k == k1l+1) k =max(k,k1r-1);}
		for(int k =k2l; k < k2r; k++) {
			int x =0, y =(1<<i)-2;
			if(k == k2l) x =max(x,(l2%(1<<i) == 0)?((1<<i)-1):(l2%(1<<i)-1));
			if(k == k2r-1) y =min(y,r2%(1<<i)-1);
			p2.push_back(make_pair(x,y));
			if(k == k2l+1) k =max(k,k2r-1);}
		ALL_THE(p1,it) ALL_THE(p2,jt) ans =max(ans,min(jt->ss,it->ss)-max(it->ff,jt->ff)+1);
		}
	cout << ans << "\n";
	return 0;}


#include<set>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;

#define fir first
#define sec second

typedef long long LL;
typedef pair<int,int> PP;

namespace INPUT{
	const int L=1<<15;
	char _buf[L],*S,*T,c;
	char _gc(){
		if(S==T){
			T=(S=_buf)+fread(_buf,1,L,stdin);
			if(S==T) return EOF;
		}
		return *S++;
	}
	void readi(int &X){
		for(c=_gc();c<'0'||c>'9';c=_gc());X=c&15;
		for(c=_gc();c>='0'&&c<='9';X=X*10+(c&15),c=_gc());
	}
}
#define readi INPUT::readi

const int Maxn=3E5+5;

int N,M,Q;
int lastans;

int n,nv,m;
int V[Maxn<<1];
int v[Maxn];
struct Edge{
	int u,v;
}e[Maxn];

int Np,P[Maxn];

int Turn(int X){return (X+lastans-1)%N+1;}

int Nt;
namespace T{
	struct E{
		int v,nxt;
	}adj[Maxn<<1];
	int hed[Maxn],TE;

	int tim;
	int id[Maxn];
	int dfn[Maxn];
	int dep[Maxn];
	int fa[Maxn][20];

	void Clear(){
		memset(hed,-1,sizeof(hed));
	}

	void addedge(int u,int v){
	++TE,adj[TE].v=v,adj[TE].nxt=hed[u],hed[u]=TE;}

	void Dfs(int u,int Fa,int ID){
		//cerr<<u<<' '<<ID<<endl;
		dfn[u]=++tim; id[u]=ID;
		fa[u][0]=Fa;dep[u]=dep[Fa]+1;
		for(int k=1;k<20;++k)
			fa[u][k]=fa[fa[u][k-1]][k-1];
		for(int k=hed[u];k!=-1;k=adj[k].nxt)
			if(adj[k].v!=Fa) Dfs(adj[k].v,u,ID);
	}

	int LCA(int X,int Y){
		if(dep[X]<dep[Y]) swap(X,Y);
		for(int k=19;k>=0;--k)
			if(dep[fa[X][k]]>=dep[Y])
				X=fa[X][k];
		if(X==Y) return X;
		for(int k=19;k>=0;--k)
			if(fa[X][k]!=fa[Y][k])
				X=fa[X][k],Y=fa[Y][k];
		return fa[X][0];
	}
}

namespace G{
	struct E{
		int v,nxt;
	}adj[Maxn<<1];
	int hed[Maxn],TE;

	int tim;
	int dfn[Maxn],low[Maxn];
	bool ins[Maxn];
	int stk[Maxn],tp;
	int bel[Maxn],Scc;
	int Bel[Maxn];

	void Clear(){
		TE=tim=tp=Scc=0;
		for(int i=1;i<=Np;++i)
			hed[P[i]]=-1,bel[P[i]]=dfn[P[i]]=low[P[i]]=0;
	}

	void Clear2(){
		TE=tim=tp=Scc=0;
		memset(hed,-1,sizeof(hed)),
		memset(bel,0,sizeof(bel)),
		memset(dfn,0,sizeof(dfn)),
		memset(low,0,sizeof(low));
	}

	void addedge(int u,int v){
	++TE,adj[TE].v=v,adj[TE].nxt=hed[u],hed[u]=TE;}

	void Addedge(int u,int v){
		//cerr<<u<<' '<<v<<endl;
		addedge(u,v),addedge(v,u);
	}

	void Tarjan(int u,int Fa){
		dfn[u]=low[u]=++tim;
		stk[++tp]=u,ins[u]=true;
		bool flag=false;
		for(int k=hed[u];k!=-1;flag|=(adj[k].v==Fa),k=adj[k].nxt)
			if(adj[k].v!=Fa||flag)
				if(dfn[adj[k].v]==0)
					Tarjan(adj[k].v,u),low[u]=min(low[u],low[adj[k].v]);
				else
					if(ins[adj[k].v]) low[u]=min(low[u],dfn[adj[k].v]);
		if(dfn[u]==low[u]){
			int top;++Scc;
			do{
				top=stk[tp--];
				ins[top]=false;
				bel[top]=Scc;
				//cerr<<top<<' '<<Scc<<endl;
			}while(top!=u);
		}
	}

	void Build_Tree(){
		T::Clear();
		set<PP> Set;
		for(int u=1;u<=N;++u)
			for(int k=hed[u];k!=-1;k=adj[k].nxt)
				if(bel[adj[k].v]!=bel[u]&&Set.find(PP(bel[u],bel[adj[k].v]))==Set.end())
					Set.insert(PP(bel[u],bel[adj[k].v])),T::addedge(bel[u],bel[adj[k].v]);
		for(int i=1;i<=N;++i) Bel[i]=bel[i];
	}

	void Work(){
		//cerr<<'a'<<endl;
		for(int i=1;i<=N;++i)
			if(dfn[i]==0) Tarjan(i,0);
		Build_Tree();
		for(int i=1;i<=Scc;++i)
			if(T::dfn[i]==0) T::Dfs(i,0,++Nt);
	}
}
using G::Bel;

bool cmp(int r,int c){
	return T::dfn[r]<T::dfn[c];
}

void Work(int qq){
	Np=0;
	sort(V+1,V+nv+1,cmp);
	static int stk[Maxn],tp=0;
	using T::dep;
	using T::LCA;
	using G::Addedge;
	//for(int i=1;i<=nv;++i) cerr<<V[i]<<endl;
	for(int i=1;i<=nv;++i){
		int t=V[i],f=0;
		while(tp>0){
			f=LCA(t,stk[tp]);
			if(tp>1&&dep[f]<dep[stk[tp-1]])
				Addedge(stk[tp],stk[tp-1]),--tp;
			else if(dep[f]<dep[stk[tp]]){
				Addedge(f,stk[tp]);--tp;break;
			}else break;
		}
		if(f>0&&stk[tp]!=f) stk[++tp]=f,P[++Np]=f;
		stk[++tp]=t,P[++Np]=t;
		if(i==nv||T::id[i+1]!=T::id[i]){
			while(tp>1) Addedge(stk[tp-1],stk[tp]),--tp;
			tp=0;
		}
	}
	for(int i=1;i<=m;++i)
		Addedge(Bel[e[i].u],Bel[e[i].v]);
	G::Tarjan(Bel[v[1]],0);
	int tmp=G::bel[Bel[v[1]]];
	bool flag=true;
	//for(int i=1;i<=n;++i) cerr<<v[i]<<' '<<Bel[v[i]]<<' '<<G::dfn[Bel[v[i]]]<<endl;
	for(int i=1;i<=n;++i)
		if(G::bel[Bel[v[i]]]!=tmp)
			{puts("NO");flag=false;break;}
	if(flag) puts("YES"),lastans+=qq;
	G::Clear();
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("CF#657E.in","r",stdin),
	freopen("CF#657E.out","w",stdout);
	#endif
	readi(N),readi(M),readi(Q);
	G::Clear2();
	for(int u,v,i=1;i<=M;++i)
		readi(u),readi(v),
		G::addedge(u,v),G::addedge(v,u);
	G::Work();G::Clear2();
	for(int qq=1;qq<=Q;++qq){
		readi(n),readi(m);nv=0;
		for(int i=1;i<=n;++i)
			readi(v[i]),v[i]=Turn(v[i]),V[++nv]=Bel[v[i]];
		for(int i=1;i<=m;++i)
			readi(e[i].u),readi(e[i].v),
			e[i].u=Turn(e[i].u),e[i].v=Turn(e[i].v),
			V[++nv]=Bel[e[i].u],V[++nv]=Bel[e[i].v];
		if(n==1){puts("YES");lastans+=qq;continue;}
		sort(V+1,V+nv+1);
		nv=unique(V+1,V+nv+1)-(V+1);
		//for(int i=1;i<=nv;++i) cerr<<V[i]<<endl;
		Work(qq);
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<cstring>
#include<cmath>
using namespace std;
const int MAX = 100;

int main()
{
	int n;
	cin>>n;
	int a=0,b=0;
	int v[10];
	memset(v,0,sizeof(v))
	for(int i=1;i<=n;i++)
	{
		a+=n/i;
		v[i%9]++;
	}
	for(int i=0;i<9;i++)
	{
		for(int j=0;j<9;j++)
		{
			b+=v[i] * v[j] * v[i*j%9];
		}
	}
	cout<<b-a<<endl;
}


#include <iostream>
#include <vector>

#define pb push_back

using namespace std;

typedef pair<int, int> pii;

int n, q;
int a[4097];
int topos[4097];

int cnt;
vector<int> part;

vector<pii> ans;
int anspos[1000001];

struct seg{
    struct node{
        int l, r;
        int pos;
    } seg[1000001];

    void query(int p, int l, int r)
    {
        if(seg[p].l>=l && seg[p].r<=r)
            part.pb(seg[p].pos);
        else{
            if(l<(seg[p].l+seg[p].r)/2)
                query(2*p, l, r);
            if(r>(seg[p].l+seg[p].r)/2)
                query(2*p+1, l, r);
        }
    }

    void build(int p, int l, int r)
    {
        seg[p].l=l, seg[p].r=r;
        if(l+1<r){
            build(2*p, l, (l+r)/2);
            build(2*p+1, (l+r)/2, r);
            int x=2*p, y=2*p+1;
            cnt++;
            seg[p].pos=cnt;
            ans.pb({seg[x].pos, seg[y].pos});
        }
        else
            seg[p].pos=topos[l];
    }
} ds;

int main()
{
    ios_base:: sync_with_stdio(0);

    int i, j;

    cin >> n >> q, cnt=n;
    for(i=1;i<=n;i++)
        cin >> a[i], topos[a[i]]=i;

    ds.build(1, 1, n+1);
    for(i=1;i<=q;i++){
        int x, y;
        cin >> x >> y;
        part.clear();
        ds.query(1, x, y+1);
        int cur=part[0];
        for(j=1;j<part.size();j++)
            ans.pb({cur, part[j]}), cnt++, cur=cnt;
        ans[i]=cur;
    }

    cout << cnt << endl;
    for(i=0;i<ans.size();i++)
        cout << ans[i].first << " " << ans[i].second << endl;
    for(i=1;i<q;i++)
        cout << anspos[i] << " ";
    cout << anspos[q] << endl;

    return 0;
}


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

struct Step {
	int x , y , r;
	Step() {}
	Step(int a,int b):x(a) , y(b) , r(a*a + b*b){}
	bool operator < (Step &cmp) const {
		return r < cmp.r;
	}
	bool operator == (Step &cmp) const {
		return r == cmp.r;
	}
};
vector <Step> vec;
vector <pair<int,int> > X , Y;
void preProcess() {
	for (int i = 0 ; i < 200 ; i ++) {
		for (int j = i ; j < 200 ; j ++) {
			vec.push_back(Step(i , j));
		}
	}
	sort(vec.begin() , vec.end());
	vec.erase(unique(vec.begin() , vec.end()) , vec.end());
}
bool cmpSlope(const Step &a,const Step &b) {
	return a.x * 1.0 / a.y < b.x * 1.0 / b.y;
}
int main() {
	preProcess();
	int n;
	cin >> n;
	int del = 0;
	for (int i = 4 , cnt = 2 , bit = 1; ; i ++) {
		int p = bit & 1;
		int q = (vec[i].x + vec[i].y) & 1;
		if (p && q) {
			if (++cnt == n) del = 2;
			++cnt;
		} else if (p && !q) {
			if (++cnt == n) del = 4;
		} else if (!p && q) {
			if (++cnt == n) del = 4;
		}
		bit = (p + q) & 1;
		if (cnt >= n) {
			int sum = 0;
			for (int j = 1 ; j <= i ; j ++) {
				if (j == del) continue;
				X.push_back(make_pair(vec[j].x , X.size()));
				Y.push_back(make_pair(vec[j].y , Y.size()));
				sum = (sum + vec[j].x) & 1;
			}
			if (sum & 1) swap(X[0].first , Y[0].first);
			break;
		}
	}
	sort(X.begin() , X.end());
	sort(Y.begin() , Y.end());
	int sumX = 0 , sumY = 0;
	for (int i = X.size() - 1 ; i >= 0 ; i --) {
		if (sumX >= X[i].first) {
			sumX -= X[i].first;
			X[i].first = -X[i].first;
		} else {
			sumX += X[i].first;
		}
		if (sumY >= Y[i].first) {
			sumY -= Y[i].first;
			Y[i].first = -Y[i].first;
		} else {
			sumY += Y[i].first;
		}
	}
	while (sumX || sumY);
	for (int i = 0; i < X.size() ; i ++) {
		vec[ X[i].second ].x = X[i].first;
		vec[ Y[i].second ].y = Y[i].first;
	}
	vec.erase(vec.begin() + X.size() , vec.end());
	sort(vec.begin() , vec.end() , cmpSlope);
	puts("YES");
	int sumx = 0 , sumy = 0;
	for (int i = 0 ; i < vec.size() ; i ++) {
		sumx += vec[i].x;
		sumy += vec[i].y;
		cout << sumx << ' ' << sumy << endl;
	}
	return 0;
}


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

using namespace std;
#define ll          long long
#define double      long double
#define endl        '\n'
#define sz(x)       (int)(x).size()

#define pb          push_back
#define pf          push_front
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))

#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define vpll        vector<pll>
#define viiii       vector<pair<pii,pii>>

#define mi          map<int,int>
#define mll         map<ll,ll>
#define mii         map<pii,int>

#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define piii        pair<int,pair<int,int>>
#define piiii       pair<pii,pii>
#define fi          first
#define se          second
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()

#define fr(a,b,c)    for(int a=b; a<=c; a++)
#define rfr(a,b,c)   for(int a=b; a>=c; a--)
#define rep(X,Y)     for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y)  for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y)    for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y)    for ((X) = 0;(X) < (Y);++(X))
#define toit ios::sync_with_stdio(0);cin.tie(0);

#define w(x)        int x; cin>>x; while(x--)

const ll mod = 1e9 + 7;;

void arshit_babariya() {
	toit
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int logb(int base, int x) {
	return (log(x) / log(base));
}
int occurs(vll v, int n) {
	auto it = lb(v, n); auto it1 = ub(v, n); int x = it1 - it; return x;
}

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

ll powm(int a, int b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * 1LL * a) % mod;
		b >>= 1;
		a = (a * 1LL * a) % mod;

	}
	return res;
}

ll nCr(ll n , ll k)
{	int fact[n];
	ll res = (fact[n] * powm(fact[k] , mod - 2)) % mod;
	return (res * powm(fact[n - k] , mod - 2)) % mod;
}

//---------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------//
ll dp[100][10];

int main()
{	arshit_babariya();
	string s;
	cin >> s;
	int n = sz(s);

	rep(i, 10) dp[0][i] = 1;

	fr(i, 1, n - 1) {
		int d = (int)(s[i] - '0');
		// cout << d << ": " << endl;
		fr(k, 0, 9) {
			int n1 = -1, n2 = -1;
			n1 = (d + k) / 2;
			if ((d + k) % 2 == 1) {
				n2 = n1 + 1;
			}

			if (0 <= n1 && n1 <= 9) {
				dp[i][n1] = dp[i][n1] + dp[i - 1][k];
			}
			if (0 <= n2 && n2 <= 9) {
				dp[i][n2] = dp[i][n2] + dp[i - 1][k];
			}
		}

	}
	ll ans = 0;
	bool f = 1;
	fr(i, 1, n - 1) {
		if (abs(s[i] - s[i - 1]) > 1)f = 0;
	}

	rep(i, 10) {
		ans += dp[n - 1][i];
	}
	cout << ans - f << endl;
	return 0;
}


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

char str[55];
int len;
int zero;
int n;
pair<int, unsigned> dat[500005];
constexpr int MOD = 1000000007;

int dp[500005][45];
bool v[500005][45];
int comb[45][45];

int C(int a, int b)
{
	if (b == a || b == 0) return 1;
	if (comb[a][b] == 0)
	{
		comb[a][b] = (C(a - 1, b - 1) + C(a - 1, b)) % MOD;
	}
	return comb[a][b];
}

int D(int idx, int z)
{
	if (z < 0) return 0;
	if (idx == n) return z == 0;
	if (v[idx][z] == false)
	{
		v[idx][z] = true;
		dp[idx][z] =
			(z * 1ll * (D(idx + 1, z) + D(idx + 1, z - 1)) + (dat[idx].first - len) * 1ll * D(idx + 1, z)) % MOD;
	}

	return dp[idx][z];
}

unordered_map<long long, int> memo[20];
int cnt;

int recur(long long flag, int idx)
{
	auto itr = memo[idx].emplace(flag, 0);
	auto &ret = itr.first->second;

	if (itr.second)
	{
		if (idx == cnt)
		{
			int z = __popcnt64(flag);

			for (int i = 0; i <= z; i++)
			{
				ret = (ret + D(idx, zero - i) * 1ll * C(z, i)) % MOD;
			}
		}
		else
		{
			for (int p = 0; p < dat[idx].first; p++)
			{
				bool wrong = false;
				for (int j = p; j < len; j += dat[idx].first)
				{
					if (str[j] == '1')
					{
						wrong = true;
						break;
					}
				}

				if (wrong) continue;
				long long nf = flag;

				for (int j = p; j < len; j += dat[idx].first) nf |= (1ll << j);
				ret = (ret + recur(nf, idx + 1)) % MOD;
			}
		}
	}

	return ret;
}

int main()
{
	scanf("%s", str);

	while (str[len])
	{
		if (str[len] == '0') zero++;
		len++;
	}

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d%u", &dat[i].first, &dat[i].second);
	}
	cnt = partition(dat, dat + n, [](auto &e) {return e.first < len;}) - dat;
	int ans = recur(0, 0);

	for (int i = 0; i < n; i++)
	{
		int mul = dat[i].first;
		int now = 0; unsigned flag = 1;
		--dat[i].second;
		while (flag <= dat[i].second)
		{
			if (flag & dat[i].second) ans = ans * 1ll * mul % MOD;
			mul = (mul * 1ll * mul) % MOD;
			flag <<= 1;
		}
	}

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int)1e6 + 34;
int p[N][3];
vector<ll> es[3];

int main() {
    //freopen("a.in", "r", stdin);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    string c;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cin >> c;
    for (int i = 0; i < n; i++) {
        int kk = 0;
        if (c[i] == 'R') kk = 0;
        if (c[i] == 'W') kk = 1;
        if (c[i] == 'O') kk = 2;
        es[kk].push_back(a[i]);
    }

    for (int j = 0; j < 3; j++) {
        sort(es[j].begin(), es[j].end());
        es[j].push_back(0);
        reverse(es[j].begin(), es[j].end());
        for (int i = 1; i < (int)es[j].size(); i++) {
            es[j][i] += es[j][i - 1];
        }
    }

    /*for (int i = 0; i < 3; i++) {
        for (int j = 0; j < (int)es[i].size(); j++) cerr << es[i][j] << " "; cerr << "\n";
    }*/

    ll ans = -1;
    for (int org = 1; org <= min(k, (int)es[2].size() - 1); org++) {
        if (k - org == 0) continue;
        if ((int)es[0].size() > k - org) {
            ans = max(ans, es[2][org] + es[0][k - org]);
        }
        if ((int)es[1].size() > k - org) {
            ans = max(ans, es[2][org] + es[1][k - org]);
        }
    }
    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define f first

#define s second
using namespace std;

template<typename T> using vc = vector<T>;
using pii=pair<int, int>;

void xmax(int & a, int b){
    a=max(a, b);
}
void xmin(int& a, int b){
   a=min(a, b);
}

void print(vc <int> & a, string s){
    cerr << "prinitng " << s << ": ";
    for (int i=0; i<a.size(); i++){
        cerr <<a[i] << " ";
    }
    cerr << endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL_RUN
    freopen("input.txt", "r", stdin);
    int ttt;
    cin >> ttt;
    while(ttt--){
    #endif // LOCAL_RUN

    int n, d, s;
    cin >> n >> d >> s;
    vc <int> term;
    int mini=s+5;
    int anz_plus=0;
    int own_start=0;
    for (int i=0; i<n;i++){
        int c, f, l;
        cin >> c >> f >> l;
        if (l<d){
            if (c>=1){
                anz_plus+=c;
            }
        }else{
            else if (c>=1){
                if (f==0){
                    own_start++;
                }
                xmin(mini, f);
                anz_plus+=c;
            }else{
                term.push_back(f);
            }
        }
    }
    sort(term.begin(), term.end());
    pii mit={0, 0};
        int cur=s;
        int anz=0;
        for (int i=0; i<term.size(); i++){
            if (cur>=term[i]){
                cur-=term[i];
                anz++;
            }
        }
        int need=s-cur;
        int anz2=0;
        int cur2=s;
        int need2=0;
        if (cur2>=mini){
            cur2-=mini;
            anz2=anz_plus+1;
            if (own_start!=0) anz2+=own_start-1;
            int left=n-anz2;
            for (int i=0; i<min(left, (int)term.size()); i++){
                if (cur2>=term[i]){
                    cur2-=term[i];
                    anz2++;
                }
            }
            need2=s-cur2;
        }
        anz2=min(anz2, n);
        int res, fuel;
        if (anz==anz2){
            res=anz;
            fuel=min(need, need2);
        }else{
            if (anz>anz2){
                res=anz;
                fuel=need;
            }else{
                res=anz2;
                fuel=need2;
            }
        }
        cout << res << " " << fuel << "\n";

    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    cin >> str;
    for (int i = 0; i < str.size(); i ++) cout << "@";
}