#pragma region Region_1

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
using VC = vector<char>;
using VVC = vector<vector<char>>;
#define MOD 1000000007
const int INF = (int)1e9 + 10;         // int max > 2*10^9
const long long INFL = (ll)2e18 + 10;  // ll max > 9*10^18

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

template <class T>
T sum(const vector<T>& v) {
    T res = 0;
    for (size_t i = 0; i < v.size(); ++i) res += v[i];
    return res;
}

/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>>& df) {
    for (auto& vec : df) {
        print(vec);
    }
}

#pragma endregion Region_1
/////////////////////////////////////////////////////////
const double PI = M_PI;

int main() {
    std::cout << std::setprecision(15);
    //////////////////////////////////////////
    int n;
    cin >> n;
    double x0, y0, x2, y2;
    cin >> x0 >> y0 >> x2 >> y2;
    double xo = (x0 + x2) / 2;
    double yo = (y0 + y2) / 2;
    // print("o", xo,yo);
    double x02 = x0 - xo;
    double y02 = y0 - yo;
    double theta = (PI*(double)2) / (double)n;
    double x1 = x02 * cos(theta) - y02 * sin(theta);
    double y1 = x02 * sin(theta) + y02 * cos(theta);
    x1 += xo;
    y1 += yo;
    print(x1, y1);

    return 0;
}

#include <bits/stdc++.h>
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
typedef double DB;
typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
// head
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<LL> a(n+1);
    LL t=0,tt=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=2;i<=n;i++) {
        t+=(a[i]-a[1])*(a[i]-a[1]);
        tt+=(a[i]-a[1]);
    }
    LL res=t;
    for(int i=3;i<=n;i++) {
        tt+=a[i-2]-a[i-1];
        t=t-(a[i-1]-a[i-2])*(a[i-1]-a[i-2])+(a[i-2]-a[i-1])*(a[i-2]-a[i-1])*(n-i+1)+2*(a[i-2]-a[i-1])*tt;
        res+=t;
        tt+=(a[i-2]-a[i-1])*(n-i+1);

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


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

#define Mod(x) (x>=P)&&(x-=P)
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=hd[a];i;i=nxt[i])

typedef long long ll;
void Max(int &x,int y){(x<y)&&(x=y);}
void Min(int &x,int y){(x>y)&&(x=y);}

bool vio;
char IO;
int rd(int res=0){
	bool f=0;
	while(IO=getchar(),IO<48||IO>57)
		f=IO=='-';
	do res=(res<<1)+(res<<3)+(IO^48);
	while(IO=getchar(),isdigit(IO));
	return f?-res:res;
}
const int M=1e3+10;
int C[M][M],A[M][M],B[M][M],n,K,S;
int Sc(int i,int j){
	return C[i][j]-C[i-K][j]-C[i][j-K]+C[i-K][j-K];
}
bool check(int x){
	rep(i,1,n)rep(j,1,n)C[i][j]=(A[i][j]<=x);
	rep(i,1,n)rep(j,1,n)C[i][j]+=C[i][j-1];
	rep(i,1,n)rep(j,1,n)C[i][j]+=C[i-1][j];
	rep(i,K,n)rep(j,K,n)
		if(Sc(i,j)>=S)return 1;
	return 0;
}
bool let;
int main(){
	cerr<<(&vio-&let)/1024.0/1024<<endl;
	n=rd(),K=rd(),S=K*K/2+1;
	S=K*K+1-S;
	rep(i,1,n)rep(j,1,n)A[i][j]=rd();
	int L=0,R=1e9,res=0;
	while(L<=R){
		int mid=(L+R)>>1;
		if(check(mid)){
			res=mid,R=mid-1;
		}else L=mid+1;
	}
	printf("%d",res);
}

 #include <bits/stdc++.h>

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

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

 template <class T> using V = vector<T>;  // from yosupo
 template <class T> using VV = V<V<T>>;  // from yosupo

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

 void __print(int x) {cerr << x;}
 void __print(long x) {cerr << x;}
 void __print(long long x) {cerr << x;}
 void __print(unsigned x) {cerr << x;}
 void __print(unsigned long x) {cerr << x;}
 void __print(unsigned long long x) {cerr << x;}
 void __print(float x) {cerr << x;}
 void __print(double x) {cerr << x;}
 void __print(long double x) {cerr << x;}
 void __print(char x) {cerr << '\'' << x << '\'';}
 void __print(const char *x) {cerr << '\"' << x << '\"';}
 void __print(const string &x) {cerr << '\"' << x << '\"';}
 void __print(bool x) {cerr << (x ? "true" : "false");}

 template<typename T, typename V>
 void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
 template<typename T>
 void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
 void _print() {cerr << "]\n";}
 template <typename T, typename... V>
 void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
 void solve() {

 	int n;
 	cin >> n;
 	int k;
 	cin >> k;

 	VV<int> c(n, V<int>(n));

 	struct node {
 		int i, j, x;
 		bool operator<(node p) {
 			return x < p.x;
 		};

 	};
 	V<node> val;
 	forn(i, n) forn(j, n) {
 		cin >> c[i][j];
 		node p;
 		p.x = c[i][j];
 		p.i = i;
 		p.j = j;

 		val.push_back(p);
 	}
 	sort(all(val));
 	int G = k * k;
 	auto issok = [&](int now) {
 		VV<int> pref(n + 1, V<int>(n + 1));
 		for(auto c : val) {
 			if(c.x <= now) {
 				pref[c.i + 1][c.j + 1]++;
 			}
 			else break;
 		}
 		for(int i = 1;i <= n;++i) {
 			for(int j = 1;j <= n;++j) {
 				pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
 			}
 		}
 		/*
 		for(int i = 1;i <= n;++i) {
 			for(int j = 1; j <= n;++j) {
 				cout << pref[i][j] << ' ';
 			}
 			cout << '\n';
 		}
 		*/
 		//debug(pref[n][n]);
 		int pk = 0;
 		for(int i = 1;i <= n;++i) {
 			for(int j = 1;j <= n;++j) {
 				int x = i + k - 1;
 				int y = j + k - 1;
 				if(x > n || y > n)continue;
 				int sum = pref[x][y] - pref[x][j - 1] - pref[i - 1][y] + pref[i - 1][j - 1];
 				//debug(i, j, x, y, sum);
 				//debug(pref[x][j - 1], pref[i][y - 1]);
 				ckma(pk, sum);
 				//debug(sum);
 			}
 		}

 		return (pk >= (G + 1) / 2);
 	};

 	int low = 0;
 	int high = 1e9;

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

 		if(issok(mid)) {
 			high = mid;
 		}
 		else low = mid + 1;
 	}
 	cout << low << '\n';

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

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

     ios::sync_with_stdio(false);
     cin.tie(nullptr);
     cout.tie(nullptr);

     solve();

 }


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

#define ll long long
const int maxn = 4e5 + 5;

int n;
int a[maxn];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++) scanf("%d",&a[i]);

	priority_queue<int> heap;
	ll sum = 0, aoki = 0;
	for(int i=1;i<=n;i++) {
		heap.push(-a[n-i+1]);
		heap.push(-a[n+i]);
		sum += a[n-i+1] + a[n+i];
		aoki += -heap.top(); heap.pop();
	}
	printf("%lld",sum - aoki);
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin>>N;
	vll v1(N),v2(N);
	rep(i,2*N){
		ll v; cin>>v;
		if (i<N) v1[i]=v;
		else v2[i-N]=v;
	}
	reverse(all(v1));
	ll ans=0;
	multiset<ll> ms;
	rep(i,N){
		ll mx = max(v1[i],v2[i]);
		ll mn = min(v1[i],v2[i]);
		ans+=mx;
		ms.ins(mx);
		if (!ms.empty() && *ms.begin()<mn){
			auto itr = ms.begin();
			ans+=mn-*itr;
			ms.ins(mn);
			ms.erase(itr);
		}
	}
	cout<<ans<<"\n";
    return 0;
}


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

typedef long long ll;

