#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N, M; RI(N); RI(M);
  vector<string> S(M);
  i64 L_min = 100, L_max = 0;
  unordered_set<string> SS;
  REP(0, M, i) {
    RS(S[i]);
    L_min = min(L_min, sz(S[i]));
    L_max = max(L_max, sz(S[i]));
  }
  sort(all(S), [](const string &lhs, const string &rhs) {
    return lhs.size() > rhs.size();
  });

  unordered_set<string> sub;
  for(auto &s: S) {
    if(!IN(sub, s)) {
      SS.insert(s);
      REP(0, sz(s), i) { // left
        REP(L_min, sz(s)-i+1, j) { // length
          sub.insert(s.substr(i, j));
        }
      }
    }
  }

  S.clear();
  for(auto &s: SS) {
    S.pb(s);
  }
  M = sz(S);
  i64 L_avg = (L_min + L_max) / 2;

  sort(all(S), [](const string &lhs, const string &rhs) {
    return lhs.size() < rhs.size();
  });

  vector<string> ans(N, string(N, '.'));
  // horizontal
  vi pos(N, 0);
  i64 idx = 0;
  bool loop = true;
  while(loop) {
    loop = false;
    REP(0, N, i) {
      if(idx < M && pos[i] + sz(S[idx]) <= N) {
        for(auto &c: S[idx]) {
          assert(ans[i][pos[i]] == '.');
          ans[i][pos[i]] = c;
          pos[i]++;
        }
        ++idx;
        loop = true;
      }
    }
  }

  i64 p_max = *max_element(all(pos));
  vi pos2(N, 0);
  loop = true;
  while(loop) {
    loop = false;
    REP(p_max, N, i) {
      if(idx < M && pos2[i] + sz(S[idx]) <= N) {
        for(auto &c: S[idx]) {
          assert(ans[pos2[i]][i] == '.');
          ans[pos2[i]][i] = c;
          pos2[i]++;
        }
        ++idx;
        loop = true;
      }
    }
  }

  REP(0, N, i) {
    REP(0, N, j) {
      if(ans[i][j] == '.') {
        ans[i][j] = 'A' + (rand() % 8);
      }
    }
  }

  REP(0, N, i) {
    WS(ans[i]);
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
string ans[20];
void output();
void init();
bool yokoni_dekirudake_umeru();
void yokoni_umeru(int,int);
int n,m;
int used_m;
string next_s();
vector<string> s;
int main(){ //2,3は無視でいいんじゃないか？
    init();
    bool filled = false;
    while(used_m < m && !filled){
        filled = yokoni_dekirudake_umeru();
    }

    output();

}

bool yokoni_dekirudake_umeru(){
    bool filled = true;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            if(ans[i][j] == '.' && (j + (int)(next_s().size()) <= n + 1)){ //tyuui koko
                yokoni_umeru(i,j);
                filled = false;
            }
        }
    }
    return filled;
}
void yokoni_umeru(int i , int j){
    for(int k = 0 ; k < next_s().size() ; k++){
        ans[i][j+k] = next_s()[k];
    }
    used_m++;
}
string next_s(){
    return s[used_m];
}

void init(){
    cin >> n >> m;
    for(int i = 0 ; i < 20 ; i++){
        for(int j = 0 ; j < 20 ; j++){
            if(j==0)ans[i] = "";

            ans[i] += ".";
        }
    }

    for(int i = 0 ; i < m ; i++){
        string st;
        cin >> st;
        s.push_back(st);
    }

    sort(s.begin(),s.end());
    reverse(s.begin(),s.end());
}
void output(){
    for(int i = 0 ; i < 20 ; i++){
        cout << ans[i] << endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}
//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    //cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n;
        cin>>n;
        priority_queue<int>pq;
        unordered_map<int,int>vis;
        int mn = inf;
        for(int i = 0; i < n; i++) {
			int x;
			cin>>x;
			mn = min(mn,x);

			if(!vis[x]) {
				vis[x] = 1;
				pq.push(x);
			}
		}
		while(pq.size() > 1) {
			int mx = pq.top();
			pq.pop();
			int nw = mx%mn;
			if(!nw) cont;
			if(!vis[nw]) {
				vis[nw] = 1;
				if(nw < mn) mn = nw;
				pq.push(nw);
			}
		}
		cout<<mn<<endl;

        //for(int i = 0; i < n; i++) {
			//int x;
			//cin>>x;
			//if(!vis[x]) {
				//ip.pb(x);
				//vis[x] = 1;
			//}
		//}
		//sort(ip.begin(),ip.end());
		//if(ip.size() > 1) {
			//ans = ip[0];
			//for(int i = 1; i < ip.size(); i++) {
				//ans = min(ans,ip[i]-ip[i-1]

    }

return 0;
}

/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 61;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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;
}

ll conbinationMemo[201][12];

void cmemoInit(){
    rep(i, 201){
        rep(j, 12){
            conbinationMemo[i][j] = -1;
        }
    }
}

ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    vector<pair<ll,ll>> ps;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        ps.push_back({x, y});
    }
    ll m;
    cin >> m;
    vector<pair<ll,ll>> ops;
    rep(i, m){
        ll t;
        cin >> t;
        if(t == 1 || t == 2){
            ops.push_back({t, -1});
        } else {
            ll p;
            cin >> p;
            ops.push_back({t, p});
        }
    }
    ll q;
    cin >> q;
    vector<pair<ll,ll>> qs;
    rep(i, q){
        ll a, b;
        cin >> a >> b;
        b--;
        qs.push_back({a, b});
    }

    ll x = 1, y = 1;
    pair<ll,ll> o = {0, 0};
    ll swp = 0;
    struct S{
        ll x;
        ll y;
        pair<ll,ll> o;
        ll swp;
    };
    vector<S> vec;
    vec.push_back({1, 1, {0, 0}, 0});
    rep(i, m){
        pair<ll,ll> op = ops[i];
        if(op.first == 1){
            x *= -1;
            swap(x, y);
            o.first *= -1;
            swap(o.first, o.second);
            swp--;
            swp %= 2;
            while(swp < 0) swp += 2;
        } else if(op.first == 2){
            y *= -1;
            swap(x, y);
            o.second *= -1;
            swap(o.first, o.second);
            swp++;
            swp %= 2;
            while(swp < 0) swp += 2;
        } else if(op.first == 3){
            //if(swp == 0){
                o.first += 2 * (op.second - o.first);
            //} else {
                //o.second += 2 * (op.second - o.second);
            //}
            x *= -1;
        } else {
            //if(swp == 0){
                o.second += 2 * (op.second - o.second);
            //} else {
                //o.first += 2 * (op.second - o.first);
            //}
            y *= -1;
        }
        vec.push_back({x, y, o, swp});
    }
    rep(i, q){
        S s = vec[qs[i].first];
        if(s.swp == 0){
            cout << ps[qs[i].second].first * s.x + s.o.first << " " << ps[qs[i].second].second * s.y + s.o.second << endl;
        } else {
            cout << ps[qs[i].second].second * s.x + s.o.first << " " << ps[qs[i].second].first * s.y + s.o.second << endl;
        }
    }

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll A, B; cin >> A >> B;
  ll result = 2*A+100 - B;
  cout << result << endl;
  return 0;
}

  #include<bits/stdc++.h>
  using namespace std;
  using ll = long long;
  #define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
  #define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
  #define repc(i,f,n) for(char i=(f); (i) <= (n); i++)
  #define PI 3.14159265358979323846264338327950ll
  #define debug(x) cout<<#x<<" :: "<<x<<"\n";
  #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
  #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
  #define Pl pair<ll, ll>
  #define dvec vector<vector<ll>>
  #define OUT(x) cout << x << endl; return 0;
  //printf("%.10f\n")
  //cout << fixed << setprecision(10);
  template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
  template<class T> inline bool chmaxe(T& a, T b){if (a <= b) { a = b; return true; } return false;}
  template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
  const ll MOD = 1000000007ll;
  const ll INF = 1e+18;
  const int iINF = 1e9;
  const double EPS = 1e-8;

vector<vector<ll>> x, y, z, memo;

ll
f(ll H, ll W, vector<string> &grd)
{
  if(H == 1 && W == 1) return 1;
  if(H < 1 || W < 1) return 0;
  if(grd[H - 1][W - 1] == '#') return 0;
  if(memo[H][W] != -1) return memo[H][W];

  x[H][W] = (f(H - 1, W, grd) + x[H - 1][W] + MOD) % MOD;
  y[H][W] = (f(H, W - 1, grd) + y[H][W - 1] + MOD) % MOD;
  z[H][W] = (f(H - 1, W - 1, grd) + z[H - 1][W - 1] + MOD) % MOD;

  return memo[H][W] = (x[H][W] + y[H][W] + z[H][W] + MOD) % MOD;
}

int
main()
{
  ll H, W; cin >> H >> W;
  vector<string> grd(H);
  rep(i, 0, H) cin >> grd[i];
  x.assign(H + 1, vector<ll>(W + 1, 0));
  y.assign(H + 1, vector<ll>(W + 1, 0));
  z.assign(H + 1, vector<ll>(W + 1, 0));
  memo.assign(H + 1, vector<ll>(W + 1, -1));

  cout << f(H, W, grd) << endl;
}


#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
const int INF = 1e9+1;
using namespace std;
using ll = long long;
using p = pair<int, int>;
using v = vector<int>;

