#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; ll x; cin >> n >> x;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  vector<ll> cnt(n);
  {
    ll rem = x;
    rep(i, n) {
      if(i == n-1) cnt[i] = rem / A[i];
      else cnt[i] = (x % A[i+1]) / A[i];
    }
  }
  vector<vector<ll>> dp(n, vector<ll>(2));
  dp[0][0] = 1;
  rep(i, n-1) {
    if(cnt[i]) {
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][0];
    } else {
      dp[i+1][0] += dp[i][0];
    }
    if(cnt[i]+1 < A[i+1]/A[i]) {
      dp[i+1][0] += dp[i][1];
      dp[i+1][1] += dp[i][1];
    } else {
      dp[i+1][1] += dp[i][1];
    }
  }
  cout << dp[n-1][0] + dp[n-1][1] << endk;
  return 0;
}

#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#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>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define fsort(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  ll sum=0;
  rep(i,n){
    cin >> a[i] >> b[i];
    c[i]=2*a[i]+b[i];
    sum-=a[i];
  }
  rsort(c);
  rep(i,n){
    sum+=c[i];
    if(sum>0){
      //cout << sum << endl;
      cout << i+1 << endl;
      return 0;
    }
  }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define print(x) cout << x << endl
#define all(v) (v).begin(),(v).end()
#define YN(ok) print((ok ? "YES" : "NO"))
#define yn(ok) print((ok ? "Yes" : "No"))
#define decimal(n) setprecision(25) << n

#define Arrays_toString(v) rep(o,(v).size()){cout<<v[o]<<", ";if(o==(v).size()-1){cout<<endl;}}

vi primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};

int main(void){
    int n; cin >> n;
    vi v(n);
    rep(i, n) cin >> v[i];
    int m = primes.size();

    ll res = 3e18;
    rep(i, (1<<m)) {
        ll s = 1;
        rep(j, m) {
            if (i & (1<<j)) {
                s *= primes[j];
            }
        }

        bool ok = true;
        rep(j, n) {
            ll g = __gcd(s, (ll)v[j]);
            if (g == 1) ok = false;
        }

        if (ok) res = min(res, s);
    }
    print(res);
}

#include<bits/stdc++.h>
#define ll long long
#define re register
#define INF 2147483647
using namespace std;

inline int read()
{
	int f=1,x=0;char s=getchar();
	while(s<'0'||s>'9')
	{
		if(s=='-') f=-1;
		s=getchar();
	}
	while(s>='0'&&s<='9')
	{
		x=x*10+s-48;
		s=getchar();
	}
	return f*x;
}

int main()
{
	int a=read(),b=read(),c=read();
	if(a>0&&b>0)
	{
		if(a==b) puts("=");
		else if(a>b) puts(">");
			else puts("<");
		return 0;
	}
	if(c&1)
	{
		if(a<=0&&b<=0)
		{
			if(abs(a)==abs(b)) puts("=");
			else if(abs(a)<abs(b)) puts(">");
				else puts("<");
		}
		if(a<=0&&b>0) puts("<");
		if(a>0&&b<=0) puts(">");
	}
	else
	{
		if(abs(a)==abs(b)) puts("=");
		else if(abs(a)<abs(b)) puts("<");
			else puts(">");
	}
	return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

// edit

void solve() {
    string S;
    cin >> S;
    string T = "ZONe";
    int cnt = 0;
    for (int i = 0; i + T.size() <= S.size(); ++i) {
        cerr << S.substr(i, 4) << endl;
        if (S.substr(i, 4) == T) {
            cnt++;
        }
    }
    cout << cnt << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();

    return 0;
}

#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
    string S;
    cin >> S;

    int result = 0;
    for (int i = 0; i < 9; i++)
    {
        if (S[i] == 'Z' && S[i+1]=='O' && S[i+2]=='N' && S[i+3]=='e')
        {
            result++;
        }
    }

    cout << result;

    return 0;
}


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

int main()
{
    int x,y;

    cin >> x >> y;
    if(x == y){
        cout << x;
    }else{
        if(x!=1 && y!=1){
            cout << 1;
        }else if(x!=2 && y!=2){
            cout << 2;
        }else{
            cout << 0;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ip cin>>
#define op cout<<
#define int long long
signed main(){
    fast
    int a, b, c;
    ip a>>b;
    if(a == b) {
        c = a;
    } else if(a == 1 && b == 2){
        c = 0;
    } else if(a == 2 && b == 1){
        c = 0;
    } else if(a == 0 && b == 1 || a == 1 && b ==0) {
        c = 2;
    } else if(a == 0 && b == 2 || a == 2 && b == 0) {
        c = 1;
    }
    op c<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)n;i++)
const ll mod = 1e9+7 ;
const ll INF = 1e18 ;
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}

int main(){
    ll n;
    cin >> n;
    vector<double> le(n);
    vector<double> ri(n);
    rep(i,n) {
        int t;
        double l, r;
        cin >> t >> l >> r;
        if(t == 2) r -= 0.01;
        if(t == 3) l += 0.01;
        if(t == 4) {
            l += 0.01;r -= 0.01;
        }
        le.at(i) = l;
        ri.at(i) = r;
    }
    ll ans = 0;
    rep(i,n) {
        for(int j = i + 1; j < n; j++) {
            if(le.at(i) <= le.at(j)) {
                if(ri.at(i) < le.at(j)) continue;
                else ans++;
            }
            else {
                if(ri.at(j) < le.at(i)) continue;
                else ans++;
            }
        }
    }
    cout << ans << endl;
}


// Fearless
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define PI (2.0 * acos(0.0))
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define info pair<int, pii>
#define mkp make_pair
const long long M = 1e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;
int dis[2002][2002], vis[2002][2002], cvis[30];
vector < pii > adj[2002][2002];
vector < pii > pos[30];
int fx[4] = {0, 1};
int fy[4] = {1, 0};
void solve () {
	int r, c;
	pii src, tr;
	cin >> r >> c;
	char str[r + 2][c + 2];
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> str[i][j];
		}
	}
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			if (str[i][j] == '#') continue;
			if (str[i][j] >= 'a' && str[i][j] <= 'z') {
				pos[str[i][j] - 'a'].pb(pii(i, j));
			}
			if (str[i][j] == 'S') {
				src = pii(i, j);
			}
			if (str[i][j] == 'G') {
				tr = pii(i, j);
			}
			for (int k = 0; k < 2; k++) {
				if (i + fx[k] < 0 || i + fx[k] >= r || j + fy[k] < 0 || j + fy[k] >= c) continue;
				if (str[i + fx[k]][j + fy[k]] == '#') continue;
				pii p1 = pii(i, j), p2 = pii(i + fx[k], j + fy[k]);
				adj[i][j].pb(p2);
				adj[i + fx[k]][j + fy[k]].pb(p1);
			}
		}
	}
	queue < pii > q;
	q.push(src);
	while (!q.empty()) {
		pii u = q.front();
		q.pop();
		int ux = u.first, uy = u.second;
		if (str[ux][uy] >= 'a' && str[ux][uy] <= 'z' && cvis[str[ux][uy] - 'a'] == 0) {
			cvis[str[ux][uy] - 'a'] = 1;
			for (pii v : pos[str[ux][uy] - 'a']) {
				int vx = v.first, vy = v.second;
				//cout << vx << " this " << vy << endl;
				if (vis[vx][vy]) continue;
				dis[vx][vy] = dis[ux][uy] + 1;
				vis[vx][vy] = 1;
				q.push(v);
			}
		}
		//cout << adj[ux][uy].size() << " size " << endl;
		for (pii v : adj[ux][uy]) {
			int vx = v.first, vy = v.second;
			//cout << vx << " " << vy << " now " << vis[vx][vy] << endl;
			if (vis[vx][vy]) continue;
			dis[vx][vy] = dis[ux][uy] + 1;
			vis[vx][vy] = 1;
			q.push(v);
		}
	}
	if (!vis[tr.first][tr.second]) cout << -1 << endl;
	else cout << dis[tr.first][tr.second] << endl;
}
int main () {
    //freopen("E:/newts/in.txt", "r", stdin);
    //freopen("E:/newts/out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //testcase {
        solve ();
    //}
    return 0;
}

/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0)

typedef double db;
typedef long long ll;

const int N=2005;
const int mod=1e9+7;

int h,w,dis[N][N];
vector<pii>v[26];
char g[N][N];
bool inside(int x,int y){
    if(g[x][y]=='#') return 0;
    if(x>0 and y>0 and x<=h and y<=w) return 1;
    return 0;
}
int bfs(pii p){
    queue<pii>q;
    q.push(p);
    rep(i,1,h) rep(j,1,w) dis[i][j]=1e9;
    dis[p.F][p.S]=0;
    while(!q.empty()){
        p=q.front();
        q.pop();
        if(g[p.F][p.S]=='G') return dis[p.F][p.S];
        if(islower(g[p.F][p.S])){
            for(pii t:v[g[p.F][p.S]-'a']) if(t!=p and dis[t.F][t.S]>dis[p.F][p.S]+1){
                q.push(t);
                dis[t.F][t.S]=dis[p.F][p.S]+1;
            }
            v[g[p.F][p.S]-'a'].clear();
        }
        rep(i,-1,1) rep(j,-1,1) if(abs(i)+abs(j)<=1 and dis[p.F+i][p.S+j]>dis[p.F][p.S]+1 and inside(p.F+i,p.S+j)){
            dis[p.F+i][p.S+j]=dis[p.F][p.S]+1;
            q.push({p.F+i,p.S+j});
        }
    }
    return -1;
}
signed main(){
    FastIO;
    cin>>h>>w;
    pii st;
    rep(i,1,h) rep(j,1,w){
        cin>>g[i][j];
        if(islower(g[i][j])) v[g[i][j]-'a'].pb({i,j});
        if(g[i][j]=='S') st={i,j};
    }
    cout<<bfs(st);
    return 0;
}