int main() {
    int N, M, A, B;
    cin >> N >> M;
    vector<vector<int>> d(N, vector<int>(N, 1e9)), edge(N);
    rep(i, N) d[i][i] = 0;
    rep(i, M) {
        cin >> A >> B;
        d[A - 1][B - 1] = 1;
        edge[A - 1].push_back(B - 1);
    }
    int ans = 0;
    rep(k, N) {
        vector<bool> done(N, false);
        queue<int> q;
        q.push(k);
        done[k] = true;
        ans++;
        while (!q.empty()) {
            int p = q.front();
            q.pop();
            rep(i, edge[p].size()) {
                int u = edge[p][i];
                if (done[u]) continue;
                q.push(u);
                done[u] = true;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define mod 1000000007
#define pi 3.14159265358979
#define  PRE(x,p) cout<<setprecision(x)<<p;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl "\n"
#define high INT_MAX
#define low INT_MIN
#define ll long long int

using namespace std;

void showa(ll a[],ll n){ for(ll i=1;i<=n;i++) cout<<a[i]<<' ';  cout<<endl;  }
void showv(vector<ll>v){ for(ll i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;}
ll modd;
ll power(ll x, ll y)
{
   ll res = 1;
   x = x % modd;
  while (y > 0)
  {

        if (y & 1)
            res = (res * x) % modd;

        y = y >> 1;
        x = (x * x) % modd;
    }
    return res;
}
void solve()
{
   ll n,m;
   cin>>n>>m;
   modd=m*m;
   cout<<(power(10,n)/m) %m;

}
int main()
{
 #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

ll t=1;
// cin>>t;
for(ll test=1;test<=t;test++)
{
    // cout<<"CASE #"<<test<<": ";
    solve();
}

return 0;
}


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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(num, 10000){
        vector<int> a(10);
        int x = num;
        rep(i,4){
            int d = x%10;
            a[d] = 1;
            x /= 10;
        }
        bool ok = true;
        rep(i,10){
            if(s[i] == 'o' && a[i] != 1) ok = false;
            if(s[i] == 'x' && a[i] != 0) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

#pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

#define F first
#define S second
#define vec vector
#define pb push_back
#define cld complex<ld>
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define all(m) m.begin(), m.end()
#define uid uniform_int_distribution
#define init(m, x) memset(m, x, sizeof(m));
#define pripii(p) cout << "{" << p.F << ", " << p.S << "} "
#define fast cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    str t; cin >> t;
    int o = 0;
    set<int> mu, nmu;
    for (int q = 0; q < 10; q++) {
        if (t[q] == 'o') mu.insert(q);
        if (t[q] == 'x') nmu.insert(q);
    }
    for (int q = 0; q < 10; q++) {
        for (int w = 0; w < 10; w++) {
            for (int e = 0; e < 10; e++) {
                for (int r = 0; r < 10; r++) {
                    set<int> tyt = {q, w, e, r};
                    int fl = 1;
                    for (int i : mu) fl &= tyt.count(i);
                    for (int i : nmu) fl &= !tyt.count(i);
                    o += fl;
                }
            }
        }
    }
    cout << o;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <unordered_map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef unsigned long long ull;

long long MX = 1e18;

int n;
int a[110];
ull x;

ull calc2(long long sum, int k) {
    sum = x - sum;
    if (sum % k) return MX;
    return sum / k;
}

long long f[110][110][110];
ull calc(int k) {
    for (int i = 0; i <= n; ++i)
        for (int h = 0; h <= k; ++h)
            for (int j = 0; j < k; ++j) f[i][h][j] = -MX;
    f[0][1][a[0] % k] = a[0];
    for (int i = 1; i < n; ++i) {
        for (int h = 2; h <= i+1 && h <= k; ++h)
            for (int j = 0; j < k; ++j) {
                f[i][h][j] = max(f[i-1][h][j], f[i-1][h-1][((j-a[i])%k+k)%k] + a[i]);
            }
        f[i][1][a[i]%k] = a[i];
        for (int j = 0; j < k; ++j) {
            f[i][1][j] = max(f[i][1][j], f[i-1][1][j]);
        }
    }
    ull ans = MX;
    for (int j = 0; j < k; ++j) {
        if (f[n-1][k][j] <= 0) continue;
        ans = min(ans, calc2(f[n-1][k][j], k));
    }
    return ans;
}

int main()
{
    cin >> n >> x;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ull ans = MX;
    for (int k = 1; k <= n; ++k) {
        ull c = calc(k);
        if (c < ans) ans = c;

    }
    cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define V vector
#define debug(v) {for(auto i: v) cout << i << " "; cout << endl;}
#define vcin(v) rep(i, v.size()) cin >> v[i]
#define wcin(v, w) rep(i, v.size()) cin >>v[i] >>w[i]

int main(){
    ll n,k;
    cin >>n >>k;
    ll a,b;
    V<pair<ll,ll>> ab(n);
    rep(i,n){
        cin >>a >>b;
        ab[i]={a,b};
    }

    sort(all(ab));
    ll kane=k,now=0;
    rep(i,n){
        if(kane>=ab[i].first-now){
            kane=kane-ab[i].first+now+ab[i].second;
            now=ab[i].first;
        }
        else break;
    }
    cout <<now+kane;
}


#include <bits/stdc++.h>

using namespace std;

//@formatter:off

//@formatter:on

int main() {
    int N, K;
    cin >> N >> K;
    int64_t res = 0;
    for (int A = 2; A <= 2 * N; A++) {
        int B = A - K;
        if (!(2 <= B and B <= 2 * N)) continue;
        int64_t pa = 0, pb = 0;
        if (A <= N )pa += A - 1;
        else pa += 2 * N - A + 1;
        if (B <= N ) pb += B - 1;
        else pb += 2 * N - B + 1;
        res += pa * pb;
    }
    cout << res << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000100100;

int main() {
    ll A, B;
    cin >> A >> B;
    ll X, Y;
    X = (A + B)/2;
    Y = A - X;
    cout << X << " " << Y << endl;

    return 0;
}


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

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  map<char, int> m;
  string s = a + b + c;
  int ss = s.size();
  int kind = 0;
  vector<char> ch;
  for(int i = 0;i < ss;i++){
    m[s[i]]++;
    if(m[s[i]] == 1){
      kind++;
      ch.push_back(s[i]);
    }
  }
  if(kind > 10){
    cout << "UNSOLVABLE" << endl;
    return 0;
  }
  vector<int> per(10);
  int as = a.size();
  int bs = b.size();
  int cs = c.size();
  for(int i = 0;i < 10;i++)
    per[i] = i;
  int ap = pow(10, as - 1);
  int bp = pow(10, bs - 1);
  int cp = pow(10, cs - 1);
  int64_t po[10];
  for(int i = 0;i < 10;i++)
    po[i] = pow(10, i);
  for(int j = 0;j < 3628800;j++){
    next_permutation(per.begin(), per.end());
    for(int i = 0;i < kind;i++){
      m[ch[i]] = per[i];
    }
    int64_t h = 0;
    int64_t l = 0;
    int64_t ans = 0;
    for(int i = 0;i < as;i++)
      h += (m[s[as - 1 - i]] * po[i]);
    for(int i = 0;i < bs;i++)
      l += (m[s[as + bs - 1 - i]] * po[i]);
    for(int i = 0;i < cs;i++)
      ans += (m[s[ss - i - 1]] * po[i]);
    if(h < ap || l < bp || ans < cp)
      continue;
    if(h + l == ans){
      cout << h << endl;
      cout << l << endl;
      cout << ans << endl;
      return 0;
    }
  }
  cout << "UNSOLVABLE" << endl;
}

#include <bits/stdc++.h>

using namespace std;
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define int long long
#define pb push_back
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = n - 2; i >= 0; i--)
#define repi(i, n) for (ll i = 1; i <= n; i++)
#define repi1(i, n) for (ll i = n; i >= 1; i--)
#define mem(arr, x) memset(arr, x, sizeof(arr))
#define CLOCK cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
typedef vector<ll> vi;
typedef vector<char> vc;
#define mp make_pair
#define ss second
#define mod 1000000007
const int MAX = 1000000000;
const int inf = 1e18;
const long double PI = 3.141592653589793238460;

void solve()
{

int n,k;
cin>>n>>k;
vector<pair<int,int>>v;
rep(i,n)
{  int p,q;
	cin>>p>>q;
	v.pb(mp(p,q));
}
sort(v.begin(),v.end());
int pai=k;
if(v[0].first>k)
{
	cout<<k<<'\n';
	return ;
}
k-=v[0].first;
int res=v[0].first;
if(n==1)
{
	cout<<res+v[0].second<<'\n';
	return;
}
//cout<<k;
map<int,int>m;
for(int i=1;i<n;i++)
{  k+=v[i-1].second;
	if(k<(v[i].first-v[i-1].first))
	{
	  res=v[i-1].first+k;
	  k=0;
	  break;
     }
     else
     {
     	k-=(v[i].first-v[i-1].first);
     	res=v[i].first;
     	m[v[i].first]++;
     //	k+=v[i].second;
     }
}
if(m[v[n-1].first])
k+=v[n-1].second;
if(k)
{
	res+=k;
}
cout<<res<<'\n';
}

int32_t main()
{
  fast_io;

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

 }


#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <array>
using namespace std;

constexpr int MOD = 1e9+7;
int modular_add(int a, int b){
    assert( a >= 0 && a < MOD && b >=0 && b < MOD);
    int ans = a + b;
    if(ans >= MOD){
        ans = ans % MOD;
    }
    return ans;
}
void solve(){
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for(int i = 0 ; i < h ; i++){
        cin >> grid[i];
        assert(w == (int) grid[i].size());
    }
    //dp[i][j][0] : number of way to move from (i,j) to goal with first move right
    //dp[i][j][1], dp[i][j][2] :  same, but first move down, diagonal
    //dp[i][j][3] : total

    vector<vector<array<int,4>>> dp(h, vector<array<int,4>>(w));

    for(int i = h - 1; i >= 0 ; i--){
        for(int j = w - 1; j >= 0 ; j--){
            //if it's a block, we cannot move
            if(grid[i][j] == '#') continue;
            //special case goal: we don't have to move in anydirection
            if(i == h - 1 && j == w -1){

                dp[i][j] = {0, 0, 0, 1};
                continue;
            }
            //try moving right
            if(j + 1 < w ){
                //we can either move to (i, j+ 1) frist or pass through it in the right direction
                dp[i][j][0] = modular_add(dp[i][j+1][3], dp[i][j+1][0]);
            }
            //try moving down
            if( i + 1 < h){
                //we can either move to (i+ 1, j) frist or pass through it in the downward direction
                dp[i][j][1] = modular_add(dp[i+1][j][3], dp[i+1][j][1]);
            }
            //try moving diagonal
            if( i + 1 < h && j + 1 < w){
                //we can either move to (i+ 1, j + 1) frist or pass through it in the diagonal direction
                dp[i][j][2] = modular_add(dp[i+1][j+1][3], dp[i+1][j+1][2]);
            }
            //finally, we count the total way
            dp[i][j][3] = modular_add(dp[i][j][0], modular_add(dp[i][j][1], dp[i][j][2]));

        }
    }
    cout << dp[0][0][3] << endl;
}

int main(){
    /*unsync iostream with stdio to improve I/O speed*/
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /************************************************/
    solve();

}

#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 1e5+5;
const dd eps = 1e-8;
const int mod = 1e9+7;
char table[2010][2010];
ll h,w,dp[2010][2010],x[2010][2010],y[2010][2010],z[2010][2010];
int main(){
    // freopen("input.txt","r",stdin);
    cin>>h>>w;
    for(int i = 1;i <= h;i++){
        for(int j = 1;j <= w;j++) cin>>table[i][j];
    }
    dp[1][1] = 1;
    for(int i = 1;i <= h;i++){
        for(int j = 1;j <= w;j++){
            if(i == 1 and j == 1) continue;
            if(table[i][j] == '#') continue;
            x[i][j] = (x[i-1][j] + dp[i-1][j])%mod;
            y[i][j] = (y[i][j-1] + dp[i][j-1])%mod;
            z[i][j] = (z[i-1][j-1] + dp[i-1][j-1])%mod;
            dp[i][j] = (x[i][j] + y[i][j] + z[i][j])%mod;
        }
    }
    cout<<dp[h][w]<<endl;
    return 0;
}


#include <bits/stdc++.h>

// 1. dp
typedef long double ld;
#define int long long

#define gcd            __gcd
#define endl           "\n"
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define pb             push_back
#define all(x)         x.begin(), x.end()
#define f              first
#define s              second
#define lb             lower_bound
#define ub             upper_bound
#define ins            insert
#define sz(x)          (int)(x).size()
#define mk             make_pair
#define deci(x, y)     fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PI             3.141592653589793238
using namespace std;
int dp[4000][4000];
int solve(int n,int k){
    if(k>n) return 0;
    if(n==0) return 1;
    if(k==0) return 0;
    if(dp[n][k]!=0)
        return dp[n][k];
    return dp[n][k]=(solve(n-1,k-1)+solve(n,2*k))%mod2;

}
void solve() {
    int n,k;
    cin>>n>>k;
    cout<<solve(n,k)<<endl;
}

int32_t main() {
    nitin;

    solve();
}

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

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

const int maxn = 3e3 + 10;
ll dp[maxn][maxn];
int n, k;
const ll m = 998244353;

int main()
{
    scanf("%d%d", &n, &k);
    fill(dp[0], dp[0]+maxn, 1);
    for (int i = 1; i <= n; ++i)
        for (int j = i; j >= 1; --j) {
            dp[i][j] = dp[i - 1][j - 1] % m;
            if (2*j <= i) dp[i][j] = (dp[i][j] + dp[i][j*2])%m;
        }
    printf("%lld\n", dp[n][k]);
    return 0;
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<ll> dec;
    ll at = 0;
    rep(i, n) {
        cin >> a[i] >> b[i];
        at += a[i];
        dec.push_back(2 * a[i] + b[i]);
    }
    sort(dec.rbegin(), dec.rend());

    int ans = 0;
    while (at >= 0) {
        at -= dec[ans];
        ans++;
    }

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

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

#define ll long long
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

const int N =100;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
ll binarySearch(ll arr[], ll l, int r, ll x,ll n)
{
	sort(arr,arr+n);
    if (r >= l) {
        ll mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x,n);
        return binarySearch(arr, mid + 1, r, x,n);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);

}
ll f(ll n) {
	return n * (n - 1) / 2;
}
bool powerof2(ll n)
{
	return n!=0 && ((n&(n-1))==0);
}
double fact(double n)
{cout<<setprecision(9);
    if(n==0 ||n==1)
    return 1;
    else
    return n*fact(n-1);
}
void solve()
{

	int n;
	cin>>n;
	int a[n][2];
	for(int i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1];
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int p = abs(a[j][1]-a[i][1]);
			int q = abs(a[j][0]-a[i][0]);
			if(p<=q)
			ans++;
		}
	}
	cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


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

#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
const ll MOD = 1000000007;
const ll ll_MAX = 1e15;
ll fast_expo(ll x,ll p){
  if(p==0) return 1;
  else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;}
  else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll invMod(ll num){
  return fast_expo(num, MOD - 2)%MOD;
}

const ll N = 3e3 + 5;
ll dp[N][N], pre[N], sum[N][N];

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

  ll t_c; t_c = 1;
  // cin >> t_c;

  for(ll t_i = 0; t_i < t_c; ++t_i){
    ll n; cin >> n;
    ll arr[n + 1]{};
    for(ll i = 1; i <= n; ++i){
      cin >> arr[i];
      pre[i] = pre[i - 1] + arr[i];
    }

    dp[0][0] = 1;
    sum[0][0] = 1;

    for(ll i = 1; i <= n; ++i){
      for(ll j = n; j > 0; --j){
        dp[i][j] = sum[j - 1][pre[i]%j];
        sum[j][pre[i]%(j + 1)] = (sum[j][pre[i]%(j + 1)] + dp[i][j])%MOD;
      }
    }

    ll ans = 0;
    for(ll i = 1; i <= n; ++i){
      ans = (ans + dp[n][i])%MOD;
    }
    cout << ans << endl;
  }
  return 0;
}

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

using namespace std;

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}
template <class Con>
string concat(const Con &c, const string &spr){
	stringstream ss;
	typename Con::const_iterator it = c.begin(), en = c.end();
	bool fst = true;
	for(; it != en; ++it){
		if(!fst){ ss << spr; }
		fst = false;
		ss << *it;
	}
	return ss.str();
}

template <class Con, class Fun>
vector<typename Con::value_type> cfilter(const Con &c, Fun f) {
	vector<typename Con::value_type> ret;
	typename Con::const_iterator it = c.begin(), en = c.end();
	for(; it != en; ++it){
		if(f(*it)){
			ret.emplace_back(*it);
		}
	}
	return ret;
}
#if __cplusplus >= 201103L
template <class Con, class Fun>
auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> {
	vector<decltype(f(*c.begin()))> ret;
	ret.reserve(c.size());
	for(const auto &x: c){
		ret.emplace_back(f(x));
	}
	return ret;
}
#endif

#if __cplusplus >= 201402L
#define lambda(e) ([&](const auto &_){ return (e); })
#define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); })
#endif

#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()
#define tget(t,i) get<i>(t)

#define MOD 1000000007LL
#define EPS 1e-8

LL extgcd(LL a, LL b, LL &x, LL &y){
	LL d = a;
	if(b){ d = extgcd(b, a % b, y, x); y -= a / b * x; }
	else{ x = 1; y = 0; }
	return d;
}
LL modinv(LL a, LL m = MOD){
	LL x, y; extgcd(a, m, x, y); return (m + x % m) % m;
}

LL gcd(LL x, LL y){
	while(y){
		LL r = x % y;
		x = y;
		y = r;
	}
	return x;
}

// a * x = b (mod m)
pair<LL,LL> linear_congruence(
	const vector<LL> &va,
	const vector<LL> &vb,
	const vector<LL> &vm
){
	LL x = 0, m = 1;
	for(size_t i = 0; i < va.size(); ++i){
		LL a = va[i] * m;
		LL b = vb[i] - va[i] * x;
		LL d = gcd(vm[i], a);
		if(b % d != 0){
			return make_pair(0, -1); // NA
		}
		LL t = b / d * modinv(a / d, vm[i] / d) % (vm[i] / d);
		x = x + m * t;
		m *= vm[i] / d;
	}
	x = (x % m + m) % m;
	return make_pair(x, m);
}

LL solve(){
	LL x, y, p, q;
	cin >> x >> y >> p >> q;

	LL ans = LLONG_MAX;
	vector<LL> va, vb, vm;
	for(LL i = 0; i < y; ++i)
	for(LL j = 0; j < q; ++j){
		va = {1, 1};
		vb = {x + i, p + j};
		vm = {2 * (x + y), p + q};

		auto r = linear_congruence(va, vb, vm);
		if(r.second != -1){
			chmin(ans, r.first);
		}
	}
	return ans;
}

void mainmain(){
	int t;
	for(cin >> t; t--; ){
		LL ans = solve();
		if(ans == LLONG_MAX){ cout << "infinity\n"; }
		else{ cout << ans << '\n'; }
	}
}

}
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}


#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
#define SZ(x) ((int)(x).size())

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

/*
aはsortしておく
最後に残る可能性がある整数
a1~anのうちいずれかの約数(この時点で1つ以上のaの要素の公約数になることは確定する)
a１以下

上の条件を満たす整数を全列挙

kが最後に残るためにはaから取り出したいくつかの要素の最大公約数になることがあれば良い
これはaの要素のうちkの倍数のものをみていき、kで割った商の集合の最大公約数が1になれば良い

計算量
約数全列挙：O(N*(maxA)^1/2)
約数の個数の最大：2e6くらい?でも直感的にはもっと少なそう<-ダメだった

*/

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/

set<ll>st;
vector<ll>a;
map<ll,ll>mp;

void divisor(ll n){
    vector<ll>ret;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
        }
    }
	for(auto x:ret){
		if(x>a[0])continue;
		mp[x]=__gcd(mp[x],n);
		//st.insert(x);
	}
	return;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	ll n;
	cin >> n;
	a.resize(n);
	rep(i,n)cin>>a[i];
	sort(a.begin(),a.end());
	rep(i,n){
		divisor(a[i]);
		//debug(mp);
	}
	ll ans = 0;
	/*
	for(auto x:st){
		ll g = 0;//大丈夫かな？
		rep(i,n){
			if(a[i]%x==0){
				g = __gcd(a[i]/x,g);
			}
		}
		if(g==1)ans++;
	}
	*/
	for(auto p:mp){
		if(p.second==p.first)ans++;
	}
	cout << ans << endl;

	return 0;
}

