//*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/

#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();

    int n;
    cin >> n;
    vi p(n);
    vi pos(n);
    rep (i, n) {
        cin >> p[i];
        p[i]--;
        pos[p[i]] = i;
    }

    set<int> st;
    vi ans;
    rep (x, n) {
        while (pos[x] != x) {
            int i = pos[x];
            int j = i - 1;
            if (st.count(j)) {
                cout << -1 << endl;
                return 0;
            }
            ans.push_back(j);
            st.insert(j);
            swap(p[j], p[i]);
            pos[p[j]] = j;
            pos[p[i]] = i;
        }
    }
    if (st.size() != n - 1) {
        cout << -1 << endl;
        return 0;
    }
    rep (i, ans.size()) {
        cout << ans[i] + 1 << endl;
    }

}

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

int main(){
  int n;

  cin >> n;

  int p[n+1];

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

  int dis[n];
  int dissum=0;
  int absdissum=0;

  for(int i=1;i<=n;i++){
    dis[i]=p[i]-i;
    if(dis[i]==0){
      printf("-1");
      return 0;
    }
    dissum+=dis[i];
    absdissum+=abs(dis[i]);
  }

  if(dissum!=0 || absdissum!=2*n-2){
    printf("-1");
    return 0;
  }

  for(int i=1;i<=n;i++){
    if(dis[i]<0){
      for(int j=1;j<=abs(dis[i]);j++){
        cout << i-j << endl ;
      }
    }
  }
  return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
//const int mod= int(1e9)+7;
const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

ld d(P a, P b){
    return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}
struct UnionFind{
    vector<int> d;
    UnionFind(int n=0):d(n,-1){}
    int root(int x){
        if(d[x]<0)return x;
        return d[x]=root(d[x]);
    }
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return false;
        if(d[x]>d[y])swap(x,y);
        d[x]+=d[y];
        d[y]=x;
        return true;
    }
    bool same(int x,int y){return root(x)==root(y);}
    int usize(int x){return -d[root(x)];}
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin >>n;
    UnionFind uni(n+2);
    vector<P>pos(n);
    for (int i = 0; i < n; ++i) {
        cin >>pos[i].first>>pos[i].second;
    }
    vector<pair<ld,P>>g;
    for (int i = 0; i < n; ++i) {
        g.push_back({100-pos[i].second,{0,i+2}});
        g.push_back({pos[i].second+100,{1,i+2}});
    }
    for (int i = 0; i < n; ++i) {
        for (int j =i+1; j <n; ++j) {
            g.push_back({d(pos[i],pos[j]),{i+2,j+2}});
        }
    }
    sort(all(g));
    int m=g.size();
    ld r=0;
    for(auto e:g){
        ld dd=e.first;
        r=dd/2;
        uni.unite(e.second.first,e.second.second);
        if(uni.same(0,1))break;
    }
    cout <<setprecision(20)<<r<<"\n";
    return 0;
}

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

int main() {
    int N;
    int ans=0, tmp, maxa=0, maxb=0, maxc=0, maxd=0, maxe=0, ai, bi, ci, di, ei;
    cin >> N;
    vector<int> a(N), b(N), c(N), d(N), e(N), m(5);

    for(int i=0; i<N; i++){
	cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i];
	if(maxa < a[i]){
	    maxa = a[i];
	    m[0] = i;
	}
	if(maxb < b[i]){
	    maxb = b[i];
	    m[1] = i;
	}

	if(maxc < c[i]){
	    maxc = c[i];
	    m[2] = i;
	}

	if(maxd < d[i]){
	    maxd = d[i];
	    m[3] = i;
	}

	if(maxe < e[i]){
	    maxe = e[i];
	    m[4] = i;
	}
    }

    for(int i=0; i<N; i++){
	for(int j=i+1; j<N; j++){
	    for(int k=0; k<5; k++){
		maxa = max(max(a[i], a[j]), a[m[k]]);
		maxb = max(max(b[i], b[j]), b[m[k]]);
		maxc = max(max(c[i], c[j]), c[m[k]]);
		maxd = max(max(d[i], d[j]), d[m[k]]);
		maxe = max(max(e[i], e[j]), e[m[k]]);

		tmp = min(min(min(min(maxa, maxb), maxc), maxd), maxe);
		ans = max(ans, tmp);
	    }
	}
    }

    // for(int i=0; i<N; i++){
    // 	if(a[i]<=ans || b[i]<=ans ||c[i]<=ans ||d[i]<=ans ||e[i]<=ans )
    // 	    continue;
    // 	for(int j=i+1; j<N; j++){
    // 	    if(a[j]<=ans || b[j]<=ans ||c[j]<=ans ||d[j]<=ans ||e[j]<=ans )
    // 		continue;

    // 	    for(int k=j+1; k<N; k++){
    // 		if(a[k]<=ans || b[k]<=ans ||c[k]<=ans ||d[k]<=ans ||e[k]<=ans )
    // 		    continue;

    // 		maxa = max(max(a[i], a[j]), a[k]);
    // 		maxb = max(max(b[i], b[j]), b[k]);
    // 		maxc = max(max(c[i], c[j]), c[k]);
    // 		maxd = max(max(d[i], d[j]), d[k]);
    // 		maxe = max(max(e[i], e[j]), e[k]);

    // 		tmp = min(min(min(min(maxa, maxb), maxc), maxd), maxe);
    // 		ans = max(ans, tmp);
    // 	    }
    // 	}
    // }
    cout << ans << endl;

}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pil pair<int,ll>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 200005
#define m 61
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
#define memset1(v) memset(v,-1,sizeof(v))
#define memset0(v) memset(v,0,sizeof(v))
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int n;
ll res[m];
ll c[N][m][2];
vector<pil>ed[N];
void dfs(int u,int pa){
	for(int i=0;i<m;i++)c[u][i][0]=1;
	for(pil p:ed[u]){
		int v=p.fi;
		ll w=p.se;
		if(pa==v)continue;
		dfs(v,u);
		for(ll i=0;i<m;i++){
			if((w>>i)&1){
				mad(res[i],c[v][i][0]*c[u][i][0]);
				mad(res[i],c[v][i][1]*c[u][i][1]);
				mad(c[u][i][0],c[v][i][1]);
				mad(c[u][i][1],c[v][i][0]);
			}
			else{
				mad(res[i],c[v][i][0]*c[u][i][1]);
				mad(res[i],c[v][i][1]*c[u][i][0]);
				mad(c[u][i][0],c[v][i][0]);
				mad(c[u][i][1],c[v][i][1]);
			}
		}
	}
}
void solve(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int u,v;
		ll w;
		cin>>u>>v>>w;
		ed[u].pb(pil(v,w));
		ed[v].pb(pil(u,w));
	}
	dfs(1,0);
	ll ans=0;
	for(ll i=0;i<m;i++)mad(ans,res[i]*((1ll<<i)%mod));
	cout<<ans;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<ll,ll>;
// #include"debug.hpp"

void calc(vector<ll> A)
{
	const ll M = 60;
	const ll mod = 1e9 + 7;
	ll n = A.size();
	vector<ll> dig(M);
	for(ll i = 0; i < n; i++) {
		ll a = A[i];
		for(ll j = 0; j < M; j++) if((1LL<<j) & (a))dig[j]++;
	}

	ll sum = 0;
	for(ll i = 0; i < M; i++) {
		ll num = (ll)dig[i] * (n - dig[i]) % mod;
		(num *= (1LL<<i) % mod) %= mod;
		(sum += num) %= mod;
	}

	cout << sum << endl;

}

vector<vector<pair<ll,ll>>> tre;
vector<ll> num;

void dfs(ll v, ll par, ll sum) {
	num[v] = sum;
	for(auto [i, len] : tre[v]) {
		if(i == par)continue;
		dfs(i, v, sum xor len);
	}

}

int main()
{
	ll N; cin >> N;
	tre.resize(N);
	num.resize(N);

	for(ll i = 0; i < N - 1; i++) {
		ll u, v, k; cin >> u >> v >> k;
		u--,v--;
		tre[u].push_back({v, k});
		tre[v].push_back({u, k});
	}

	dfs(0, -1, 0);
	// print(num);
	calc(num);

}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k, m;
  cin >> n >> k >> m;
  int sm = 0;
  rep(i, n - 1) {
    int a;
    cin >> a;
    sm += a;
  }
  int ans = m * n - sm;
  if (ans < 0) ans = 0;
  if (ans > k)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}

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

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

int T;

int extGCD(int a, int b, int &x, int &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }

    int ret = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return ret;
}

int unit(int a, int b)
{
    if(a < 0)return 0;
    return (a + b - 1) / b;
}