#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

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; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  /*
  どの頂点を選ぶか？

  その頂点を選ぶことによって、どれだけ自分がプラスになるか
  自分の手番が継続できるか

  優先度
  手番が継続できて、収支プラス
  ↓
  手番が継続できなくて、収支プラス（大きい方から）
  ↓
  手番が継続できなくて、収支マイナス（マシな方から）
  ↓
  手番が継続できて、収支マイナス

  */

  int N; cin >> N;
  vvi es(N);
  FOR(i, 1, N) {
    int p; cin >> p; p--;
    es[p].push_back(i);
  }
  v(bool) bs(N); // 手番が継続できるかどうか
  vi ss(N); // 収支

  int big = 2000002;
  auto vscore = [&](int v) {
    int s = ss[v];
    if (bs[v]) {
      if (ss[v] >= 0) s += big;
      else s -= big;
    }
    return s;
  };

  auto vcmp = [&](int a, int b) {
    return vscore(a) < vscore(b);
  };

  auto dfs = [&](auto dfs, int v) {

    if (!sz(es[v])) {
      bs[v] = false;  // 相手の手番に
      ss[v] = -1;
      return;
    }

    priority_queue<int, deque<int>, decltype(vcmp)> pq(vcmp);
    for (auto c : es[v]) {
      dfs(dfs, c);
      pq.push(c);
    }
    int turn = 1; // 相手の手番なら-1
    int score = 0;
    while (sz(pq)) {
      auto c = pq.top(); pq.pop();
      score += ss[c] * turn;
      if (!bs[c]) turn = turn * -1;
    }
    ss[v] = -1+score;
    bs[v] = turn < 0; // 1回戻るので、手番は逆になる
  };
  dfs(dfs, 0);
  //cout << ss;

  /*
  a+b=N a-b=ss[0]
  */
  int a = (N - ss[0]) / 2;
  cout << a << newl;
}
#endif

#include <bits/stdc++.h>
#define int long long
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbd(a) cout << #a << ": " << a << endl
#define dbd2(a,b) cout << #a << ": " << a << ", " << #b << ": " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto _i:a) cout << _i << " "; cout << endl
#define adbp(a) for(auto _i:a) cout << _i.first << " " << _i.second << endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define N 3010
#define M 200010
using namespace std;

int n;
vector<int> a, pre;
vector<vector<int>> dp;
vector<vector<vector<int>>> modmap;

// i: current position, j: current subset
int solve(int i, int j)
{
    if(i == n) return 1;
    if(dp[i][j] != -1) return dp[i][j];

    int curmod = pre[i] % j;

    auto &mp = modmap[j][curmod];
    auto index = lower_bound(mp.begin(), mp.end(), i) - mp.begin();

    int ret = (index == mp.size()) ? (0) :
                (solve(mp[index] + 1, j) + (mp[index] != n - 1) * solve(mp[index] + 1, j + 1));

    ret = (ret % mod);

    return dp[i][j] = ret;
}

signed main()
{
    fastIO;
    cin >> n;

    a.resize(n);
    for(int i=0; i<n; i++) cin >> a[i];

    pre.resize(n + 1);
    for(int i=0; i<n; i++) pre[i + 1] = pre[i] + a[i];

    modmap.assign(n + 1, vector<vector<int>>(n + 1, vector<int>()));
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<n; j++)
        {
            modmap[i][pre[j + 1] % i].push_back(j);
        }
    }

    dp.assign(n + 1, vector<int>(n + 1, -1));

    cout << solve(0, 1);
}


#include <iostream>
using namespace std;

int main(void){
  int x, y;
  cin >> x >> y;
  if (x == y) {
    cout << x << endl;
  } else if (x == 0 && y == 1) {
    cout << 2 << endl;
  } else if (x == 1 && y == 0) {
    cout << 2 << endl;
  } else if (x == 0 && y == 2) {
    cout << 1 << endl;
  } else if (x == 2 && y == 0) {
    cout << 1 << endl;
  } else if (x == 1 && y == 2) {
    cout << 0 << endl;
  } else if (x == 2 && y == 1) {
    cout << 0 << endl;
  }
}

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

int main() {
  int N, W;
  cin >> N >> W;

  int ans = N / W;

  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int nax=2e5+100,mod=1e9+7;
int dp[nax][19];
int32_t main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        string a;
        cin>>a;
        int k;
        cin>>k;
        set<int> s;
        s.clear();
        for(int i=0;i<a.size();i++)
        {
            for(int j=0;j<17;j++)
            {
                dp[i+1][j]+=dp[i][j]*j;
                dp[i+1][j]%=mod;
                dp[i+1][j+1]+=dp[i][j]*(16-j);
                dp[i+1][j+1]%=mod;
            }
            int num=a[i]-'0';
            if(a[i]>='A')
            num=10+a[i]-'A';
            for(int j=0;j<num;j++)
            {
                if(i==0 and j==0)
                continue;
                if(s.count(j))
                {
                    dp[i+1][s.size()]++;
                    dp[i+1][s.size()]%=mod;
                }
                else
                {
                    dp[i+1][s.size()+1]++;
                    dp[i+1][s.size()+1]%=mod;
                }
            }
            s.insert(num);
            if(i!=0)
            dp[i+1][1]+=15;
        }
        int res=dp[a.size()][k];
        set<char> ss;
        for(int i=0;i<a.size();i++)
        ss.insert(a[i]);
        if(ss.size()==k)
        ++res;
        cout<<res;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,a,n) for (ll i = a;i<(n);++i)