/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define F(i,a,b) for(i=a;i<b;i++)
#include <ext/pb_ds/assoc_container.hpp> // policy based data structure header files
#include <ext/pb_ds/tree_policy.hpp> // policy based data structure header files
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
using namespace __gnu_pbds; // for pbds
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // have functions like order_of_key, find_by_order
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641;
const ll M=1e16;
const ll MAXN=100200;
ll i,j,mask;
void solve()
{
  ll n;
  cin>>n;
  ll minn=M;
  map<ll,ll> mp;
  F(i,0,n)
  {
      ll x;
      cin>>x;
      minn=min(minn,x);
      for(j=1;j*j<=x;j++)
      {
          if(x%j==0)
          {
              mp[j]=__gcd(mp[j],x);
              ll k=x/j;
              mp[k]=__gcd(mp[k],x);
          }
      }
  }
     set<ll> st;
      for(auto x:mp)
      {
          if(x.second<=minn)
          {
              st.insert(x.second);
          }
      }
      cout<<st.size();
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#*/
/*ll t,test;
cin>>test;
F(t,1,test+1)
{
    //cout<<"Case #"<<t<<": ";
    solve();
    nl
}*/
solve();
return 0;
}


//多分分かったけど、みんな速くない？
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
typedef vector<int> Array;
typedef vector<Array> Mat;

const int mod = 1000000007;

Array mul(Mat mat, Array vec) {
	int n = mat.size();
	int m = mat[0].size();
	Array ret(m, 0);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			ret[i] += mat[i][j] * vec[j];
			ret[i] %= mod;
		}
	}
	return ret;
}

Mat identify(int n) {
	Mat mat(n, Array(n, 0));
	int i;
	rep(i, n) mat[i][i] = 1;
	return mat;
}

Mat mul(Mat a, Mat b) {
	int n = a.size();
	int m = b[0].size();
	Mat mat(n, Array(m, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < a[0].size(); k++) {
				mat[i][j] += a[i][k] * b[k][j];
				mat[i][j] %= mod;
			}
		}
	}
	return mat;
}

Mat powmod(Mat a, int n) {
	if (n == 0) return identify(a.size());
	if (n % 2 == 0) return powmod(mul(a, a), n / 2);
	return mul(a, powmod(a, n - 1));
}

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return a * powmod(a, n - 1, mod) % mod;
}