int main(){
  int N, M, T;
  cin >> N >> M >> T;
  v A(M), B(M);
  int n = N;
  int t = 0;
  REP(i, M) cin >> A[i] >> B[i];
  REP(i, M) {
    n -= (A[i]-t);
    if (n <= 0) {
      cout << "No" << endl;
      return 0;
    }
    n = min(N, n+(B[i]-A[i]));
    t = B[i];
  }
  n -= T-t;
  if (n <= 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}

/*
ID: alec3
LANG: C++14
PROG:
/*

*/

#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" " << endl;
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define line cout << "--------------" << endl;

typedef long long ll;
typedef unsigned long long ull;

int pct(int x) { return __builtin_popcount(x); }

using namespace std;

void setIO(string name) {
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
	ios_base::sync_with_stdio(0);
}

int main()
{
    io;
    int n, x;
    cin >> n >> x;
    string s; cin >> s;

    ll points = x;
    for (int i = 0; i < n; i++){
        if (s[i] == 'x'){
            if (points > 0)
                points --;
        }
        else
            points ++;
    }
    cout << points << endl;

    return 0;
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define getchar_unlocked getchar

int A[100005];
int B[100005];
int offset[100005];
int minLevel1[100005];
int minLevel2[100005];
int N, L;

inline int nextInt(){
    int x=0;
    char ch=0;
    do{
        ch=getchar_unlocked();
    }while(ch<'0'||ch>'9');
    while(ch>='0'&&ch<='9'){
        x=10*x+(ch-'0');
        ch=getchar_unlocked();
    }
    return x;
}

int main(){
    N = nextInt();
    L = nextInt();
    for(int i = 1; i <= N; i ++){
        A[i] = nextInt();
        offset[i] = A[i]-i;
    }
    for(int i = 1; i <= N; i ++){
        B[i] = nextInt();
    }

    for(int i = 1; i <= N; i ++){
        minLevel1[i] = 0;
        minLevel2[i] = 0;
        //printf("offset[%d]=%d\n", i, offset[i]);
    }

    long long ans = 0;
    int lo = 1;
    int hi2 = 1;
    for(int i = 1; i <= N; i ++){
        if(A[i] == B[i]){continue;}
        if(B[i] == i || B[i] == L-N+i){
            ans ++;
        }else{
            while(lo < N+2 && offset[lo] < B[i]-i){
                lo ++;
            }

            if((lo == N+2) || (offset[lo] != B[i]-i)){
                printf("-1");
                return 0;
            }

            while(hi2 < N+2 && offset[hi2] <= B[i]-i){
                hi2 ++;
            }

            int hi = hi2-1;
            //int hi = upper_bound(offset+1, offset+(1+N), B[i]-i) - offset - 1;

            if(lo > i){
                minLevel2[lo] = max(minLevel2[lo], lo - i);
            }else{
                minLevel1[hi] = max(minLevel1[hi], i - hi);
            }

            //printf("i=%d [%d, %d]\n", i, lo, hi);
            //ans += min(abs(lo - i), abs(hi - i));
        }
    }

    for(int i = 1; i <= N; i ++){
        ans += minLevel1[i] + minLevel2[i];
    }

    printf("%lld\n", ans);
    return 0;
}


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test() int t; cin>>t; while(t--)
#define all(v) v.begin(),v.end()
#define st(v) sort(all(v))
#define stA(arr,n) sort(arr,arr+n)
#define dp(n,c) vector<vector<ll>> dp(n,vector<ll>(c,0))
#define vc(v,n,f) vector<ll> v(n,f)
#define vct(v) vector<ll> v
#define findInVec(v,key) (find(all(v),key)!=v.end())
#define findInSet(v,key) (v.find(key) != v.end())
#define findInStr(s,key) (s.find(key) != string::npos)
#define findInMap(m,key) (mp.find(key) != mp.end())
#define prt(i) cout<<i<<"\n"
#define fos(v) for(auto x:v)
#define fo(m,n,i) for(int i=m;i<n;i++)
#define Fo(m,n,i) for(int i=m;i>n;i--)
#define setbit(i) __builtin_popcount(i)
#define del(v,pos) v.erase(v.begin()+pos)
#define cnt(v,key) (count(all(v),key))
#define cnts(s,key) (s.count(key))
#define sumArr(a,s,e,sum)(accumulate(a+s,a+e,sum))
typedef long long ll;
using namespace std;
ll stringToLong(string s){stringstream raaz(s);ll x = 0;raaz >> x;return x;}
string longToString(ll k){stringstream ss;ss<<k;string s; ss>>s; return s;}
bool isPowerOfTwo(int n){if(n==0) return false; return (ceil(log2(n)) == floor(log2(n)));}
void scanArr(int *arr,int n){fo(0,n,i) cin>>arr[i];}
void printArr(int *arr,int n){fo(0,n,i) cout<<arr[i]<<" ";}
void scanVector(vector<ll> &v,int n){fo(0,n,i){int temp;cin>>temp;v.push_back(temp);}}
void printVector(vector<ll> v){fos(v) cout<<x<<" ";}
int main()
{
	IOS
    vc(v,3,0);
    fo(0,3,i)
    cin>>v[i];
    st(v);
    if(v[2]-v[1]==v[1]-v[0])
    prt("Yes");
    else
    prt("No");
    return 0;
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n, m;
    cin >> n >> m;
    if(n == 1) {
        if(m == 0) {
            cout << "1 2" << endl;
            return;
        }
        else {
            cout << -1 << endl;
            return;
        }
    }
    if(m < 0 || m >= n - 1) {
        cout << -1 << endl;
        return;
    }
    vll l(n), r(n);
    for(int i = 0; i < m + 1; ++i) {
        l[i] = 2 * i + 2;
        r[i] = l[i] + 1;
    }
    l[m + 1] = 1;
    r[m + 1] = r[m] + 1;
    for(int i = m + 2; i < n; ++i) {
        l[i] = 2 * (i - m - 2) + r[m + 1] + 1;
        r[i] = l[i] + 1;
    }
    rep(i, n) {
        cout << l[i] << ' ' << r[i] << endl;
    }
    return;
}

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


#include<fstream>
#include<iostream>
#include<sstream>
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<tuple>
#include<iomanip>
#include<stdio.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using graph = vector<vector<int>>;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
using ll = long long;
using P = pair<int, int>;

int h,w;
bool used[16][16];

ll dfs(int i,int j,int a,int b){
   if(a<0||b<0) return 0;
   if(j==w){
     j = 0;i ++;
   }
   if(i==h) return 1;
   if(used[i][j]) return dfs(i,j+1,a,b);

   used[i][j] = true;
   ll res = 0;

   res += dfs(i,j+1,a,b-1);

   if(j+1<w&&!used[i][j+1]){
     used[i][j+1] = true;
     res += dfs(i,j+1,a-1,b);
     used[i][j+1] = false;
   }

   if(i+1<h&&!used[i+1][j]){
     used[i+1][j] = true;
     res += dfs(i,j+1,a-1,b);
     used[i+1][j] = false;
   }
   used[i][j] = false;

 return res;
}

int main(){
    cin >> h >> w;
    int a,b;cin >> a >> b;

    cout << dfs(0,0,a,b) <<endl;
}

#include <bits/stdc++.h>
using namespace std;
#include<limits>
#define endl '\n'
#define ll long long int
#define ld long double
#define fl float
#define vi vector<int>
#define vll vector<ll>
#define sll set<ll>
#define null NULL
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define infinity (ll)100000000000
#define mod (ll)1000000007
#define pb push_back
#define test  ll t; cin >> t; while(t--)
#define srtv(a)sort(a.begin(),a.end())
#define srtrev(a)sort(a.begin(),a.end(),greater<int>())
#define loop(i,n)for(int i=0;i<n;i++)
#define loopx(i,x,n)for(int i=x;i<n;i++)
#define looprev(i,n)for(ll i=n-1;i>=0;i--)
#define lcm(a,b)(a*b/gcd(a,b))
#define max3(a,b,c)max(a,max(b,c))
#define min3(a,b,c)min(a,min(b,c))
#define sz(a)a.size()
#define p1(x)cout<<x<<endl
#define p2(x,y)cout<<x<<" "<<y<<endl
#define p3(x,y,z)cout<<x<<" "<<y<<" "<<z<<endl
#define p4(x,y,z,a)cout<<x<<" "<<y<<" "<<z<<" "<<a<<endl
#define pn1(x)cout<<x<<" "
#define pn2(x,y)cout<<x<<" "<<y<<" "
#define pn3(x,y,z)cout<<x<<" "<<y<<" "<<z<<" "
#define sv(a)loop(i,a.size())cin>>a[i]
#define pv(a)for(auto x:a)cout<<x<<" ";cout<<endl;
#define flush cin.ignore(numeric_limits<streamsize>::max(),'\n')
vll primefactors;vll fact;
void getPrimeFactors(ll n){primefactors.clear();for(ll i=2;i*i<=n;i++){if(n%i==0){primefactors.pb(i);while(n%i==0)n=n/i;}}if(n!=1)primefactors.pb(n);}
int binomialCoeff(int n,int k){int C[n+1][k+1];for(int i=1;i<=n;i++){for(int j=0;j<=k&&j<=i;j++){if(j==0||j==i)C[i][j]=1;else C[i][j]=(C[i-1][j-1]+C[i-1][j]);}}return C[n][k];}//nCk=n-1Ck-1+n-1Ck
ll pwr(ll base,ll exp){if(exp==0)return 1;ll x;if(exp%2==0){x=pwr(base,(exp)/2);return(x*x)%mod;}else{return(base*pwr(base,exp-1))%mod;}}
ll pwrm(ll a,ll b,ll m){a%=m;ll res=1;while(b>0){if(b&1)res=res*a%m;a=a*a%m;b>>=1;}return res;}
int gcd(int a,int b){if(b==0){return a;}return gcd(b,a%b);}
void printstack(stack<int>b){while(!b.empty()){cout<<b.top()<<" ";b.pop();}cout<<endl;}
void getFactorial(ll n){fact.pb(1);for(ll i=1;i<=n;i++)fact.pb((i*1ll*fact[i-1])%mod);}
bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;i++)if(n%i==0)return false;return true;}
int fib(int n) {double phi = (1 + sqrt(5)) / 2;return round(pow(phi, n) / sqrt(5));}