#define all(v) v.begin(),v.end()
#define bit(n) (1LL<<(n))
#define pu(n) push_back(n)
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5
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 (b<a) { a=b; return 1; } return 0; }
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
bool IsPrime(ll num){
    if (num < 2) return false;else if (num == 2) return true;else if (num % 2 == 0) return false; double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)return false;
    }
    return true;
}//???true
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;
}//?????
uintmax_t combi(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;uintmax_t dividend = 1;uintmax_t divisor  = 1;for ( unsigned int i = 1; i <= r; ++i ) { dividend *= (n-i+1);divisor  *= i;}return dividend / divisor;
}
using Graph = vector<vector<int>>;
/*--------------<<fixed<<setprecision(15)----->>-------------------------------------------------------------------------------------------------------------*/
int main(){
    ll n,m;cin>>n>>m;
    vector<pair<ll,ll>>ab(m);
    rep(i,0,m){ll a,b;cin>>a>>b;ab[i].first=a-1;ab[i].second=b-1;}
    ll k;cin>>k;
    vector<pair<ll,ll>>cd(k);
    rep(i,0,k){ll a,b;cin>>a>>b;cd[i].first=a-1;cd[i].second=b-1;}
    ll ans=0;
    rep(bit,0,(1<<k)){
        vector<ll>dish(n,0);ll cnt=0;
        rep(i,0,k){
            if(bit&(1<<i)){
                dish[cd[i].second]++;
            }
            else{
                dish[cd[i].first]++;
            }
        }

        rep(i,0,m){
            bool c=true;
            if(!dish[ab[i].first]>=1)c=false;
            if(!dish[ab[i].second]>=1)c=false;
            if(c)cnt++;
        }
        ans=max(ans,cnt);

    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;cin>>S;
    deque<char> ans;

    bool f=false;

    for(char c:S){
        if(c=='R'){
            f^=1;
        }else{
            if(!f){
                ans.push_back(c);
                if(si(ans)>=2&&ans[si(ans)-1]==ans[si(ans)-2]){
                    ans.pop_back();
                    ans.pop_back();
                }
            }else{
                ans.push_front(c);
                if(si(ans)>=2&&ans[0]==ans[1]){
                    ans.pop_front();
                    ans.pop_front();
                }
            }
        }
    }

    if(f){
        for(int i=si(ans)-1;i>=0;i--) cout<<ans[i];
        cout<<endl;
    }else{
        for(int i=0;i<si(ans);i++) cout<<ans[i];
        cout<<endl;
    }
}

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(_,__) (_+(__-1))/__
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;

inline int read()
{
	int x=0,y=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') y=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*y;
}

deque<char> dq;

int main(){
	bool fl=false;

	char ch;
	while(cin>>ch)
		if(ch=='R') fl^=1;
		else if(fl) dq.pf(ch);
		else if(!fl) dq.pb(ch);

	string res;
	while(dq.size()){
		if(res.size() && res.back()==dq.front()) res.pop_back();
		else res+=dq.front();

		dq.pop_front();
	}
	if(fl) reverse(res.begin(), res.end());
	cout<<res<<endl;

    return 0;
}


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

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

    ll K,N,M; cin >> K >> N >> M;
    vector<ll> A(K),B(K);
    rep(i,K) cin >> A[i];
    rep(i,K) B[i] = M * A[i] / N;

    ll x = M;
    vector<pair<ll,ll>> v;
    rep(i,K) x -= B[i];
    rep(i,K) v.push_back({M * A[i] - N * B[i], i});
    sort(v.rbegin(), v.rend());

    rep(i,x) B[v[i].second] += 1;
    rep(i,K){
        if(i) cout << " ";
        cout << B[i];
    }cout << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
#define TO_STRING(VariableName) # VariableName
#define debug(x) cerr<<TO_STRING(x)<<" : "<<x<<" "<<endl;
void debugs() { cerr << endl; }
template <class T, class... Args>
void debugs(const T& x, const Args &... args) {
		cerr << x << " ";
		debugs(args...);
}
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
		ost << "{ " << p.first << ", " << p.second << " }";
	return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
	ost << "{ ";
	for (int i = 0; i < v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << " }";
	return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>& v) {
	ost << "{ ";
	for (auto p : v) {
		ost << "{ " << p.first << ", " << p.second << " }";
	}
	ost << " }";
	return ost;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

ll u[212345];

int main() {
	ll n, w;
	cin >> n >> w;
	ll mt = 0;
	rep(i,n){
		ll s, t, p;
		cin >> s >> t >> p;
		//s--;
		//t--;
		u[s]+=p;
		u[t]-=p;
		mt = max(mt,t);
	}
	rep(i,mt-1) u[i+1] += u[i];
	bool f = false;
	rep(i,mt) if (u[i] > w) f=true;
	(f) ? cout << "No" << endl : cout << "Yes" << endl;
	return 0;
}


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

/*
提出前に確認!
- 配列は+10ぐらい余分にとっておく
- setとmultisetを間違えない
*/

/*
デバッグ時にチェック!
- RE
	配列の取りうる最大値、最小値を**すべて**チェックする
*/

int a[110];
int b[110];
bool used[220];
bool dp[200][200];
int zero_cnt[200][200];

int	main(void)
{
	int n;
	cin >> n;
	int zero_all = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
		if (a[i] == -1 && b[i] == -1) zero_all++;
		if (a[i] != -1 && b[i] != -1 && a[i] > b[i])
		{
			cout << "No" << endl;
			return (0);
		}
		if (a[i] != -1)
		{
			if (used[a[i]])
			{
				cout << "No" << endl;
				return (0);
			}
			used[a[i]] = true;
		}
		if (b[i] != -1)
		{
			if (used[b[i]])
			{
				cout << "No" << endl;
				return (0);
			}
			used[b[i]] = true;
		}
	}
	dp[0][1] = true;
	for (int i = 1; i <= n + 1; i++)
	{
		for (int j = i + 1; j <= n + 1; j++)
		{
			bool is_valid = true;
			for (int k = 0; k < j - i; k++)
			{
				bool flag = false;
				for (int w = 0; w < n; w++)
				{
					if (flag) break ;
					if (a[w] == i * 2 - 1 + k && b[w] == i * 2 - 1 + (j - i) + k) flag = true;
					else if (a[w] == -1 && !used[i * 2 - 1 + k] && b[w] == i * 2 - 1 + (j - i) + k) flag = true;
					else if (a[w] == i * 2 - 1 + k && b[w] == -1 && !used[i * 2 - 1 + (j - i) + k]) flag = true;
					else if (a[w] == -1 && !used[i * 2 - 1 + k] && b[w] == -1 && !used[i * 2 - 1 + (j - i) + k])
					{
						flag = true;
						zero_cnt[i][j]++;
					}
				}
				if (!flag) is_valid = false;
			}
			dp[i][j] = is_valid;
		}
	}
	for (int i = 0; i <= n + 1; i++)
	{
		for (int j = i + 1; j <= n + 1; j++)
		{
			for (int v = j + 1; v <= n + 1; v++)
			{
				if (dp[i][j] && dp[j][v] && zero_cnt[i][j] + zero_cnt[j][v] <= zero_all) dp[i][v] = true, zero_cnt[i][v] = zero_cnt[i][j] + zero_cnt[j][v];
			}
		}
	}
	if (dp[0][n + 1] && zero_cnt[0][n + 1] <= zero_all) cout << "Yes" << endl;
	else cout << "No" << endl;
	return (0);
}

#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
// #define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 3000+10;

int a[maxn][6];
int n;
int v[maxn];
bool present[50];

bool help(int x){
	int temp = 31;
	for (int i = 0; i < (1 << 5); ++i)
	{
		if(!present[i]) continue;
		if((i|x) == temp) return 1;
	}
	return 0;
}

bool check(int x){
	fo(i, 1, n){
		v[i] = 0;
		for (int j = 0; j < 5; ++j)
		{
			if(a[i][j] >= x) v[i] |= (1 << j);
		}
	}
	for (int i = 0; i < 40; ++i)
	{
		present[i] = 0;
	}
	fo(i, 1, n){
		if(help(v[i])) return 1;
		fo(j, 1, i - 1){
			present[(v[i] | v[j])] = 1;
		}
	}
	return 0;
}

int32_t main(){
    fast_io;
    cin >> n;
    fo(i, 1, n){
    	for (int j = 0; j < 5; ++j)
    	{
    		cin >> a[i][j];
    	}
    }
    int ans = 1, l = 1, r = 1e9;
    while(l <= r){
    	int m = (l + r) / 2;
    	if(check(m)){
    		ans = m;
    		l = m + 1;
    	}
    	else{
    		r = m - 1;
    	}
    }
    show(ans);
    return 0;
}


/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define bits(x,i) (((x) >> (i)) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
#define ll long long
using namespace std;
const int N = 2005;
int n,m;
int a[N];
const int mod = 1e9 + 7;
ll power(ll x, ll n){
	ll ans = 1;
	for(int i=0;i<31;++i){
		if (bits(n, i)) ans = (ans * x) % mod;
		x = (x * x) % mod;
	}
	return ans;
}
ll inv(ll num, ll den){
	return (num * power(den, mod - 2)) % mod;
}
int s = 0;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	up(i,1,n) cin >> a[i], s += a[i];
	ll ans = 1;
	if (m < s) { cout << "0"; return 0; }
	up(i, m - s + 1, m + n) ans = (ans * i) % mod;
	up(i,2,s + n) ans = inv(ans, i);
	cout << ans;
}

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
LL mod = 1e9 + 7;
const int MAXN = 4e6 + 5 + 2e3;

LL inv[MAXN];

LL C(LL a , LL b) {
	LL res = 1;
	for (LL i = 1; i <= b; ++i) {
		res = res * (a - i + 1) % mod * inv[i] % mod;
	}
	return res;
}

int main() {
	inv[1] = 1;
	for (int i = 2; i <= MAXN - 5; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	LL n , m;
	scanf("%lld %lld" , &n , &m);
	LL tot = 0;
	for (int i = 1; i <= n; ++i) {
		int x;scanf("%d" , &x);
		tot += x;
	}
	printf("%lld" , C(m + n , tot + n));
	return 0;
}


// @author: the__martian
// 108
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

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

  int h, w; cin >> h >> w;
  int mx = 500000;
  vector<vector<int>> v(h, vector<int>(w));
  for (auto &r : v) {
    for (auto &e : r) {
      cin >> e;
      mx = min(e, mx);
    }
  }
  ll res = 0;
  for (auto &r : v) {
    for (auto &e : r) {
      res += e - mx;
    }
  }
  cout << res;
}

 #include <bits/stdc++.h>

 #define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
 #define all(v) (v).begin(), (v).end()
 using namespace  std;
 #define forn(i,n) for (int i = 0; i < (n); ++i)
 #define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
 using ll = long long;
 int mod = (ll)1e9 + 7;
 #define PI acos(-1)
 typedef pair<int, int> pairs;

 const int INF = 1e9 + 1;
 const int N = 2e5 + 100;
 const double eps = 1e-7;

 template <class T> using V = vector<T>;
 template <class T> using VV = V<V<T>>;

 template <typename XPAX>
 void ckma(XPAX &x, XPAX y) {
     x = (x < y ? y : x);
 }
 template <typename XPAX>
 void ckmi(XPAX &x, XPAX y) {
     x = (x > y ? y : x);
 }

 void solve() {

 	using D = long double;

 	int n;cin >> n;

 	V<int>a (n);

 	forn(i, n) cin >> a[i];

 	D ans = 0;
 	sort(all(a));
 	D x = a[(n - 1) / 2] * 0.5;

 	ans += n * x;

 	forn(i, n) {
 		ans -= min((D)a[i], x * 2.0);

 		ans += a[i];
 	}
 	ans /= n;
 	cout << FIXED_FLOAT(ans) << '\n';

 }
 void test_case() {
     int t;
     cin >> t;
     forn(p, t) {

         //cout << "Case #" << p + 1 << ": ";
         solve();
     }
 }
 int main() {

     ios::sync_with_stdio(false);
     cin.tie(0);

     solve();
 }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
#define N 1010

vector<vector<ll>> ansl(N,vector<ll>(N,INF));
vector<vector<vector<ll>>> conn(N,vector<vector<ll>>(26));

int main(){
    ll n, m; cin >> n >> m;
    REP(i,m) {
        ll a, b; char c; cin >> a >> b >> c;
        a--; b--; c-='a';
        conn[a][c].pb(b); conn[b][c].pb(a);
    }
    ansl[0][n-1]=0;
    queue<P> q;
    q.push({0,n-1});
    while (!q.empty()) {
        ll x = q.front().first; ll y = q.front().second; q.pop();
        REP(i,26) {
            for (ll nex : conn[x][i]) for (ll ney : conn[y][i]) if (ansl[nex][ney]==INF) {
                ansl[nex][ney]=ansl[x][y]+1;
                q.push({nex,ney});
            }
        }
    }
    ll ans = INF;
    REP(i,n) ans = min(ans,2*ansl[i][i]);
    REP(i,n) {
        REP(j,26) for (ll k : conn[i][j]) {
            ans = min(ans,2*ansl[i][k]+1);
        }
    }
    if (ans==INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int n, m;
vector<pair<int, char>> edges[1000];
int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        edges[i].clear();
    for (int i = 0; i < m; ++i) {
        int from, to;
        char c;
        cin >> from >> to >> c;
        --from;
        --to;
        edges[from].push_back({ to, c });
        edges[to].push_back({ from, c });
    };
    queue<pair<int, int>> q, qq;
    q.push(make_pair(0, n - 1));
    int d = 0;
    int res = -1;
    bool visited[1000][1000] = { 0 };
    while (!q.empty()) {
        while (!q.empty()) {
            auto front = q.front();
            q.pop();
            int x = front.first;
            int y = front.second;
            for (auto edgeA : edges[x]) {
                for (auto edgeB : edges[y]) {
                    if (edgeA.second != edgeB.second)
                        continue;
                    if (visited[edgeA.first][edgeB.first])
                        continue;
                    visited[edgeA.first][edgeB.first] = true;
                    if (edgeA.first == edgeB.first) {
                        res = (res == -1 || res > 2 * (d + 1)) ? 2 * (d + 1) : res;
                    } else if (edgeA.first == y && edgeB.first == x) {
                        res = (res == -1 || res > 2 * d + 1) ? 2 * d + 1 : res;
                    } else {
                        qq.push(make_pair(edgeA.first, edgeB.first));
                    }
                }
            }
        }
        swap(q, qq);
        ++d;
    }
    cout << res << endl;
    return 0;
}


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

ll a[1000000],tree[1000000];

void update(ll i,ll val,ll s,ll e,ll idx)
{
    if(i==s&&s==e)
    {
        tree[idx]=tree[idx]^val;
        return;
    }
    if(i>e||i<s)
    {
        return;
    }
    ll mid=(s+e)/2;
    update(i,val,s,mid,2*idx);
    update(i,val,mid+1,e,2*idx+1);
    tree[idx]=tree[2*idx]^tree[2*idx+1];
}

ll query(ll qs,ll qe,ll s,ll e,ll idx,ll ee)
{
    if(s>=qs&&e<=qe)
    return tree[idx];
    if(e<qs||s>qe)
    return 0;

    ll mid=(s+e)/2;
    ll left = query(qs,qe,s,mid,2*idx,ee);
    ll right = query(qs,qe,mid+1,e,2*idx+1,ee);

    return left^right;
}

void build(ll idx,ll s,ll e)
{
    if(s==e)
    {
        tree[idx]=a[s];
        return;
    }
    if(s>e)
    return;

    ll mid = (s+e)/2;
    build(2*idx,s,mid);
    build(2*idx+1,mid+1,e);
    tree[idx]=tree[2*idx]^tree[2*idx+1];
    //cout<<s<<' '<<e<<':'<<tree[idx]<<'\n';
}

void fun()
{
  ll n,q;
  cin>>n>>q;
  for(ll i=0;i<n;i++)
  {
      cin>>a[i];
  }
  build(1,0,n-1);
  ll q1,q2,qa;
  while(q--)
  {
      cin>>qa>>q1>>q2;
      q1--;
      q2--;
      if(qa==2)
      cout<<query(q1,q2,0,n-1,1,q1)<<'\n';
      else
      update(q1,q2+1,0,n-1,1);
  }
}

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

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

struct BIT{
  vector<int> a;
  BIT(int n):a(n+1){}
  void xadd(int i,int x){
    while(i<a.size()){
      a[i]^=x;
      i+=i&-i;
    }
  }
  int xsum(int i){
    int ret=0;
    while(i>0){
      ret^=a[i];
      i-=i&-i;
    }
    return ret;
  }
};

int main(){
  int n,q;
  cin>>n>>q;
  BIT bit(n);
  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    bit.xadd(i,a);
  }
  for(int i=0;i<q;i++){
    int t,x,y;
    cin>>t>>x>>y;
    if(t==1)
      bit.xadd(x,y);
    else
      cout<<(bit.xsum(y)^bit.xsum(x-1))<<endl;
  }
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
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 main(){
  int N ; cin >> N;
  ll T; cin >> T;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  int n1=N/2, n2=N-N/2;
  vector<ll> v1,v2;
  rep(i,(1<<n1)){
    ll sum = 0;
    rep(j,n1){
      if(i&(1<<j)) sum+=A[j];
    }
    v1.pb(sum);
  }

  rep(i,(1<<n2)){
    ll sum = 0;
    rep(j,n2){
      if(i&(1<<j)) sum+=A[j+N/2];
    }
    v2.pb(sum);
  }
  sort(all(v1));
  sort(all(v2));
  ll ans = 0;
  rep(i,sz(v1)){
    ll tmp = v1[i];
    if(tmp>T) continue;
    if(upper_bound(all(v2),T-tmp)!=v2.begin()){
      tmp += *(upper_bound(all(v2),T-tmp)-1);
    }

    chmax(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const double PI = acos(-1);
const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int mex(vector<int> a) {
    sort(ALL(a));
    if (a[0] - 1 >= 0) return a[0] - 1;
    for(int i = 1; i < a.size(); i++) {
        if (a[i] - a[i-1] > 1) return a[i-1] + 1;
    }
    return a[a.size()-1] + 1;
}

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

    //vector<int> am(m);
    //for(int i = 0; i < m; i++) {
    //    am[i] = a[i];
    //}
    //int mex_n = mex(am);

    //for(int i = m; i < n; i++) {
    //    am.erase(am.begin());
    //    am.push_back(a[i]);
    //    mex_n = min(mex_n, mex(am));
    //}
    //cout << mex_n << endl;
    vector<int> ans;
    vector<int> pre(n, -1);
    REP(i, n) {
        if (i - pre[a[i]] > m) {
            ans.push_back(a[i]);
        }
        pre[a[i]] = i;
    }
    REP(i, n) {
        if (n - pre[i] > m) {
            ans.push_back(i);
        }
    }
    if (ans.size() == 0) {
        cout << n << endl;
        return 0;
    }
    sort(ALL(ans));
    cout << ans[0] << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define inf 1e9
#define linf 1e18
#define BASE 1000000
#define EPS 1e-10
#define PI acos(-1)
#define pii pair<int,int>
#define piii pair<int, pair<int, int> >
#define pdi pair<double,int>
#define vi vector<int>
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define ms(x,val_add) memset(x, val_add, sizeof(x))
#define pb(x) push_back(x)
#define make_unique(x) sort(ALL(x)) ; x.erase( unique(ALL(x)), x.end()) ;
#define dbg(x) do { cout << #x << " = " << x << endl; } while(0)
#define mp(x, y) make_pair(x, y)
#define minimize(x, y) x = min(x, y)
#define maximize(x, y) x = max(x, y)

/*** IMPLEMENTATION ***/
bool exitInput = false;
int ntest = 1, itest = 1 ;

const int dx[4] =
{
    -1, 0, 1, 0
};
const int dy[4] =
{
    0, 1, 0, -1
};
// const int dx[8] = {-2, -1, -1, +0, +0, +1, +1, +2};
// const int dy[8] = {+0, -1, +1, -2, +2, -1, +1, +0};

/** Knight Move **/
// const int dx[8] = {+1, +2, +2, +1, -1, -2, -2, -1};
// const int dy[8] = {+2, +1, -1, -2, -2, -1, +1, +2};

const ll Mod = 1000000007LL;
const int maxn = 500 + 5;
const int maxv = 500 + 5;
const int maxe = 10000 + 5;

ll addMod( ll &x, ll y )
{
    x = ( x + y ) % Mod;
}

int main()
{
#ifdef HOME
    freopen( "input.txt", "r", stdin );
    freopen( "output.txt", "w", stdout );
#endif // HOME
    ios_base::sync_with_stdio( false );
    cin.tie( NULL );
    cout << setprecision( 10 );
    cout << fixed;

    int A, B;
    cin >> A >> B;
    A = A + B;
    if(A >= 15 && B >= 8)
        cout << 1;
    else if(A >= 10 && B >= 3)
        cout << 2;
    else if(A >= 3)
        cout << 3;
    else
        cout << 4;

    return 0;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll A, B; cin >> A >> B;
  ll ans = 1;
  for (ll x = 1; x <= B; x++) {
    ll z = (B / x) * x;
    ll y = z - x;
    if (A <= y) ans = x;
  }
  cout << ans << endl;

  return 0;
}


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

#define int long long
#define mod 1000000007
#define pb push_back
#define ss second
#define ff first
#define all(v) v.begin(), v.end()
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)

int32_t main() {

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

    int n;
    cin >> n;

    pair<int,int> t;
    cin >> t.ff >> t.ss;
    double ans = 0.0;
    pair<int,int> v[n];
    double x2 = t.ff,y2 = t.ss;
    for(int i = 0; i < n; ++i) {
        cin >> v[i].ff >> v[i].ss;

        double x1 = v[i].ff, y1 = v[i].ss;
        if(x1 == x2)
            continue;
        double cur = (y1 * x2 - x1 * y2) / (x2 - x1);

        ans = max(ans,cur);
    }

    cout <<fixed << setprecision(6) << ans;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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 (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<int>> needs(n, vector<int>(4));
	vector<int> a(n), b(n), c(n), d(n);
	rep(i,n) {
		int x, y, r;
		cin >> x >> y >> r;
		needs[i][0] = r; needs[i][1] = x; needs[i][2] = y; needs[i][3] = i;
		a[i] = x, c[i] = x+1;
		b[i] = y, d[i] = y+1;
	}
	sort(needs.begin(), needs.end());
	// rep(i,n) cout << needs[i][0] << ' ' << needs[i][1] << ' ' << needs[i][2] << ' ' << needs[i][3] << ' ' << "\n";

	rep(i,n) cout << a[i] << ' ' << b[i] << ' ' << c[i] << ' ' << d[i] << ' ' << "\n";
	return 0;
}


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

vector<int> neigh[105];
bool vis[105];
int cnt[105];

void dfs(int v)
{
	if (vis[v]) return;
	vis[v] = true;
	cnt[v]++;

	for (int u : neigh[v]) {
		dfs(u);
	}
}

long double fact[105];

long double C(int n, int m) {
	if (m > n) return 0;
	return fact[n] / fact[m] / fact[n - m];
}

long double f(int n, int m)
{
	long double res = 0;
	for (int i = 1; i <= n; i++) {
		res += C(n - i, m) * fact[m] * fact[n - m - 1];
	}
	res /= fact[n];
	return res;
}

int main()
{
	fact[0] = 1;
	for (int i = 1; i < 105; i++) {
		fact[i] = fact[i - 1] * i;
	}

	int n;
	ignore = scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		char s[105];
		ignore = scanf(" %s", s);
		for (int j = 0; j < n; j++) {
			if (s[j] == '1') {
				neigh[i].push_back(j);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		memset(vis, 0, sizeof vis);
		dfs(i);
		cnt[i]--;
	}

	long double ans = 0;

	for (int i = 0; i < n; i++) {
		ans += f(n, cnt[i]);
	}

	printf("%.15Lf\n", ans);
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; ++i) {
        cin >> S[i];
    }

    double ans = 0;
    for (int i = 0; i < N; ++i) {
        vector<bool> used(N, false);
        queue<int> q;
        q.emplace(i);
        used[i] = true;
        while (!q.empty()) {
            int j = q.front();
            q.pop();
            for (int k = 0; k < N; ++k) {
                if (S[k][j] == '1' && used[k] == false) {
                    q.emplace(k);
                    used[k] = true;
                }
            }
        }
        int cnt = 0;
        for (auto e : used) {
            if (e) ++cnt;
        }

        ans += 1.0 / cnt;
    }
    cout << std::fixed << std::setprecision(15) << ans << endl;
}


/*
K.D. Vinit  |,,|
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int mod = 998244353;

void solve()
{
    int n, m;
    cin>>n>>m;

    int a[n+1][m+1];

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            char x;
            cin>>x;

            if(x=='.') a[i][j]=0;
            if(x=='R') a[i][j]=1;
            if(x=='B') a[i][j]=2;
        }
    }

    int cnt[3][n+m+1];

    for(int i=1; i<=n+m; i++)
    {
        cnt[0][i]=0;
        cnt[1][i]=0;
        cnt[2][i]=0;
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            int x = i+j;
            int y = a[i][j];
            cnt[y][x]++;
        }
    }

    int ans = 1;
    for(int i=2; i<=n+m; i++)
    {
        if(cnt[1][i]!=0 && cnt[2][i]!=0)
        {
            cout<<0<<endl;
            return;
        }

        if(cnt[2][i]==0 && cnt[1][i]==0)
        {
            ans*=2;
            ans%=mod;
        }
    }

    cout<<ans<<endl;
}

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

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
// typedef pair<int,int> P;
// typedef pair<int,P> IP;
// typedef pair<P,P> PP;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=998244353;

ll mpow(ll x,ll n){
    if(n==0) return 1;
    else if(n%2) return x*mpow(x,n-1)%MOD;
    return mpow(x*x%MOD,n/2)%MOD;
}

int H,W;
char S[500][500];

int main(){
    cin>>H>>W;
    rep(i,H) rep(j,W) cin>>S[i][j];

    ll cnt=0;
    rep(k,H+W-1){
        int r=0, b=0, d=0;
        int j=0;
        for(int i=k;i>=0;i--){
            j=k-i;
            if(0<=i && i<H && 0<=j && j<W){
                // cout<<'('<<i<<','<<j<<')'<<endl;
                if(S[i][j]=='R') r++;
                if(S[i][j]=='B') b++;
                if(S[i][j]=='.') d++;
            }
        }
        if(r>0 && b>0){
            cout<<0<<endl;
            return 0;
        }
        if(r==0 && b==0) cnt++;
    }

    ll ans=mpow(2,cnt);
    cout<<ans<<endl;

    return 0;
}


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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const double PI = acos(-1);
const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int main() {
    int h, w;
    cin >> h >> w;
    vector<pair<int, int>> ps, d_ps, uniq_ps;
    REP(i, h) REP(j, w) {
        char c;
        cin >> c;
        if (c == '#') {
            ps.push_back(make_pair(i * 10 - 5, j * 10 - 5));
            ps.push_back(make_pair(i * 10 + 5, j * 10 - 5));
            ps.push_back(make_pair(i * 10 - 5, j * 10 + 5));
            ps.push_back(make_pair(i * 10 + 5, j * 10 + 5));
        }
    }
    sort(ps.begin(), ps.end());
    uniq_ps = ps;
    UNIQ(uniq_ps);

    REP(i, uniq_ps.size()) {
        //cout << ps[i].first << " " << ps[i].second << endl;
        int cnt = count(ps.begin(), ps.end(), uniq_ps[i]);
        if (cnt == 2 || cnt == 4) {
            continue;
        }
        d_ps.push_back(uniq_ps[i]);
        //if (ps[i-1] == ps[i] && ps[i+1] == ps[i]) {
        //    d_ps.push_back(ps[i]);
        //    continue;
        //}
        //if (ps[i-1] == ps[i] || ps[i+1] == ps[i]) {
        //    continue;
        //}
        //d_ps.push_back(ps[i]);
    }
    //REP(i, d_ps.size()) {
    //    cout << d_ps[i].first << " " << d_ps[i].second << endl;
    //}
    cout << d_ps.size() << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) v.begin(), v.end()
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 (b<a) { a=b; return 1;} return 0;}

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H); rep(i, H) cin >> S[i];

    int dy[] = {0, 0, 1, 1};
    int dx[] = {0, 1, 0, 1};

    int res = 0;
    for (int i = 0; i < H-1; ++i) {
        for (int j = 0; j < W-1; ++j) {
            int cnt = 0;
            for (int k = 0; k < 4; ++k) {
                if (S[i+dy[k]][j+dx[k]] == '#') ++cnt;
            }
            if (cnt == 1 || cnt == 3) {
                ++res;
            }
        }
    }
    cout << res << endl;
}


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
void fail() {print("No"); exit(0);}
// clang-format on

int main() {
    ll n, m, t;
    cin >> n >> m >> t;
    //vector<pll> ab(m);
    ll n0 = n;
    ll curt = 0;
    for (ll i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        n = n - (a - curt);
        if (n <= 0) fail();
        n = n + (b - a);
        n = min(n0, n);
        curt = b;
    }
    n = n - (t - curt);
    if (n <= 0) fail();

    print("Yes");
}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;
    ll N,M,K,T;
    ll A[100010],B,C,X;
    bool F=true;
    ll ans=0;
    string S;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>M>>T;
    ll pos=0;
    ll res=N;
    REP(i,M){
        ll a,b;
        cin>>a>>b;
        if(N-(a-pos)<=0){
            cout<<"No"<<endl;
            return 0;
        }
        if(N+b-a-(a-pos)<=res)N+=b-a-(a-pos);
        else N=res;
        pos=b;
        DEB(N)DEB(pos)
    }
    cout<<(N-(T-pos)>0?"Yes":"No")<<endl;
    return 0;
}


#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;
long LCM(long m, long n){
    //nPrime = 1000000007
    if (m < n){
        swap(m,n);
    }
    if (m % n == 0){
        return n;
    }
    long a = m, b = n;
    while (b > 0) {
        long t = a / b;
        a -= t * b;
        swap(a, b);
    }
    return a;
}

long Inverse(const long m, const long n){
    //nPrime = 1000000007
    if (m % n == 0){
        return 0;
    }
    long a = m, b = n, u = 1, v = 0;
    while (b > 0) {
        long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= n;
    if (u < 0){
        u += n;
    }
    return u;
}

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        long n,s,k;
        scanf("%ld %ld %ld", &n, &s, &k);
        long ilcm = LCM(n,k);
        if(s % ilcm != 0){
            printf("-1\n");
            continue;
        }
        n /= ilcm;
        s /= ilcm;
        k /= ilcm;
        long nAns = Inverse(k,n) * (n-s);
        nAns %= n;
//        printf("%ld %ld %ld\n", n, s, k);
        printf("%ld\n",nAns);
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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 (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

// {g,x,y}: ax+by=g
tuple<ll,ll,ll> extgcd(ll a, ll b) {
    if (b == 0) return {a,1,0};
    ll g, x, y;
    tie(g,x,y) = extgcd(b, a%b);
    return {g,y,x-a/b*y};
}

void solve() {
    ll n, s, k;
    cin >> n >> s >> k;
    ll g, x, y;
    tie(g,x,y) = extgcd(k,n);
    if (s%g != 0) {
        cout << -1 << endl;
        return;
    }
    n /= g;
    s /= g;
    k /= g;
    ll ans = ((x*-s)%n+n)%n;
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    rep(i,t) solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
int ans = 0;
for (int i = 1; i <n ; i++)
{
    int j = n - i;
    if(j>=1)ans++;
}
cout<<ans+1/2<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	string s;
	cin>>s;
	if(s.size()%2){
		string ss;
		for(int i=0;i<s.size()/2;i++){
			ss+='9';
		}
		if(ss.size()==0)ss="0";
		cout<<ss;
		return 0;
	}
	string a=s.substr(0,s.size()/2),b=s.substr(s.size()/2,s.size()/2);
	int x=stoi(a),y=stoi(b);
	cout<<max(x-1,min(x,y));
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000005,M=998244353;
int n,m,i,mi[21],su[N];
int main()
{
	scanf("%d",&n);
	for(i=0;i<n;++i)
		printf("%d %d\n",i*2%n+1,(i*2+1)%n+1);
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;}
template<class T> void print(const T &t) { cout << t << "\n"; }
const ll INF = 1LL << 62;
const int iINF = 1 << 30;

#define pq(T) priority_queue<T, vector<T>, greater<T>>
struct Edge {ll to; ll w; Edge(ll to, ll w) : to(to), w(w) {}};
using Graph = vector<vector<Edge>>;

vl dijkstra(Graph &G, int s){
    int n = G.size();
    vl dist(n, INF);
    dist[s] = 0;

    using pp = pair<ll, ll>;
    pq(pp) que;
    que.push({dist[s], s});

    while (!que.empty()) {
        ll v = que.top().second;
        ll d = que.top().first;
        que.pop();

        if (d > dist[v]) continue;
        if(!G[v].empty()) fore(e, G[v]) {
            if (chmin(dist[e.to], dist[v] + e.w)) {
                que.push({dist[e.to], e.to});
            }
        }
    }
    return dist;
}

int n;

int main() {
    fio(); cin>>n;
    Graph E(n+1);
    rep1(i,n){
        ll x = (2*i)%n+1, y=(2*i+1)%n+1;
        cout<<x<<" "<<y<<"\n";
        E[i].emplace_back(x,1);
        E[i].emplace_back(y,1);
    }
    ll ans = 0;
    rep1(i,n) {
        vl dist = dijkstra(E,i);
        ll tmp = 0;
        rep1(i,n) chmax(tmp,dist[i]);
        chmax(ans,tmp);
    }
}


#include <cstdio>

#define For(i, l, r) for(i=int(l); i<=int(r); i++)
#define Fo(i, n) For(i, 1, n)

typedef long long int64;

const int MOD = 1e9 + 7;

inline int qpow(int64 b, int p, int mod=MOD) {
	int res=1;
	while(p) {
		if(p & 1)
			res=res*b%mod;
		b=b*b%mod;
		p>>=1;
	}
	return res;
}

int main() {
	int i, sum = 0;
	int x, invx;
	int n, m;

	scanf("%d %d", &n, &m);
	Fo(i, n) {
		scanf("%d", &x);
		sum += x;
	}
	sum += n;
	m += n;

	if(sum > m) {
		printf("0\n");
		return 0;
	}
	x = invx = 1;
	Fo(i, sum) {
		x = x * (m - i + 1LL) % MOD;
		invx = 1LL * invx * i % MOD;
	}

	printf("%lld\n", 1LL * x * qpow(invx, MOD - 2) % MOD);

	return 0;
}

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

int main() {
    int n, k, m, sum = 0, ans;
    cin >> n >> k >> m;
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p;
        sum += p;
    }
    if (m * n - sum < 0)
        ans = 0;
    else if (k < m * n - sum)
        ans = -1;
    else
        ans = m * n - sum;
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
int solve(string s1,string s2)
{
    int x=0,y=0,n1=s1.size(),n2=s2.size();
    for(int i=0,f=0;i<n1;++i)
    {
        if(!f&&s1[i]=='0') continue;
        else f=1,x=(x<<3)+(x<<1)+(s1[i]^48);
    }
    for(int i=0,f=0;i<n2;++i)
    {
        if(!f&&s2[i]=='0') continue;
        else f=1,y=(y<<3)+(y<<1)+(s2[i]^48);
    }
    return x-y;
}
signed main()
{
    int n,k,res;cin>>n>>k;res=n;
    for(int i=1;i<=k;++i)
    {
        string s1=to_string(res);
        sort(s1.begin(),s1.end());
        string s2=s1;
        reverse(s1.begin(),s1.end());
        res=solve(s1,s2);
    }
    cout<<res;return 0;
}

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

using ll = long long;

ll powk(ll a, ll n = 2){
  ll r = 1;
  for(ll i = 0;i < n;i++){
    r *= a;
  }

  return r;
}

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

  ll t = n;
  for(ll i = 0;i < k;i++){
    string st;
    st = to_string(t);
    sort(st.begin(),st.end());
    ll m = 0, u = 0;
    for(ll j = 0;j < st.size();j++){
      m += pow(10, j) * (st[st.size() - j - 1] - '0');
      u += pow(10, j) * (st[j] - '0');
    }
    t = u - m;
  }

  cout << t;

  return 0;
}


#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
//#define file
using namespace std;

int n,K,i,j,k,l,L,R,Mid,sum,s1,s2;
int a[400001][2],ls[200001],len;
int f[200001];

void New(int x,int y) {++len;a[len][0]=y;a[len][1]=ls[x];ls[x]=len;}
void dfs(int Fa,int t)
{
	int i,s1=n+1,s2=-n-1;
	bool bz=0;
	f[t]=0;
	for (i=ls[t]; i; i=a[i][1])
	if (a[i][0]!=Fa)
	{
		dfs(t,a[i][0]),bz=1;
		s1=min(s1,f[a[i][0]]+1);
		s2=max(s2,f[a[i][0]]+1);
		f[t]=max(f[t],f[a[i][0]]+1);
	}
	if (bz)
	{
		if (s1+1<0 && s1+1+s2<=0) f[t]=s1;
		else
		{
			f[t]=s2;
			if (f[t]==Mid)
			f[t]=-Mid-1,++sum;
		}
	}
}

int main()
{
	#ifdef file
	freopen("e.in","r",stdin);
	#endif

	scanf("%d%d",&n,&K);
	fo(i,1,n-1) scanf("%d%d",&j,&k),New(j,k),New(k,j);

	L=1,R=n;
	while (L<R)
	{
		Mid=(L+R)/2;
		sum=0;
		dfs(0,1);
		s1=n+1,s2=-n-1;
		for (i=ls[1]; i; i=a[i][1])
		{
			s1=min(s1,f[a[i][0]]+1);
			s2=max(s2,f[a[i][0]]+1);
		}
		if (!(f[1]<0 || s1+1+s2<=0)) ++sum;

		if (sum>K) L=Mid+1; else R=Mid;
	}
	printf("%d\n",L);

	fclose(stdin);
	fclose(stdout);
	return 0;
}

//Target for Pupil
//Implementation and Data structures
//Prodip sarker(student_ip)
#define bn begin()
#define en end()
#define mx 5000010
#define pb push_back
#define PI (2.0*acos(0.0))
#define al(a) a.begin(),a.end()
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rep(a,b) for(int a=0;a<b;++a)
#define fastio ios::sync_with_stdio(false)
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int>  vi;
typedef vector<ll>   vll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
	long long unsigned a,b,c,x,y,n,i,t,tmp,d,e,f,p;
	cin>>x>>y>>a>>b;
	ll sum=0;
	while(x<y)
	{
//		cout<<x<<"\n";
		if(LLONG_MAX/x >= a &&x*a<x+b&&(x*a<y))
		{
			sum++;
			x=x*a;
		}
		else
		{
			y-=1;
			sum+=(y-x)/b;
			break;
		}
	}
	cout<<sum<<endl;

	return 0;
}


#include<bits/stdc++.h>

#define st first
#define nd second
#define pb(x) push_back(x)
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)

using namespace std;

///~~~~~~~~~~~~~~~~~~~~~~~~~~

void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);

///~~~~~~~~~~~~~~~~~~~~~~~~~

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;

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

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

const int N=2e5+5, INF=1e9+5, mod=998244353;
ll pot(ll a, ll b){
    if(b==0) return 1ll;
    if(b==1) return a;
    ll c=pot(a, b/2);
    c=(c*c)%mod;
    return (c*pot(a, b&1))%mod;
}
int main(){
	int a, b, k;
	cin>>a>>b>>k;
	if(a==1){
		cout<<pot(k, b);
	}
	else if(b==1){
		cout<<pot(k, a);
	}
	else{
		ll ans=0;
		for(int i=1; i<=k+1; i++){
			ans+=(pot(i, a)-pot(i-1, a))*1ll*pot(k+1-i, b);
			ans%=mod;
		}
		cout<<(ans+mod)%mod;
	}
}

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define inf 1000000000
#define pii pair<int,int>
#define fi first
#define se second
#define inp(a) for(auto &x: a)cin>>x
#define fr(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) for(int i=a;i<b;++i)
int binpow(int a,int b,int m){
    a%=m;
    int res=1;
    while(b>0){
        if(b&1)res=res*a%m;
        a=a*a%m;b/=2;
    }
    return res;
}
signed main(){
    int a,b,c,mod=998244353;
    cin>>a>>b>>c;
    if(a==1){cout<<binpow(c,b,mod);return 0;}
    if(b==1){cout<<binpow(c,a,mod);return 0;}
    int ans=0;
    for(int i=1;i<=c;i++){
        ans=(ans+binpow(c-i+1,b,mod)*((binpow(i,a,mod)-binpow(i-1,a,mod)+mod)%mod)%mod)%mod;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define watch(x) std::cout << (#x) << " is " << (x) << std::endl
using LL = long long;
using pii = std::pair<int, int>;
using pll = std::pair<LL, LL>;

int main() {
	//freopen("in","r",stdin);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	LL s, p;
	std::cin >> s >> p;
	__int128 S = s, P = p;
	if (S * S < 4 * P) {
		std::cout << "No\n";
		return 0;
	}
	__int128 b = std::sqrt(1.0 * S * S - 4 * P + 0.5);
	if (b * b == S * S - 4 * P && ((b + s) % 2 == 0)) {
		std::cout << "Yes\n";
	} else std::cout << "No\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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; }
const int INF = 1000100100;
const int MOD = 1000000007;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

ll S, P;

int main() {
    cin >> S >> P;

    vector<ll> div = divisor(P);

    for(ll i = 0; i < div.size(); ++i) {
        if(div.at(i) + (P/div.at(i)) == S) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

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

    int a[n];

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

    vector<int> fre(300001,0);

    for(int i=0;i<n;i++)
        fre[a[i]]++;

    vector<int> mn_fre(300001);
    ll ans = 0;
    for(int i=0;i<=300000;i++)
    {
        if(i == 0)
            mn_fre[i] = min(k,fre[i]);
        else
        {
            mn_fre[i] = min(mn_fre[i-1],fre[i]);
            ans += (mn_fre[i] - mn_fre[i-1]<0)*((mn_fre[i-1] - mn_fre[i])*i);
        }
    }

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

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"
#define cauto const auto

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
void ouT(ll x,int d=3){auto re=to_string(x);if((int)re.size()>d) re=x>0?"oo":"-oo";cout<<string(d-re.size(),' ')<<re<<",";}
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;}
template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;}
template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;}
template<class T=ll> T read(){ T re; cin>>re; return move(re);}
template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;}
template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);}
template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);}
vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);}
vv<int> readG(const int &n){ return readG(n,n-1);}
#define TT cauto TTT=read();rep(_,TTT)
const ll MOD=1e9+7; //998244353;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	cauto n=read();
	cauto t=read();
	cauto vs=readV(n);
	vector<int> cnt(n+1);
	for(cauto &v:vs) ++cnt[v];
	ll re=0;
	rep(_,t){
		int i=0;
		for(;cnt[i];++i) --cnt[i];
		re+=i;
	}
	cout<<re NL;
  return 0;
}


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

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

  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  deque<int> A, B;
  for (int i = 0; i < N; i++) {
    if (S[i] == '1') A.emplace_back(i);
    if (T[i] == '1') B.emplace_back(i);
  }

  long long ans = 0;

  for (int i = 0; i < N; i++) {
    int s = binary_search(begin(A), end(A), i);
    int t = T[i] - '0';
    if (s == t) {
      if (s == 1) {
        assert(A.front() == i);
        A.pop_front();
      }
      continue;
    }
    if (s == 0 && t == 1) {
      if (A.empty()) {
        cout << -1 << '\n';
        return 0;
      }
      ans += abs(A.front() - i);
      A.pop_front();
    } else if (s == 1 && t == 0) {
      assert(A.front() == i);
      A.pop_front();
      if (A.empty()) {
        cout << -1 << '\n';
        return 0;
      }
      ans += abs(A.front() - i);
      A.pop_front();
    } else {
      assert(false);
    }
  }

  cout << ans << '\n';
  return 0;
}

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void sc(int &x){scanf("%d",&x);}
void sc(int &x,int &y){scanf("%d%d",&x,&y);}
void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void sc(ll &x){scanf("%lld",&x);}
void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);}
void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}
void sc(char *x){scanf("%s",x);}
void sc(char *x,char *y){scanf("%s%s",x,y);}
void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);}
void out(int x){printf("%d\n",x);}
void out(ll x){printf("%lld\n",x);}
void out(int x,int y){printf("%d %d\n",x,y);}
void out(ll x,ll y){printf("%lld %lld\n",x,y);}
void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);}
void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);}
using namespace std;
const int N=2e5+5;
int n,a[N],b[N];
unordered_map<int,int>vis;
vector<int>v[N];
int bit[N];
void add(int x)
{
    while(x<=n) bit[x]++,x+=x&-x;
}
int query(int x)
{
    int ans=0;
    while(x) ans+=bit[x],x-=x&-x;
    return ans;
}
int main()
{
    sc(n);
    rep(i,1,n) sc(a[i]),a[i]+=i-1;
    rep(i,1,n) sc(b[i]),b[i]+=i-1;
    int id=0;
    rep(i,1,n)
        if(!vis[a[i]])
            vis[a[i]]=++id;
    nep(i,n,1)
        v[vis[a[i]]].push_back(i);
    ll ans=0;
    rep(i,1,n)
    {
        int x=vis[b[i]];
        if(!x||v[x].size()==0)
        {
            out(-1);return 0;
        }
        int pos=v[x].back()+(i-1-query(v[x].back()));
        add(v[x].back());
        v[x].pop_back();
        ans+=pos-i;
    }
    out(ans);
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i =0; i <(n); i++)
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 1<<30;
    rep(s,1<<(n-1)){
        int now = 0;
        int o = 0;
        rep(i,n){
            o |= a[i];
            if(s>>i&1){
                now ^= o;
                o = 0;
            }
        }
        now ^= o;
        ans = min(ans,now);
    }
    cout << ans;
}

#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N), B(N);
    for(auto&& i : A)cin >> i;
    for(auto&& i : B)cin >> i;
    priority_queue<unsigned long> pq;
    reverse(begin(A), end(A));
    unsigned long ans{0};
    for(unsigned long i{0}; i < N; ++i){
        pq.emplace(A.back());
        pq.emplace(B.back());
        A.pop_back();
        B.pop_back();
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
using namespace std;

int main(){
	int n, x; char c;
	cin >> n >> x;

	for (int i=1; i<=n; i++){
		cin >> c;
		if (c == 'o') x++;
		else if (c == 'x'){
			if (x != 0) x--;
			else continue;
		}
	}

	cout << x << endl;
	return 0;
}

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

template<int M>
struct static_mint {
	static_assert(0 < M, "Module must be positive");

	int val;
	static_mint(): val() {}
	static_mint(long long x) : val(x % M) { if (val < 0) val += M; }
	static_mint pow(long long n) const { static_mint ans = 1, x(*this); while (n) { if (n & 1) ans *= x; x *= x; n /= 2; } return ans; }
	static_mint inv() const { return pow(M - 2); }

	friend static_mint pow(const static_mint &m, long long n) { return m.pow(n); }
	friend static_mint inv(const static_mint &m) { return m.inv(); }

	static_mint operator+() const { static_mint m; m.val = val; return m; }
	static_mint operator-() const { static_mint m; m.val = M - val; return m; }
	static_mint &operator+=(const static_mint &m) { if ((val += m.val) >= M) val -= M; return *this; }
	static_mint &operator-=(const static_mint &m) { if ((val -= m.val) < 0) val += M; return *this; }
	static_mint &operator*=(const static_mint &m) { val = (long long) val * m.val % M; return *this; }
	static_mint &operator/=(const static_mint &m) { val = (long long) val * m.inv().val % M; return *this; }

	friend static_mint operator+ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) += rhs; }
	friend static_mint operator- (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) -= rhs; }
	friend static_mint operator* (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) *= rhs; }
	friend static_mint operator/ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) /= rhs; }
	friend bool operator==(const static_mint &lhs, const static_mint &rhs) { return lhs.val == rhs.val; }
	friend bool operator!=(const static_mint &lhs, const static_mint &rhs) { return lhs.val != rhs.val; }

	static_mint &operator++() { return *this += 1; }
	static_mint &operator--() { return *this -= 1; }
	static_mint operator++(int) { static_mint result(*this); *this += 1; return result; }
	static_mint operator--(int) { static_mint result(*this); *this -= 1; return result; }

	template <typename T> explicit operator T() const { return T(val); }

	friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
		return os << m.val;
	}

	friend std::istream &operator>>(std::istream &is, static_mint &m) {
		long long x; is >> x; m = x;
		return is;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	using mint = static_mint<998244353>;

	int n, m;
	cin >> n >> m;

	vector<string> a(n);
	for (auto &x : a) cin >> x;

	vector<int> mask(n + m - 1);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[i][j] == 'R') {
				mask[i + j] |= 1;
			}
			if (a[i][j] == 'B') {
				mask[i + j] |= 2;
			}
		}
	}

	mint ans = 1;
	for (int lvl = 0; lvl < n + m - 1; lvl++) {
		if (mask[lvl] == 3) {
			ans = 0;
		} else if (mask[lvl] == 0) {
			ans *= 2;
		}
	}
	cout << ans << '\n';
	return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int main ()
{
    ll A,B;
    cin >> A >> B;

    vector<ll> ans;
    REP(i,A) ans.push_back(i + 1);
    REP(i,B) ans.push_back(-(i + 1));

    ll Asum = 0, Bsum = 0;
    REP(i,A) Asum += i + 1;
    REP(i,B) Bsum += i + 1;

    ll diff = abs(Asum - Bsum);
    if (Asum < Bsum) {
        ans[A - 1] += diff;
    } else if (Asum > Bsum) {
        ans[A + B - 1] -= diff;
    }

    REP(i,ans.size()) {
        cout << ans[i] << ((i < ans.size() - 1) ? " " : "\n");
    }

    return 0;
}

#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

ll mpow(ll a, ll b){
	if(b >= (MOD-1)) b %= (MOD-1);
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);   t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
ll modinverse(ll a, ll m){
	ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1) return 0;
    while (a > 1){
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0) x += m0;
    return x;
}
ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}

void solve(){
    ll a,b;
    cin>>a>>b;

    ll x=0;

    if(a==1 && b!=1){
        forsn(i, 1, b+1){
            cout<<-1*i<<" ";
            x+=i;
        }
        cout<<x;
        return;
    }
    if(a!=1 && b==1){
        forsn(i, 1, a+1){
            cout<<i<<" ";
            x+=i;
        }
        cout<<-1*x;
        return;
    }

    if(a>b){
        forsn(i, b, a+1){
            x+=i;
        }
        forsn(i, 1, a+1){
            cout<<i<<" ";
        }
        forsn(i, 1, b){
            cout<<-1*i<<" ";
        }
        cout<<-1*x;
    }
    else if(a<b){
        forsn(i, a, b+1){
            x+=i;
        }
        forsn(i, 1, a){
            cout<<i<<" ";
        }
        forsn(i, 1, b+1){
            cout<<-1*i<<" ";
        }
        cout<<x;
    }
    else{
        forsn(i, 1, a+1){
            cout<<i<<" ";
        }
        forsn(i, 1, b+1){
            cout<<-1*i<<" ";
        }

    }

}

int main()
{
	fast_cin();
    ll t=1;
    // cin>>t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
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 (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((ll)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
// static const int INF = (1 << 30) - 1;  // 1073741824 - 1
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

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

    ll N; cin >> N;
    VLL A(N); REP(i,N) cin >> A[i];

    ll ans = 0;
    ll total = 0;
    ll S = 0;
    ll max_S = -INF;
    REP(i,N) {
        S += A[i];
        chmax(max_S, S);
        chmax(ans, total + max_S);
        total += S;
    }
    COUT(ans);

    return 0;
}

#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <type_traits>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using ISS = istringstream;
using OSS = ostringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;
template < typename T = int > using OSI = ostream_iterator< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }

void in_impl(){};
template < typename T, typename... TS > void in_impl( T &head, TS &... tail ){ cin >> head; in_impl( tail ... ); }
#define IN( T, ... ) T __VA_ARGS__; in_impl( __VA_ARGS__ );

template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define NUMBERED( name, number ) NUMBERED2( name, number )
#define NUMBERED2( name, number ) name ## _ ## number
#define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n )
#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a ) ( remove_all_extents< decltype( a ) >::type * )a, ( remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( remove_all_extents< decltype( a ) >::type )

#define SZ( v ) ( (int)( v ).size() )
#define EXISTS( c, e ) ( ( c ).find( e ) != ( c ).end() )

template < typename T > inline bool chmin( T &a, const T &b ){ if ( b < a ) { a = b; return true; } return false; }
template < typename T > inline bool chmax( T &a, const T &b ){ if ( a < b ) { a = b; return true; } return false; }

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

//     Λ   Λ＿_
//  ／(*ﾟーﾟ)／＼
// ／| ￣U U￣|＼／
//   |      |／

int main()
{
	cin.tie( nullptr );
	ios::sync_with_stdio( false );
	cout << setprecision( 12 ) << fixed;

	IN( LL, N );

	if ( N == 2 )
	{
		cout << 1 << endl;
		return 0;
	}

	LL lb = 0, ub = sqrt( N ) * 2;
	while ( lb + 1 < ub )
	{
		const LL mid = ( lb + ub ) / 2;
		( mid * ( mid + 1 ) / 2 <= N + 1 ? lb : ub ) = mid;
	}
	cout << N + 1 - lb << endl;

	return 0;
}


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

int main(void){
    int H, W, Abuf;
    int minNum = 101;
    int sumNum = 0;
    cin >> H >> W;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> Abuf;
            minNum = min(minNum, Abuf);
            sumNum +=Abuf;
        }
    }
    cout << sumNum - minNum*H*W << endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long int;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
const long long INF = 1LL << 60;
const int inf = 1001001001;
const ll mod = 1000000007;

int main()
{
    int h, w;
    cin >> h >> w;
    vi a(h*w); rep(i,h*w) cin >> a[i];
    sort(ALL(a));
    int min = a[0];
    int res = 0;
    for (int i = 1; i < h*w; i++) {
        res += a[i] - min;
    }
    cout << res << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (int)(l); i < (int)(n); i++)
#define drep(i, n, l) for (int i = (int)(n); i > (int)(l); i--)
#define INF INT_MAX
#define INFF (pow(2,64))
#define def (200007)
#define MOD (1000000007)
typedef int64_t intt;
typedef vector<int> veci;
typedef vector<vector<int>> Veci;
typedef vector<int64_t> vecit;
typedef vector<vector<int64_t>> Vecit;
typedef vector<vector<double>> Vecd;
typedef vector<double> vecd;
typedef pair<intt, intt> P;
typedef unordered_set<int> uset;
typedef unordered_set<intt> usett;

int main(){
  int N;cin>>N;
  int max=0;
  veci a;
  int maxa=0;
  int gcd;
  rep(i,0,N){
    int A;cin>>A;
    a.push_back(A);
    maxa=maxa>A?maxa:A;
  }
  rep(i,2,maxa+1){
    int at_sum=0;
    rep(j,0,N){
      if(a[j]%i==0)at_sum++;
    }
    if(max<at_sum){
      gcd=i;
      max=at_sum;
    }
  }
  cout<<gcd<<endl;
}

#include<iostream>

int main(){
  int max_gcd = 0, ans = 0;
  int n;
  std::cin >> n;
  int a[n];
  for(int i=0; i < n; i++){
    std::cin >> a[i];
  }
  for(int h=2; h < 1000; h++){
    int gcd=0;
    for(int i=0; i < n; i++){
      if(a[i] % h == 0){
        gcd++;
      }
    }
    if(gcd > max_gcd){
      max_gcd = gcd;
      ans = h;
    }
  }
  if(!ans){
    std::cerr << "error" << std::endl;
  }else{
    std::cout << ans << std::endl;
  }
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define e "\n"
#define fl(x,n) for(ll i=x;i<=n;i++)
#define fl2(x,n) for(ll i=x;i>=n;i--)
using namespace std;
int main()
{

       ll n;
       cin >> n;
       if(n%100==0)
        cout << 100 << e;
       else
       {
           ll d=ceil((double)n/100);

           cout << d*100-n << e;
       }

       return 0;
}

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

int main() {
  int X;
  cin >> X;
  if (X % 100 == 0) {
    cout << 100 << endl;
  }
  else {
    cout << 100 - X % 100 << endl;
  }
  return 0;
}


/////////////////////////////////////////////////////////////
//                          Give me AC!!!                                     //
////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c, n) for (int i = c; i < (n); ++i)
#define yn(ok, True, False) if (ok) { p(True) } else {p(False)};
//以下debug用
#define d(x) cout << #x << "; " << x << endl;
#define p(x) cout << x << endl;
#define f(x)                         \
  for (int i = 0; i < x.size(); i++) \
    cout << #x << "[" << i << "]; " << x[i] << endl;

int a, b, c, i, j, m, n, M, N, L, R, ans = 0, counter = 0, num = 0;
long long llans = 0, llcounter = 0, llnum = 0;
string str, str1, str2, str3;
bool ok = false;

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, 0, h) cin >> s[i];
  rep(i,0,h-1)rep(j,0,w-1){
    int cnt = 0;
    rep(di, 0, 2) rep(dj, 0, 2) if (s[i + di][j + dj] == '#') cnt++;
    if (cnt ==1 || cnt == 3)
      ++ans;
  }
  p(ans)

  return 0;
}


#include <stdio.h>

#include <algorithm>
#include <vector>

using namespace std;

#define cm (1 << 17)
char cn[cm], *ci = cn + cm, ct;

inline char getcha() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}

inline int getint() {
  int A = 0;
  while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
  return A;
}

inline int up(const void* a, const void* b) {
  return *(int*)a < *(int*)b ? -1 : *(int*)a > *(int*)b ? 1 : 0;
}
inline void sortup(int* a, int n) {
  qsort(a, n, sizeof(int), up);
}

#define mxN 200005
int h[mxN], w[mxN];
long long sum_l[mxN], sum_r[mxN];

int main() {
  int n = getint(), m = getint(), pos = 0;
  for (int i = 0; i < n; i++) {
    h[i] = getint();
  }
  for (int i = 0; i < m; i++) {
    w[i] = getint();
  }
  sortup(h, n);
  sortup(w, m);
  sum_l[0] = sum_r[0] = 0;
  for (int i = 0; i < n / 2; i++) {
    sum_l[i + 1] = sum_l[i] + h[2 * i + 1] - h[2 * i];
    sum_r[i + 1] = sum_r[i] + h[2 * i + 2] - h[2 * i + 1];
  }
  long long ans = 1LL << 60, right = sum_r[n / 2];
  for (int i = 0; i < m; i++) {
    while (pos < n && h[pos] < w[i]) pos++;
    ans = min(ans, sum_l[pos / 2] + right - sum_r[pos / 2] +
                       abs(h[pos - pos % 2] - w[i]));
  }
  printf("%lld", ans);
}

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};
using mint = ModInt<>;

int n;
vector<long long> b;
vector<vector<mint>> dp;

mint solve();

int main() {
  cin >> n;
  b.assign(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  cout << solve() << endl;
  return 0;
}

mint solve() {
  mint res = 0;
  dp.assign(n + 1, vector<mint>(n + 1, 0));
  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = n; j >= 1; --j) {
      mint now = dp[j - 1][b[i] % j];
      if (j != n) dp[j][b[i] % (j + 1)] += now;
      if (i == n) res += now;
    }
  }
  return res;
}