int n, m, K;
int a[100];
bool exist[100][100];

signed main() {
	int i, j, k;

	cin >> n >> m >> K;
	rep(i, n) cin >> a[i];
	rep(i, m) {
		int x, y; cin >> x >> y;
		x--; y--;
		exist[x][y] = exist[y][x] = true;
	}

	Mat mat(n, Array(n, 0));
	vector<vector<double>> mat_debug(n, vector<double>(n, 0));
	rep(i, n) {
		mat[i][i] = 1;
		mat_debug[i][i] = 1.0;
	}

	rep(i, n) {
		rep(j, n) {
			if (exist[i][j]) {
				mat[j][i] = (mat[j][i] + mod + powmod(2 * m, mod - 2, mod)) % mod;
				mat[i][i] = (mat[i][i] + mod - powmod(2 * m, mod - 2, mod)) % mod;
				//mat_debug[j][i] += 1.0 / (2 * m);
				//mat_debug[i][i] -= 1.0 / (2 * m);
			}
		}
	}

	/*cout << "mat" << endl;
	rep(i, n) {
		rep(j, n) {
			cout << mat_debug[i][j] << " ";
		}
		cout << endl;
	}*/

	Array vec(n);
	rep(i, n) vec[i] = a[i];

	//(mat ** k) * vecを求めたい
	Mat res = powmod(mat, K);
	Array ans = mul(res, vec);

	/*cout << "res" << endl;
	rep(i, n) {
		rep(j, n) {
			cout << res[i][j] << " ";
		}
		cout << endl;
	}*/

	//cout << "ans" << endl;
	rep(i, ans.size()) {
		cout << ans[i] << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i,a,b) for (ll i = (a); i < (ll)(b); i++)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define MT make_tuple
#define fr first
#define sc second

using namespace std;
template <class T, class U> inline bool chmax(T &a, const U &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return (a > b ? a = b, 1 : 0); }
template <class T> using vc = vector<T>;
template <class T> using vv = vc<vc<T>>;
template <class T> using vvv = vc<vv<T>>;
template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
using vs = vc<string>;
using vpl = vc<pll>;
using vpd = vc<pdd>;
using vvi = vv<int>;
using vvl = vv<ll>;
using vvpl = vv<pll>;

const ld pi = 3.141592653589793;
const ll linf = 1001001001001001001LL;
const int inf = 1001001001;

constexpr int MOD = 1e9+7;
// constexpr int MOD = 998244353;

struct mint {
long long x;
  mint(long long x = 0) noexcept : x((x%MOD + MOD) % MOD) {}

  // basis
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) noexcept { if((x += a.x) >= MOD) x -= MOD; return *this; }
  mint& operator-=(const mint a) noexcept { if((x += MOD-a.x) >= MOD) x -= MOD; return *this; }
  mint& operator*=(const mint a) noexcept { (x *= a.x) %= MOD; return *this; }
  mint operator+(const mint a) const noexcept { return mint(*this) += a; }
  mint operator-(const mint a) const noexcept { return mint(*this) -= a; }
  mint operator*(const mint a) const noexcept { return mint(*this) *= a; }
  mint mpow(long long t) const noexcept {
    if(!t) return 1;
    mint a = mpow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const noexcept { return mpow(MOD-2); }
  mint& operator/=(const mint a) noexcept { return *this *= a.inv(); }
  mint operator/(const mint a) const noexcept { return mint(*this) /= a; }

  // comparison
  bool operator==(const mint &a) const noexcept { return this->x == a.x; }
  bool operator!=(const mint &a) const noexcept { return this->x != a.x; }

  // I/O stream
  friend istream& operator>>(istream& is, mint& a) noexcept { return is >> a.x; }
  friend ostream& operator<<(ostream& os, const mint& a) noexcept { return os << a.x; }
};
// additional
mint mpow(const long long &a, long long n) noexcept { return mint(a).mpow(n); }
mint mpow(const mint &a, long long n) noexcept { return a.mpow(n); }

int main() {
  ll h, w;
  cin >> h >> w;
  vs S(h);
  rep(i,h) cin >> S[i];
  vvl R(h, vl(w, 0)), C(h, vl(w, 0));
  rep(i,h) {
    ll l = 0, r = 0;
    while (l < w) {
      while (r < w && S[i][r] == '.') r++;
      repr(j,l,r) R[i][j] = r-l;
      if (l == r) r++;
      l = r;
    }
  }
  rep(i,w) {
    ll l = 0, r = 0;
    while (l < h) {
      while (r < h && S[r][i] == '.') r++;
      repr(j,l,r) C[j][i] = r-l;
      if (l == r) r++;
      l = r;
    }
  }
  ll K = 0;
  rep(i,h)rep(j,w) K += S[i][j] == '.';
  vc<mint> pow2(5000);
  rep(i,5000) pow2[i] = mpow(2, i);
  mint ans = 0;
  rep(i,h)rep(j,w) {
    if (S[i][j] == '#') continue;
    ans += (pow2[R[i][j]+C[i][j]-1]-1)/pow2[R[i][j]+C[i][j]-1];
  }
  ans *= mpow(2, K);
  cout << ans << endl;
}


#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
string solve(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,s,d; cin >> n >> s >> d;
  vi x(n),y(n); rep(i,n) cin >> x[i] >> y[i];
  rep(i,n){
    if(x[i] < s && d < y[i]) return "Yes";
  }
  return "No";
}
int main(){
  cout << solve() << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,s,d,a,b;
int main()
{
	cin>>n>>s>>d;
	for(int i=1;i<=n;++i)
	{
		cin>>a>>b;
		if(a<s&&b>d)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define X first
#define Y second
using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef pair <int,int> pii;
const int Size=2e6+10;
const int INF=0x3f3f3f3f;

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

vi f[Size];
int main()
{
    int n=read(),m=read(),a;
    for (int i=0;i<=n;++i) f[i].pb(0);
    for (int i=1;i<=n;++i) {a=read(); f[a].pb(i);}
    for (int i=0;i<=n;++i) f[i].pb(n+1);

    int res;
    for (int i=0;i<=n;++i)
    {
        int siz=f[i].size();
        bool flag=false;
        for (int j=1;j<=siz-1;++j)
            if (f[i][j]-f[i][j-1]>=m+1) {flag=true; break;}
        if (flag) {res=i; break;}
    }
    printf("%d\n",res);
    return 0;
}

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

vector<vector<int>>G, dG;
vector<int>in, out;
int cnt = 0, depth = 0;

void dfs(int n){
    in[n] = cnt++;
    dG[depth].push_back(in[n]);

    for(int g : G[n]){
        depth++;
        dfs(g);
        depth--;
    }

    out[n] = cnt++;
}

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

    in = out = vector <int>(n);
    G = dG = vector <vector <int>>(n+1, vector <int> (0));

    int p;
    for(int i=1; i<n; i++){
        cin >> p;
        p--;
        G[p].emplace_back(i);

    }

    dfs(0);

    int q, u, d;
    cin >> q;

    for(int i=0; i<q; i++){
        cin >> u >> d;
        u--;
        const auto& v = dG[d];
        cout << lower_bound (v.cbegin(), v.cend(), out[u]) -
        lower_bound (v.cbegin(), v.cend(), in[u]) << endl;
    }

    return 0;

}


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i <= n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n)
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
using Edge = pair<int, ll>;
const int MAX = 100000;
const ll INF = 1LL << 60;

struct UnionFind
{
    vector<int> par, siz;
    UnionFind(int n) : par(n, -1), siz(n, 1) {} // 連結成分サイズの配列。最初はみんな根、サイズ1。

    // 木の根を求める
    int root(int x)
    {
        if (par[x] < 0)
            return x; // 根
        else
            return root(par[x]); // 経路圧縮(O(logn)になる)
    }

    // xとyの属する集合を併合。小さい方をくっつける。
    bool unite(int x, int y)
    {
        // 先に経路圧縮。根どうしを結合する。
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (siz[x] < siz[y])
            swap(x, y); // sizの大きい方を根に
        par[y] = x;     //yの根はxに。葉はrootの値が正になる。
        siz[x] += siz[y];
        return true;
    }

    //xとyが同じ集合に属するか判定
    bool issame(int x, int y) { return root(x) == root(y); }

    //集合のサイズを返す
    int size(int x) { return siz[root(x)]; }
};

int main()
{
    // cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vll a(n), b(n);
    REP(i, n)
    cin >> a[i];
    REP(i, n)
    cin >> b[i];

    // 無向グラフを連結
    UnionFind uf(n);
    REP(i, m)
    {
        int x, y;
        cin >> x >> y;
        --x, --y;
        uf.unite(x, y);
    }

    // 連結部分の総和
    vll sa(n, 0), sb(n, 0);
    REP(v, n)
    {
        int r = uf.root(v);
        sa[r] += a[v], sb[r] += b[v];
    }
    bool ans = true;
    // 任意の頂点について、根の総和が一致するか確認
    REP(v, n)
    {
        int r = uf.root(v);
        if (sa[r] != sb[r])
            ans = false;
    }
    if (ans)
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
char inverse_char(char c) {
  if(isupper(c)) return tolower(c);
  else return toupper(c);
}
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;
}
struct edge {
  ll to, cost;
};

vector<ll> C;

vector<vector<ll>> tree;
vector<ll> res; // その頂点にたどり着いたか？
vector<ll> ans; // 答え

map<ll, ll> _tmp;
void dfs(ll pnt) {
  res[pnt] = 1; _tmp[C[pnt]]++;
  if(_tmp[C[pnt]] == 1) ans.push_back(pnt);
  for(int i = 0; i < tree[pnt].size(); ++i) {
    if(res[tree[pnt][i]] == 1) continue;
    dfs(tree[pnt][i]);
  }
  _tmp[C[pnt]]--;
}

int main() {
  ll N; cin >> N;
  C.resize(N); REP(i, N) cin >> C[i];
  vector<ll> A(N - 1), B(N - 1);
  REP(i, N - 1) {
    cin >> A[i] >> B[i];
    --A[i]; --B[i];
  }
  tree.resize(N); res.resize(N);
  REP(i, N - 1) {
    tree[A[i]].push_back(B[i]);
    tree[B[i]].push_back(A[i]);
  }
  dfs(0); sort(all(ans));
  REP(i, ans.size()) cout << ans[i] + 1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

int main() {
    int n;
	cin >> n;
    int ans[n];
    fr(i,n){
      ans[i]=1;
    }
    if(n>=15){
    int count=1;
    fr(i,n*8/15){
      ans[i]*=6;
      ans[i]*=count;
      count++;
      if(count%5==0)count++;
    }
    count=1;
    fro(i,n*8/15,n*4/5){
      ans[i]*=10;
      ans[i]*=count;
      count++;
      if(count%3==0)count++;
    }
    count=1;
    fro(i,n*4/5,n*14/15){
      ans[i]*=15;
      ans[i]*=count;
      count++;
      if(count%2==0)count++;
    }
    count=1;
    fro(i,n*14/15,n){
      ans[i]*=30;
      ans[i]*=count;
      count++;
    }
    }else{
    int count=1;
    fr(i,n/3){
      ans[i]*=6;
      ans[i]*=count;
      count++;
      if(count%5==0)count++;
    }
    count=1;
    fro(i,n/3,n*2/3){
      ans[i]*=10;
      ans[i]*=count;
      count++;
      if(count%3==0)count++;
    }
    count=1;
    fro(i,n*2/3,n){
      ans[i]*=15;
      ans[i]*=count;
      count++;
      if(count%2==0)count++;
    }
    }
    fr(i,n){
      cout << ans[i] << " ";
    }
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  set<int> a;
  a.insert(6);
  a.insert(10);
  a.insert(15);
  for(int i=3;i<=1666;i++) a.insert(6*i);
  for(int i=2;i<=1000;i++) a.insert(10*i);
  for(int i=2;i<=666;i++) a.insert(15*i);
  vector<int> t(a.begin(),a.end());
  for(int i=0;i<n;i++){
    cout<<t[i]<<" ";
  }
}


#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

const int MOD = 1e9 + 7;

using mint = ModInt<MOD>;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s;
    rep(i, h){
        string x;
        cin >> x;
        s.push_back(x);
    }

    vector<vector<int>> hbox(h), wbox(w);
    rep(i, h){
        hbox[i].push_back(-1);
        hbox[i].push_back(w);
    }
    rep(i, w){
        wbox[i].push_back(-1);
        wbox[i].push_back(h);
    }

    int messcnt = 0;

    rep(i, h){
        rep(j, w){
            if(s[i][j]=='#'){
                messcnt++;
                hbox[i].push_back(j);
                wbox[j].push_back(i);
            }
        }
    }

    rep(i, h){
        sort(hbox[i].begin(), hbox[i].end());
    }

    rep(i, w){
        sort(wbox[i].begin(), wbox[i].end());
    }

    vector<mint> two(h*w-messcnt+1);
    two[0] = 1;
    rep2(i, 1, h*w-messcnt+1){
        two[i] = two[i-1]*2;
    }

    mint res = 0;

    rep(i, h){
        rep(j, w){
            if(s[i][j]=='.'){
                auto it = upper_bound(hbox[i].begin(), hbox[i].end(), j);
                int hnum = (*(it) - *(--it)) - 1;
                it = upper_bound(wbox[j].begin(), wbox[j].end(), i);
                int wnum = (*(it) - *(--it)) - 1;
                int x = hnum + wnum - 1;
                res += two[h*w-messcnt] - two[h*w-messcnt - x];
            }
        }
    }

    cout << res << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    vector<vector<int>> A(H, vector<int> (W, -1));
    vector<vector<int>> y(H, vector<int> (W, -1));
    vector<vector<int>> t(H, vector<int> (W, -1));
    for (int i = 0; i < H; i++) {
        if(S[i][0] == '.'){
            y[i][0] = 1;
        }
        for (int j = 1; j < W; j++) {
            if(S[i][j-1] == '#'){
                if(S[i][j] == '.'){
                    y[i][j] = 1;
                }
            }
            else{
                if(S[i][j] == '.'){
                    y[i][j] = y[i][j-1] + 1;
                }
            }
        }
        int tmp = -1;
        for (int j = W-1; j >= 0; j--) {
            if(y[i][j] == -1){
                tmp = -1;
            }
            else{
                if(tmp == -1){
                    tmp = y[i][j];
                }
                else{
                    y[i][j] = tmp;
                }
            }
        }
    }
    for (int i = 0; i < W; i++) {
        if(S[0][i] == '.'){
            t[0][i] = 1;
        }
        for (int j = 1; j < H; j++) {
            if(S[j-1][i] == '#'){
                if(S[j][i] == '.'){
                    t[j][i] = 1;
                }
            }
            else{
                if(S[j][i] == '.'){
                    t[j][i] = t[j-1][i] + 1;
                }
            }
        }
        int tmp = -1;
        for (int j = H-1; j >= 0; j--) {
            if(t[j][i] == -1){
                tmp = -1;
            }
            else{
                if(tmp == -1){
                    tmp = t[j][i];
                }
                else{
                    t[j][i] = tmp;
                }
            }
        }
    }
    ll cnt = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            A[i][j] = y[i][j] + t[i][j] - 1;
            if(S[i][j] == '.') cnt++;
        }
    }

    vector<ll> p(5000);
    p[0] = 1;

    vector<ll> inv(5); inv[1] = 1;
    for (int i = 2; i < 5; i++) {
        inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
    }
    for (int i = 1; i < 5000; i++) {
        p[i] = p[i-1] * inv[2] % MOD;
    }

    ll tk = 1;
    for (ll i = 0; i < cnt; i++) {
        tk = tk * 2 % MOD;
    }

    ll ans = 0; ll tmp;
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            if(A[i][j] >= 1){
                tmp = (1 - p[A[i][j]] + MOD) % MOD;
                ans = (ans + tmp) % MOD;
            }
        }
    }
    ans = ans * tk % MOD;
    printf("%lld\n", ans);
    // printf("%lld\n", tk);
    // printf("%d\n", A[0][0]);
    // printf("%d\n", A[0][1]);
    // printf("%d\n", A[0][2]);
    // printf("%d\n", y[0][0]);
    // printf("%d\n", y[0][1]);
    // printf("%d\n", y[0][2]);

    // printf("%d\n", t[0][0]);
    // printf("%d\n", t[0][1]);
    // printf("%d\n", t[0][2]);
    // printf("%d\n", t[1][0]);
    // printf("%d\n", t[1][1]);
    // printf("%d\n", t[1][2]);
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif
const long long Inf=2e18;
const int MAX_V=2e5;
long long D[MAX_V];
using P=pair<long long, int>;
using Edge=tuple<int, long long, long long>;
vector<Edge> G[MAX_V];
void dijkstra(int V, int st) {
  for(int i=0; i<V; ++i) D[i]=Inf;
  priority_queue<P,vector<P>,greater<P>> Q; Q.emplace(0,st); D[st]=0;
  while(Q.size()>0) {
    long long t; int u;
    tie(t,u)=Q.top(),Q.pop();
    if(t!=D[u]) continue;
    for(auto e : G[u]) {
      long long c,d; int v; tie(v,c,d)=e;

      auto f=[&](LL t) -> LL { return t+c+d/(t+1); };

      LL tmin=f(t),m=(LL)sqrt(d+0.5);
      FORE(d,-100,100) if(m+d>=t) {
        SMIN(tmin,f(m+d));
      }

      //dump(u,v,t,tmin);
      if(tmin<D[v]) D[v]=tmin,Q.emplace(tmin,v);
    }
  }
}
// $ cp-batch RushHour2 | diff RushHour2.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address RushHour2.cpp && ./a.out