//----------------------------------------------Code below----------------------------------------------------------//
//ctrl+a+k+f
vector<vi>c(17,vi(17,0));
int coun=0;
void recursion(int h,int w,int a,int b,int i,int j)
{
    if(i==h)
    {
        if(a==0 && b==0)
        {
            coun++;
        }
        return;
    }
    int x=0;
    if((j+1)%w==0)
    {
        x++;
    }
    if(j+1<w && c[i][j]==0 && c[i][j+1]==0 && a>0)
    {
        c[i][j]=1;c[i][j+1]=1;
        recursion(h,w,a-1,b,i+x,(j+1)%w);
        c[i][j]=0;c[i][j+1]=0;
    }
    if(i+1<h && c[i][j]==0 && c[i+1][j]==0 && a>0)
    {
        c[i+1][j]=1;c[i][j]=1;
        recursion(h,w,a-1,b,i+x,(j+1)%w);
        c[i+1][j]=0;c[i][j]=0;
    }
    if(c[i][j]==0 && b>0)
    {
        c[i][j]=1;
        recursion(h,w,a,b-1,i+x,(j+1)%w);
        c[i][j]=0;
    }
    recursion(h,w,a,b,i+x,(j+1)%w);
}
int main()
{
    fast;
    int h,w;
    int a,b;
    cin>>h>>w>>a>>b;
    recursion(h,w,a,b,0,0);
    p1(coun);
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//const long long INF=1e15;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//auto dist=uniform_int_distribution<int>(0,INF);
//const long double pi = acos(-1);
//primes for hashing 937, 1013
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T, typename U> static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
void shikhar7s(int cas)
{
    int n,i;
    cin>>n;
    vp v;
    int x,y;
    fr(i,n)
    {
        cin>>x>>y;
        v.pb(mp(y,x));
    }
    sort(all(v));
    vi a,b,aa,ba;
    i=0;
    int l=mini,r=-mini;
    while(i<n&&v[i].F==v[0].F)
    {
        a.pb(v[i].S);
        l=min(l,v[i].S);
        r=max(r,v[i].S);
        i++;
    }
    sort(all(a));
    aa.resize(sz(a));
    int j;
    fr(j,sz(a))
    {
        if(l>=0)
            aa[j]=2*r-a[j];
        else if(a[j]>0)
            aa[j]=2*(r-l)-a[j];
        else if(r>0)
            aa[j]=2*(r-l)+a[j];
        else
            aa[j]=a[j]-2*l;
    }
    rep(i,i,n)
    {
        int j=i,l=mini,r=-mini;
        while(j<n&&v[j].F==v[i].F)
        {
            b.pb(v[j].S);
            l=min(l,v[j].S);
            r=max(r,v[j].S);
            j++;
        }
        i=j-1;
        sort(all(b));
        ba.resize(sz(b),mini);
        fr(j,sz(b))
        {
            int k=lower_bound(all(a),r)-a.begin();
            if(k<sz(a))
                ba[j]=min(ba[j],aa[k]+a[k]+b[j]-2*l);
            k--;
            if(k>=0)
                ba[j]=min(ba[j],aa[k]+2*(r-l)+b[j]-a[k]);
            k=lower_bound(all(a),l)-a.begin();
            if(k<sz(a))
                ba[j]=min(ba[j],aa[k]+2*(r-l)+a[k]-b[j]);
            k--;
            if(k>=0)
                ba[j]=min(ba[j],aa[k]+2*r-a[k]-b[j]);
            // cout<<b[j]<<" "<<ba[j]<<endl;
        }
        a=b;
        aa=ba;
        b.clear();
        ba.clear();
    }
    int ans=mini;
    fr(i,sz(a))
    {
        ans=min(ans,aa[i]+abs(a[i]));
    }
    cout<<ans;
}
signed main()
{
    fast;
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    //cout<<"Case #"<<cas<<": ";
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
#include <utility>

using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e15;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(T in,const vector<T>&ar){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(T in,const vector<T>&ar){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	int n,i,j;cin>>n;
	vector<llint>xL(n+2,inf);
	vector<llint>xR(n+2,-inf);
	xL[0]=0;xR[0]=0;
	for(i=0;i<n;i++){
		llint x;int c;cin>>x>>c;
		chmin(xL[c],x);
		chmax(xR[c],x);
	}
	xL[n+1]=0;xR[n+1]=0;
	llint L=0,R=0,b=0;
	for(i=1;i<=n+1;i++){
		if(xL[i]==inf){continue;}
		llint sa=xR[i]-xL[i];
		llint nL=min(L+abs(xL[b]-xR[i]),R+abs(xR[b]-xR[i]))+sa;
		llint nR=min(L+abs(xL[b]-xL[i]),R+abs(xR[b]-xL[i]))+sa;
		L=nL;R=nR;b=i;
	}
	cout<<min(L,R)<<endl;
	return 0;
}


/*
      JAI SHREE RAM
*/
#include<bits/stdc++.h>
using namespace std;
#define fast            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fo(i,n)         for(i=0;i<n;i++)
#define foi(i,k,n)      for(i=k;i<n;i++)
#define wt              long t; cin>>t; while(t--)
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vl              vector<long>
#define vll             vector<long long>
#define mii             map<int,int>
#define pqi             priority_queue<int>
#define pr(a)           cout<<a<<" ";
#define pra(a)          for(i=0;i<a.size();i++){cout<<a[i]<<" ";}
#define pry             cout<<"YES\n"
#define prn             cout<<"NO\n"
#define endl             cout<<endl;

bool p[1000000]={0};
vl v;
void primeFacTillN(ll n)
{
  p[0]=1;
  p[1]=1;
  // int i=0;
  for(ll i=2;i<=n;i++)
  {
    if(!p[i])
    {
      for(ll j=2*i;j<=n;j+=i)
        p[j]=1;
    }
  }
  for(ll i=2;i<=n;i++)
  {
    if(!p[i])
      v.pb(i);
  }
 }

//base any number

long long baseN(long long a,long long n){
if(a<n)
return a;
else{
return(a%n + 10*baseN((a/n),n));
}
}
ll binarySearch(ll arr[], ll l, ll r, ll x)
{   ll count=0;
    while (l <= r) {
        ll m = l + (r - l) / 2;
        count++;
        // Check if x is present at mid
        if (arr[m] == x)
            return count;

        // If x greater, ignore left half
        if (arr[m] < x)
            l = m + 1;

        // If x is smaller, ignore right half
        else
            r = m - 1;
    }

    // if we reach here, then element was
    // not present
    return -1;
}
ll binarySearch2(ll a[],ll l,ll h,ll k)
{
  ll count=0;
  while(l<=h)
  {
    ll mid= (l+h)>>1;
    count++;
    if(a[mid]>mid)
      l=mid+1;
    else if (a[k]<mid)
      h=mid-1;
    else return mid;
  }
  return -1;

}
ll GCD(ll A, ll B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
ll isprime(ll x)
{
  ll i;
  for(i=2;i*i<=x;i++)
  {
    if(x%i==0)
      return 1;
  }
  return 0;
}
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("outputhelp2.txt", "w", stdout);
#endif

  ll n,i;
  cin>>n;
  n= pow(2,n);
  vll v(n);

  for(ll i=0;i<n;i++)
    cin>>v[i];
  vll w(n);
  for(i=0;i<n;i++)
    w[i]=v[i];
  while(v.size()>2){
  for(i=0;i<=v.size()-2;i+=2)
  {
    if(v[i]>v[i+1])
      {v.erase(v.begin()+i+1);
        i--;
      }
    else
      {v.erase(v.begin()+i);
        i--;
      }

  }}

  ll x = *min_element(v.begin(), v.end());

  for(i=0;i<n;i++)
  {
    if(x== w[i])
    {
      cout<<i+1;
      break;
    }
  }

return 0;
}

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

int main() {
  int n;
  cin >> n;
  int c = 1 << n;
  vector<int> a(c);
  for (int i = 0; i < c; i++) {
    cin >> a[i];
  }
  map<int, int> mp;
  for (int i = 0; i < c; i++) {
    mp[a[i]] = i + 1;
  }

  while (a.size() > 2) {
    vector<int> na;
    for (int i = 0; i < a.size(); i += 2) {
      na.push_back(max(a[i], a[i + 1]));
    }
    swap(a, na);
  }
  int ans = min(a[0], a[1]);
  cout << mp[ans] << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a) for(int i = 0; i < (int) a; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

	int n; cin >> n;
	int ans = 1e9+7;

	FOR(i, n){
		int a, b, c; cin >> a >> b >> c;

		if(c > a) ans = min(ans, b);
	}

	if(ans == 1e9+7) cout << "-1\n";
	else cout << ans << '\n';

	return 0;
}

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

const ll mod = 10;

int main(){
  int n;
  cin >> n;
  vector<tuple<int,int,int>> pax(n);
  for(int i = 0; i < n; i++){
    int a, p, x;
    cin >> a >> p >> x;
    pax[i] = make_tuple(p,a,x);
  }
  sort(pax.begin(),pax.end());
  for(int i = 0; i < n; i++){
    if(get<1>(pax[i])<get<2>(pax[i])){
      cout << get<0>(pax[i]) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll bitree[4][225816];
int t[225816],x[225816];
ll y[225816],a[2][225816];
std::vector<ll> v;

void update(int x, ll ret, int k){
	++x;
	while(x<225816){
		bitree[k][x] += ret;
		x += (x&(-x));
	}
}

ll query(int x, int k){
	ll ret = 0ll;
	++x;
	while(x){
		ret += bitree[k][x];
		x -= (x&(-x));
	}
	return ret;
}

int main(void){
	int n,m,q,i,l,r,p;
	ll ans = 0ll;
	std::cin >> n >> m >> q;
	v.push_back(0ll);
	update(0,n,0); update(0,m,1);
	for(i=0; i<q; ++i){
		std::cin >> t[i] >> x[i] >> y[i];
		--t[i]; --x[i];
		v.push_back(y[i]);
	}
	std::sort(v.begin(),v.end());
	for(i=0; i<q; ++i){
		r = (int)(std::lower_bound(v.begin(),v.end(),a[t[i]][x[i]])-v.begin());
		ans -= query(r,(1^t[i]))*a[t[i]][x[i]] + query(q+1,(3^t[i]))-query(r,(3^t[i]));
		update(r,-1ll,t[i]);
		update(r,-a[t[i]][x[i]],t[i]+2);
		a[t[i]][x[i]] = y[i];
		r = (int)(std::lower_bound(v.begin(),v.end(),y[i])-v.begin());
		ans += query(r,(1^t[i]))*a[t[i]][x[i]] + query(q+1,(3^t[i]))-query(r,(3^t[i]));
		update(r,1ll,t[i]);
		update(r,y[i],t[i]+2);
		std::cout << ans << std::endl;
	}
	return 0;
}

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#define MOD 1000000007
using namespace std;

int main() {
  long long T; cin >> T;
  for (int i = 0; i < T; i++){
    long long N, A, B; cin >> N >> A >> B;
    if (N < A + B){
      cout << 0 << endl;
      continue;
    }
    long long p = ((N - A - B + 1) * (N - A - B + 2) * 2) % MOD;
    long long q = (N - A + 1) * (N - B + 1) % MOD;
    long long ans = (p * q) % MOD;
    long long r = (N - A - B + 1) * (N - A - B + 2) % MOD;
    ans -= (r * r) % MOD;
    ans = ((ans % MOD) + MOD) % MOD;;
    cout << ans << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pp;
const int mxn=10000;
vector<int>visited(mxn,0);
vector<int>adj[mxn];
int prime[mxn];
int M=1e9+7;
void boost() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void sieve(int ending)
{
    for(int i=2;i<ending;i++)
        prime[i]=1;
    for(int i=2;i*i<=ending;i++)
    {
        if(prime[i]==1)
        {
            for(int j=2*i;j<=ending;j=j+i)
            {
                prime[j]=0;
            }
        }
    }
    prime[1]=0;
}

int ncrmodp(int num,int r)
{
    vector<int>C(r+1,0);
    int i,j;
    C[0]=1;
    for(i=1;i<=num;i++)
    {
        for(j=min(i,r);j>0;j--)
        {
            C[j]=((C[j])%M+(C[j-1])%M)%M;
        }
    }
    return C[r];
}

int power(int x,int y)
{
    int res = 1;
    x = x % M;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1; // y = y/2
        x = (x*x) % M;
    }
    return res;
}

void solve()
{

}

signed main()
{
    boost();
    int t;
    cin>>t;
    int ans=0;
    for(int i=0;i<t;i++){
        int a,b;
        cin>>a>>b;
        int sum1=(a-1)*(a)/2;
        int sum2=b*(b+1)/2;
        ans+=sum2-sum1;
    }
    cout<<ans<<endl;
}

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	long long ans = 0;
	while (n--) {
		int l, r; cin >> l >> r;
		ans += (long long) r * (r + 1) / 2 - (long long) (l - 1) * l / 2;
	}
	cout << ans << '\n';
	return 0;
}


// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
// #pragma GCC optimize("-Ofast","-funroll-all-loops")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <list>
#include <cstdlib>
#include <bitset>
#include <assert.h>
#include <time.h>
#include <iomanip>
#include <functional>
#include <unordered_map>
#include <unordered_set>
// #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
// char buf[(1 << 21) + 1], * p1 = buf, * p2 = buf;
// #define int long long
#define lowbit(x) (x & (-x))
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> VI;
#define rg register
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define SZ(x) ((int)((x).size()))
#define bug puts("BUG")
#define ALL(x) x.begin(),x.end()
const long long INF = 2e18; //0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-10;
void err(){puts("");}
template<typename T,typename... Args>void err(const T& arg,const Args&... args){
    std::cout << arg << ' ';
    err(args...);
}
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
    read(first);
    read(args...);
}
template<typename T>void chmax(T& a,T b){
    if (b > a)
        a = b;
}
template<typename T>void chmin(T& a,T b){
    if (b < a)
        a = b;
}
#ifdef LOCAL
#define dbg(x...) do{std::cout<<#x<<" -> ";err(x);}while(0)
FILE *_INPUT = freopen("input.txt", "r", stdin);
// FILE *_OUTPUT = freopen("output.txt", "w", stdout);
#else
#define dbg(x...) ;
#endif
using namespace std;
const int maxn = 2e5 + 10;
const int DEG = 20;
int fa[maxn][20];
int deep[maxn], son[maxn], len[maxn];
vector<int> G[maxn];
int lca(int u,int v)
{
    if (deep[u] < deep[v])
        swap(u, v);
    int x = deep[u] - deep[v];
    for (int i = 0; i < DEG && x; ++i)
    {
        if (x & 1)
            u = fa[u][i];
        x >>= 1;
    }
    if (u == v)
        return u;
    for (int i = 0; i < DEG; ++i)
    {
        if (fa[u][i] == fa[v][i])
            continue;
        u = fa[u][i];
        v = fa[v][i];
    }
    return fa[u][0];
}

void dfs(int u, int pre)
{
    son[u] = 0;
    len[u] = 0;
    deep[u] = deep[pre] + 1;
    fa[u][0] = pre;
    for (int i = 1; i < DEG; ++i)
    {
        fa[u][i] = fa[fa[u][i - 1]][i - 1];
    }
    for (int v : G[u])
    {
        if (v == pre)
            continue;
        dfs(v, u);
        len[u] = max(len[u], len[v] + 1);
        if (len[v] > len[son[u]])
            son[u] = v;
    }
}
ll ans[maxn];
int las = 0;
void dfs2(int u, int pre)
{
    ans[u] = ans[las] + deep[u] + deep[las] - 2 * deep[lca(u, las)];
    las = u;
    for (int v : G[u])
    {
        if (v == pre || v == son[u])
            continue;
        dfs2(v, u);
    }
    if(son[u])
        dfs2(son[u], u);
}

int main()
{
    int n;
    int u, v;
    read(n);
    for (int i = 1; i < n; ++i)
    {
        read(u, v);
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    dfs(1, 0);
    int R = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (deep[i] > deep[R])
            R = i;
    }
    dfs(R, 0);
    dfs2(R, 0);
    for (int i = 1; i <= n; ++i)
        printf("%lld%c", ans[i], " \n"[i == n]);
}

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

int n;
vector<vector<int>> e;
P longest(int v, int per){
	P mx=P(0, v);
	for(int u : e[v]) if(u!=per){
		P p=longest(u, v);
		mx=max(mx, P(p.first+1, p.second));
	}
	return mx;
}

vector<int> p;
void setp(int v, int per){
	p[v]=per;
	for(int u : e[v]) if(u!=per) setp(u, v);
}

vector<int> ans;
int c;
void setans(int v, int per){
	ans[v]=c++;
	if(p[v]==-1) return;
	for(int u : e[v]) if(u!=per && u!=p[v]) setans(u, v);
	if(p[v]!=per) setans(p[v], v);
	c++;
}

int main(){
	cin>>n;
	e=vector<vector<int>>(n);
	rep(i, n-1){
		int a, b;
		cin>>a>>b; a--; b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	int a=longest(0, -1).second;
	int b=longest(a, -1).second;

	p=vector<int>(n, -1);
	setp(a, -1);

	ans=vector<int>(n);
	c=1;
	setans(b, -1);

	for(int e : ans) cout<<e<<" ";
	cout<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>
#define ll long long int
#define inf 1000000000000
#define mod 1000000007

// templates
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ps(x,y)   fixed<<setprecision(y)<<x
#define fo(i,a,b) for(int i=a;i<b;i++)
#define ro(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define sc(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pr(n) printf("%d\n",n)
#define pl(n) printf("%lld\n",n)
#define prs(n) printf("%d ",n)
#define pls(n) printf("%lld ",n)
using namespace std;

ll GCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1LL;
		y = 0LL;
		return a;
	}
	ll x1, y1;
	ll d = GCD(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * 1LL * (a / b);
	return d;
}
void solve()
{
	ll n, s, k;
	sl(n), sl(s), sl(k);
	ll x, y;
	ll gc = __gcd(n, k);
	if (s % gc) {
		pl(-1LL);
	}
	else {
		// y->loops x->moves x*k+s=y*n => (x*k-y*n=-s)
		n /= gc, s /= gc, k /= gc;
		gc = GCD(k, n, x, y);
		ll mod_inv = (x % n + n) % n; // k inverse
		ll ans = ((-s * mod_inv) % n + n) % n;
		pl(ans);
	}
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	scanf("%d", &t);
	while (t--) {
		solve();
	}

}

#include <iostream>
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer
//#define mp make_pair
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define pb push_back

#define min(a,b) (a<b?a:b)
#define forn(n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define MAX 1e18;
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define vmin *min_element
#define vmax *max_element
#define pii pair<int,int>
const int mod = 1e9 + 7;
const int N=1e6+1;
const int N2 = 1e5+1;
#define pi 3.141592653589793238

using namespace std;
vector<int>v(100002);
unsigned long long power(unsigned long long x,
                                  int y, int p)
{
    unsigned long long res = 1;

    x = x % p;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

bool key(string s, int b,int m)
{
		int k = 0;
		int n = s.size();
	for(int  i=0; i<s.size(); i++)
	{
		if(pow(b,n-1-i)<0)
		return false;
		k+=s[i]*pow(b,n-1-i);
	}

	return (k>m);
}

int bsa(int low, int high, int m, string s)
{
    int mid;
  int ans;

    while (low < high) {
        mid =  (high + low) / 2;

//  cout<<mid<<endl;

        if ( key(s,mid,m)) {
          high = mid;

        }

        else {
           low = mid+1;
        }

    }

    return low;
}

int ordertrip(int n)
{
int c =0;
for(int i=1; i*i<=n; i++)
{
	if(n%i==0)
	{
		if(i==n/i)
		{
			c++;
		}
		else
		{
			c+=2;
		}
	}
}
return c;

}

void solve()
{
int k;
cin>> k;
int ans = 0;

vector<int>dp(k+1);
dp[1] = 1;
for(int i =2; i<=k;i++)
{
	dp[i] = dp[i-1] + ordertrip(i);
}
for(int i=1; i<=k; i++)
{

		ans+= dp[k/i];

}
cout<<ans;

	}
signed  main()
{
IOS;

//memset(dp,-1,sizeof(dp));
//  freopen("input.txt","r",stdin);
//  freopen("new.txt","w",stdout);
 int t = 1;
//cin>>t;

 while(t--)
 {
	IOS;
 	solve();
 	cout<<endl;
 }

 }

//cccccccccccccccccccccccccccccccccccccccc


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll a,b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>a>>b;
    cout<<2*a+100-b;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {

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

  int h, w;
  cin >> h >> w;

  bool grid[h][w];

  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {

      char c;
      cin >> c;

      grid[i][j] = c == '#';

    }

  int vertices = 0;

  for (int i = 0; i < h - 1; i++) {

    for (int j = 0; j < w - 1; j++) {

      int sum = grid[i][j] +
                grid[i + 1][j] +
                grid[i][j + 1] +
                grid[i + 1][j + 1];

      vertices += sum == 1 || sum == 3;

    }

  }

  cout << vertices << endl;

  return 0;

}


#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, long long M)
{
    if(N==1 && M == 0){
        cout << "1 2" << endl;
        return;
    }
    ll r_max = 1000000000;
    // Mが正の時を考える
    if (M < 0 || N - 1 <= M)
    {
        cout << -1 << endl;
        return;
    }
    vector<pair<ll, ll>> ans;

    ll l = 1, r = r_max / 2;
    // 青木くんの個数を1とする
    ll cnt = 0;
    ans.push_back(P(l, r));
    cnt++;
    // 高橋くんがM+1個選べるように選択する
    ll tmp_l = (l+r)/2;
    ll tmp_r = tmp_l+1;
    while (cnt <= M + 1)
    {
        ans.push_back(P(tmp_l, tmp_r));
        cnt++;
        tmp_l += 2;
        tmp_r += 2;
    }

    tmp_r += r;
    tmp_l -=(l+r)/2;
    while (cnt < N)
    {
        ans.push_back(P(tmp_l, tmp_r));
        cnt++;
        tmp_l++;
        tmp_r++;
    }

    for (auto &&i : ans)
    {
        cout << i.first << " " << i.second << endl;
    }
}

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

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

struct num {
  ll n, i;
  num operator+ (const num &x) const { return (num){n+x.n, i+x.i}; }
  num operator- (const num &x) const { return (num){n-x.n, i-x.i}; }
};

struct SegTree {
  ll size;
  vector<num> pos;
  SegTree(ll N) { size = 1; while(size<N) size<<=1; pos.resize(2*size,(num){0,0}); }
  num operator[](const ll &x) const { return pos[x+size]; }

  void set(ll x, const num v) { pos[x+size] = v; }
  void update(ll x, const num v) { set(x,v); x+=size; while (x>>=1) operate(x); }
  num query(ll a, ll b) {
    num L = {0,0}, R = {0,0};
    for (a+=size, b+=size; a<b; a>>=1, b>>=1) {
      if (a&1) { L = q(L,pos[a]); a++; }
      if (b&1) { b--; R = q(pos[b],R); }
    }
    return q(L,R);
  }
  void operate(ll i) { pos[i] = q(pos[i*2], pos[i*2+1]); }
  num q(num x, num y) { return x + y; }
};

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

int main() {
  ll N, M, Q; cin >> N >> M >> Q;
  ll T[Q], X[Q], Y[Q]; rep(i,Q) { cin >> T[i] >> X[i] >> Y[i]; X[i]--; }
  set<ll> nset; rep(i,Q) nset.insert(Y[i]); nset.insert(0);
  vector<ll> nv; for (auto x: nset) nv.push_back(x);
  map<ll, ll> nv_idx; rep(i,nv.size()) nv_idx[nv[i]] = i;
  // debug(all(nv));

  ll now_row[N] = {}, now_col[M] = {};
  ll nvs = nv.size();
  SegTree st_row(nvs); st_row.update(0,{0,N});
  SegTree st_col(nvs); st_col.update(0,{0,M});
  ll result = 0;
  rep(i,Q) {
    if (T[i]==1) {
      ll fp = nv_idx[now_row[X[i]]], tp = nv_idx[Y[i]];
      ll sum_from = st_col.query(0,fp).i * now_row[X[i]] + st_col.query(fp,nvs).n;
      ll sum_to   = st_col.query(0,tp).i * Y[i]          + st_col.query(tp,nvs).n;
      result += sum_to - sum_from;
      st_row.update(fp, st_row[fp] - (num){now_row[X[i]],1});
      st_row.update(tp, st_row[tp] + (num){Y[i],1});
      now_row[X[i]] = Y[i];
    }
    else {
      ll fp = nv_idx[now_col[X[i]]], tp = nv_idx[Y[i]];
      ll sum_from = st_row.query(0,fp).i * now_col[X[i]] + st_row.query(fp,nvs).n;
      ll sum_to   = st_row.query(0,tp).i * Y[i]          + st_row.query(tp,nvs).n;
      result += sum_to - sum_from;
      st_col.update(fp, st_col[fp] - (num){now_col[X[i]],1});
      st_col.update(tp, st_col[tp] + (num){Y[i],1});
      now_col[X[i]] = Y[i];
    }
    cout << result << endl;
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a,b,c;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	if(!c)puts(a>b?"Takahashi":"Aoki");
	else puts(a<b?"Aoki":"Takahashi");
	return 0;
}

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

int main()
{
    int n,m,c;
    bool flag;
    while(cin>>n>>m>>c)
    {
        if(c==0)
        {
            flag=true;
        }
        else{
            flag=false;
        }
        if(flag&&n==0)
        {
            printf("Aoki\n");
            continue;
        }
        else if(!flag&&m==0)
        {
            printf("Takahashi\n");
            continue;
        }
        while(n!=0&&m!=0)
        {
            if(flag)
            {
                n--;
                flag=!flag;
                if(n<=0)
                {
                    printf("Aoki\n");
                    break;
                }
            }
            else{
                m--;
                flag=!flag;
                if(m<=0)
                {
                    printf("Takahashi\n");
                    break;
                }
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = b - 1; a <= i; i--)
ll MOD = 1000000007;

ll N, K, A[800][800];

int main () {
  cin >> N >> K;
  rep (i, 0, N) rep (j, 0, N) cin >> A[i][j];

  // 中央値がx以下の区画が存在する
  // <=> ある区画aが存在して、aのマスの内高さがxより大きいものがfloor(K^2 / 2)個以下存在
  // cnt[i][j] : 右下のマスが(i,j)であるような区画に存在する高さがより大きいマスの個数
  // (i < K-1 || j < K-1)の場合、はみ出す部分は無視する

  ll l = -1, r = 1e9;
  while (r - l > 1) {
    ll x = (l + r) / 2;
    ll cnt[N][N];
    rep (i, 0, N) rep (j, 0, N) {
      cnt[i][j] = (A[i][j] > x);
      if (0 <= i - 1) cnt[i][j] += cnt[i-1][j];
      if (0 <= j - 1) cnt[i][j] += cnt[i][j-1];
      if (0 <= i - 1 && 0 <= j - 1) cnt[i][j] -= cnt[i-1][j-1];
      if (0 <= i - K) cnt[i][j] -= (A[i-K][j] > x);
      if (0 <= j - K) cnt[i][j] -= (A[i][j-K] > x);
      if (0 <= i - K && 0 <= j - K) cnt[i][j] += (A[i-K][j-K] > x);
    }

    // ---プリントデバッグ用---
    // cout << "---\n";
    // cout << "x = " << x << endl;
    // rep (i, 0, N) {
    //   rep (j, 0, N) {
    //     cout << left << setw(3) << cnt[i][j];
    //   }
    //   cout << endl;
    // }
    // ---

    bool b = false;
    rep (i, K - 1, N) {
      rep (j, K - 1, N) {
        if (cnt[i][j] <= floor(K * K / 2)) {
          b = true;
          break;
        }
      }
      if (b) break;
    }

    if (b) r = x;
    else l = x;
  }

  cout << r;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define int long long
const int N=1e6+5;
const int p=998244353;
template<class T>inline void read(T &x) {
	T 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-'0';s=getchar();}
	x*=f;
}
int fac[5001],inv[5001];
inline int ksm(int a,int b) { int ans=1; for(;b;b>>=1,(a*=a)%=p) if(b&1) (ans*=a)%=p; return ans; }
inline int C(int a,int b) { return fac[a]*inv[b]%p*inv[a-b]%p; }
int f[5001],g[5001];
int n,m;
signed main() {
	fac[0]=1; inv[0]=1;
	rep(i,1,5000) (fac[i]=fac[i-1]*i%p),inv[i]=ksm(fac[i],p-2);
	read(n); read(m);
	f[0]=1;
	rep(nw,0,12) {
		memset(g,0,sizeof(g));
		rep(i,0,m) {
			rep(j,0,n) {
				if((i+(1<<nw)*j*2)>m) break;
				(g[i+(1<<nw)*j*2]+=f[i]*C(n,j*2)%p)%=p;
			}
		}
		rep(i,0,m) f[i]=g[i];
	}
	printf("%lld\n",f[m]);
}


// ============================================================================
// ||                                                                        ||
// ||             International University of Business,Agriculture           ||
// ||                           And Technology                               ||
// ||                           Redwan Ahmed Khan                                ||
// ||                  Bismillah-ir-Rahman-ir-Rahim                          ||
// ||                                                                        ||
// ============================================================================
#include<bits/stdc++.h>

#define int                           long long
#define ld                            long double
#define ull                           unsigned long long int
#define chr                           char
#define st                            string

#define pb                            push_back
#define pp                            pop_back
#define mp                            make_pair
#define vin                           vector<int>
#define vch                           vector<char>
#define vst                           vector<string>
#define pii                           pair<int,int>
#define triplet                       pair<ll,pair<ll,ll>>
#define mpin                          map<int,int>
#define mod                           1000000007
#define pi                            2 * acos (0.0)
#define mx1                           320000

#define print(x)                      printf("%lld\n",x)
#define input(x)                      scanf("%lld",&x)
#define stringin                      scanf(" %[^\n]%*c", a)
#define sz(x)                         (x).size()
#define read(x)                       int x; cin >> x;
#define loj(case_no,result)           cout<<"Case "<<case_no<<": "<<result<<endl
#define loj2(case_no,result)          cout<<"Case "<<case_no<<":"<<endl<<result<<endl
#define fr(a,b)                       for(int i = a; i < b; i++)
#define frc(a,b)                       for(int i = a; i > b; i--)
#define rep(i,a,b)                    for(int i = a; i < b; i++)
#define testcase(t)                   int t ; cin>>t ; while(t--)
#define all(x)                        (x).begin(), (x).end()
#define setbits(x)                    __builtin_popcountll(x)
#define zrobits(x)                    __builtin_ctzll(x)
#define prDouble(x)                   cout << fixed << setprecision(10) << x<<endl
#define lcm(a,b)                      (a*b)/__gcd(a,b);
#define erase(a,b)                     a.erase(a.begin()+(b-1))
#define mem(a, b)                      memset(a, b, sizeof(a))
#define trv(x)                         ((x).begin(),(x).end())

#define db(x)                         cout<<#x <<"=" <<x<<endl
#define time                          cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
#define fast_io                       ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

void solve()
{	testcase(t)
	{
		read(n);
		int  c = 0;
		while (n && n % 2 == 0)
		{
			c++;
			n /= 2;
		}
		if (c == 1)cout << "Same" << endl;
		else if (c == 0)cout << "Odd" << endl; \
		else cout << "Even" << endl;
	}
}
void init_code() {
	fast_io;

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

#endif
}

int32_t main()
{
	init_code();
	solve();
	time;
	return 0;
}

// Alhamdulillah. I have solved this problem by the grace of the Almighty Allah

#include    <bits/stdc++.h>
using       namespace std;
#define     endl "\n"
#define     pb push_back
#define     ll long long
#define     int ll
#define     mod 1000000007
#define     DEBUG cout<<"Hello1\n";
#define     all(v) (v).begin(),(v).end()
#define     deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int   N = 1e6 + 5;
const ll    inf = 1e18 + 5;
typedef     pair<int, int> pii;
void        fileIO();

template<class T> void print_container(T &container);
template<class T> void print_pair_container(T &container);
template<class T> void printArr(T &a, int n);
template<typename T> void debug(string s, T x);
template<typename T, typename... Args>
void debug(string s, T x, Args... args);

int n, m;

void solve(int tc = 0) {
	cin >> n;

	if (n % 2) {
		cout << "Odd\n";
	} else {
		if ((n / 2) % 2 == 0) {
			cout << "Even\n";
		} else {
			cout << "Same\n";
		}
	}
}

int32_t main()
{
	fileIO();

	int t = 1; cin >> t; for (int i = 1; i <= t; i++)
		solve();

	return 0;
}

void fileIO() {

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

template<typename T> void debug(string s, T x)
{
	cout << s << " = " << x << "\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args)
{
	cout << s.substr(0, s.find(',')) << " = " << x << " | ";
	debug(s.substr(s.find(',') + 2), args...);
}

template<class T> void print_container(T &container)
{
	for (auto &t : container)
	{
		cout << t << " ";
	}
	cout << endl;
}
template<class T> void print_pair_container(T &container)
{
	for (auto &t : container)
	{
		cout << t.first << " " << t.second << endl;
	}
	cout << endl;
}
template<class T> void printArr(T &a, int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << a[i] << " ";
	}
	cout << endl;
}


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

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

int main(){
  int n;
  cin >> n;
  ll ans = 0;
  rep(i,n){
    int a;
    cin >> a;
    if(i == 0){
      ans = a;
    }
    else{
      ans = gcd(ans,a);
    }
  }
  cout << ans << endl;
}

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(int n){
   if(n < 10)  return n;
   return digit(n/10) + n%10;
}
int main(){
  int K;
  ll N;
  cin>>N>>K;
  for(int i=0;i<K;i++){
    if(N%200==0) N/=200;
    else N=N*1000+200;
  }
  cout<<N;
return 0;}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >
#define pq priority_queue
#define dbg(x) cerr << #x << ": " << x << '\n'
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)

namespace FastRead
{
    char buff[5000];int lg = 0 , p = 0;
    char nc()
    {
        if(lg == p){lg = fread(buff , 1 , 5000 , stdin);p = 0;if(!lg) return EOF;}
        return buff[p++];
    }
    template<class T>void read(T&x)
    {
        T sgn = 1; char c;while(!isdigit(c = nc()))if(c == '-')sgn = -1;
        x = c - '0';while(isdigit(c = nc()))x = x * 10 + c - '0';x *= sgn;
    }
}

using namespace FastRead;
using namespace std;

const int N = 1e5 + 10;
const int M = 1e9 + 7;
const ld PI = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

char a[70];
int fr[4];

signed main()
{
	#ifndef ONLINE_JUDGE
		FastIO , FILES;
    #endif

    cin >> a + 1;

    for(int i = 1 ; i <= strlen(a + 1) ; i++)
        ++fr[ (a[i] - '0') % 3 ];

    int sum = fr[1] + 2 * fr[2];
    sum %= 3;

    int val = 0;

    if(sum == 1 && fr[1])
        val = 1;
    else if(sum == 1 && fr[2] > 1)
        val = 2;
    else if(sum == 1)
        val = strlen(a + 1);

    if(sum == 2)
    {
        if(fr[2])
            val = 1;
        else if(fr[1] > 1)
            val = 2;
        else val = strlen(a + 1);
    }

    if(val == strlen(a + 1))
        cout << -1;
    else cout << val;

    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint mpow(int x, int n){
  if(n==0)return 1;

  mint y = mpow(x, n/2);
  y *= y;

  if(n%2==1) y *=x;
  return y;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int di[4] ={-1,1,0,0};
int dj[4] ={0,0,1,-1};

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i,h)cin >> s[i];
  int cnt=0;
  REP(i,h)REP(j,w)if(s[i][j]=='.')cnt++;
  vvi a(h,vi(w,0));
  vvi b(h,vi(w,0));

  REP(i,h){
    int c=0;
    REP(j,w){
      if(s[i][j]=='.'){
        c++;
      }else{
        REP(k,c){
          a[i][j-1-k] = c;
        }
        c=0;
      }
    }
    REP(k,c){
      a[i][w-1-k] = c;
    }
  }
  REP(i,w){
    int c=0;
    REP(j,h){
      if(s[j][i]=='.'){
        c++;
      }else{
        REP(k,c){
          b[j-1-k][i] = c;
        }
        c=0;
      }
    }
    REP(k,c){
      b[h-1-k][i] = c;
    }
  }

  // REP(i,h)REP(j,w){
  //   cout << a[i][j] << (j==w-1 ? "\n" : " ");
  // }
  // REP(i,h)REP(j,w){
  //   cout << b[i][j] << (j==w-1 ? "\n" : " ");
  // }

  mint all=mpow(2,cnt);
//  cout << all.x << endl;

  mint ans=0;
  REP(i,h)REP(j,w){
    if(s[i][j]=='#')continue;
    // int c=1;
    // REP(k,4){
    //   int ni = i;
    //   int nj = j;
    //   while(true){
    //     ni += di[k];
    //     nj += dj[k];
    //     if(ni < 0 || ni >= h || nj < 0 ||nj >= w)break;
    //     if(s[ni][nj]=='#')break;
    //     c++;
    //   }
    // }
//    cout << c << endl;
    int c = a[i][j] + b[i][j] - 1;
    ans += (mpow(2,c)-1) * mpow(2,cnt-c);
//    cout << ((mpow(2,c)-1) * mpow(2,cnt-c)).x << endl;
  }
  cout << ans.x << endl;

}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int>pi;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int x , y ;
    cin >> x >> y ;
    if( x == y ) cout << x << "\n";
    else cout << 3 - x - y << '\n' ;
    return 0;
}


#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll
const long double pi = 3.14159265358979323846;
const long double eps = 1e-12;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,T; cin >> n >> T;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<ll> one, two, a1, a2;
    ll m = n / 2;
    rep(i,0,n){
        if (i < m) a1.emplace_back(a[i]);
        else
            a2.emplace_back(a[i]);
    }
    rep(i,0, 1LL << m){
        ll t = 0;
        rep(j, 0, m) {
            if((i >> j) & 1){
                t += a1[j];
            }
        }
        if(t <= T){
            one.emplace_back(t);
        }
    }
    m = n - m;
    rep(i,0,1LL << m){
        ll t = 0;
        rep(j,0,m){
            if((i >> j) & 1){
                t += a2[j];
            }
        }

        if (t <= T) two.emplace_back(t);
    }

    sort(all(one));
    sort(all(two));
    debug(one, two);
    ll ans = 0;
    m = two.size();
    for (auto i : one) {
        ll id = upper_bound(all(two), T - i) - two.begin();
        if(id)chmax(ans, i + two[id-1]);
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using vt = vector<T>;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define EACH(x, a) for (auto& x: a)
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using ll = long long;
using pll = pair<ll, ll>;

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}

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

template<class ForwardIterator> void print_vec(ForwardIterator first,
		ForwardIterator last, string sep = " ", string end = "\n") {
	bool ft = true;
	while (first != last) {
		if (!ft) {cout << sep;} else {ft = false;}
		cout << (*first);
		++first;
	}
	cout << end;
}

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) {
	return o << p.F << " " << p.S;
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x, y);
}

ll bin_search(ll lo, ll hi, function<bool(ll)> predicate) {
	int sign = lo < hi ? 1 : -1;
	lo *= sign;
	hi *= sign;
	hi++;
	while (lo < hi) {
		ll mid = lo + floorDiv(hi-lo, 2);
		if (!predicate(sign * mid)) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

vector<ll> part[2];
ll sums[2][(1<<20)+5];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	ll t;
	cin >> t;

	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		part[(int)(i >= n/2)].pb(x);
	}

	int sizes[] = {n/2,n-n/2};

	for (int p = 0; p <= 1; p++) {
		int limit = 1 << sizes[p];
		for (int j = 0; j < limit; j++) {
			ll s = 0;
			for (int i = 0; i < sizes[p]; i++) {
				if (TEST(j,i)) {
					s+=part[p][i];
				}
			}
			sums[p][j]=s;
		}
	}
	sort(sums[1], sums[1]+(1 << sizes[1]));
	int limit0 = 1 << sizes[0];

	ll best = 0;

	for (int i = 0; i < limit0; i++) {
		ll value = sums[0][i];
		if (value == t) {
			cout << t << "\n";
			return 0;
		}
		if (value > t) {
			continue;
		}
		best = max(best,value);
		ll left = t - value;
		auto it = upper_bound(sums[1], sums[1]+(1 << sizes[1]), left);
		if (it == sums[1]) continue;
		it--;
		best = max(best, value + *it);
	}
	cout << best << "\n";
}


#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;
}

const int N=2005;
int a[N],b[N],dp[N][N];

int main()
{
	int n=read(),m=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=m;i++) b[i]=read();
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	for(int i=1;i<=n;i++) dp[i][0]=i;
  	for(int i=1;i<=m;i++) dp[0][i]=i;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(a[i]==b[j]) dp[i][j]=dp[i-1][j-1];
			dp[i][j]=min(dp[i][j],1+min(min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1]));
		}
	printf("%d\n",dp[n][m]);
	return 0;
}

//Bismillahir Rahmanir Raheem
#ifdef ONLINE_JUDGE
    #include<bits/stdc++.h>
#endif
#include<iostream>
#include<numeric>
#include<tuple>
#include<iomanip>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<math.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<string>
#include<sstream>
#include<string.h>
#include<deque>
#include<set>
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define clr(cnt, x) memset((cnt), (x), sizeof(cnt))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int,int> > vii;
typedef pair<int, int> pii;
typedef vector<bool> vbl;
typedef vector<pair<ll,ll> > vll;
typedef pair<ll, ll> pll;
#define PQ priority_queue
#define ff first
#define ss second
#define MP make_pair
#define MT make_tuple
#define mxN (int)2e5 + 2
#define sz(n) (int)(n).size()
#define fasterIO ios::sync_with_stdio(0); cin.tie(0);
#define forc(cn) for(auto &x : (cn))
#define findc(cn, x) ((cn).find(x) != (cn).end())

#define PI 2*acos(0)
#define forc(cn) for(auto &x : (cn))
#define MAXN 300010
#define torad ((2*acos(0))/180.0)
const int inf = INT_MAX;
int n, m;
vi a, b;
int dp[1010][1010];
int f(int i, int j) {
    if(i == n || j == m) {
        return max(n - i, m - j);
    }
    int &ret = dp[i][j];
    if(ret != -1) return ret;
    ret = inf;
    if(a[i] != b[j]) {
        ret = min(ret, f(i + 1, j) + 1);
        ret = min(ret, f(i, j+1) + 1);
    }
    ret = min(ret, f(i+1, j+1) + (a[i] != b[j]));
    return ret;

}
void solve()
{
    clr(dp, -1);
    cin >> n >> m;
    a = vi(n);
    b = vi(m);
    forc(a) cin >> x;
    forc(b) cin >> x;
    cout << f(0, 0) << endl;
}
int main()
{
    //fasterIO
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


#include<iostream>
#include<map>
using namespace std;
const int BUF = 300005;

int nVal;
int val[BUF];

void read() {
    cin >> nVal;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}

void work() {
    map<int, int> v2cnt;
    for (int i = 0; i < nVal; ++i) {
        ++v2cnt[val[i]];
    }

    long long sum = 0;
    for (map<int, int>::iterator it = v2cnt.begin(); it != v2cnt.end(); ++it) {
        sum += 1LL * it->second * (nVal - it->second);
    }

    cout << sum / 2 << endl;
}

int main() {
    read();
    work();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll linf = (1ll << 60);

int N, M;
int X[50];
bool notprime[51];
int prime[50];

int main() {
	cin >> N;
	for(int i = 2; i <= 50; i++) {
		if(notprime[i]) continue;
		prime[M++] = i;
		for(int j = i; j <= 50; j += i) {
			notprime[j] = 1;
		}
	}
	for(int i = 0; i < N; i++) cin >> X[i];
	ll ans = linf;
	for(int bit = 0; bit < (1 << M); bit++) {
		bool found = false;
		for(int i = 0; i < N; i++) {
			bool g = false;
			for(int j = 0; j < M; j++) {
				if(!(bit & (1 << j))) continue;
				if(X[i] % prime[j] == 0) g = true;
			}
			if(!g) found = true;
		}
		if(!found) {
			ll tmp = 1;
			for(int j = 0; j < M; j++) {
				if(!(bit & (1 << j))) continue;
				tmp *= prime[j];
			}
			ans = min(ans, tmp);
		}
	}
	cout << ans << endl;
}


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

const ll MX = 1e18;
const long double PI = acos(-1);

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;
}

int main()
{
    int n;
    cin >> n;
    int l = 0;
    int r = 1005;

    rep(i,n)
    {
        int a;
        cin >> a;
        if(l < a)
            l = a;
    }

    rep(i,n)
    {
        int a;
        cin >> a;
        if(a < r)
            r = a;
    }

    if( r-l < 0 )
        pri(0);
    else
        pri(r-l+1);

    return 0;
}

// *** Though I am not John Snow, yet I know nothing ***
#include <bits/stdc++.h>
using namespace std;
#define F(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define range(a, b) substr(a, b - a + 1)
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define FIO                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

void solve()
{
    string s;
    cin >> s;
    string ans;
    int i = 0, n = s.size();
    while (i < n && s[i] != '.')
    {
        ans.push_back(s[i]);
        i++;
    }
    cout << ans;
}

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

    FIO;

    solve();

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int matrix[50][50];
int n, k;
long long MOD =  998244353LL;
vector<int> comp;

long long fact (long long i) {
    long long ans = 1;
    while (i > 1ll) {
        ans = (i * ans) % MOD;
        i--;
    }
    return ans;
}

void update (vector<int>* g) {

    bool vis[n];
    memset(vis, 0, sizeof vis);

    for (int i = 0; i < n; i++) {
        if (vis[i]) { continue; }
        int cont = 0;
        queue<int> q;
        q.push(i);
        vis[i] = true;
        while (!q.empty()) {
            int x = q.front(); q.pop();
            cont++;
            for (int &y: g[x]) {
                if (vis[y]) { continue; }
                vis[y] = true;
                q.push(y);
            }
        }
        comp.push_back(cont);
    }

}

int main () {

    scanf("%d %d", &n, &k);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%d", &matrix[i][j]);
        }
    }
    vector<int> g_rows[n];
    vector<int> g_cols[n];
    for (int i = 0; i < n; i++) {
	      for (int j = i + 1; j < n; j++) {
            bool faro_row = true, faro_col = true;
            for (int l = 0; l < n; l++) {
                if (matrix[i][l] + matrix[j][l] > k) {
                    faro_row = false;
                }
                if (matrix[l][i] + matrix[l][j] > k) {
                    faro_col = false;
                }
            }
            if (faro_row) {
                g_rows[i].push_back(j);
                g_rows[j].push_back(i);
            }
            if (faro_col) {
                g_cols[i].push_back(j);
                g_cols[j].push_back(i);
            }
        }
    }

    update(g_rows);
    update(g_cols);

    long long ans = 1;
    for (int& i: comp) {
        ans = (ans * fact(i * 1ll)) % MOD;
    }

    printf("%lld\n", ans);

    return 0;
}

#include<bits/stdc++.h>
#define PI 3.14159265358979323846264338327950288419716939937510
#define eps 1e-15
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
int vis[1005][1005],n,m;
char c[1005][1005];
vector<int> a[1005],b[1005];
void bfs(int sx,int sy){
    queue<pii> q;
    q.push({sx,sy});
    vis[sx][sy]=1;
    while(q.size()){
        int x=q.front().first,y=q.front().second;q.pop();
        for(auto j:a[x]){
            q.push({x,j});vis[x][j]=1;
        }
        for(auto j:b[y]){
            q.push({j,y});vis[j][y]=1;
        }
        a[x].clear();b[y].clear();
    }
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>c[i][j];
        }
    }
    c[1][1]='#';c[1][m]='#';
    c[n][1]='#';c[n][m]='#';
    int h=0,s=0;
    for(int i=1;i<=n;i++){
        int t=0;
        for(int j=1;j<=m;j++){
            if(c[i][j]=='#'){t=1;break;}
        }
        h+=t;
    }
    for(int i=1;i<=m;i++){
        int t=0;
        for(int j=1;j<=n;j++){
            if(c[j][i]=='#'){t=1;break;}
        }
        s+=t;
    }
    int num=min(m-s,n-h),v=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(c[i][j]=='#'){
                a[i].push_back(j);
                b[j].push_back(i);
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(vis[i][j]) continue;
            if(c[i][j]!='#') continue;
            bfs(i,j);v++;
        }
    }
    cout<<num+v-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int N, M;
int board[105][105];
bool vis[105][105];
int dy[4] = {-1, 1, 0, 0};
int dx[4] = {0, 0, -1, 1};
int X, Y;
bool valid(int y, int x) {
    return 1<=y && y<=N && 1<=x && x<=M;
}

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cin >> N >> M >> Y >> X;
    for(int i=1;i<=N;++i) {
        string s; cin >> s;
        for(int j=1;j<=M;++j) {
            board[i][j] = s[j-1] == '#';
        }
    }
    int ans = 0;
    for(int i=0;i<4;++i) {
        int y = Y;
        int x = X;
        while(valid(y, x) && board[y][x] == 0) {
            if(!vis[y][x]) {
                vis[y][x] = true;
                ++ans;
            }
            y += dy[i];
            x += dx[i];
        }
    }
    cout << ans << '\n';
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
using Int=__int128;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>b)return 0; a=b; return 1;}
#define bitUP(x,a) ((x>>a)&1)
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double EPS = 1e-6;
long double PI = acos(-1);
const ll INF=(1LL<<62);
const int MAX=(1<<30);
constexpr ll MOD=1000000000+7;