signed main()
{
    cin >> T;
    rep(_, T)
    {
        int X, Y, P, Q;
        cin >> X >> Y >> P >> Q;

        int T1 = 2 * (X + Y), T2 = P + Q;
        int ans = -1;
        rep(i, Y)rep(j, Q)
        {
            int x, y;
            int c = P + j - X - i;
            int d = extGCD(T1, -T2, x, y);
            if(d < 0)
            {
                d = -d;
                x = -x;
                y = -y;
            }
            if(c % d != 0)continue;
            // cout << T1 << "*" << x << "+" << -T2 << "*" << y << "=" << d << endl;
            x *= c / d, y *= c / d;

            // cout << T1 << "*" << x << "+" << -T2 << "*" << y << "=" << c << endl;

            int t1 = T1 / d, t2 = T2 / d;

            if(x < 0 || y < 0)
            {
                int MAX = max(unit(-x, t2), unit(-y, t1));
                // cout << "((" << -x << ", " << t2 << ")" << unit(-x, t2) << ", " << "(" << -y << ", " << t2 << ")" << unit(-y, t1) << ")" << endl;
                // cout << "MAX : " << MAX << endl;
                x += MAX * t2, y += MAX * t1;
                if(ans == -1)ans = x * T1 + i + X;
                else ans = min(ans, x * T1 + i + X);
                // assert(x * T1 + i + X == y * T2 + P + j);
            }
            else
            {
                int MIN = min(x / t2, y / t1);
                // cout << "MIN : " << MIN << endl;
                x -= MIN * t2, y -= MIN * t1;
                if(ans == -1)ans = x * T1 + i + X;
                else ans = min(ans, x * T1 + i + X);
                // assert(x * T1 + i + X == y * T2 + P + j);
            }
        }

        if(ans == -1)cout << "infinity " << endl;
        else cout << ans << endl;
    }
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (c % 2 == 0)
	{
		if (a < 0)
			a = -a;
		if (b < 0)
			b = -b;
	}
	if (a == b)
		printf("=\n");
	if (a > b)
		printf(">\n");
	if (a < b)
		printf("<\n");
	return 0;
}

#include <iostream>
using namespace std;

int hantei(long long n);

int main(){
  long long t, n;
  cin >> t;
  for (int i = 0; i < t; i++){
    cin >> n;
    if (hantei(n) == -1) cout << "Odd" << endl;
    else if (hantei(n) == 0) cout << "Same" << endl;
    else if (hantei(n) == 1) cout << "Even" << endl;
  }
  return 0;
}

int hantei(long long n){
  if (n % 2 == 1) return -1;
  else if (n % 4 == 0) return 1;
  else return 0;
}


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

#define fi first
#define se second
#define rng(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define per(i, b) gnr(i, 0, b)
#define all(obj) begin(obj), end(obj)
#define allr(obj) rbegin(obj), rend(obj)
#define cinv(a) rep(i, (int)a.size()) cin >> a[i]
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<Pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const int MOD =	1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const long double eps = 1e-10;
const char nl = '\n';

ll power(ll a, ll b) { return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; }

ll nCk(int n, int k)
{
	ll x = 1, y = 1;
	for (int i = 1; i <= k; ++i)
	{
		x = x * (n - i + 1) % MOD;
		y = y * i % MOD;
	}
	return x * power(y, MOD - 2) % MOD;
}

struct UF
{
	vi d;
	UF(int n) : d(n, -1) {}
	int root(int x)
	{
		if (d[x] < 0)
			return x;
		return d[x] = root(d[x]);
	}
	bool unite(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (d[x] > d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -d[root(x)]; }
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(20);
	ll n; cin >> n;
	int ans = 2;
	for (ll i = 1, k; (k = i*(i+1)/2) < n; ++i)
		if ((n-k)%(i+1) == 0) ans += 2;
	cout << ans << nl;
}

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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ff first
#define Ss second
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
    ll n;
    cin >> n;

    while (n % 2 == 0)
    {
        n /= 2;
    }

    ll m = sqrt(n), ans = 0;

    for (ll i = 1; i <= m; i++)
    {
        if (n % i == 0)
        {
            ans += 2;
        }
    }

    if (m * m == n)
        ans--;

    cout << ans * 2 << endl;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for (int i = n-1; i >= 0; --i)
#define repA(i, a, n) for (int i = a; i <= n; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define vs vector<string>
#define vd vector<double>
#define vb vector<bool>

#define vpii vector<pii>
#define vpll vector<pll>
#define vpdd vector<pdd>

#define mod 1000000007
#define ps(x,y) fixed << setprecision(y) << x
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

void solve()
{
	string s;
	cin >> s;

	rep(i, s.length()) {
		if (i % 2 == 0) {
			if (s[i] < 97 || s[i] > 122) {
				cout << "No" << '\n';
				return;
			}
		}
		else {
			if (s[i] < 65 || s[i] > 90) {
				cout << "No" << '\n';
				return;
			}
		}
	}

	cout << "Yes" << '\n';
}

int main()
{
	fastio;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin>>t;
	while (t--) solve();

	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_map>
#include <stack>
#include <math.h>
#include <queue>
#include <functional>
#include <iomanip>
using namespace std;

#define ll long long

bool comp(pair<int,int> a, pair<int,int> b){
    return a.first<b.first;
}

const int N=1000001;

bool solve(string s){
    for(int i=0; i<s.length();i++){
        char c= s.at(i);
        if(i%2==0){
            if(c-tolower(c)!=0) return true;
        } else{
            if(c-toupper(c)!=0) return true;
        }
    }
    return false;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin>>s;
    cout<<(solve(s) ? "No":"Yes")<<"\n";

    return 0;
}


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

int read();
#define LL long long
#define fr(i,l,r) for(int i = (l);i <= (r);++i)
#define rf(i,l,r) for(int i = (l);i >= (r);--i)
#define fo(i,l,r) for(int i = (l);i < (r);++i)
#define foredge(i,u,v) for(int i = fir[u],v;v = to[i],i;i = nxt[i])
#define ci const int &
#define cl const LL &
#define I inline void
#define filein(File) freopen(File".in","r",stdin)
#define fileout(File) freopen(File".out","w",stdout)

const int N = 1e5 + 5,MOD = 1e9 + 7;
int n,a[N];
LL ans = 1;
int main() {
	cin >> n;
	fr(i,1,n) cin >> a[i];
	sort(a+1,a+n+1);
	fr(i,1,n) ans = ans * (a[i]-a[i-1]+1) % MOD;
	cout << ans << endl;
	return 0;
}

const int S = 1 << 21;
char p0[S],*p1,*p2;
#define getchar() (p2 == p1 && (p2 = (p1 = p0) + fread(p0,1,S,stdin)) == p1 ? EOF : *p1++)
inline int read() {
	static int x,c,f;x = 0;f = 1;
	do c = getchar(),c == '-' && (f = -1);while(!isdigit(c));
	do x = x * 10 + (c & 15),c = getchar();while(isdigit(c));
	return x * f;
}


#include<bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define int ll
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define viii vector<vii>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf 1e9
#define minf -1e9
#define dd double
#define fori(i,x,n) for(ll i=x;i<=n;i++)
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>
#define mm 998244353
#define mod2 1000000009
#define br cout<<"\n"

// typedef tree<pii,null_type,less<pii>,rb_tree_tag,
// tree_order_statistics_node_update>PBDS;
ll n;
vi a;

map<pair<pii, ll>, ll>dp;

ll fun(ll i, ll orval, ll xorval) {
	if (i == n)return (xorval ^ orval);

	if (dp.count({{orval, xorval}, i}))return dp[ {{orval, xorval}, i}];

	return dp[ {{orval, xorval}, i}] = min(fun(i + 1, orval | a[i], xorval), fun(i + 1, a[i], xorval ^ orval));
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t;
	t = 1;
	// cin >> t;
	fori(test, 1, t) {

		cin >> n;

		a.resize(n);

		fori(i, 0, n - 1)cin >> a[i];

		cout << fun(0, 0, 0);

	}

	return 0;
}

#include<stdio.h>
#include<queue>
#define INF 1000000000000007
#define int long long
using namespace std;
struct pr{
	int now;
	int data;
};
int a[25];
queue<pr> q;
signed main(){
	int n,ans=INF;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	pr x;x.data=0;x.now=1;
	q.push(x);
	while(!q.empty()){
		x=q.front();q.pop();
		if(x.now>n){
			if(x.data<ans) ans=x.data;
          //hello,thank you
			continue;
		}
		int sum=x.data;
		int ths=x.now;
		int r=0;
		for(int i=ths;i<=n;i++){
			r|=a[i];
			pr y;y.data=sum^r;y.now=i+1;
			q.push(y);
		}
	}
	printf("%lld",ans);
	return 0;
}


#include <bits/stdc++.h>

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A[3]; rep(i, 3) cin >> A[i];
    sort(A, A+3);
    if(A[0] == A[1]) cout << A[2] << endl;
    else if(A[1] == A[2]) cout << A[0] << endl;
    else cout << 0 << endl;
    return 0;
}

//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
const int inf=1e9;
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
	inv[0]=1;
	inv[1] = 1;
	for(int i = 2; i <=1e6 ; ++i)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
	invf[0]=1;invf[1]=1;
	for(int i=2;i<=1e6;i++){
		invf[i]=invf[i-1]*inv[i]%mod;
	}
}*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{
	int r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	if(r1==r2 && c1==c2){
		cout<<"0"<<endl;
	}
	else if(r1+c1==r2+c2 || r1-c1==r2-c2 || abs(r1-r2)+abs(c1-c2)<=3){
		cout<<"1"<<endl;
	}
	else if((r1+r2+c1+c2)%2==0 || abs(r1-r2)+abs(c1-c2)<=6 || abs((r1-c1)-(r2-c2))<=3 || abs((r1+c1)-(r2+c2))<=3){
		cout<<"2"<<endl;
	}
	else{
			cout<<"3"<<endl;
	}
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int h,w;
  cin >> h >> w;
  int k[h][w];
  ll p=1000000007;
  int u=0;
  rep(i,h){
    string s;
    cin >> s;
    rep(j,w){
      if(s[j]=='#'){
        k[i][j]=1;
      }
      else{
        k[i][j]=0;
        u++;
      }
    }
  }
  ll o[u+1];
  o[0]=1;
  rep(i,u)o[i+1]=o[i]*2%p;
  ll ans=0;
  int hh[h][w];
  int ww[h][w];
  rep(i,h){
    rep(j,w){
      //cout << ans << endl;
      if(k[i][j]==1)continue;
      else{
        int cnt=1;
        if(i>0){
          if(k[i-1][j]==0){
            cnt=cnt-1+hh[i-1][j];
            hh[i][j]=hh[i-1][j];
          }
        }
        if(cnt==1){
          int a=i+1;
          while(true){
            if(a<0||a>h-1)break;
            if(k[a][j]==1)break;
            cnt++;
            a++;
          }
          hh[i][j]=cnt;
          //if(i==0&&j==1)cout << cnt << endl;
        }
        if(j>0){
          if(k[i][j-1]==0){
            cnt=cnt-1+ww[i][j-1];
            ww[i][j]=ww[i][j-1];
          }
        }
        if(cnt==hh[i][j]){
          int a=j+1;
          while(true){
          if(a<0||a>w-1)break;
          if(k[i][a]==1)break;
          cnt++;
          a++;
          }
          ww[i][j]=a-j;
        }

        //cout << cnt <<" " <<  o[cnt] << " " << u-cnt << endl;
        ans=(ans+(o[cnt]-1)*o[u-cnt])%p;
      }
    }
  }
  //rep(i,3)cout << hh[0][i] << endl;
  cout << ans << endl;
}