/*

 6/6/2021

 14:48-15:48 give up

 https://atcoder.jp/contests/ABC204/editorial/224
 https://motsu-xe.hatenablog.com/entry/2021/06/06/224341

 */

int N,M;

void solve() {
  dijkstra(N,0);
  LL res=D[N-1];
  if(res>=Inf) res=-1;
  cout<<res<<endl;
}

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

  cin>>N>>M;
  REP(i,M) {
    int u,v,c,d; cin>>u>>v>>c>>d;
    --u,--v;
    G[u].emplace_back(v,c,d),G[v].emplace_back(u,c,d);
  }
  solve();

  return 0;
}

#define _DEBUG
#include "bits/stdc++.h"
//#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define PI acosl(-1)
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba emplace_back
#define pubamp(a,b) emplace_back(mp(a,b))
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	prin((N-1)/100+1);
	return 0;
}


#include <bits/stdc++.h>
#define INF LLONG_MAX/2
#define rep(i,n) for(int i = 0; i <(n) ; i++)
using namespace std;
typedef long long ll;
typedef  __int128_t LL; //入出力では使えないことに注意が必要. 計算過程で途中64bitを超える可能性があるときに使う
typedef pair<ll,ll> pll;
#define all(x) (x).begin(), (x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<ll> A;

// vector<vector<ll> > dp(N+1, vector<ll>(2, 0));
// vector<vector<vector<ll> > > dp(N, vector<vector<ll> >(M, vector<ll>(L, 0)));
int main(){
    string s;
    ll N;
    cin >> s;
    N = s.size();

    vector<ll> idx;
    idx.push_back(-1);
    ll rnum = 0;
    for(ll i=0; i<N; i++){
        if(s[i]=='R'){
            idx.push_back(i);
            rnum ++;
        }
    }
    string T = "";

    for(ll i=rnum; i>=1; i-=2){
        for(int j = idx[i]-1; j > idx[i-1]; j--){
            T += s[j];
            if(T[T.size()-1] == T[T.size()-2]){
                T = T.erase(T.size()-2);
            }
        }
    }
    // cout << T << endl;
    ll p = 0;
    if(rnum%2==1) p =1;
    for(ll i=p; i<rnum; i+=2){
        for(int j = idx[i]+1; j < idx[i+1]; j++){
            T += s[j];
            if(T[T.size()-1] == T[T.size()-2]){
                T = T.erase(T.size()-2);
            }
        }
    }
    // cout << T << endl;

    // for(int i = 1; i < idx.size(); i++){
    //     for(int j = idx[i]-1; j > idx[i-1]; j--){
    //         T += s[j];
    //         if(T.size()>=2){
    //             if(T[T.size()-1] == T[T.size()-2]){
    //                 T = T.erase(T.size()-2);
    //             }
    //         }else if(T.size()==2){
    //             if(T[T.size()-1] == T[T.size()-2]){
    //                 T = "";
    //             }
    //         }
    //         // cout << s[j] << endl;
    //     }
    // }
    for(ll i=idx[idx.size()-1]+1; i<N; i++){
        T += s[i];
        if(T[T.size()-1] == T[T.size()-2]){
                T = T.erase(T.size()-2);
            }
            // cout << T << endl;
    }

    cout << T << endl;

    // T = "";
    // for(ll i=0; i<N; i++){
    //     if(s[i]=='R'){
    //         reverse(all(T));
    //     }else{
    //         T += s[i];
    //         if(T[T.size()-1] == T[T.size()-2]){
    //             T = T.erase(T.size()-2);
    //         }
    //     }
    // }
    // cout << T << endl;
    return 0;
}