inline void bin101(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
}

using pii=pair<int,int>;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using psi=pair<string,int>;
using pis=pair<int,string>;
using psl=pair<string,ll>;
using pls=pair<ll,string>;
using pss=pair<string,string>;

using Graph=vector<vector<int>>;

template<typename T >
struct edge {
	int to;
	T cost;
	edge()=default;
	edge(int to, T cost) : to(to), cost(cost) {}

};
template<typename T>
using WeightGraph=vector<vector<edge<T>>>;

//1-indexed vector cin
template<typename T>
inline void vin1(vector<T> &v){
	for(size_t i=1;i<v.size();i++) cin>>v[i];
}

//0-indexed vector cin
template<typename T>
inline void vin0(vector<T> &v){
    for(size_t i=0;i<v.size();i++) cin>>v[i];
}

//1-indexed vector<vector> cin
template<typename T>
inline void vin1(vector<vector<T>> &v){
    for(size_t i=1;i<v.size();i++){
        for(size_t j=1;j<v[i].size();j++) cin>>v[i][j];
    }
}

//0-indexed vector<vector> cin
template<typename T>
inline void vin0(vector<vector<T>> &v){
    for(size_t i=0;i<v.size();i++){
        for(size_t j=0;j<v[i].size();j++) cin>>v[i][j];
    }
}