#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll bpow(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b & 1)
            res = 1LL * res * a % MOD;
        a = 1LL * a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i, j, k;

    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(auto &e : S)
        cin >> e;
    vector<vll> cv;
    vector<vll> ch;
    for(i = 0; i < H; i++) {
        vll h(W);
        ll p = 0;
        for(j = 0; j < W; j++) {
            if(S[i][j] == '.') {
                p++;
            } else {
                p = 0;
            }
            h[j] = p;
        }
        for(j = W - 2; j >= 0; j--) {
            if(h[j] > 0 && h[j + 1] > 0) {
                h[j] = h[j + 1];
            }
        }
        ch.push_back(h);
    }
    for(j = 0; j < W; j++) {
        vll v(H);
        ll p = 0;
        for(i = 0; i < H; i++) {
            if(S[i][j] == '.') {
                p++;
            } else {
                p = 0;
            }
            v[i] = p;
        }
        for(i = H - 2; i >= 0; i--) {
            if(v[i] > 0 && v[i + 1] > 0) {
                v[i] = v[i + 1];
            }
        }
        cv.push_back(v);
    }
    for(i = 0; i < H; i++) {
        for(j = 0; j < W; j++) {
            ch[i][j] += cv[j][i] - 1;
        }
    }

    ll n_e = 0;
    for(i = 0; i < H; i++) {
        for(j = 0; j < W; j++) {
            if(S[i][j] == '.')
                n_e++;
        }
    }
    ll n_b = bpow(2, n_e);

    ll ans = 0;
    for(i = 0; i < H; i++) {
        for(j = 0; j < W; j++) {
            if(S[i][j] == '#')
                continue;
            ll sub = n_b;
            ll msub = bpow(2, n_e - ch[i][j]);
            sub = (sub + MOD - msub) % MOD;
            ans = (ans + sub) % MOD;
        }
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
//1.takes nothing returns nothing
//2.takes nothing returns something
//3.takes something returns something
//4.takes something returns nothing
int digi(ll n){
    ll f=0;
    while(n>0){
        n/=10;f++;
    }
    return f;
}
bool isPrime(int n)
{

    if (n <= 1)
        return false;

    for (int i = 2; i < n; i++)
        if (n % i == 0)
             return false;

    return true;
}

ll Sum(string s)
{
    ll count=0;
    for(ll i=0;i<(s.size()-1);i++)
    {
        if(s[i]==s[i+1])
        count += 2;
        else
        count += 1;
    }
    return count;
}
ll SieveOfEratosthenes(ll n)
{

    bool prime[n + 1];
    memset(prime, true, sizeof(prime));

    for (ll p = 2; p * p <= n; p++)
    {
        // If prime[p] is not changed,
        // then it is a prime
        if (prime[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
    ll f=1;
    for (int p = 2; p <= n; p++){
        if (prime[p]==true && p*2>n){
            f++;//cout<<p<<" ";
            }

    }
    return f;
}
void print(int n){
   ll i=0,sum=0;
    for(i=0;i<n;i++){

        sum+=i;
    }
    cout<<sum<<" ";
}
//function declaration
//function defining
//function calling
int main() {
    ll t;t=1;
    while(t--){
    ll n,m,i,f=0;cin>>n>>m;ll a[n+5];
   if(n==m)
   cout<<n<<endl;
   else if(n==1&&m==2)
    cout<<"0"<<endl;
     else if(n==0&&m==1)
    cout<<"2"<<endl;
     else if(n==2&&m==1)
    cout<<"0"<<endl;
     else if(n==1&&m==0)
    cout<<"2"<<endl;
     else if(n==0&&m==2)
    cout<<"1"<<endl;
     else if(n==2&&m==0)
    cout<<"1"<<endl;

    }
}

#include<bits/stdc++.h>
#define ll long long int
#define ld long  double
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)

#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{

	fio;
    ll t,i,j,u,v,n,m,x,k,p,c,y;
    cin>>x>>y;
    ll mini=min(x,y),maxi=max(x,y);
    if(mini+3>maxi)
    {
    	cout<<"Yes";
	}
	else
	cout<<"No";

}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<ll>

#define all(v) v.begin(), v.end()
#define endl "\n"

#define MOD 1e9 + 7

int main()
{
    int n, i, j;
    cin >> n;
    int A[n], B[n];
    for (i = 0; i < n; i++)
        cin >> A[i];
    for (i = 0; i < n; i++)
        cin >> B[i];
    vector<int> v;
    int cnt = 0;
    for (i = 1; i <= 1000; i++)
    {
        int c = 0;
        for (j = 0; j < n; j++)
        {
            if (i <= B[j] && i >= A[j])
                c++;
        }
        if (c == n)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

#include <bits/stdc++.h>
#define setIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265358979
#define f first
#define s second
#define ar array
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<long long, long long> pll;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
typedef pair<double, double> pdd;
typedef pair<int, string> pis;
int main() { // Ladder: Do 43
    setIO;
    int a; cin >> a;
    int mx = INT_MIN, mn = INT_MAX;
    for (int i = 0; i < a; i++) {
        int x; cin >> x;
        mx = max(mx, x);
    }
    for (int i = 0; i < a; i++) {
        int x; cin >> x;
        mn = min(mn, x);
    }
    if (mn-mx<0) cout << 0;
    else cout << mn-mx+1;
}


#include <bits/stdc++.h>
using namespace std;
char s[4];
int main()
{
	cin >> s;
	cout << s[1] << s[2] << s[0] << endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 998244353;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//union-find木について
//サイズによる更新をしている
ll par[201010];
ll rank2[201010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 1;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
		rank2[y] += rank2[x];
	}
	else {
		par[y] = x;
		rank2[x] += rank2[y];
	}
}

ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
vector<vector<pair<ll, ll>>>to;
bool flag[101010];
ll dist[101010];

void dfs(ll v) {
	flag[v] = true;
	for (auto nv : to[v]) {
		ll nv2 = nv.first;
		ll dist2 = nv.second;
		if (flag[nv2] == false) {
			dist[nv2] = dist[v] + dist2;
			dfs(nv2);
		}
	}
}

ll c[1010][1010];
ll a[1010], b[1010];
ll dp[201010], dp2[201010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	string s, ans;
	cin >> s;
	for (ll i = 1;i <= 2;++i)ans += s[i];
	ans += s[0];
	cout << ans << endl;
	return 0;
}


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

int main ()
{
    long long int n, t, save;
    cin >> n;
    t= 0;
    for(long long int i=1; ; i++)
    {
        t+= i;
        if(t>=n)
        {
            save= i;
            break;
        }
    }

    cout << save << endl;

    return 0;
}

/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define int      long long
#define double   long double
#define uint     unsigned long long
#define all(vec) vec.begin(),vec.end()
#define endl "\n"
int google_itr = 1;
#define google(x) cout<<"Case #"<<x<<": "
#define pi 3.14159265358979323846264338327950L

vector<string> vec_splitter(string s) {
        s += ',';
        vector<string> res;
        while(!s.empty()) {
                res.push_back(s.substr(0, s.find(',')));
                s = s.substr(s.find(',') + 1);
        }
        return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
        if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
        stringstream ss; ss << H;
        cerr << args[idx] << " = " << ss.str();
        debug_out(args, idx + 1, LINE_NUM, T...);
}

#define XOX
#ifdef XOX
    #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
    #define deb(...) 42
#endif

const int mod = 1e9+7;
const int inf = 1e18;

void virus(){
        int n;
        cin >> n;
        cout << ((n&1) ? "Black" : "White");
}

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

  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    int t = 1;
    //cin >> t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
           //cerr << "\n Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}


#include<bits/stdc++.h>
#include<chrono>
using namespace std;
using namespace chrono;
typedef long long int lli;
typedef long long ll;

lli M=1000000007;
lli mod(lli a) { return ((a%M+M)%M);}
lli add(lli a,lli b) { return mod(mod(a)+mod(b));}
lli multiply(lli a,lli b) { return mod(mod(a)*mod(b));}
lli min(lli a,lli b) { if(a<b) return a; return b;}
lli max(lli a,lli b) { return (a>b)?a:b;}
lli modexpo(lli a,lli b){
    lli res = 1;
    while(b>0){
    	if(b&1) res = (res*a)%M;
    	a = (a*a)%M;
    	b/=2;
    }
    return res;
}

void solve(){
  ll n;
  cin>>n;
  n*=2;
  ll i=1;
  ll ans=0;
  while(true && i<n){
    if(n%i==0){
      ll a=i;
      ll b=n/i;
      // cout<<a<<":"<<b<<" ";
      if(a>b) break;
      // if(a==b){
      //   ll j=2*n-i-1;
      //   if(j%2==0) ans+=1;
      //   break;
      // }
      ll j=(b-i-1);
      if(j<0) break;
      // ll t=2*n
      // cout<<j<<" ";
      if(j%2==0) ans+=2;
      i++;
    }
    else if((i*i)>n) break;
    else i++;
  }
  cout<<ans<<"\n";
}

int main(){
    #ifndef ONLINE_JUDGE
		freopen("input.txt", "r" ,stdin);
		// freopen("output.txt", "w" ,stdout);
	  #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // auto start1 = high_resolution_clock::now();
    solve();
    // int t;
    // cin>>t;
    // while(t--) solve();
    // auto stop1 = high_resolution_clock::now();
	  // auto duration = duration_cast<microseconds>(stop1 - start1);
    // #ifndef ONLINE_JUDGE
		// cerr << "Time: " << duration.count() / 1000.0 << endl;
	  // cout<<duration.count()/1000.0<<endl;
    // #endif
    return 0;
}

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

using namespace std;

#define fr(i, s, t) for(int (i) = s; (i) <= t; (i)++)

typedef long long ll;

const int MAX_V = 100005;
const int IINF = 0x3f3f3f3f;

double x[MAX_V], h[MAX_V];

int n, m, q;

void solve()
{
	string s;
	cin>>s;
	s += s[0];
	s.erase(s.begin());
	cout<<s<<'\n';
}

int main(void)
{
	int t = 1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
    x = 0; int c = gc(); int flag = 0;
    while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
    if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int N = 200005, inf = 0x3f3f3f3f;
int n, k;
vector<int> G[N];
int l[N], z1, Q;
int dis[N], dp[N], far[N];
void add_edge(int x, int y)
{
	G[x].push_back(y);
}

void dfs(int x, int f, int d)
{
	l[x] = d;
	for (int i = 0; i < sz(G[x]); ++i)
	{
		int to = G[x][i];
		if (to == f) continue;
		dfs(to, x, d + 1);
	}
}

void init()
{
	read(n); read(k);
	for (int i = 1, v, u; i < n; ++i)
	{
		read(u); read(v);
		add_edge(u, v);
		add_edge(v, u);
	}
	dfs(1, 0, 0);
	int mx = 0;
	for (int i = 1; i <= n; ++i) if (checkmax(mx, l[i])) z1 = i;
}

void run(int x, int f)
{
	dp[x] = 0; far[x] = -inf; dis[x] = inf;
	int child = 0;
	for (int i = 0; i < sz(G[x]); ++i)
	{
		int to = G[x][i];
		if (to == f) continue;
		++child;
		run(to, x);
		checkmin(dis[x], dis[to] + 1);
		dp[x] += dp[to];
	}
	if (child == 0)
	{
		dp[x] = far[x] = 0;
		dis[x] = inf;
	}
	else
	{
		for (int i = 0; i < sz(G[x]); ++i)
		{
			int to = G[x][i];
			if (to == f) continue;
			if (Q < dis[x] + far[to] + 1) checkmax(far[x], far[to] + 1);
		}
		//out(x); out(far[x]); outln(dis[x]);
		if (far[x] == Q || dis[x] == Q + Q + 1)
		{
			++dp[x];
			dis[x] = 0; far[x] = -inf;
		}
	}
	//out(Q); out(x); out(dp[x]); out(dis[x]); outln(far[x]);
}

bool check(int mid)
{
	Q = mid;
	run(z1, 0);
	if (dis[z1] > Q) ++dp[z1];
	if (dp[z1] <= k) return 1;
	else return 0;
}

void solve()
{
	int l = 1, r = n - 1, mid, best = n - 1;
	while (l <= r)
	{
		mid = (l + r) >> 1;
		if (check(mid)) best = mid, r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", best);
}

int main()
{
	//setIO("");
	init();
	solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,K,V;
vector<int> E[202020];

int need[202020],aff[202020];
int num;

void dfs(int cur,int pre) {
	need[cur]=0;
	aff[cur]=-1;

	FORR(e,E[cur]) if(e!=pre) {
		dfs(e,cur);
		if(aff[e]>=0) aff[cur]=max(aff[cur],aff[e]-1);
		if(need[e]>=0) need[cur]=max(need[cur],need[e]+1);
	}

	if(aff[cur]>=need[cur]) {
		need[cur]=-1;
	}
	else {
		if(need[cur]>=V) {
			need[cur]=-1;
			aff[cur]=V;
			num++;
		}
		else {
			aff[cur]=-1;
		}
	}

}

int ok(int v) {
	if(v<=0) return 0;

	V=v;
	num=0;
	dfs(0,0);
	if(need[0]>=0) num++;
	return num<=K;
}

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

	cin>>N>>K;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	int ret=N;
	for(j=20;j>=0;j--) if(ok(ret-(1<<j))) ret-=1<<j;
	cout<<ret<<endl;

}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define all(x) (x).begin(), (x).end()
#define Unique(a)       a.erase(unique(all(a)), a.end())
#define ld long double
#define pb push_back
#define fi first
#define se second
#define inf 1e9
using namespace std;
typedef long long int ll;

const int mxn=2e5+5,mod=1e9+7;

int main(void){
    fast;
    int n;
    cin>>n;
    int t[n],sum=0;
    for(int i=0;i<n;i++){
        cin>>t[i];
        sum+=t[i];
    }
    int dp[sum+1]={0};
    dp[0]=1;
    for(int i=0;i<n;i++){
        for(int j=sum-t[i];j>=0;j--){
            if(dp[j]){
                dp[j+t[i]]=1;
            }
        }
    }
    int i,ans=sum;
    for(i=1;i<=sum;i++){
        if(dp[i]==1)
            ans=min(ans,max(i,sum-i));
    }
    cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 998244353
typedef  long long ll;
typedef long double ld;
long double pi=3.14159265358979323846;

vll al[300005];
ll I[101][101];

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

bool isPrime(int n)
{
    if (n<=1) return false;
    if (n<=3) return true;
    if (n%2==0||n%3==0) return false;
    for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false;
    return true;
}

ll bpow(ll n, ll po)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res=(res*n)%mod;
			po--;
		}
		else
		{
			n=(n*n)%mod;
			po/=2;
		}
	}
	return res;
}

void swap(ll *a, ll *b)
{
	ll temp=*a;
	*a=*b;
	*b=temp;
}

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

ll modInverse(ll n,ll p)
{
	return bpow(n,p-2);
}

ll fac[300001];

ll nCr(ll n,ll r)
{
    if (r == 0) return 1;
    return (fac[n] * modInverse(fac[r], mod) % mod * modInverse(fac[n - r], mod) % mod) % mod;
}

//bool bipartite_dfs(ll node, ll flag)
//{
//	vis[node]=1;
//	ll cflag=flag;
//	color[node]=cflag;
//	for(ll child : al[node])
//	{
//		if(!vis[child])
//		{
//			bool n=bipartite_dfs(child,1-cflag);
//			if(n==false) return false;
//		}
//		else if(color[child]==color[node]) return false;
//	}
//	return true;
//}

void mmul(ll A[][101], ll B[][101], ll dim)
{
	ll res[dim][dim];
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		res[i][j]=0;
		for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007;
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j];
}

void mpow(ll A[][101],ll dim, ll po)
{
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		if(i==j) I[i][j]=1;
		else I[i][j]=0;
	}
	while(po>0)
	{
		if(po%2==1)
		{
			mmul(I,A,dim);
			po--;
		}
		else
		{
			mmul(A,A,dim);
			po/=2;
		}
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j];
}

int main()
{
	FAST
//	freopen("d.txt","r",stdin);
//    freopen("outputd.txt","w",stdout);
	ll testcases=1;
//	cin>>testcases;
//	fac[0]=1;
//	for(ll i=1;i<300001;i++) fac[i]=(fac[i-1]*i)%mod;
	while(testcases--)
	{
		ll n;
		cin>>n;
		ll a[n];
		for(ll i=0;i<n;i++) cin>>a[i];
		sort(a,a+n);
		ll sum=0,ans=0;
		for(ll i=0;i<n;i++) sum+=a[i];
		ll dp[n+1][sum/2+1];
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for(ll i=1;i<=n;i++)
		{
			for(ll j=0;j<=sum/2;j++)
			{
				if(j<a[i-1]) dp[i][j]=dp[i-1][j];
				else dp[i][j]=max(dp[i-1][j-a[i-1]],dp[i-1][j]);
			}
		}
//		for(ll i=0;i<=n)
		for(ll i=sum/2;i>=0;i--)
		{
			if(dp[n][i]==1)
			{
				ans=sum-i;
				break;
			}
		}
		cout<<ans;
	}
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define ull unsigned long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    double a,b;
    cin >> a >> b;
    cout << fixed << setprecision(8) << a*b/100.0 << endl;
}

#include<iostream>
using namespace std;
int main()
{
    float a,b;
    cin >> a;
    cin >> b;
    cout << a*(b/100);
    return 0;
}


#include <iostream>
#include <cmath>

int main(void) {
  int64_t A;
  int64_t B;
  int64_t C;

  std::cin >> A >> B >> C;

  if (C % 2 == 0) {
    if (std::abs(A) == std::abs(B)) {
      std::cout << "=" << std::endl;
    } else if (std::abs(A) < std::abs(B)) {
      std::cout << "<" << std::endl;
    } else {
      std::cout << ">" << std::endl;
    }
  } else {
    if (A == B) {
      std::cout << "=" << std::endl;
    } else if (A < B) {
      std::cout << "<" << std::endl;
    } else {
      std::cout << ">" << std::endl;
    }
  }
}

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define cerr if(0) cerr
#define ll  long long int
#define fp cout<<fixed<<setprecision(15);
#define loop(var,s,n) for(ll var=s ;var<n;var++)
#define rloop(var,s,n) for(ll var=s ;var>=n;var--)
#define pb push_back
#define endl '\n'
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define ipair pair<ll,pair<ll,ll>>
using namespace std;

int main() {
#ifdef KEVIN
  freopen("ingoing3.txt", "r", stdin);
  freopen("outgoing3.txt", "w", stdout);
#endif
  FAST
  int t = 1;
 // cin >> t;
  while (t--)
  {
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b)
    {
      cout<<"=";
      return 0;
    }
    if(a>=0&&b>=0)
    {
      if(a<b)cout<<"<";
      else cout<<">";
      return 0;
    }
    if(c%2==0)
    {
      if(abs(a)>abs(b))
      {
        cout<<">";
      }
      else if(abs(a)<abs(b))
      {
        cout<<"<";
      }
      else cout<<"=";
      return 0;
    }
    if(a<b)cout<<"<";
    else cout<<">";
   }
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    string s;
    cin >> s;
    itn time  = 0;
    FOR(i,3,s.size()){
        string a;
        a.push_back(s[i - 3]);
        a.push_back(s[i - 2]);
        a.push_back(s[i - 1]);
        a.push_back(s[i]);
        if(a == "ZONe") time++;
    }

    println(time);
    return 0;
}

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

int main(){
    long N,i,ans;
    cin>>N;
    string a,b,c;
    for(i=0;i<N;++i){
        a.replace(i,1,"1");
        b.replace(i,1,"1");
        c.replace(i,1,"1");
        if(i%3==0){
            c.replace(i,1,"0");
        }
        else if(i%3==1){
            b.replace(i,1,"0");
        }
        else{
            a.replace(i,1,"0");
        }
    }
    string T;
    cin>>T;
  if(N>=2){
    if(T.compare(a)==0){
        ans=1e10-(N+2)/3+1;
    }
    else if(T.compare(b)==0){
        ans=1e10-N/3;
    }
    else if(T.compare(c)==0){
        ans=1e10-(N+1)/3;
    }
    else{
        ans=0;
    }
}
  if(N==1){
        if(T.compare("1")==0){
            ans=2*1e10;
        }
        else{
            ans=1e10;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main() {
  int N;
  string s,t;
  cin >> N >> s;
  for (char c: s) {
    t.append(1,c);
    if (t.length()>2 && t.substr(t.length()-3,3) == "fox") {
      t.resize(t.length()-3);
    }
  }

  cout << t.length() << endl;
}

//IQ134高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int mobius[1000001] = {};

int main() {
	ll ans = 0;
	ll tmp = 0;
	//int n; cin >> n;
    ll L, R; cin >> L >> R;

	//エラトステネスの篩でP_max以下の素数vector primeをつくる
	bool *pr;
	int P_max = 2000000; //10^6くらいまでが現実的か
	pr = (bool*)malloc(sizeof(bool) * (P_max+1));
	REP(i, P_max + 1) pr[i] = true;
	pr[0] = false;
	pr[1] = false;
	int dx[P_max] = {}; // xを割り切る最小の素数の配列(素因数分解に使う)
	for(int i = 2; i * i <= P_max; i++){
		if(pr[i] == true){
			for(int j = 2 * i; j <= P_max; j+=i){
				pr[j] = false;
				if(dx[j] == 0) dx[j] = i;
			}
		}
	}
	vector<int> prime;
	for(int i = 2; i <= P_max; i++){
		if(pr[i]) prime.push_back(i);
	}
	//

	//配列dxを使って整数Xの素因数分解の結果をmapで返す。
	map<int, int> prf;
    for(int mo = 2; mo <= R; mo++){
        int X = mo;
        int diving = X; //これをどんどん割っていく。dividingが正しい
        prf.clear();
        while(dx[diving] != 0){
            prf[dx[diving]]++;
            diving /= dx[diving];
            //重複なしで割り切れる素数を列挙する場合は上の行をコメントアウトして下を使う
            //int nowdx = dx[diving]; while (diving % nowdx == 0) diving /= nowdx;
        }
        if(diving > 1)prf[diving]++;
        //これは素因数分解の結果が見たくなったときに使うもの
        //for(auto i = prf.begin(); i!= prf.end(); i++) cout << i->first << "," << i->second << " "; cout << endl;
        //
        //メビウス関数の計算
        mobius[mo] = 1;
        for(auto i = prf.begin(); i!= prf.end(); i++){
            if(i->second == 1) mobius[mo] *= -1;
            else if(i->second > 1) mobius[mo] = 0;
        }
        //メビウス関数の結果の反映
        ll a = R / mo - (L-1) / mo;
        ans += (-1LL) * mobius[mo] * a * (a-1) / 2;
    }
    for(int k = max(2LL, L); k <= R; k++){
        ans -= R / k - (L-1) / k - 1;
    }
	cout << ans * 2 << endl;
}


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

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

LL a, b, c;

LL cal(LL x){
	x = (x + 1) * x / 2;
	return x % mod;
}

int main(){
	scanf("%lld %lld %lld", &a, &b, &c);
	printf("%lld\n", cal(a) * cal(b) % mod * cal(c) % mod);
	return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<algorithm>
constexpr long long MOD = 998244353;
constexpr long long MOD32 = 665496236;

int main(){
    long H=0, W=0, K=0;
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {H=(H<<1)+(H<<3)+c-'0'; c=getchar_unlocked();}
    c=getchar_unlocked();
    while(c<='9'&&c>='0') {W=(W<<1)+(W<<3)+c-'0'; c=getchar_unlocked();}
    c=getchar_unlocked();
    while(c<='9'&&c>='0') {K=(K<<1)+(K<<3)+c-'0'; c=getchar_unlocked();}
    char f[H][W];
    std::fill(f[0], f[H], 0);

    long long y = H * W - K;
    while(--K>=0){
        long h=0, w=0;
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {h=(h<<1)+(h<<3)+c-'0'; c=getchar_unlocked();}
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {w=(w<<1)+(w<<3)+c-'0'; c=getchar_unlocked();}
        f[h-1][w-1] = getchar_unlocked();
        getchar_unlocked();
    }
    --H; --W;
    long long dp[W+1] = {0};
    dp[0] = 1;
    for(int i = 0; i < H; ++i){
        for (int j = 0; j < W; ++j){
            switch(f[i][j]) {
                case 'R':
                    dp[j + 1] += dp[j];
                    dp[j] = 0;
                    break;
                case '\0':
                    dp[j] = dp[j] * MOD32 % MOD;
                case 'X':
                    dp[j + 1] += dp[j];
            }
        }
            switch(f[i][W]) {
                case 'R':
                    dp[W] = 0;
                    break;
                case '\0':
                    dp[W] = dp[W] * MOD32 % MOD;
            }
    }
    for (int j = 0; j < W; ++j){
        switch(f[H][j]) {
            case '\0':
                dp[j] = dp[j] * MOD32 % MOD;
            case 'R':
            case 'X':
                dp[j + 1] += dp[j];
        }
    }

    long long ans = dp[W] % MOD;
    long long x = 3;
    while(y) {
      if(y & 1) ans = ans * x % MOD;
      x = x * x % MOD;
      y >>= 1;
    }
    printf("%d", ans);

    return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

//head

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  ll n;
  cin >> s >> n;
  ll u = *max_element(all(s))-'0';
  u++;
  int cnt = 0;
  int siz = s.size();
  if(siz == 1) {
    cout << (n >= stoi(s)) << endl;
    return 0;
  }
  if(siz == 2) {
    if(u*(s[0]-'0')+(s[1]-'0') > n) {
      cout << "0\n";
      return 0;
    }
    int s0 = s[0]-'0';
    int s1 = s[1]-'0';
    ll x = (n-s1)/s0;
    cout << x-u+1 << endl;
    return 0;
  }
  if(siz == 3) {
    ll s0 = s[0]-'0';
    ll s1 = s[1]-'0';
    ll s2 = s[2]-'0';
    if(s0*u*u+s1*u+s2 > n) {
      cout << "0\n";
      return 0;
    }
    __int128_t lb = u, ub = 1e9+100;
    while(ub != lb+1) {
      __int128_t mid = (lb+ub)/2;
      if(s0*mid*mid+s1*mid+s2 > n) ub = mid;
      else lb = mid;
    }
    cout << ll(ub-u) << endl;
    return 0;
  }
  while(true) {
    __int128_t k = 1, x = 0;
    rep(i, siz-1) {
      k *= u;
      if(k > n) goto OUT;
    }
    rep(i, siz) {
      x += k*(s[i]-'0');
      k /= u;
    }
    if(x > n) goto OUT;
    u++;
    cnt++;
  }
OUT:;
  cout << cnt << endl;
}

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

#define int long long
#define FOR(i, size) for (int i = 0; i < size; i++)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define MOD 1000000007

#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template <typename... Args>
void logger(string vars, Args &&...values)
{
	cout << vars << " = ";
	string delim = "";
	(..., (cout << delim << values, delim = ", "));
}

template <typename T>
void print_list(vector<T> collection, bool newline = true)
{
	for (const auto &item : collection)
	{
		cout << item << " ";
	}
	if (newline)
		cout << endl;
}

#define ONE_TESTCASE 1

int n, m, timer;

void Solve()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int de = c * d - b;
	if (de <= 0)
	{
		cout << -1;
		return;
	}

	int ans = a / de;
	cout << (ans + (a % de == 0 ? 0 : 1));
}

int32_t main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

#if ONE_TESTCASE
	int test = 1;
#else
	int test;
	cin >> test;
#endif

	for (int t = 1; t <= test; t++)
	{
		Solve();
		cout << endl;
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include <utility>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,l,n) for(ll i=(l);i<(n);i++)
#define per(i,n) for(ll i=(n);i>0;i--)
#define pf(n) printf("%d\n",n)
#define pf_(a) printf("%d  ",a);
#define all(v) begin(v),end(v)
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);
const ll mod = 1000000007;

struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n) {
		rep(i, n) par[i] = i;
	}
	int root(int x) {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	ll n, w;
	cin >> n >> w;
	vector<ll> T(1001001, 0);
	ll mt = 0;
	rep(i, n) {
		ll s, t, p;
		cin >> s >> t >> p;
		T[s] += p;
		T[t] += -p;
		mt = max(mt, t);
	}
	ll cnt = 0;
	bool ok = true;
	rep(i, mt) {
		if (T[i] > 0) {
			cnt += T[i];
			//cout << cnt << endl;
			if (cnt > w) ok = false;
		}
		else if(T[i] < 0){
			cnt += T[i];
		}
	}
	puts(ok ? "Yes" : "No");

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   fastIO
    int x,y; cin>>x>>y;
    if(x==y){
      cout<<x<<"\n";
    }
    else{
      set<int> s;
      rep(i,0,3)s.insert(i);
      s.erase(x),s.erase(y);
      cout<<*s.begin()<<"\n";
    }
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n; cin >> n;
    double ans = 0;
    for (int i = 1; i <= n-1; i++){
        ans += 1.0*n/i;
    }
    cout << fixed << setprecision(8) << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second)return a.second < b.second;
    else return a.first < b.first;
}

void solve(long long N){
    double ret = 0;
    for(int i= N-1; i >=1; i--){
        ret+=(double)N/(double)i;
    }
    cout<<setprecision(12)<<ret<<endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> r(n);
    for(int i = 0;i < n;i++)cin >> x[i] >> y[i] >> r[i];
    for(int i = 0;i < n;i++){
        ll xsi = 0;
        ll ysi = 0;
        ll xmin = 10000;
        ll ymin = 10000;
        for(int j = 0;j < n;j++){
            if(x[i] < x[j])xmin = min(xmin,x[j]);
            if(y[i] < y[j])ymin = min(ymin,y[j]);
        }
        //if(xmin * ymin > r[i])xmin = max((ll)1,r[i] / ymin - 1);
        /*while(1){
            bool can = true;
            for(int j = 0;j < n;j++){
                if(i == j || (x[i] > x[j] && y[i] > y[j]))continue;
                if(x[j] <= x[i] + xsi && y[j] <= y[i] + ysi){
                    can = false;
                    j = n;
                }
            }
            if(!can || xsi * ysi >= r[i] || x[i] + xsi >= 10000 || y[i] + ysi >= 10000)break;
            xsi++,ysi++;
        }*/
        cout << x[i] << " " << y[i] << " " << xmin << " " << ymin << endl;
    }
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,a[200010],b[200010],p[200010],pos[200010];
vector <int> v;
vector <pii> ans;

bool cmp(int x,int y)
{
  return b[x]>b[y];
}

int main()
{
  cin>>n;
  rep(i,n) scanf("%d",&a[i]);
  rep(i,n) scanf("%d",&b[i]);
  rep(i,n)
  {
    scanf("%d",&p[i]),--p[i];
    if(p[i]!=i&&b[p[i]]>=a[i])
    {
      puts("-1");
      return 0;
    }
    pos[p[i]]=i;
    v.pb(i);
  }
  sort(v.begin(),v.end(),cmp);
  //rep(i,v.size()) cout<<v[i]<<'p'<<endl;
  rep(i,n)
  {
    if(pos[v[i]]==v[i]) continue;
    ans.pb(mpr(pos[v[i]],v[i]));
    int aa=pos[v[i]],bb=v[i],cc=v[i],dd=p[v[i]];
    p[cc]=bb;
    p[aa]=dd;
    pos[bb]=cc;
    pos[dd]=aa;
  }
  cout<<ans.size()<<endl;
  rep(i,ans.size()) printf("%d %d\n",ans[i].fi+1,ans[i].se+1);
	return 0;
}

//Jo Hack kiya Wo Madharchod

#include"bits/stdc++.h"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long int
#define inf 1e18+5
#define sr string
#define M 1000000007 //998244353//
#define start int t;cin>>t;while(t--)
#define db(x) cout<<#x<<"="<<x<<"\n"
#define db2(a,b)cout<<#a<<": "<<a<<" , "<<#b<<": "<<b<< endl;
#define db3(a,b,c)cout<<#a<<": "<<a<<" , "<<#b<<": "<<b<<" , "<<#c<<": "<<c<<endl;
#define forr(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = 1; i <= n; i++)
#define rep(i,j,k) for(int i = j; i < k; i++)
#define rp(i,j,k) for(int i = j; i <=k; i++)
#define nn "\n"
#define en "\n"
#define vvi vector<vector<ll>>
#define vi vector<int>
#define si set<ll>
#define mlsi multiset<ll>
#define vc vector<char>
#define vli vector<long long int>
#define vpii vector<pair<ll,ll>>
#define pii pair<ll,ll>
#define mii map<ll,ll>
#define msi map<string,int>
#define mci map<char,int>
#define umii unordered_map<ll,ll>
#define umsi unordered_map<string,int>
#define umci unordered_map<char,int>
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sortv(x) sort(x.begin(),x.end())
#define sorta(x,n) sort(x,x+n)
#define sorted(x) is_sorted(x.begin(),x.end())
#define print_all(x) for(auto t:x) cout<<t<<" ";cout<<en;
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define ad(x) accumulate(all(x),0)
#define ub upper_bound
#define lb lower_bound
#define go(x) for(auto &[u,v]:x)
#define gov(v) for(auto &x:v)
#define in(x) cin>>x
#define in2(x,y) cin>>x>>y
#define in3(x,y,z) cin>>x>>y>>z
#define in4(x,y,z,v) cin>>x>>y>>z>>v
#define oo(x) cout<<x<<en
#define oo2(x,y) cout<<x<<" "<<y<<en
#define oo3(x,y,z) cout<<x<<" "<<y<<" "<<z<<en
#define ood(n,x) cout<<fixed<<setprecision(n)<<x<<"\n"
#define sz(x) x.size()
#define ff first
#define ss second
#define ooy cout<<"Yes\n"
#define oon cout<<"No\n"
#define ooyy cout<<"YES\n"
#define oonn cout<<"NO\n"
#define rr return
#define cc continue

using namespace std;

template<class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

void read(vli &a,int n){
    a.resize(n);
    forr(i,n) cin>>a[i];
}

bool fine=0;
vli a;
ll n,m,k,x,p,q;

void solve(){

    in(n);
    if(n&1){
        cout<<"Black";
    }
    else cout<<"White";

}
int main(){
   #ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
    freopen("output1.txt", "w", stdout);
    #endif
    fast;
    if(fine){
        start{
            solve();
        }
   }
   else solve();
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

template <class T>
void chmin(T& a, T b) {
  if (a > b) a = b;
}

template <class T>
void chmax(T& a, T b) {
  if (a < b) a = b;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  ll ans = 0;
  rep(l, 0, n) {
    int x = a[l];
    rep(r, l, n) {
      chmin(x, a[r]);
      chmax(ans, x * (r - l + 1));
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define rep(i,a) for(i=0;i<=a;i++)
#define repr(i,a) for(i=a;i>=0;i--)
#define repp(i,a,b) for(i=a;i<=b;i++)
#define reppr(i,b,a) for(i=b;i>=a;i--)
#define maxarr(a,n) *max_element(a,a+n);
#define minarr(a,n) *min_element(a,a+n);
#define ll long long int
#define p(ans) cout<<ans<<endl;
#define pb push_back
#define pob pop_back
#define Groza ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define MOD 1000000007
#define Max 1000000000
#define pyn(flag) cout<<(flag?"YES":"NO")<<endl;
#define f first
#define s second
#define parr(a,i,n) for(i=0;i<n;i++)cout<<a[i]<<" ";
#define all(v) v.begin(),v.end()
#define in insert
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll poww(const ll &a, ll b, const ll &m = MOD)
{   if (b == 0)
        return 1;
    ll x = poww(a, b / 2, m);
    x = x * x % m;
    if (b & 1)
        x = x * a % m;
    return x;
}
template <class T>
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr = "")
{
    typename T::const_iterator pos;

    std::cout << optcstr;
    for (pos = coll.begin(); pos != coll.end(); ++pos) {
        std::cout << *pos << ' ';
    }
    std::cout << std::endl;
}
template <class T>
inline void INSERT_ELEMENTS (T& coll, int first, int last)
{
    for (int i = first; i <= last; ++i) {
        coll.insert(coll.end(), i);
    }
}

//ll spf[1000000],sum;

/*const int N = 5005;
std::vector<int> v[N];
bool ans = false;
int vis[N];
map<ll, ll>m;
//ll cnt = 0;

void dfs(ll n, ll par, ll cnt)
{
    vis[n] = 1;
    for (auto x : v[n])
    {
        if (!vis[x])
        {
            dfs(x, n, cnt + 1);
        }
        else if (vis[x] && cnt == 3 && par != x)
        {
            ans = true;
            return;
        }
    }
}*/

/*std::vector<ll> res;
bool prime[MOD];
void seive(int n)
{
    memset(prime, true, sizeof(prime));

    for (int p = 2; p * p <= n; p++)
    {
        if (prime[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
    for (int p = 2; p <= n; p++)
        if (prime[p])
            res.pb(p);
}

/*const int N = 1000007;
int fact[N];
int nCr(int n, int r){
   int x =fact[r]*fact[n-r]%MOD;
   return (fact[n]*poww( x ,MOD-2))%MOD;
}
*/

float Round(float var)
{
    float value = (int)(var * 100 + .5);
    return (float)value / 100;
}

ll sumofdigit(ll n)
{
    ll sum = 0;
    while (n > 0)
    {
        sum += 1;
        n = n / 10;
    }
    return sum;
}

/*
int lcs( string X, string Y, int m, int n )
{
    int L[m + 1][n + 1];
    int i, j;
    for (i = 0; i <= m; i++)
    {
        for (j = 0; j <= n; j++)
        {
        if (i == 0 || j == 0)
            L[i][j] = 0;

        else if (X[i - 1] == Y[j - 1])
            L[i][j] = L[i - 1][j - 1] + 1;

        else
            L[i][j] = max(L[i - 1][j], L[i][j - 1]);
        }
    }
    return L[m][n];
} */

using namespace __gnu_pbds;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    Groza;
    ll t = 1;
    //cin >> t;
    //seive(MOD);
    while (t--)
    {
        ll n, k;
        cin >> n >> k;
        ll i = 0, sum = 0, j = 0, rem = 0;
        repp(i, 1, n)
        {
            rem = i * 100;
            repp(j, 1, k)
            {
                sum += (rem + j);
            }
        }
        p(sum);
    }
    return 0;
}


#include <bits/stdc++.h>

#define forsn(i,s,n) for(tint i=(s);i<(tint)(n); i++)
#define forn(i,n) forsn(i,0,n)
#define dforn(i,n) for(tint i = tint(n)-1; i >= 0; i--)
#define debug(x) cout << #x << " = "  << x << endl

using namespace std;

typedef long long tint;

random_device rd;
mt19937 gen(rd());

uniform_int_distribution<tint> dis(1, 10000);

void imprimirVector (vector<tint> v)
{
	if (!v.empty())
	{
		tint p = tint(v.size());
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

const tint MAXR = 7;

tint mod(tint a, tint b)
{
	a %= b;
	if (a < 0)
		a += b;
	return a;
}

tint mult_table[10][10];

int main()
{
	#ifdef ACMTUYO
		assert(freopen("entrada.in", "r", stdin));
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	tint n;
	string s, x;
	forn(k1,10)
	forn(k2,10)
		mult_table[k1][k2] = mod(k1*10 + k2, MAXR);
	while (cin >> n >> s >> x)
	{
		vector<vector<tint> > win (n+1, vector<tint> (MAXR,0));
		forn(k,MAXR)
			win[n][k] = 0;
		win[n][0] = 1;

		for (tint i = n-1; i >= 0; i--)
		{
			if (x[i] == 'A')
			{
				forn(k,MAXR)
				{
					tint move1 = win[i+1][mult_table[k][0]];
					tint move2 = win[i+1][mult_table[k][s[i]-'0']];
					win[i][k] = tint((move1 + move2 ) == 2);
				}
			}
			else
			{
				forn(k,MAXR)
				{
					tint move1 = win[i+1][mult_table[k][0]];
					tint move2 = win[i+1][mult_table[k][s[i]-'0']];
					win[i][k] = tint((move1 + move2) > 0);
				}
			}
		}

		if (win[0][0] > 0)
			cout << "Takahashi\n";
		else
			cout << "Aoki\n";

	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  string x; cin >> x;
  set<int> st;
  rep(i, 10) if(i) st.insert(i);
  reverse(all(s));
  reverse(all(x));
  rep(i, n) {
    if(x[i] == 'T') {
      set<int> nextSt;
      rep(j, 10) nextSt.insert(j);
      rep(j, 10) {
        if(!st.count((j*10+(s[i]-'0'))%7)) nextSt.erase(j);
        if(!st.count((j*10)%7)) nextSt.erase(j);
      }
      st = nextSt;
    } else {
      set<int> nextSt;
      rep(j, 10) {
        if(st.count((j*10+(s[i]-'0'))%7)) nextSt.insert(j);
        if(st.count((j*10)%7)) nextSt.insert(j);
      }
      st = nextSt;
    }
  }
  cout << (st.count(0) ? "Aoki" : "Takahashi") << endk;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
vector<int>v[N];

int main()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   if(s[0]==s[s.size()-1])
   {
       char x=s[0];
       int o=0;
   for(int i=1; i<s.size()-1; i++)
   {
       if(x!=s[i] && x!=s[i+1])
       {
           o=1;
           break;
       }
   }
   if(o==1)
   {
       cout<<"2"<<endl;
   }
   else
   {
       cout<<"-1"<<endl;
   }
   }
   else
   {
       cout<<1<<endl;
   }
}

/*########################################################################
# File Name: d.cpp
# Author: SoMnus_L
# Mail: lr599909928@gmail.com
# Created Time:六  5/15 22:12:23 2021
########################################################################*/
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}

int n,m;
string s[N];
int dp[2005][2005];

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	me(dp,-INF,sizeof(dp));
	rep(i,0,n-1){
		cin>>s[i];
	}

	dp[n-1][m-1]=0;
	per(i,n-1,0){
		per(j,m-1,0){
			if(i+1<n){
				if(s[i+1][j]=='+') dp[i][j]=max(dp[i][j],1-dp[i+1][j]);
				else dp[i][j]=max(dp[i][j],-1-dp[i+1][j]);
			}
			if(j+1<m){
				if(s[i][j+1]=='+') dp[i][j]=max(dp[i][j],1-dp[i][j+1]);
				else dp[i][j]=max(dp[i][j],-1-dp[i][j+1]);
			}
		}
	}

	if(dp[0][0]==0) cout<<"Draw\n";
	else if(dp[0][0]>=1) cout<<"Takahashi\n";
	else cout<<"Aoki\n";

    return 0;
}


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

#define INF 1234567890
#define ll long long

int N;
int A[100101];

double f(double X)
{
	double ret = 0;
	for(int i=1; i<=N; i++)
	{
		ret += X + A[i] - min(1.0*A[i], X+X);
	}
	ret /= N;

	return ret;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	cin >> N;
	for(int i=0; i<N; i++)
		cin >> A[i];
	sort(A, A+N);

	cout << setprecision(12) << fixed;
	cout << f(A[N/2]/2.0) << "\n";
	return 0;
}

#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int gcd(int a, int b) {
    if(a < b) return gcd(b, a);
    if(b == 0) return a;
    return gcd(b, a % b);
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a = 1;
    REP(i, 2, 30) {
        a = a * i / gcd(a, i);
    }
    //REP(i, 2, 30) cout << (a + 1) % i << endl;
    cout << a + 1 << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <assert.h>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>

#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef std::pair<long long, long long> Pll;
typedef std::vector<int> vi;
typedef std::vector<long long> vl;
typedef std::vector<std::string> vs;
typedef std::vector<std::pair<long long, long long>> vpll;
typedef std::vector<std::vector<ll>> vvl;
template<class T> using V  = std::vector<T>;
template<class T> using VV = std::vector<std::vector<T>>;
template<class T> using PQue  = std::priority_queue<T>;
template<class T> using RPQue = std::priority_queue<T, std::vector<T>, std::greater<T>>;

const long double PI = (acos(-1));
const long long MOD = 1000000007;

static const int MAX_INT = std::numeric_limits<int>::max(); // 2147483647 = 2^31-1
static const ll  MAX_LL  = std::numeric_limits<long long>::max();
static const int INF     = (1 << 29);   // cf) INT_MAX   = 2147483647 = 2^31-1
static const ll  INFLL   = (1ll << 61); // cf) LLONG_MAX = 9223372036854775807 = 2^63 - 1

#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define rrep(i,n) RREP(i,0,n)
#define RREP(i,x,n) for(ll i=(ll)(n)-1ll;i>=(ll)(x);--i)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define SUM(x) accumulate(ALL(x), 0ll)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)

// view
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

// change min/max
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void Main() {
    ll X, Y; cin >> X >> Y;
    if (X > Y) swap(X, Y);

    bool ans = ((Y - X) < 3);
    cout << (ans ? "Yes" : "No") << endl;

}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(15);
    Main();

    double tmp;
    cin >> tmp;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if(abs(x-y)<3)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<ll,int>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define sz(x) int(x.size())
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

struct ed{
  int to,t,k;
  ed(int to,int t,int k):to(to),t(t),k(k){}
};

int main(){
  cci(n,m);
  cci(sx,sy);
  sx--;sy--;

  V<V<ed>> v(n);

  rep(i,0,m){
    cci(x,y);
    x--;y--;

    cci(t,k);

    v[x].eb(y,t,k);
    v[y].eb(x,t,k);
  }

  ll inf=3e18;
  vll dist(n,inf);
  dist[sx]=0;

  minpq<P>q;
  q.push(P(0,sx));

  while(sz(q)){
    ll d=q.top().first;
    int x=q.top().second;
    q.pop();

    if(dist[x]<d)continue;

    for(auto e:v[x]){
      int nx=e.to;
      ll k=e.k;

      ll tm=(d+k-1)/k*k+e.t;

      if(dist[nx]>tm){
        dist[nx]=tm;
        q.push(P(tm,nx));
      }
    }
  }

  ll ans=dist[sy];
  if(ans==inf)ans=-1;

  co(ans);
}

//clear adj and visited vector declared globally after each test case
//check for long long overflow
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Incase of close mle change language to c++17 or c++14
/**#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops”)**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n, m, q;
    cin>>n>>m>>q;
    vector <pii> v;
    rep(i,0,n)
    {
        int a, b;
        cin>>a>>b;
        v.pb({a, b});
    }
    sort(all(v));
    int ar[m];
    rep(i,0,m)
    cin>>ar[i];
    while(q--)
    {
        int l, r;
        cin>>l>>r;
        l--,r--;
        vi temp;
        rep(i,0,l)
        temp.pb(ar[i]);
        rep(i,r+1,m)
        temp.pb(ar[i]);
        sort(all(temp));
        mii s;
        int cur=0, ans=0;
        for(auto num:temp)
        {
            while(cur<n && v[cur].ff<=num)
            s[(-v[cur].ss)]++, cur++;
            if(!s.empty())
            {
                auto it=*s.begin();
                ans-=it.ff;
                s[it.ff]--;
                if(s[it.ff]==0)
                s.erase(it.ff);
            }
        }
        cout<<ans<<"\n";
    }
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return (temp*temp);
    else
        return (((x*temp))*temp);
}

//nCr % mod
const int N0 = 2e6 + 5;
ll fact[6*N0];
ll inv[6*N0],invfac[6*N0];
ll mod = 1e9 + 7;

void factorial()
{
    fact[0] = invfac[0] = fact[1] = invfac[1] = 1;
    inv[1] = 1;
    for(int i=2;i<=5*N0 + 10;i++)
    {
        fact[i] = (fact[i-1]*i)%mod;
        inv[i] = (inv[mod%i]*(mod - mod/i))%mod;
        invfac[i] = (invfac[i-1]*inv[i])%mod;
    }
}

vector<ll> primes;

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primes.push_back(p);
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

const int N = 2e5 + 5;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,m;
    ll sum = 0;
    cin >> n >> m;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin >> x;
        sum += x;
    }
    m += n;
    sum += n;
    if(m < sum)
        return cout << 0,0;
    ll ans = 1;
    factorial();
    //cout << m << " " << sum << '\n';
    for(int i=0;i<sum;i++)
    {
        ll val = (m - i)*(inv[sum - i])%mod;
        //cout << val << "\n";
        ans = (ans * val)%mod;
    }
    cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

vector<long long int> inverse;

void factorial_Initialize(int max){
    inverse.assign(max+1,1);

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
    }
}

long long int nCr(int n, int r){
    factorial_Initialize(r);
    if(n < r || r < 0) return 0;

    long long int ans = 1;
    for(int i=0; i<r; i++){
        ans = ans * (n-i) % MOD * inverse[i+1] % MOD;
    }
    return ans;
}

int main(){
    int n, m;
    cin >> n >> m;

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

    long long int ans = nCr(m+n, sum+n);
    cout << ans << endl;
    return 0;
}


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

//TEMPLATE
#define len(a)            (ll) a.size()
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)
#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)

#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cots(a)           cout << a << " "
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotcase(cs)       cout << "Case " << cs << ": "
#define yes               cout << "Yes\n"
#define no                cout << "No\n"
#define line              cout << "\n"

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)

#define ll                long long
#define pb                push_back
#define mp                make_pair
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 17;
const ll mod = 1e9+7;

string s, s1, s2;
ll n, k, ans = 0;
ll a[SZ];
//ll b[SZ];

struct dat {
    ll x, y, z;
} ct[SZ];
ll dp[20][(1LL<<SZ)+5];

bool check(ll x, ll pos) {
    return (x & (1LL << pos));
}

ll set1(ll x, ll pos) {
    return (x = x | (1LL << pos));
}

ll cal(dat c1, dat c2) {
    ll d = abs(c1.x - c2.x) + abs(c1.y - c2.y) + max(0LL, c2.z-c1.z);
    return d;
}

ll solve(ll in, ll msk) {
    if(bitcount(msk) == n) return cal(ct[in], ct[0]);
    ll i, t, &res = dp[in][msk];
    if(res != -1) return res;
    res = INF;

    for0(i, n) {
        if(check(msk, i)) continue;
        t = cal(ct[in], ct[i]) + solve(i, set1(msk, i));
        res = min(res, t);
    }

    return res;
}

int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0;
//    ll a, b, d;
//    string s, s1, s2;

    cin1(n);
    for0(i, n) cin3(ct[i].x, ct[i].y, ct[i].z);

    ms(dp, -1);
    cot1(solve(0, 1));

    return 0;
}

//ll min_len[1<<8];
//void __(){
//    _(ll,n);
//    _(ll,m);
//    _(vl,a,n);
//    _(vpll,b,m);
//    rep(bm,1<<n){
//        ll w = 0;
//        rep(i,n)
//            if(bm&(1<<i))
//                w += a[i];
//        rep(i,m){
//            if(b[i].Y < w)
//                min_len[bm] = max(min_len[bm],b[i].X);
//        }
//    }
//    rep(i,n)
//        if(min_len[1<<i] != 0){
//            print -1;
//            return;
//        }
//    vi order(n);
//    iota(all(order),0);
//    ll ans = INF;
//    do{
//        vl x(n);
//        rep(i,1,n-1){
//            x[i] = x[i-1];
//            ll bm = 1<<order[i];
//            per(j,i){
//                bm |= 1<<order[j];
//                x[i] = max(x[i],min_len[bm]+x[j]);
//            }
//        }
//        ans = min(ans,x.back());
//    }while(next_permutation(all(order)));
//    print ans;
//}
//
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_INT(i,l,r) for(int i = (l); i <= (r); ++i)
#define REP_ZERO_INT(i,r) for(int i = 0; i < (r); ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define PER_ZERO_INT(i,r) for(int i = (r)-1; i >= 0; --i)
#define GET_PER_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define per(...) GET_PER_MACRO(__VA_ARGS__,PER_ANY,PER_INT,PER_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define X first
#define Y second
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<int> vi;
const ll INF = ll(2e18) + 666;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
template <typename F, typename S> static
istream& operator>>(istream& stream, pair<F, S>& t){
    return stream >> t.first >> t.second;
}
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout)
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }

    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
#define INPUT_WITHOUT_INIT(type,name) type name; cin >> name
#define _IWI(type,name,...) type name(__VA_ARGS__); cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)
ll min_len[1<<8];
void __(){
    _(ll,n);
    _(ll,m);
    _(vl,a,n);
    _(vpll,b,m);
    rep(bm,1<<n){
        ll w = 0;
        rep(i,n)
            if(bm&(1<<i))
                w += a[i];
        rep(i,m){
            if(b[i].Y < w)
                min_len[bm] = max(min_len[bm],b[i].X);
        }
    }
    rep(i,n)
        if(min_len[1<<i] != 0){
            print -1;
            return;
        }
    vi order(n);
    iota(all(order),0);
    ll ans = INF;
    do{
        vl x(n);
        rep(i,1,n-1){
            x[i] = x[i-1];
            ll bm = 1<<order[i];
            per(j,i){
                bm |= 1<<order[j];
                x[i] = max(x[i],min_len[bm]+x[j]);
            }
        }
        ans = min(ans,x.back());
    }while(next_permutation(all(order)));
    print ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        __();
}