// For the purpose of C++ competitive programming only.
#include "bits/stdc++.h"
using namespace std;

#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define FORL(a, b, c) for (int(a) = (b); (a) < (c); (a)++)
#define FORR(a, b, c) for (int(a) = (b); (a) > (c); (a)--)
#define INF 1000000000000000003
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define mp make_pair
#define endl '\n'

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    deque<char> ret;
    bool rev = false;
    for (auto &c : s) {
        if (c == 'R') {
            rev ^= 1;
        } else {
            if (!rev) {
                if (ret.size() && ret.back() == c) {
                    ret.pop_back();
                } else {
                    ret.push_back(c);
                }
            } else {
                if (ret.size() && ret.front() == c) {
                    ret.pop_front();
                } else {
                    ret.push_front(c);
                }
            }
        }
    }
    if (!rev) {
        for (auto it = ret.begin(); it != ret.end(); it++) {
            cout << *it;
        }
    } else {
        for (auto it = ret.rbegin(); it != ret.rend(); it++) {
            cout << *it;
        }
    }
    cout << endl;
    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 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
    int n;
    cin>>n;
    vector<int>a,b;
    int mn=INT_MAX,mx=INT_MAX;
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        a.push_back(k);
    }
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        b.push_back(k);
    }
    int r=b[0],l=a[0];
    for (int i = 1; i < n; i++) {
        if (a[i] > r || b[i] < l) {
            cout <<"0";
            return 0;
        }
        else {
            l = max(l, a[i]);
            r = min(r, b[i]);
        }
    }
    cout<<(r-l)+1;
    return 0;
}

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

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define LL long long
#define ULL unsigned long long
#define LB lower_bound
#define MOD1 1000000007
#define MOD2 1000000009
#define int LL
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
const int maxn = 1e5 + 1;

void solve()
{
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for(auto &i: a) cin >> i;
  for(auto &i: b) cin >> i;
  if(n == 0){
      cout << 0;
      return;
  }

  int ll = a[0], ul = b[0];

  for(int i = 1; i < n; i++){
      if(a[i] > ll) ll = a[i];
      if(b[i] < ul) ul = b[i];
  }
	int zero = 0;
    int ans = max(zero,ul-ll+1);
    cout << ans;

}

signed main()
{
    static const int _ = []() {
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        return 0;
    }();
    int t = 1;
    // cin >> t;

    while (t--)
    {
        solve();
    }
    return 0;
}


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

// ---------- Debugger

#define TRACE

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(char c) {
    return '\'' + string(1, c) + '\'';
}

string to_string(char * s) {
    return to_string((string) s);
}