//要素数n 初期値x
template<typename T>
inline vector<T> vmake(size_t n,T x){
	return vector<T>(n,x);
}

//a,b,c,x data[a][b][c] 初期値x
template<typename... Args>
auto vmake(size_t n,Args... args){
	auto v=vmake(args...);
	return vector<decltype(v)>(n,move(v));
}

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

//pair cin
template<typename T, typename U>
inline istream &operator>>(istream &is,pair<T,U> &p) {
	is>>p.first>>p.second;
	return is;
}

//ソート
template<typename T>
inline void vsort(vector<T> &v){
    sort(v.begin(),v.end());
}

//逆順ソート
template<typename T>
inline void rvsort(vector<T> &v){
	sort(v.rbegin(),v.rend());
}

//1ビットの数を返す
inline int popcount(int x){
	return __builtin_popcount(x);
}
//1ビットの数を返す
inline int popcount(ll x){
	return __builtin_popcountll(x);
}

ll modpow(ll x,ll N,ll mod){
    ll ret=1;
    while(N>0){
        if(bitUP(N,0)) ret=ret*x%mod;
        x=x*x%mod;
        N>>=1;
    }
    return ret;
}

void solve(){
	ll A,B,C;
	cin>>A>>B>>C;
	vector<int> v;
	v.push_back(A%10);
	bool fi=true;
	while(not (fi==false and v.back()==v[0])){
		v.push_back(v.back()*A%10);
		fi=false;
	}
	v.pop_back();
	ll size=v.size();
	ll x=modpow(B,C,size);
	x--;
	if(x==-1) x=size-1;
	cout<<v[x]<<endl;
}

int main(){
    bin101();
    int T=1;
    //cin>>T;
    while(T--) solve();
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef   long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.14159265358979323846264338327950288419716939937510
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}

ll gcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll d = gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}

bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) {
	g = gcd(abs(a), abs(b), x0, y0);
	if (c % g) {
		return false;
	}

	x0 *= c / g;
	y0 *= c / g;
	if (a < 0) x0 = -x0;
	if (b < 0) y0 = -y0;
	return true;
}
void shift_solution(ll & x, ll & y, ll a, ll b, ll cnt) {
	x += cnt * b;
	y -= cnt * a;
}

ll find_all_solutions(ll a, ll b, ll c, ll minx, ll miny) {
	ll x, y, g;
	if (!find_any_solution(a, b, c, x, y, g))
		return inf;
	a /= g;
	b /= g;

	ll sign_a = a > 0 ? +1 : -1;
	ll sign_b = b > 0 ? +1 : -1;

	shift_solution(x, y, a, b, (minx - x) / b);
	if (x < minx)
		shift_solution(x, y, a, b, sign_b);
	ll lx1 = x;
	shift_solution(x, y, a, b, -(miny - y) / a);
	if (y < miny)
		shift_solution(x, y, a, b, -sign_a);
	ll lx2 = x;
	return max(lx1, lx2);
}