string to_string(const char * s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template < typename A >
string to_string(A v);

template < typename A, typename B >
string to_string(pair < A, B > p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template < typename C > struct rge { C b, e; };
template < typename C > rge<C> range(C i, C j) { return rge<C>{i, j}; }

template < typename C >
string to_string(rge<C> v) {
    bool first = true;
    string res = "[";
    for(auto it = v.b; it != v.e; it++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(*it);
    }
    res += "]";
    return res;
}

template < typename A >
string to_string(A v) {
    return to_string(range(v.begin(), v.end()));
}

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Head >
void __f(const string names, Head arg1) {
    cerr << names << " : " << to_string(arg1) << endl;
}
template < typename Head, typename...Tail >
void __f(const string names, Head arg1, Tail...args) {
    int b = 0, comma = names.size();
    for(int i=0;i<names.size();i++) {
        if(names[i] == ',' && b == 0) {
            comma = i;
            break;
        }
        if(names[i] == '(' || names[i] == '{' || names[i] == '[' || names[i] == '<') b++;
        else if(names[i] == ')' || names[i] == '}' || names[i] == ']' || names[i] == '>') b--;
    }
    // size_t comma = names.find(', ');
    cerr << names.substr(0, comma) << " : " << to_string(arg1) << " | ";
    __f(names.substr(comma + 1), args...);
}
#else
#define trace(...)
#endif

// ---------- Debugger

#define LL long long
#define FI ios_base::sync_with_stdio(false); cin.tie(NULL);
#define PREC cout << setprecision(10) << fixed;

const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 9;
const int MX = (int)1e5 + 5;

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

    int ms = a + b;

    if(ms >= 15 && b >= 8) {
        cout << 1;
    }
    else if(ms >= 10 && b >=3) {
        cout << 2;
    }
    else if(ms >= 3) {
        cout << 3;
    }
    else {
        cout << 4;
    }
    cout << endl;

    return 0;
}

#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define REP(s,n) for(int i=s;i<n;i++)
#define IOS ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define ee "\n"
using namespace std;
void slove()
{
    ll a,b;
    cin>>a>>b;
    ll ansa = 0,ansb=0;
    a=a+b;
    if(a>=15)	ansa=1;
    else if(a>=10 && a<15)	ansa=2;
    else if(a>=3 && a<10)	ansa=3;
    else	ansa=4;

    if(b>=8)	ansb=1;
    else if(b>=3 && b<8)	ansb=2;
    else if(b>=0 && b<3)	ansb=3;
    else ansb=4;
    cout<<max(ansa,ansb)<<"\n";
}
int main()
{
    IOS
    int t=1;
    //cin>>t;//For test case
    while(t--){
       slove();
    }
    return 0;
}


//This Code is written by Anubhav Srivastava(anubhavsrivastavawebpage.wordpress.com)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
//Defines
#define pb push_back
#define f(i,n) for(ll i=0;i<n;i++)
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec(x) vector<x>
#define mp make_pair
#define popc(x) __builtin_popcountll(x)
#define iter(it, s) for(auto it = s.begin(); it != s.end(); it++)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define pair(x,y) pair<ll x,ll y>
#define deb(x) cout << #x << "=" << x << "\n"
#define PI 3.1415926535897932384626
const int mod = 1000000007;

//Important Functions
//Main Function
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,v1,t,k,m,q;
    cin >>  n >> k;
    vec(ll) v(200005,0);
    int flag=0;
    f(i,n){
        cin >> t >> m >> q;
        v[t]+= q;
        v[m]-=q;
    }
    ll sum=0;
    f(i,n){
        sum+=v[i];
        if(sum>k) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";

	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (ll i = k; i < n; i++)
#define ford(i, k, n) for (ll i = k; i >= n; i--)
#define pb push_back
#define ff first
#define ss second

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <queue>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;

const ll mod = 998244353;

void imult(ll& lhs, const ll& rhs) {
	lhs = ((lhs % mod) * (rhs % mod)) % mod;
}

void iadd(ll& lhs, const ll& rhs) {
	lhs = ((lhs%mod) + (rhs%mod)) % mod;
}

void isubt(ll& lhs, const ll& rhs) {
	ll ret = (lhs - rhs) % mod;
	lhs = ret + (ret < 0 ? mod : 0);
}

ll bpw(const ll& lhs, const ll& rhs) {
	if (rhs == 0)return 1;
	ll ret = bpw(lhs, rhs >> 1);
	imult(ret, ret);
	if (rhs & 1) imult(ret, lhs);
	return ret;
}

ll inv(const ll& x) {
	return bpw(x, mod - 2);
}

ll mult(const ll& lhs, const ll& rhs) {
	return ((lhs % mod) * (rhs % mod)) % mod;
}

ll add(const ll& lhs, const ll& rhs) {
	return ((lhs%mod) + (rhs%mod)) % mod;
}

ll subt(const ll& lhs, const ll& rhs) {
	ll ret = (lhs - rhs) % mod;
	return ret + (ret < 0 ? mod : 0);
}

ll div(const ll& lhs, const ll& rhs) {
	return mult(lhs, inv(rhs));
}

const int sz = 5005, LOG = 13;
int n, m;
ll dp[LOG+1][sz];
ll chs[sz][sz];

void initchs() {
	foru(i, 0, sz)chs[i][0] = 1;
	foru(i, 1, sz) {
		foru(j, 0, i + 1) {
			if (!j)chs[i][j] = 1;
			else chs[i][j] = add(chs[i - 1][j], chs[i - 1][j - 1]);
		}
	}
}

int main() {
	fast;
	cin >> n >> m;
	initchs();
	ford(bit, LOG - 1, 0) {
		ll msk = (1 << bit);
		foru(sum, 0, m + 1) {
			for (int i = 0; 2 * i <= n && sum > 2 * i * msk; i++) {
				iadd(dp[bit][sum], mult(dp[bit + 1][sum - 2 * i * msk], chs[n][2 * i]));
			}
			if (sum % (2 * msk) == 0)
				iadd(dp[bit][sum], chs[n][sum / msk]);
		}
	}
	cout << dp[0][m] << '\n';
	return 0;
}


// #pragma GCC optimize("O2")
#include <bits/stdc++.h>
// #include "D:/program_learning/vs_code/workplace/ACMtemplate/data_struct/UnionFindSet.hpp"
using namespace std;

#define mp make_pair
#define phb push_back
#define ppb pop_back
#define eb emplace_back
#define pp pop
#define ph push
#define ff first
#define ss second
#define htl(v, n) (v)+1,(v)+1+(n), greater<decltype((v)[1])>()
#define lth(v, n) (v)+1,(v)+1+(n), less<decltype((v)[1])>()
#define Max(a, b) (((a) > (b)) ? (a) : (b))
#define Min(a, b) (((a) < (b)) ? (a) : (b))
#define isZero(x) ((x)>0?(x):-(x)<eps)
#define isEqual(x, y) (abs((x)-(y))<eps)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define iFOR(it, begin, end) for(auto it = (begin); it!=(end);it++)
#define rFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define vFOR(it, a) for(auto it = a.begin();it != a.end();it++)
#define aFOR(a, s) for(auto & (a) : (s))
#define pFOR(i, j, l, r, sit) for(int i = l,j = r; sit ;i++, j--)
#define DEBUG(x) cout << #x << " = " << (x) << endl
#define checktime() cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" ; system("pause")
#define endl '\n'
#define faster_cpp_io() std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0)
#define setp(n) fixed << setprecision(n)
#define cases(t,i) int t;cin >> t;for(int i = 1;i<=t;i++)

using pll = pair<long long,long long>;
using pii = pair<int,int>;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using vs = vector<string>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mll = map<long long, long long>;
using umll = unordered_map<long long, long long>;

constexpr ll mod = 10007;
constexpr ll inf = 0x7f7f7f7f7f7f7f7f;
constexpr ld eps = 1e-9;
constexpr ll cap = 1e5+5;
constexpr ld pi = acos(-1);

string in;ll ans;
ll dic[26];

void solve(){
    cin >> in;
    ll len = in.size();
    rFOR(i, len - 1, 0){
        if(i >= len - 2){
            dic[in[i] - 'a'] ++;
        }
        else{
            if(in[i] == in[i + 1] && in[i] != in[i + 2]){
                ans += (len - i - 1 - dic[in[i] - 'a']);
                FOR(j, 0, 25){
                    if(in[i] - 'a' == j){
                        dic[in[i] - 'a'] = len - i;
                    }else{
                        dic[j] = 0;
                    }
                }
            }
            else
                dic[in[i] - 'a'] ++ ;
        }
    }
    cout << ans << endl;
}

int main()
{
	faster_cpp_io();

    // cases(t,i)
    solve();

    // checktime();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    string s;
    cin >> s;
    int n = s.size();
    reverse(ALL(s));
    ll ans = 0;
    ll cnt[26] = {};
    char pre = '(';
    rep(i, n) {
        if (pre == s[i]) {
            rep(j, 26) {
                if (j == s[i] - 'a') continue;
                ans += cnt[j];
                cnt[s[i] - 'a'] += cnt[j];
                cnt[j] = 0;
            }
        }
        cnt[s[i] - 'a']++;
        pre = s[i];
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
inline int read() {
	int x=0,f=1;char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
using namespace std;
const int M=1e5+5;
long long res[M];
int A[M],B[M],C[M],sz[M];
int main() {
	int n=read();
	rep(i,1,n)A[i]=read();
	rep(i,1,n)B[i]=read();
	rep(i,1,n)C[i]=read(),sz[C[i]]++;
	rep(i,1,n)res[B[i]]+=sz[i];
	long long ans=0;
	rep(i,1,n)ans+=res[A[i]];
	cout<<ans;
	return 0;
}

#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define For(i,l,r) for(int i=l;i<=r;i++)
#define Pair pair<int,int>
#define F first
#define S second
#define pb push_back
#define abs(x) ((x)>0?(x):-(x))
#define MAXN 200001
int N;Pair x[MAXN],y[MAXN];
int main()
{
	cin>>N;For(i,1,N)cin>>x[i].F>>y[i].F,x[i].S=y[i].S=i;sort(x+1,x+N+1);sort(y+1,y+N+1);
	vector<int>b;b.pb(x[N].F-x[1].F),b.pb(x[N-1].F-x[1].F),b.pb(x[N].F-x[2].F),max(y[N].S,y[1].S)!=max(x[N].S,x[1].S)||min(y[N].S,y[1].S)!=min(x[N].S,x[1].S)?b.pb(y[N].F-y[1].F),0:0,b.pb(y[N-1].F-y[1].F),b.pb(y[N].F-y[2].F);
	sort(b.begin(),b.end(),greater<int>());cout<<b[1]<<endl;return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, int>;
int ctoi(char c) {
  if (c == 'R') {
    return 0;
  } else if (c == 'G') {
    return 1;
  } else{
    return 2;
  }
}
int main () {
  int N;
  cin >> N;
  P A[200020];
  int cnt[] = {0, 0, 0};
  for (int i = 0; i < N * 2; i ++) {
    ll a;
    char c;
    cin >> a >> c;
    int b = ctoi(c);
    cnt[b] ++;
    A[i] = make_pair(a, b);
  }
  sort(A, A + (N * 2));
  if ((cnt[0] % 2 + cnt[1] % 2 + cnt[2] % 2) == 0) {
    cout << 0 << endl;
    return 0;
  }
  int a = 0;
  while (cnt[a] % 2 == 0) a ++;
  int b = a + 1;
  while (cnt[b] % 2 == 0) b ++;
  ll inf = 1e8 + 8;
  inf = inf * inf;
  ll ans = inf;
  //cout << a << ' ' << b << endl;
  ll mim[] = {-inf, -inf, -inf};
  int re = 3 - a - b;
  ll ans1 = inf;
  ll ans2 = inf;
  for (int i = 0; i < N * 2; i ++) {
    ll p;
    int q;
    tie(p, q) = A[i];
    mim[q] = p;
    if (q == re) {
      ans1 = min(ans1, p - mim[a]);
      ans2 = min(ans2, p - mim[b]);
    } else if (q == a) {
      ans1 = min(ans1, p - mim[re]);
      ans = min(ans, p - mim[b]);
    } else {
      ans2 = min(ans2, p - mim[re]);
      ans = min(ans, p - mim[a]);
    }
  }
  ans = min(ans, ans1 + ans2);
  cout << ans << endl;
}

#define _USE_MATH_DEFINES
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cassert>
#include <numeric>
#include <unordered_map>
#include <queue>
#include <math.h>
#include <climits>
#include <set>
#include <map>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
//template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;

#define FOR(i, a, b) for(ll i=(a); i<(b);i++)
#define REP(i, n) for(ll i=0; i<(n);i++)
#define ROF(i, a, b) for(ll i=(b-1); i>=(a);i--)
#define PER(i, n) for(ll i=n-1; i>=0;i--)
#define REPREP(i,j,a,b) for(ll i=0;i<a;i++)for(ll j=0;j<b;j++)
#define VV(type) vector< vector<type> >
#define VV2(type,n,m,val) vector< vector<type> > val;val.resize(n);for(ll i;i<n;i++)val[i].resize(m)
#define vec(type) vector<type>
#define VEC(type,n,val) vector<type> val;val.resize(n)
#define VL vector<ll>
#define VVL vector< vector<ll> >
#define SZ size()
#define all(i) begin(i),end(i)
#define SORT(i) sort(all(i))
#define BITI(i) (1<<i)
#define BITSET(x,i) x | (1<<i)
#define BITCUT(x,i) x & ~(1<<i)
#define EXISTBIT(x,i) ((x>>i) & 1 != 0)
#define ALLBIT(n) (1<<n-1)

class UndirectedGraph {
public:
  struct edge { ll to,cost; };  // 行先,容量,逆容量,コスト

  UndirectedGraph(ll n) {
    edges.resize(n);
  }
  void addEdge(ll from, ll to, ll cost) {
    edge eF = { to,cost };
    edges[from].push_back(eF);
    edge eT = { from,cost };
    edges[to].push_back(eT);
  }

  void FindConnect(ll v, vector<bool>& out) {
    out.assign(edges.size(), false);
    vector<ll> stack;
    stack.push_back(v);
    out[v] = true;
    while (!stack.empty()) {
      v = stack.back(); stack.pop_back();
      for (int i = 0; i < edges[v].size(); i++) {
        ll t = edges[v][i].to;
        if (!out[t]) {
          out[t] = true;
          stack.push_back(t);
        }
      }
    }
  }
  vector<vector<edge>> edges;
};

int main() {
  ll n, m;
  cin >> n >> m;
  VL a(m), b(m), c(m);
  UndirectedGraph g(n);

  REP(i, m) {
    char cc;
    cin >> a[i] >> b[i] >> cc;
    a[i]--; b[i]--;
    c[i] = cc - 'a';
    g.addEdge(a[i], b[i], c[i]);
  }

  queue<tuple<ll, ll, ll>> que;
  vector<vector<bool>> used(n);
  REP(i, n) {
    used[i].assign(n, false);
  }
  que.push({ 0,0,n - 1 });
  used[0][n - 1] = true;
  used[n - 1][0] = true;

  ll find = -1;
  while (!que.empty()) {
    auto [dist, l, r] = que.front();
    que.pop();
    if (find != -1 && find < dist) {
      cout << find * 2 + 1;
      return 0;
    }
    if (l == r) {
      cout << dist * 2;
      return 0;
    }
    REP(i, g.edges[l].size()) {
      REP(j, g.edges[r].size()) {
        if (g.edges[l][i].cost == g.edges[r][j].cost) {
          if (g.edges[l][i].to == r && g.edges[r][j].to == l) {
            find = dist;
            continue;
          }
          if (used[g.edges[l][i].to][g.edges[r][j].to])
            continue;
          que.push({ dist + 1,g.edges[l][i].to ,g.edges[r][j].to });
          used[g.edges[l][i].to][g.edges[r][j].to] = true;
          used[g.edges[r][j].to][g.edges[l][i].to] = true;
        }
      }
    }
  }
  if (find != -1) {
    cout << find * 2 + 1;
    return 0;
  }
  cout << -1;
}


#ifdef _DEBUG
#include "../../../library/src/debug_template.hpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <variant>

using namespace std;
using lint = long long;
constexpr int INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
    init() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} init_;

template<class T>
class FenwickTree {
public:
    explicit FenwickTree(int sz, T &&x = T{}) : n(sz), bit(n + 1) {
        for (int i = 0; i < n; i++) add(i, x);
    }

    void add(int k, const T &x) { for (; k < n; k |= k + 1) bit[k] += x; }
    void set(int k, const T &x) { add(k, x - sum(k, k + 1)); }

    [[nodiscard]] T sum(int k) const {
        T res = 0;
        for (k--; k >= 0; k = (k & (k + 1)) - 1) res += bit[k];
        return res;
    }
    [[nodiscard]] T sum(int l, int r) const { return sum(r) - sum(l); }

private:
    int n;
    vector<T> bit;
};

int main() {

    string S;
    cin >> S;
    const int N = S.size();

    vector<FenwickTree<int>> alpha(26, FenwickTree<int>(S.size()));
    for (int i = 0; i < N; i++) {
        alpha[S[i] - 'a'].add(i, 1);
    }

    lint ans = 0;
    char prev = '*';
    // [last.index, N) = last.char
    pair<int, char> last = {N, '*'};
    for (int i = N - 1; i >= 0; prev = S[i], i--) {
        if (prev == S[i]) {
            const auto[li, lc] = last;
            ans += N - (i + 2) - (lc == prev) * (N - li) - alpha[S[i] - 'a'].sum(i + 2, li);
            last = {i, S[i]};
        }
    }

    cout << ans << '\n';

    return 0;
}

// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string s;
    cin >> s;
    ll n = s.size(), c = 0;
    vector<ll> f(26);
    for (ll i = n - 1; i; i--)
    {
        ll x = s[i] - 'a';
        if (s[i] == s[i - 1])
        {
            c += n - 1 - i - f[x];
            for (ll i = 0; i < 26; i++)
                f[i] = 0;
            f[x] = n - 1 - i;
        }
        f[x]++;
    }
    cout << c;
}


// Problem: B - Products of Min-Max
// Contest: AtCoder - AtCoder Regular Contest 116
// URL: https://atcoder.jp/contests/arc116/tasks/arc116_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_ll_distribution<ll>(x, y)(rng)

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

const ll max_n = 1e5 + 9;
const ll mod = 998244353;
const ll inf = 1e9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
void solve(){
	ll n;
	cin >> n;

	vector<ll> a(n);
	for(ll &it : a) {
		cin >> it;
	}

	sort(all(a));

	ll sum = 0;

	for(ll i = 0 ; i < n ; i++) {
		sum += (a[i]*a[i])%mod;
		sum %= mod;
	}

	// for(ll  i = 0 ; i < n ; i++) {
		// for(ll j = i ; j >= 0 ; j--) {
			// sum += (a[i] * a[j] * power(2 , max(0ll , i - j - 1))) % mod;
			// sum %= mod;
		// }
	// }

	ll b[n];

	for(ll i = n - 2 , j = 0 ; i >= 0 ; j++ , i--) {
		b[i] = (a[i]*power(2,j))%mod;
	}

	ll suff[n];
	suff[n-1] = a[n-1]%mod;
	for(ll i = n-2 ; i >= 0 ; i--) {
		suff[i] = (suff[i+1] + b[i]) % mod;
	}

	for(ll i = n-1 , j = 0 ; i >= 0 ; i-- , j++) {
		assert(suff[0]-suff[i]+mod >= 0);
		assert(power(power(2,j),mod-2) < mod);
		assert(((suff[0]-suff[i]+mod)%mod) < mod);
		sum += ((a[i]%mod) * ((((suff[0]-suff[i]+mod)%mod)*power(power(2,j),mod-2))%mod))%mod;
		sum %= mod;
	}

	cout << sum << "\n";
}
signed main(){
	ll t = 1;
	// cin >> t;
	for(ll i = 1 ; i <= t ; i++){
		solve();
	}
}

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

#define ll long long
#define fo(i,x,y) for(ll i=x;i<=y;i++)

using namespace std;
const ll mod=998244353;
const int N=2e5+10;
ll n,m,i,j,k,tot,ans,s,t,x,y,z,er;
ll a[N];
ll e[N];

void read(ll &a) {
	a=0; char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') {a=a*10-48+c; c=getchar();}
	return;
}

ll ksm(ll i,ll j) {
	ll re=1;
	while (j>0) {
		if (j&1) re=re*i%mod;
		j/=2; i=i*i%mod;
	}
	return re;
}

int main() {
	e[0]=1; fo(i,1,N-1) e[i]=e[i-1]*2%mod;

	read(n);
	fo(i,1,n) read(a[i]);
	sort(a+1,a+n+1);

	s=0;
	fo(i,1,n) s=(s+a[i]*e[i-1])%mod;

	er=ksm(2,mod-2);
	ans=0;
	fo(i,1,n) {
		s=(s-a[i]+mod)*er%mod;

		ans=(ans+a[i]*s)%mod;
		ans=(ans+a[i]*a[i])%mod;
	}

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


#include <iostream>

using namespace std;

int main() {
    int a, b, a_sum = 0, b_sum = 0;

    cin >> a >> b;

    for (int i = 0; i < 3; i++){
        a_sum += (a % 10);
        a = (a / 10);

        b_sum += (b % 10);
        b = (b / 10);
    }

    int result = a_sum > b_sum ? a_sum : b_sum;
    cout << result;
}

#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T x=0,f=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=4e5+9;
	map<char,int> mp;
	int C[4][4];
	inline int Lucas(int n,int m){
		if(n<3 && m<3) return C[n][m];
		return Lucas(n/3,m/3)*Lucas(n%3,m%3)%3;
	}
	int n;char s[N];
	int main(){
		n=read<int>(),scanf("%s",s+1);
		for(int i=0;i<4;i++){
			C[i][0]=1;
			for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%3;
		}

		mp['W']=0,mp['R']=1,mp['B']=2;
		int ans=0;
		for(int i=1;i<=n;i++) ans=(Lucas(n-1,i-1)*mp[s[i]]+ans)%3;

	//	cout<<ans<<endl;
		if(!ans) puts("W");
		else{
			if(~n&1) ans^=3;
			if(ans==1) puts("R");
			else puts("B");
		}
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}


#include <functional>
#include <tuple>
#include <optional>
#include <variant>
#include <string>
#include <string_view>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <valarray>
#include <random>
#include <numeric>
#include <iostream>
#include <cassert>
#include <sstream>

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename K> using hset = gp_hash_table<K, null_type>;
template <typename K, typename V> using hmap = gp_hash_table<K, V>;

using namespace std;

using ll = long long;

using vi = vector<int>;
using vvi = vector<vector<int>>;

template <typename T>
using minq = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxq = priority_queue<T>;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vi a(n + 1);
    for (int i = 0; i < n + 1; ++i) {
        cin >> a[i];
    }

    int k = 100000000;
    for (int i = 0; i < n; ++i) {
        k = min(k, abs(a[i] - a[i + 1]));
    }

    vvi res(k);
    for (int i = 0; i < n + 1; ++i) {
        for (int j = 0; j < k; ++j) {
            res[j].push_back((a[i] + j) / k);
        }
    }

    cout << k << '\n';
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < n + 1; ++j) {
            cout << res[i][j] << ' ';
        }
        cout << '\n';
    }

}

//#define NDEBUG

#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

  using i32 = std::int32_t;
  using i64 = std::int64_t;
  using u32 = std::uint32_t;
  using u64 = std::uint64_t;
  using isize = std::ptrdiff_t;
  using usize = std::size_t;

  struct rep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { ++i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  struct revrep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { --i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  template <class T> auto md_vec(const usize n, const T& value) {
    return std::vector<T>(n, value);
  }
  template <class... Args> auto md_vec(const usize n, Args... args) {
    return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
  }
  template <class T> constexpr T difference(const T& a, const T& b) noexcept {
    return a < b ? b - a : a - b;
  }
  template <class T> void chmin(T& a, const T& b) noexcept {
    if (b < a)
      a = b;
  }
  template <class T> void chmax(T& a, const T& b) noexcept {
    if (a < b)
      a = b;
  }
  template <class F> class rec_lambda {
    F f;

  public:
    rec_lambda(F&& f) : f(std::move(f)) {}
    template <class... Args> auto operator()(Args &&... args) const {
      return f(*this, std::forward<Args>(args)...);
    }
  };
  template <class F> auto make_rec(F&& f) { return rec_lambda<F>(std::move(f)); }
  template <class T> T scan() {
    T ret;
    std::cin >> ret;
    return ret;
  }
  constexpr char eoln = '\n';
  template <class T> T ceildiv(const T& l, const T& r) {
    return l / r + (l % r != 0 ? 1 : 0);
  }

} // namespace n91

namespace n91 {

  void main_() {
    /*
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    //*/

    const usize n = scan<usize>();
    scan<std::string>();
    std::vector<usize> a(n + 1);
    for (auto& e : a) {
      std::cin >> e;
    }
    usize k = 100000;
    for (const usize i : rep(0, n)) {
      chmin(k, difference(a[i], a[i + 1]));
    }

    std::cout << k << eoln;
    for (const usize j : rep(0, k)) {
      for (const auto& e : a) {
        std::cout << (e + j) / k << " ";
      }
      std::cout << eoln;
    }
  }

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll k,ra[500005],ans;
int main(){
    ios::sync_with_stdio(false);
    cin >> k;

    for(int i=1; i<=k; i++){
        ra[i] = ra[i - 1];
        for(int j=1; j*j<=i; j++){
            if(i % j == 0){
                if(j * j == i)ra[i]++;
                else ra[i] += 2;
            }
        }
    }

    for(int i=1; i<=k; i++){
        ans += ra[k / i];
    }

    cout << ans << '\n';

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define full(a) memset(a, 0x3f, sizeof(a))
#define mset(a, b) memset(a, b, sizeof(a))
#define cpy(a,b) memcpy(a, b, sizeof(a))
#define fornext(x, i) for(signed i = hd[x], y = ver[i]; i; i = nxt[i], y = ver[i])
#define Rep(i, a, b) for(signed i = (signed)(a); i <= (signed)(b); ++i)
#define dRep(i, a, b) for(signed i = (signed)(a); i >= (signed)(b); --i)
#define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define pb push_back
#define It iterator
#define endl '\n'
#define un unsigned
#define int ll
#define ll long long
#define db double
#define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
#define dbg cout<<"c "
#define dbug(x) cerr << #x " = " << (x) << endl
template<typename _T> inline void _prt(_T _d) { cerr << _d << ' '; }
template <typename _T, typename ...Args> inline void _prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...); }
template <typename _T, typename ...Args> inline void prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...), cerr<<endl; }
template <typename _T, typename ...Args> inline void prt(_T _d) { cerr << _d <<endl; }
template<typename _T> inline void rd(_T &_d) {
	signed _f; char _c; _f = 1,_d = 0; while (_c = getchar(), !isdigit(_c)) if(_c=='-') _f=-1;
	while (isdigit(_c)) _d = _d * 10 + _c - '0', _c = getchar();
	_d=_f*_d;
}
template <typename _T, typename ...Args> inline void rd(_T &_d, Args &..._a) { rd(_d); rd(_a...); }

const int N=2e5+5;
int f[N];

signed main() {
	int n,ans=0;
	rd(n);
	Rep(i,1,n) Rep(j,1,n/i) f[i*j]++;
	Rep(i,1,n) Rep(j,1,n/i) ans+=f[j];
	cout<<ans<<endl;
	return 0;
}