int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> t;
	while (t--) {
		ll p, q;
		cin >> x >> y >> p >> q;
		ll a = 2 * (x + y), b = -(p + q);
		ll mn = inf;
		for (i = x; i < x + y; i++) {
			for (j = p; j < p + q; j++) {
				ll c = j - i;
				z = find_all_solutions(a, b, c, 0ll, 0ll);
				if (z != inf) {
					mn = min(mn, a * z + i);
				}
			}
		}
		if (mn == inf) cout << "infinity\n";
		else cout << mn << '\n';
	}

	return 0;

}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;

typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vp;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 998244353;
const ld PI = acos(-1);
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
const ld EPS = 1e-11;
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(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

inline ll ksm(ll a,ll b,const ll m=MOD) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = 1ll * ans * a % m;
        a = 1ll * a * a % m;
        b >>= 1;
    }
    return ans;
}

set<int> divisor(int* n) {
    set<int> ret;
    for (int i = 1; i * i <= *n; i++) {
        if (*n % i == 0) {
            ret.insert(i);
            if (i * i != *n) ret.insert(*n / i);
        }
    }
    // sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int f(int i){
    int ret=0;
    while(i!=0){
        ret+=i%10;
        i/=10;
    }
    return ret;
}

int main(){
    ll n,ret=0,cnt=0;
    cin>>n;
    vll A;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        A.push_back(a*2+b);
        ret+=a;
    }
    RSORT(A);
    rep(i,n){
        ret-=A[i];
        cnt+=1;
        if(ret<0)break;
    }
    co(cnt);
}