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

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

int N;
int A[3010], B[3010], C[3010], D[3010], E[3010];
bool dp[3010][100][10];

bool unit(int mid)
{
    memset(dp, false, sizeof(dp));

    rep(i, N)
    {
        int bit = 0;
        bit |= (1LL << 0) * (A[i] >= mid);
        bit |= (1LL << 1) * (B[i] >= mid);
        bit |= (1LL << 2) * (C[i] >= mid);
        bit |= (1LL << 3) * (D[i] >= mid);
        bit |= (1LL << 4) * (E[i] >= mid);
        dp[0][0][0] = true;
        rep(j, (1LL << 5))rep(k, 3 + 1)
        {
            dp[i + 1][j][k] |= dp[i][j][k];
            dp[i + 1][j | bit][k + 1] |= dp[i][j][k];
        }
    }

    rep(i, 4)if(dp[N][(1LL << 5) - 1][i])return true;
    return false;
}

signed main()
{
    cin >> N;
    rep(i, N)cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];

    int l = 0, r = 1e10;
    rep(_, 100)
    {
        int mid = (l + r) / 2;
        if(unit(mid))l = mid;
        else r = mid;
    }

    cout << l << endl;

    return 0;
}

#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<cstring>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<deque>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<string>
#include<sstream>
#include<climits>
#include<chrono>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<ctype.h>
#include<cassert>
#include<numeric>
#include<functional>
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef long double ldb; typedef double db;typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef pair<ll, int> pli;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Debug cout<<"\nRight Here\n";
const double Pi = acos(-1.0); constexpr int inf = 1 << 29, Mod = 1e9 + 7, N = 1e5 + 3; constexpr ll INF = 1ll << 60;
ll qpow(ll a, ll b, ll mod = Mod, ll ans = 1) {
	for (; b; b >>= 1, a = (a * a + mod) % mod)if (b & 1)ans = (ans * a + mod) % mod;
	return ans;
}
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }; ll lcm(ll a, ll b) { return a * b / (gcd(a, b)); }
pii EXgcd(int x, int y) {        //return.first ny
	if (!y) { return { 1,0 }; }pii a = EXgcd(y, (x + y) % y);
	return { a.second, a.first - a.second * (x / y) };
}
inline bool Ezisprime(const int n) {
	if (n <= 1)return 0; if (n <= 3)return 1;
	vector<int> ezp{ 5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
	for (int i = 0; i < ezp.size(); i++)if (n == ezp[i])return 1;
	for (int i = 2; i <= sqrt(n); i++)if (n % i == 0)return 0;
	return 1;
}
pll Fib(ll n) {
	if (n == 0) return { 0, 1 };
	auto p = Fib(n >> 1);
	ll c = p.first * ((p.second) << 1 - p.first), d = p.first * p.first + p.second * p.second;
	if (n & 1)return { d, c + d }; else return { c, d };
}
inline vector<ll> EuSieve(const ll& n) {
	vector<ll> prime; vector<bool>is_prime(n + 1, 1);
	for (ll i = 2; i <= n; ++i) {
		if (is_prime[i])prime.emplace_back(i);
		for (auto& p : prime) {
			if (i * p > n)break;
			is_prime[i * p] = 0;
			if (i % p == 0)break;
		}
	}
	return prime;
}
inline ll Digsum(ll n, ll ans = 0) {
	for (; n; n /= 10)ans += n % 10;
	return ans;
}
inline void modize(ll& n, const ll add, const ll mod = Mod) { n = ((n + add) % mod + mod) % mod; }
inline bool cmp(const pii a, const pii b) {  //default more and more larger
	return a.second < b.second;
}
//partial_sum(begin,end,place,minus<int>()) adjacent_differece(begin,end,place)
//count(begin(),end(),char=='x') count_if(begin(),end(),boolcmp) vector<int> p(n);iota(p.begin(), p.end(), 0);
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Code follows ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\

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

	int n; cin >> n;
	vector<vector<ll>>a(n, vector<ll>(5));
	for (auto& i : a)for (auto& j : i)cin >> j;
	int l = 0, r = 1e9 + 1;
	auto check = [&](int x)->bool
	{
		set<int>s;
		for (auto i : a)
		{
			int bit = 0;
			for (auto j : i)
			{
				bit <<= 1;
				bit |= j >= x;
			}
			s.insert(bit);
		}
		for (auto i : s)for (auto j : s)for (auto k : s)if ((i | j | k) == 31)return 1;
		return 0;
	};
	while (r - l > 1)
	{
		int mid = (l + r) >> 1;
		(check(mid) ? l : r )= mid;
//		cout << "l= " << l << " r= " << r << '\n';
	}
	cout << l << '\n';

}
/*

*/


#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define MAXN 1000005
#define lowbit(x) (x&-x)
#define reg register
#define mp make_pair
#define fir first
#define sec second
typedef long long LL;
typedef unsigned long long uLL;
const int INF=0x7f7f7f7f;
const int jzm=233;
const int mo=1e9+7;
const int zero=200;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
LL k,n,dp[5][MAXN*3];
signed main(){
	read(n);read(k);
	for(LL i=1;i<=n;i++)dp[1][i]=1LL,dp[1][i]+=dp[1][i-1];
	for(LL i=n+1;i<=3*n;i++)dp[1][i]=dp[1][n];
	for(LL i=2;i<=2*n;i++)dp[2][i]+=dp[1][i-1]-dp[1][max(0LL,i-n-1LL)],dp[2][i]+=dp[2][i-1];
	for(LL i=2*n+1;i<=3*n;i++)dp[2][i]=dp[2][2*n];
	for(LL i=3;i<=3*n;i++)dp[3][i]+=dp[2][i-1]-dp[2][max(0LL,i-n-1LL)];
	for(LL i=3;i<=3*n;i++){
		//printf("%lld %lld %lld %lld\n",k,dp[3][i],dp[2][i]-dp[2][i-1],dp[1][i]-dp[1][i-1]);
		if(k<=dp[3][i]){
			for(LL j=1;j<=n;j++){
				if(i-j>2*n)continue;
				LL down=max(1LL,i-j-n),up=min(n,i-j-1);
				//printf("%lld:%lld %lld\n",j,up,down);
				if(k>up-down+1LL)k-=(up-down+1LL);
				else{
					printf("%lld %lld %lld\n",j,down+k-1LL,i-j-down-k+1LL);
					return 0;
				}
			}
		}
		else k-=dp[3][i];
	}
	return 0;
}
/*
3:1
4:3
5:3
6:1
*/

#include <bits/stdc++.h>
using namespace std;
int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; }
int __fastio = fastio();

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...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long ll;
typedef pair<ll, ll> ii;
#define fi first
#define se second
#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int main(){
    ll n;
    cin >> n;
    ll res = 1;
    set<ll> can;
    // sqrtN
    for(ll i=2;i*i<=n;i++) {
        if(can.count(i)) continue;
        ll cur = i;
        // logN
        while(cur*i <= n) {
            cur *= i;
            can.insert(cur);
        }
    }
    cout << n - can.size() << "\n";
}


#include <bits/stdc++.h>
#define ll int
const ll maxx=1e9;
using namespace std;

ll func(string s[],vector<vector<ll>> &dp,ll x,ll y,ll h,ll w){
    if(dp[x][y]!=maxx)
        return dp[x][y];
    if((x+y)%2==1){
        ll val=maxx;
        if(x<h-1)
            val=min(val,func(s,dp,x+1,y,h,w));
        if(y<w-1)
            val=min(val,func(s,dp,x,y+1,h,w));
        if(x==h-1 and y==w-1)
            val=0;
        if(x!=0 or y!=0){
            if(s[x][y]=='-')
               val-=1;
            else
                val+=1;
        }
        dp[x][y]=val;
    }
    else{
        ll val=-maxx;
        if(x<h-1)
            val=max(val,func(s,dp,x+1,y,h,w));
        if(y<w-1)
            val=max(val,func(s,dp,x,y+1,h,w));
        if(x==h-1 and y==w-1)
            val=0;
        if(x!=0 or y!=0){
            if(s[x][y]=='-')
               val+=1;
            else
                val-=1;
        }
        dp[x][y]=val;
    }
    return dp[x][y];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int h,w;
	cin>>h>>w;
	string s[h];
	for(int i=0;i<h;i++)
		cin>>s[i];
    vector<vector<ll>> dp;
    for(ll i=0;i<h;i++){
        vector<ll> v;
        for(ll j=0;j<w;j++)
            v.push_back(maxx);
        dp.push_back(v);
    }
    ll val=func(s,dp,0,0,h,w);
    if(val==0)
        cout<<"Draw";
    else if(val>0)
        cout<<"Takahashi";
    else
        cout<<"Aoki";
	return 0;
}

//我的代码：
#include<bits/stdc++.h>
#define N 2005
using namespace std;
int n,m,c[N][N],t[N][N],a[N][N],ted[N][N],aed[N][N];
//ted/aed[i][j]分别表示t/a[i][j]是否已经计算完毕
char ch;
string s;
int A(int x,int y);
int T(int x,int y);
int main(){
	cin>>n>>m,getline(cin,s);//读入
	for(int i=1;i<=n;getline(cin,s),i++)
		for(int j=1;j<=m;j++)c[i][j]=(ch=getchar()=='+')*2-1;
	ted[n][m]=aed[n][m]=1;//初始化
	if(T(1,1)<A(1,1))cout<<"Aoki"<<endl;
	else if(T(1,1)>A(1,1))cout<<"Takahashi"<<endl;
	else cout<<"Draw"<<endl;
//	for(int i=1;i<=n;cout<<endl,i++)
//		for(int j=1;j<=m;j++)cout<<T(i,j)-A(i,j)<<" ";//调试语句
	return 0;
}
int T(int x,int y){//A的最优化
	if(ted[x][y])return t[x][y];//记忆化
	ted[x][y]=1;
	if((x+y)&1)return A(x,y),t[x][y];//无操作权，交给对方转移
	if(x==n)return aed[x][y]=1,a[x][y]=A(x,y+1),t[x][y]=T(x,y+1)+c[x][y+1];//只能向右走
	if(y==m)return aed[x][y]=1,a[x][y]=A(x+1,y),t[x][y]=T(x+1,y)+c[x+1][y];//只能向下走
	if(T(x,y+1)+c[x][y+1]-A(x,y+1)>T(x+1,y)+c[x+1][y]-A(x+1,y))//决策下和右哪个更优
		return aed[x][y]=1,a[x][y]=A(x,y+1),t[x][y]=T(x,y+1)+c[x][y+1];
	else return aed[x][y]=1,a[x][y]=A(x+1,y),t[x][y]=T(x+1,y)+c[x+1][y];
}
int A(int x,int y){//B的最优化
	if(aed[x][y])return a[x][y];//记忆化
	aed[x][y]=1;
	if(!((x+y)&1))return T(x,y),a[x][y];//无操作权，交给对方转移
	if(x==n)return ted[x][y]=1,t[x][y]=T(x,y+1),a[x][y]=A(x,y+1)+c[x][y+1];//只能向右走
	if(y==m)return ted[x][y]=1,t[x][y]=T(x+1,y),a[x][y]=A(x+1,y)+c[x+1][y];//只能向下走
	if(A(x,y+1)+c[x][y+1]-T(x,y+1)>A(x+1,y)+c[x+1][y]-T(x+1,y))//决策下和右哪个更优
		return ted[x][y]=1,a[x][y]=A(x,y+1)+c[x][y+1],t[x][y]=T(x,y+1);
	else return ted[x][y]=1,a[x][y]=A(x+1,y)+c[x+1][y],t[x][y]=T(x+1,y);
}


//112c.cpp created at 02/13/21 03:48:55

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "qpwoeirut/debug.h"
#else
#define debug
#define debug1
#define debug2
#define debug3
#endif

#define PB push_back
#define INS insert

#define FI first
#define SE second
#define sz(obj) ((int)(obj.size()))
#define all(obj) begin(obj), end(obj)

#define LB lower_bound
#define UB upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef unsigned long long ull;
typedef long double dbl;
typedef pair<int,bool> pib;
typedef pair<ll,bool> plb;
typedef pair<dbl,dbl> pdd;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef map<char,int> mci;
typedef map<string,int> msi;
typedef map<string,string> mss;

ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}

template <class T1,class T2> struct cmpf {
	bool rev;
	inline bool operator()(const pair<T1,T2>& a, const pair<T1,T2>& b) const {return (a.first<b.first)^rev;}
	cmpf(bool b=false) {rev=b;}
};
template <class T1,class T2> struct cmps {
	bool rev;
	inline bool operator()(const pair<T1,T2>& a, const pair<T1,T2>& b) const {return (a.second<b.second)^rev;}
	cmps(bool b=false) {rev=b;}
};

ll binpow(ll x, ll p, const ll& mod) {assert(mod>0);
    ll ret = 1;
    for(; p>0; p>>=1, x = x*x % mod) if(p & 1) ret = ret*x % mod;
    return ret;
}

template <class T> bool chmn(T& a, const T& b) {return (greater<T>()(a, b) ? (a=b, true) : false);}
template <class T> bool chmx(T& a, const T& b) {return (less<T>()(a, b) ? (a=b, true) : false);}

void setIO(const string& filename = "") {
    if (filename.size() > 0) {
        freopen((filename + ".in").c_str(), "r", stdin);
        freopen((filename + ".out").c_str(), "w", stdout);
    }
	cin.tie(0)->sync_with_stdio(0);
}

int chr[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int chc[8] = {0, 1, 0, -1, -1, 1, -1, 1};

const ll MOD = 1e9+7; //998244353 //1e9+9 //1e9+21 // 1e9+33;
const int INIT = 1001001001;
const int MN = 1001001;
const ll INF = 2e18 + 1;

ll N, M, K, Q;
ll A[MN]; //, B[MN];
//ll G[MN][MN];
set<ll> adj[MN];

void process(const int u) {
    A[u] = 1;
    for (const int v: adj[u]) {
        process(v);
        A[u] += A[v];
    }
}

int dp[MN];
void dfs(const int u) {
    dp[u] = 1;
    if (adj[u].empty()) {
        return;
    }

    multiset<pii> keep, change;
    for (const int v: adj[u]) {
        dfs(v);
        const int taker = dp[v];
        const int mover = A[v] - dp[v];
        if (A[v] & 1) {
            change.emplace(taker - mover, v);
        } else {
            keep.emplace(taker - mover, v);
        }
    }

    while (keep.size() > 0 && keep.begin()->FI <= 0) {
        dp[u] += (A[keep.begin()->SE] + keep.begin()->FI) >> 1;
        keep.erase(keep.begin());
    }

    bool flip = false;
    while (change.size() > 0) {
        if (!flip) {
            dp[u] += (A[change.begin()->SE] + change.begin()->FI) >> 1;
        } else {
            dp[u] += A[change.begin()->SE] - ((A[change.begin()->SE] + change.begin()->FI) >> 1);
        }
        change.erase(change.begin());
        flip = !flip;
    }

    while (keep.size() > 0) {
        if (!flip) {
            dp[u] += (A[keep.begin()->SE] + keep.begin()->FI) >> 1;
        } else {
            dp[u] += A[keep.begin()->SE] - ((A[keep.begin()->SE] + keep.begin()->FI) >> 1);
        }
        keep.erase(keep.begin());
    }
}

void solve(int testcase) {
    cin >> N;
    for (int i=1; i<N; ++i) {
        int p;
        cin >> p;
        --p;
        adj[p].insert(i);
    }

    process(0);
    dfs(0);

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

int main() {
    setIO();

    ll T = 1;

    for (int t=1; t<=T; ++t) {
        solve(t);
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

typedef unsigned int unt;

std::vector<std::vector<unt>> adj;

int solve(unt v) {
  std::vector<int> odd_difs;
  int pos_even_dif_sum = 0, neg_even_dif_sum = 0;
  for (auto u : adj[v]) {
    int dif = solve(u);
    if (dif % 2) { odd_difs.push_back(dif); }
    else if (dif > 0) { pos_even_dif_sum += dif; }
	else if (dif < 0) { neg_even_dif_sum += dif; }
  }
  std::sort(odd_difs.begin(), odd_difs.end());
  bool par = true;
  int a = 0;
  for (auto d : odd_difs) {
    if (par) { a += d; }
    else { a -= d; }
    par = !par;
  }
  return 1 + neg_even_dif_sum + a + (par ? pos_even_dif_sum : -pos_even_dif_sum);
}

int main() {
  unt n;
  std::cin >> n;
  adj.resize(n);
  for (unt i = 1u; i < n; i++) {
    unt c;
    std::cin >> c;
    adj[c-1u].push_back(i);
  }
  int dif = solve(0);
  std::cout << (int(n) + dif) / 2 << '\n';
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <string>
#include <list>
#include <map>
#include <unordered_map>
using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    int n;

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
        n=N;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        n-=1;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int groupnumber(void){
        return n;
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

/*
    sort(b.begin(),b.end(),[](const vector<int> &alpha,const vector<int> &beta){return alpha[0] < beta[0];});
    第一成分で昇順
    sort(r.begin(),r.end(),[](const vector<int> &alpha,const vector<int> &beta){return alpha[1] > beta[1];});
    第二成分で降順

    setprecision(15)
    double型の表示桁数
*/

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

long long int gcd(long long int a, long long int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

long long int lcm(long long int a, long long int b)
{
    return a * b / gcd(a, b);
}

int main(){
    long long int N,M,ans;
    cin>>N>>M;
    ans=modpow(10LL,N,M*M);
    ans=ans/M;
    cout<<ans%M<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
#define lin(x) ll x; cin>>x;
#define stin(x) string x; cin>>x;
#define yn(x)  if(x) {  cout<<"Yes"<<endl;   }    else {    cout<<"No"<<endl;   }
#define YN(x)  if(x) {  cout<<"YES"<<endl;   }    else {    cout<<"NO"<<endl;   }
#define co(x) cout<<x<<endl;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll mod=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
    return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
    return ((a > b) ? (a = b, true) : (false));
}
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}

int main() {
lin(N);
  lin(M);
  ll x=powmod(10,N,M*M);
  ll y=(x/M)%M;
  co(y);
}


#include <bits/stdc++.h>

#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vpii = vector<pair<ll,ll>>;

vvi matrix_product(vvi a,vvi b) {
    vvi matrix(3,vi(3,0));
    REP(i,3)REP(j,3)REP(k,3) {
        matrix[i][j] += a[i][k] * b[k][j];
    }
    return matrix;
}

void solve() {

     const auto op1 = []()-> vvi {
        vvi matrix(3,vi(3,0));
        matrix[0][1] = 1;
        matrix[1][0] = -1;
        matrix[2][2] = 1;
        return matrix;
    }();

    const auto op2 = []()-> vvi {
        vvi matrix(3,vi(3,0));
        matrix[0][1] = -1;
        matrix[1][0] = 1;
        matrix[2][2] = 1;
        return matrix;
    }();

    const auto gen_op4 = [](int p)-> vvi {
        vvi matrix(3,vi(3,0));
        matrix[0][0] = 1;
        matrix[1][1] = -1;
        matrix[1][2] = 2 * p;
        matrix[2][2] = 1;
        return matrix;
    };

    const auto gen_op3 = [](int p)-> vvi {
        vvi matrix(3,vi(3,0));
        matrix[0][0] = -1;
        matrix[0][2] = 2 * p;
        matrix[1][1] = 1;
        matrix[2][2] = 1;
        return matrix;
    };

    int N; cin >> N;
    vpii pieces(N);
    REP(i,N) {
        int X,Y; cin >> X >> Y;
        pieces[i] = make_pair(X,Y);
    }

    vvi matrix(3,vi(3,0));

    // 正則行列にする。
    REP(i,3) matrix[i][i] = 1;

    int M; cin >> M;

    // x回目の累積積
    vvvi states(M+1,vvi(3,vi(3,0)));
    states[0] = matrix;

    FOR(i,1,M+1) {
        int op; cin >> op;
        if (op == 1) states[i] = matrix_product(op1,states[i-1]);
        else if (op == 2) states[i] = matrix_product(op2,states[i-1]);
        else if (op == 3) {
            int p; cin >> p;
            states[i] = matrix_product(gen_op3(p),states[i-1]);
        }
        else if (op == 4) {
            int p; cin >> p;
            states[i] = matrix_product(gen_op4(p),states[i-1]);
        }
        else assert(false);
    }

    int Q; cin >> Q;
    REP(_,Q) {
        int A,B; cin >> A >> B; --B;

        vvi piece_matrix(3,vi(3,0));
        piece_matrix[0][0] = pieces[B].first;
        piece_matrix[1][0] = pieces[B].second;
        piece_matrix[2][0] = 1;

        auto ans = matrix_product(states[A],piece_matrix);
        cout << ans[0][0] << " " << ans[1][0] << endl;
    }
}

int main() {
    solve();
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <string>

using namespace std;

typedef long long int ll;

int gcd(int a, int b)
{

    while (a>0 && b>0)
    {
        if (a>b)
        {
            int c=b;
            b=a%b;
            a=c;
        }
        else
        {
            int c=a;
            a=b%c;
            b=c;
        }

    }

    return max(a,b);
}

int n,m;

int counter;

vector<vector<int>> r;

vector<int> used;

void dfs(int v)
{
    used[v]=1;
    counter++;

    for (auto x : r[v])
        if (used[x]==0)
            dfs(x);
}

void inputdirgr()
{
    cin>>n>>m;

    r.resize(n);

    for (int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;

        a--;
        b--;

        r[a].push_back(b);
    }
}

int t[100];

int a[100][200001];

int main()
{
    int x,y;

    int n;

    cin>>n;

    int T=0;
    for (int i=0; i<n; i++)
    {
        cin>>t[i];
        T+=t[i];
    }

    for (int i=0; i<n; i++)
        for (int q=0; q<200001; q++)
            a[i][q]=T+1;

    a[0][100000+t[0]]=t[0];
    a[0][100000-t[0]]=t[0];

    for (int i=1; i<n; i++)
        for (int q=-T; q<=T; q++)
            if (a[i-1][100000+q]!=T+1)
            {
                if (q<0)
                {
                int ttt=a[i-1][100000+q];
                int t1=max(q+t[i]+ttt,ttt);
                int q1=q+t[i];

                int t2=t[i]+ttt;
                int q2=q-t[i];

                a[i][100000+q1]=min(a[i][100000+q1],t1);
                a[i][100000+q2]=min(a[i][100000+q2],t2);
                }
                else
                {
                int ttt=a[i-1][100000+q];
                int t1=t[i]+ttt;
                int q1=q+t[i];

                int t2=max(-q+t[i]+ttt,ttt);
                int q2=q-t[i];

                a[i][100000+q1]=min(a[i][100000+q1],t1);
                a[i][100000+q2]=min(a[i][100000+q2],t2);
                }
            }

     int mint=T;

     for (int i=0; i<200001; i++)
         if (a[n-1][i]<mint)
             mint=a[n-1][i];

     cout<<mint;

    /*counter=0;

    for (int i=0; i<n; i++)
    {
        used.assign(n,0);

        dfs(i);
    }

    cout<<counter;*/

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define mems(p) memset(p,-1,sizeof(p))
#define pb push_back
#define eb emplace_back
#define nl "\n"
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vd = vector<double>;
using vc = vector<char>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvpi = vector<vector<pi>>;
using vvpl = vector<vector<pl>>;
using vvvi = vector<vector<vector<int>>>;
using vvvl = vector<vector<vector<ll>>>;
using vvvb = vector<vector<vector<bool>>>;
using vvvd = vector<vector<vector<double>>>;
using vvvc = vector<vector<vector<char>>>;
using vvvpi = vector<vector<vector<pi>>>;
using vvvpl = vector<vector<vector<pl>>>;

const int mxN = 8e5 + 100;
const ll MOD = 1e9 + 7;

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

ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

vl factorial;

ll expo(ll x, ll exp, ll mod = MOD) {
    if (exp <= 0) return 1;
    ll tmp = (x*x) % mod;
    if (exp%2) {
        return (expo(tmp, exp/2, mod) * x) % mod;
    }
    return (expo(tmp, exp/2, mod)) % mod;
}

ll choice(ll n, ll r, ll mod = MOD) {
    if (n < r) return 0;
    ll numer = factorial[n];
    ll denom = (factorial[r] * factorial[n-r]) % mod;
    return numer * expo(denom, mod - 2, mod) % mod;
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}

int main() {
    fast();
    ll n, ans;
    cin >> n;
    ans = n;
    map<ll, int> mp;
    for (ll i = 2; i*i <= n; ++i)
    {
        ll cur = i*i;
        if (mp[cur]) continue;
        while (cur <= n) {
            if (!mp[cur]) --ans;
            mp[cur] = true;
            cur *= i;
        }
    }
    cout << ans << nl;
}

#include <iostream>
#include <unordered_set>
using namespace std;
using ll = int64_t;

int main(){
    ll N;
    cin >> N;
    unordered_set<ll> s;
    for(ll a = 2; a * a <= N; a++){
        ll x = a * a;
        while(x <= N){
            s.insert(x);
            x *= a;
        }
    }
    cout << N - s.size() << endl;
}


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

int n;

void solve()
{
  for(int i=0;i<n;++i){
  	cout<<(2*i)%n+1<<' '<<(2*i+1)%n+1<<'\n';
  }
}

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

#include <cstdio>
#include <cstring>
#include <algorithm>
#define reg register
const int N=400002;
long long ans;
bool cmp(const int &i,const int &j) {
	return i>j;
}
struct heap{
	int h[N],n;
	void push(reg int x) {
		h[++n]=x;
		std::push_heap(h+1,h+1+n,cmp);
	}
	void pop() {
		std::pop_heap(h+1,h+1+n,cmp);
		--n;
	}
	int top() {
		return h[1];
	}
}q;
int a[N];
int R()
{
	reg int x=0; reg bool f=0; reg char ch=getchar();
	for(;ch<48||ch>57;ch=getchar()) f|=ch=='-';
	for(;ch>=48&&ch<=57;ch=getchar()) x=x*10+ch-48;
	return f?-x:x;
}
int main()
{
	reg int n=R(),i;
	for(i=1;i<=n<<1;++i) ans+=a[i]=R();
	for(i=1;i<=n;++i) q.push(a[n+i]),q.push(a[n-i+1]),ans-=q.top(),q.pop();
	printf("%lld",ans);
}


#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <cmath>

std::array<int, 2> cog(const  std::vector < std::array<int, 2>>& ps)
{
  std::array<int, 2> result = { 0,0 };
  for (auto& e : ps)
  {
    result[0] += e[0];
    result[1] += e[1];
  }

  result[0] /= (int)ps.size();
  result[1] /= (int)ps.size();
  return result;
}

void counter_tranlate_all(std::vector<std::array<int,2>>& ps, const std::array<int,2>& m)
{
  for (auto& e : ps)
  {
    e[0] -= m[0];
    e[1] -= m[1];
  }
}

bool test_rot(
  std::map<int, std::set<double>> ss_polar,
  std::map<int, std::set<double>> ts_polar,
  double rot)
{
  for (auto&& d : ts_polar)
  {
    auto x = ss_polar[d.first];
    auto y = ts_polar[d.first];
    if (x.size() != y.size()) { return false; }

    if(d.first == 0 )
    {
      continue;
    }

    std::set<double> mov_y;
    for (auto e : y)
    {
      mov_y.insert(e + rot);
    }

    for (auto& y : mov_y)
    {
      bool ok = false;
      for (auto& e : x)
      {
        if (std::remainder(y - e, 360.) < 1e-6)
        {
          ok = true;
          break;
        }
      }
      if (!ok) { return false; }
    }
  }

  return true;
}

int main()
{
  int N;
  std::cin >> N;
  std::vector<std::array<int, 2>> ss(N);
  for (auto& e : ss)
  {
    std::cin >> e[0] >> e[1];
    e[0] *= N;
    e[1] *= N;
  }
  std::vector<std::array<int, 2>> ts(N);
  for (auto& e : ts)
  {
    std::cin >> e[0] >> e[1];
    e[0] *= N;
    e[1] *= N;
  }

  auto cog_ss = cog(ss);
  auto cog_ts = cog(ts);

  counter_tranlate_all(ss, cog_ss);
  counter_tranlate_all(ts, cog_ts);

  int dist2_ss = 0;
  for (auto& e : ss)
  {
    int d = e[0] * e[0] + e[1] * e[1];
    if (dist2_ss < d) { dist2_ss = d; }
  }

  int dist2_ts = 0;
  for (auto& e : ts)
  {
    int d = e[0] * e[0] + e[1] * e[1];
    if (dist2_ts < d) { dist2_ts = d; }
  }

  if (dist2_ss != dist2_ts)
  {
    std::cout << "No" << std::endl;
    return 0;
  }

  double PI = 3.14159265359;

  std::map<int, std::set<double>> ss_polar;
  for (auto& e : ss)
  {
    int d = e[0] * e[0] + e[1] * e[1];
    ss_polar[d].insert(std::atan2(e[1],e[0])*180 /PI);
  }

  std::map<int, std::set<double>> ts_polar;
  for (auto& e : ts)
  {
    int d = e[0] * e[0] + e[1] * e[1];
    ts_polar[d].insert(std::atan2(e[1], e[0]) * 180 / PI);
  }

  std::set<double> moves;
  {
    double b = *ss_polar[dist2_ss].begin();
    for (auto& t : ts_polar[dist2_ss])
    {
      moves.insert(b - t);
    }
  }

  for (auto& e : moves)
  {
    auto ret = test_rot(ss_polar, ts_polar, e);
    if (ret)
    {
      std::cout << "Yes" << std::endl;
      return 0;
    }
  }

  std::cout << "No" << std::endl;
  return 0;
}

//#include <atcoder/all>
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<pair<ll, ll>>>;
vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;

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

    vector<pair<ll, ll>> S(N), T(N);
    vll La(N), Ra(N);
    set<pair<ll, ll>> TP;
    rep(i, N) {
        ll L, R;
        cin >> L >> R;
        S[i] = make_pair(L, R);
    }
    rep(i, N) {
        ll L, R;
        cin >> L >> R;
        T[i] = make_pair(L, R);
        TP.insert(T[i]);
    }

    if (N == 1) {
        cout << "Yes" << endl;
        return 0;
    }
    if (N == 2) {
        if ((S[0].first - S[1].first) * (S[0].first - S[1].first) + (S[0].second - S[1].second) * (S[0].second - S[1].second) == (T[0].first - T[1].first)
            * (T[0].first - T[1].first) + (T[0].second - T[1].second) * (T[0].second - T[1].second)) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }

        return 0;
    }
    rep(i, N) {
        //S[0]→T[i]
        rep(j, N) {
            //S[1]→T[j]
            if (i == j)continue;
            if ((S[0].first - S[1].first) * (S[0].first - S[1].first) + (S[0].second - S[1].second) * (S[0].second - S[1].second) != (T[i].first - T[j].first)
                * (T[i].first - T[j].first) + (T[i].second - T[j].second) * (T[i].second - T[j].second)) {
                continue;
            }
            ll r = (S[0].first - S[1].first) * (S[0].first - S[1].first) + (S[0].second - S[1].second) * (S[0].second - S[1].second);
            bool c = true;
            for (ll k = 2; k < N; k++) {
                ll dx1 = -S[0].first + S[1].first;
                ll dy1 = -S[0].second + S[1].second;
                ll dx = -S[0].first + S[k].first;
                ll dy = -S[0].second + S[k].second;

                ll dx2 = -T[i].first + T[j].first;
                ll dy2 = -T[i].second + T[j].second;

                ll tx = (dx * dx1 + dy1 * dy) * dx2 - (-dx * dy1 + dy * dx1) * dy2;
                ll ty = (dx * dx1 + dy1 * dy) * dy2 + (-dx * dy1 + dy * dx1) * dx2;
                tx /= r;
                ty /= r;
                if (!TP.count(make_pair(tx+ T[i].first, ty+ T[i].second))) {
                    c = false;
                }

            }
            if (c) {
                cout << "Yes" << endl;
                return 0;
            }

        }
    }
    cout << "No" << endl;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int t,n,a[100005];
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		int flag=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+1,a+n+1);
		if(n%2==1) printf("Second\n");
		else
		{

			for(int i=2;i<=n;i+=2)
			{
				if(a[i]!=a[i-1]) flag=1;
			}
			if(!flag) printf("Second\n");
			else printf("First\n");
		}
	}
	return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<set>
#include<map>
#include<iterator>
#define ll              long long
#define lli             long long int
#define pb              push_back
#define RIP(i,n)        for(int i=0; i<n; i++)
#define F(i,a,b)          for(int i=a; i<b; i++)
#define RIP1(i,n)       for(int i=n-1; i>=0; i--)
#define FOR(i,a,b)      for(int i=a;i<(b); i++)
#define FOR1(i,a,b)     for(int i=a; i>=(b); i--)
#define sc(a)           scanf("%lld",&a)
#define SC(a)           scanf("%d",&a)
#define cin(a)          cin >> a
#define cout(a)         cout << a
#define pi              acos(-1)
#define pr(a)           printf("%lld\n",a)
#define PR(a)           printf("%lld ",a)
#define s(a,b)          sort(a,b)
#define sz(x)           (int)(x).size()
#define nl              '\n'
#define Max             110
#define mod             1e9 + 7
using namespace std;
void c_p_c()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /*#ifdef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif*/
}
int main()
{
    int n;
    cin >> n;
    int x[n],y[n];
    RIP(i,n)
    {
        cin >> x[i] >> y[i];
    }
    bool yes=false;
    RIP(i,n)
    {
        F(j,0,i)
        {
            F(k,0,j)
            {
                int x1=x[i];
                int y1=y[i];
                int x2=x[j];
                int y2=y[j];
                int x3=x[k];
                int y3=y[k];
                x1-=x3;
                x2-=x3;
                y1-=y3;
                y2-=y3;
                if(x1*y2==x2*y1)
                {
                    yes=true;
                    break;
                }
            }
            if(yes)
            {
                break;
            }
        }
        if(yes)
        {
            break;
        }
    }
    if(yes)
    {
        cout << "Yes" << nl;
    }
    else
    {
        cout << "No" << nl;
    }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <stack>
#include <cstdlib>
#include <set>
#define mp make_pair
#define pb push_back
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
#define pii pair<ll,ll>
const ll INF=1000000007;
const ll DMAX=1000000+15;
const ll MOD=10000007;
template<class T> inline void read(T &x){
    x=0;
    T f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch<='9' && ch>='0'){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    x*=f;
}
template<class T> void print(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    int a[20];
    int cnt=0;
    do{
        a[++cnt]=x%10;
        x/=10;
    }while(x>0);
    for(int i=cnt;i>=1;i--){
        putchar(a[i]+'0');
    }
    puts("");
}
int n;
ll a[2002];
map<ll,ll> ma;
ll lp[DMAX],cnt=0;
int main(){
    read(n);
    ll mx=INF;
    for(int i=1;i<=n;i++){
        read(a[i]);
        mx=min(mx,a[i]);
    }
    ma.clear();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=sqrt(a[i]);j++){
            if(a[i]%j==0){
                if(ma[j]==0){
                    ma[j]=a[i];
                    lp[++cnt]=j;
                }
                else{
                    ma[j]=__gcd(ma[j],a[i]);
                }
                ll plo=a[i]/j;
                if(ma[plo]==0){
                    ma[plo]=a[i];
                    lp[++cnt]=plo;
                }
                else{
                    ma[plo]=__gcd(ma[plo],a[i]);
                }
            }
        }
    }
    ll ans=0;
    for(int i=1;i<=cnt;i++){
        if(ma[lp[i]]==lp[i] && lp[i]<=mx){
            ans++;
        }
    }
    print(ans);
    return 0;
}

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

//最大公約数
ll gcd(ll x,ll y){

	x = abs(x);
	y = abs(y);

	if(x < y){
		swap(x,y);
	}
	if(y == 0){
		return x;
	}else{
		return gcd(y,x%y);
	}
}

map<ll,ll> MAP;

void func(ll num,ll base){

	auto at = MAP.find(base);
	if(at == MAP.end()){

		MAP[base] = num;
	}else{

		ll tmp = MAP[base];
		MAP[base] = gcd(tmp,num);
	}
}

int main(){

	int N;
	scanf("%d",&N);

	ll A;
	ll mini = HUGE_NUM;

	for(int i = 0; i < N; i++){

		scanf("%lld",&A);
		mini = min(mini,A);

		for(ll k = 1; k*k <= A; k++){
			if(A%k != 0)continue;

			func(A,k);
			func(A,A/k);
		}
	}

	int ans = 1;
	for(auto at = MAP.begin(); at != MAP.end(); at++){

		if(at->first < mini && at->first == at->second){

			ans++;
		}
	}

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

	return 0;
}


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

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> vs;
    rep(i,N){
      int a,b,c;
      cin >> a >> b >> c;
      vector<int> tmp={a,b,c};
      vs.push_back(tmp);
    }
    long long INF=10000000000000000;
  	long long DP[N][1<<N];
    rep(i,N){
      rep(j,(1<<N)){
        DP[i][j]=INF;
      }
    }
    DP[0][0]=0;
    rep(t,N){
    rep(i,N){
      int a,b,c;
      a=vs[i][0];
      b=vs[i][1];
      c=vs[i][2];
      rep(j,N){
        if(i==j){
          continue;
        }
        int p,q,r;
        p=vs[j][0];
        q=vs[j][1];
        r=vs[j][2];
        int cost1=abs(p-a)+abs(q-b)+max(0,r-c);
        int cost2=abs(a-p)+abs(b-q)+max(0,c-r);
        rep(k,(1<<N)){
          DP[j][k|(1<<i)]=min(DP[j][k|(1<<i)],DP[i][k]+cost1);
        }
        rep(k,(1<<N)){
          DP[i][k|(1<<j)]=min(DP[i][k|(1<<j)],DP[j][k]+cost2);
        }
      }
    }
    }

    cout << DP[0][(1<<N)-1] << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(int i = a; i <=b; i++)
#define rep2(i,a,b) for(int i = a; i>=b; i--)
#define PB push_back
#define MP make_pair
#define db long double
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define cases int testcases;cin>>testcases; while(testcases--)
#define INF 2000000000
const double PI = acos(-1);
const int N = 100005;
#define eps 1e-6
#define MOD 1000000007
  int32_t main()
  {
    IOS

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

       	m*=(n);
        int arr[n];
        int sum = 0;

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

        int l = max(0LL,m-sum);

        if(l > k)
        {
        	l = -1;
        }

        cout << l;

    return 0;
      }


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

int main() {
 int a,b,c;
  cin >> a >> b >> c;
  if (a == b == c) {
    cout << c;
  }
  else if (a == b) {
    cout << c;
  }
  else if (b == c) {
    cout << a;
  }
  else if (a == c) {
    cout << b;
  }
  else {
    cout << 0;
  }
}

#include<iostream>
#include<math.h>
using namespace std;
int main() {
	float R, X, Y;
	cin >> R >> X >> Y;
	float d = sqrt(X * X + Y * Y);
	int a = ceil(d / R);
	if (d < R) cout << 2 << endl;
	else cout << a << endl;
}


#include "bits/stdc++.h"
#define int long long
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 1000000007;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	reverse(s1.begin(), s1.end());
	reverse(s2.begin(), s2.end());
	reverse(s3.begin(), s3.end());
	int n1 = s1.size(), n2 = s2.size(), n3 = s3.size();
	map<char, int>mp;
	for (int i = 0; i < n1; i++) {
		mp[s1[i]]++;
	}
	for (int i = 0; i < n2; i++) {
		mp[s2[i]]++;
	}for (int i = 0; i < n3; i++) {
		mp[s3[i]]++;
	}
	map<char, int>tmp;
	int now = 0;
	for (auto p : mp) {
		tmp[p.first] = now;
		now++;
	}
	mp = tmp;
	int S = mp.size();
	if (S > 10) {
		cout << "UNSOLVABLE" << endl; return 0;
	}
	vector<int>pe;
	for (int i = 0; i < 10; i++) {
		pe.push_back(i);
	}
	do {
		bool ok = true;
		int t = 1;
		int ans1 = 0, ans2 = 0, ans3 = 0;
		for (int i = 0; i < n1; i++) {
			int nv = pe[mp[s1[i]]];
			if (i == n1 - 1 && nv == 0)ok = false;
			ans1 += nv * t;
			t *= 10;
		}
		t = 1;
		for (int i = 0; i < n2; i++) {
			int nv = pe[mp[s2[i]]];
			if (i == n2 - 1 && nv == 0)ok = false;
			ans2 += nv * t;
			t *= 10;
		}
		t = 1;
		for (int i = 0; i < n3; i++) {
			int nv = pe[mp[s3[i]]];
			if (i == n3 - 1 && nv == 0)ok = false;
			ans3 += nv * t;
			t *= 10;
		}
		if (ans1 + ans2 != ans3)ok = false;
		if (ok) {
			cout << ans1 << endl;
			cout << ans2 << endl;
			cout << ans3 << endl;
			return 0;
		}
	} while (next_permutation(pe.begin(), pe.end()));
	cout << "UNSOLVABLE" << endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

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

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

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

  vi cnt(n+1);
  rep(i,0,n) {
    int x;
    cin >> x;
    ++cnt[x];
  }

  int tot = min(cnt[0], k);
  ll ans = 0;
  rep(i,1,n+1) {
    if (tot == 0) break;
    // how many i do we have
    int nxt = min(tot, cnt[i]);
    int rm = tot-nxt;
    ans += ll(i) * ll(rm);
    tot = nxt;
  }
  cout << ans << '\n';
}


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

void p(){cout<<"Yes"<<endl;};
void q(){cout<<"No"<<endl;};

int main(){
  int N;cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    int a;cin>>a;
    A.at(i)=a%200;
  }
  //sort(A.begin(),A.end());
  //set<int> s;
  map<int,vector<int>> X;
  /*for(int i=0;i<N;i++){
    if(s.count(A[i].first)){
      p();
      cout<<1<<' '<<A[i].second<<endl;
      cout<<X[A[i].first].size()<<' ';
      for(auto x:X[A[i].second]) cout<<x;
      cout<<endl;
      return 0;
    }
    else{
      s.insert(i);
      X[A[i].first].push_back(A[i].second);
    }
  }*/
  int n=min(N,16),cnt=0,y=0;
  int l=pow(2,n),m=0;
  //cout<<l<<endl;
  vector<int> Y;
  for(int i=1;i<l;i++){
    Y.clear();
    m=i;
    y=0;
    cnt=0;
    while(m>0){
      if(m&1){
        y+=A[cnt];
        Y.push_back(cnt+1);
      }
      m=m>>1;
      cnt++;
    }
    y%=200;
    sort(Y.begin(),Y.end());
    if(X.count(y)){
      p();
      cout<<X[y].size()<<' ';
      for(auto x:X[y]) cout<<x<<' ';
      cout<<endl;
      cout<<Y.size()<<' ';
      for(auto z:Y) cout<<z<<' ';
      cout<<endl;
      return 0;
    }
    else X[y]=Y;
  }
  q();
  return 0;
}

#include <iostream>
#include <vector>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <climits>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

typedef long long ll;
#define debuglist(x) for(int i = 0; i < x.size(); ++i) { cout << x[i] << " "; } cout << endl;

void solve(){
    int n;
    cin >> n;
    vector<int> ar(n+1, 0);
    for(int i = 0; i < n; ++i){
        cin >> ar[i];
    }

    stack<pair<int, int>> st;
    int maxOrange = 0;
    for(int i = 0; i < n+1; ++i){
        if(st.empty()) {
            st.push({ar[i], i});
        } else {
            int first_idx = -1;
            int first_min = INT_MAX;
            while(!st.empty() && ar[i] < st.top().first) {
                auto [val, idx] = st.top(); st.pop();
                int orange = val*(i-idx);
                maxOrange = max(orange, maxOrange);
                first_idx = idx;
                first_min = min(val, first_min);
            }
            if(first_idx != -1) {
                st.push({ar[i], first_idx});
            } else {
                st.push({ar[i], i});
            }
        }
    }
    cout << maxOrange << "\n";
}

int main() {
//    int cas;
//    cin >> cas;
//
//    while (cas--) {
//        solve();
//    }

    solve();

    return 0;
}


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

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

const long long MOD = 1000000007;

int main(){
  long double ax,ay,bx,by;
  cin >> ax >> ay >> bx >> by;
  if(ax==bx) cout << ax << endl;
  else{
    cout << fixed << setprecision(10);
    if(ax<bx){
	    cout<<ax+(bx-ax)*(ay/(ay+by))<<endl;
    }
    else{
	    cout<<bx+(ax-bx)*(by/(ay+by))<<endl;
    }
  }

}

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

int n;
vector<int> t,l,r;

void solve() {
  ll ans = 0;
  REP(i,n) {
    int left = l[i], right = r[i];
    int left_kai = 0, right_kai = 0;
    if (t[i] == 1) {
    } else if (t[i] == 2) {
      right_kai = 1;
    } else if (t[i] == 3) {
      left_kai = 1;
    } else {
      right_kai = 1;
      left_kai = 1;
    }

    for(int j = i+1; j < n; j++) {
      int leftj = l[j], rightj = r[j];

      int leftj_kai = 0, rightj_kai = 0;
      if (t[j] == 1) {
      } else if (t[j] == 2) {
        rightj_kai = 1;
      } else if (t[j] == 3) {
        leftj_kai = 1;
      } else {
        rightj_kai = 1;
        leftj_kai = 1;
      }

      if (right_kai && leftj_kai) {
        if (right <= leftj) continue;
      }
      if (!right_kai && leftj_kai) {
        if (right <= leftj) continue;
      }
      if (right_kai && !leftj_kai) {
        if (right <= leftj) continue;
      }
      if (!right_kai && !leftj_kai) {
        if (right < leftj) continue;
      }

      if (rightj_kai && left_kai) {
        if (rightj <= left) continue;
      }
      if (!rightj_kai && left_kai) {
        if (rightj <= left) continue;
      }
      if (rightj_kai && !left_kai) {
        if (rightj <= left) continue;
      }
      if (!rightj_kai && !left_kai) {
        if (rightj < left) continue;
      }

      ans++;
    }
  }

  cout << ans << endl;
  return;
}

int main() {
  cin >> n;
  t.resize(n);
  l.resize(n);
  r.resize(n);
  REP(i,n) cin >> t[i] >> l[i] >> r[i];

  solve();
  return 0;
}


//#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, A[101010], B[101010];

void solve() {
}

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

    int SUM = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
        SUM += A[i] * B[i];
    }
    Yes(SUM == 0);

    solve();
    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<functional>
#include<utility>
using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> b[i];
    }

    int product = 0;
    for(int i = 0; i < n; ++i){
        product += a[i] * b[i];
    }

    if(product == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

// @@ !! LIM()

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

  ll a, b, c, d; cin >> a >> b >> c >> d;
  cout << b - c << endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define sf(a) scanf("%d",&a)
#define pf(a) printf("%d",a);
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}

int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      cin>>a>>b>>c>>d;

      ans=a-c;

      ans=max(ans,a-d);

      ans=max3(ans,b-c,b-d);

      cout<<ans<<endl;

      return 0;

}


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

template<class T>
vector<T> make_vec(size_t a){
	return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
	return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

/* Some Libraries */

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

bool dp[201][201][201][2];
using P = tuple<int,int,int,int>;
P prv[201][201][201][2];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vll a(N);
    rep(i,N) cin>>a[i], a[i]%=200;

    dp[0][0][0][0] = true;
    rep(i,N)rep(j,200)rep(k,200)rep(l,2){
        if (!dp[i][j][k][l]) continue;
        {
            int nj = (j+a[i])%200;
            dp[i+1][nj][k][1] = true;
            prv[i+1][nj][k][1] = P(i,j,k,l);
        }
        {
            int nk = (k+a[i])%200;
            dp[i+1][j][nk][1] = true;
            prv[i+1][j][nk][1] = P(i,j,k,l);
        }
        {
            int nj = (j+a[i])%200;
            int nk = (k+a[i])%200;
            dp[i+1][nj][nk][l] = true;
            prv[i+1][nj][nk][l] = P(i,j,k,l);
        }
    }
    int s=-1,t=-1;
    rep(i,200){
        if (dp[N][i][i][1]){
            s=i, t=i;
            break;
        }
    }
    if (s==-1){
        cout<<"No\n";
        return 0;
    }
    vi B,C;
    P cur(N,s,t,1);
    // fprintf(stderr, "%d %d %d %d\n", N,s,t,1);
    while(true){
        int i,j,k,l;
        tie(i,j,k,l) = cur;
        if (i==0) break;
        P p = prv[i][j][k][l];
        int ni,nj,nk,nl;
        tie(ni,nj,nk,nl) = p;

        if (nl==0 && l==1){
            if ((nj+a[ni])%200==j){
                B.pb(i);
            }else{
                C.pb(i);
            }
        }else{
            if ((nj+a[ni])%200==j) B.pb(i);
            if ((nk+a[ni])%200==k) C.pb(i);
        }
        // fprintf(stderr, "%d %d %d %d\n", ni,nj,nk,nl);

        cur = p;
    }
    reverse(all(B));
    reverse(all(C));
    cout<<"Yes\n";
    cout<<B.size();
    rep(i,B.size()) cout<<" "<<B[i]; cout<<"\n";
    cout<<C.size();
    rep(i,C.size()) cout<<" "<<C[i]; cout<<"\n";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define nl "\n"
typedef pair<int,int>ii;
typedef vector<int>vi;
typedef vector<ii>vii;
typedef vector<vi>vvi;
typedef vector<long long>vl;
typedef vector <vl>vvl;
template<class T>
void print(T& a)
{
    for(auto x:a)
        cout<<x<<" ";
    cout<<"\n";
}
int main()
{

    FastIO

    int n;
    cin>>n;

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

    vvi v(205);
    int len=pow(2,min(n,8));

    for(int i=1; i<len; i++)
    {
        ll sum=0;
        vi vv;
        for(int j=0; j<min(n,8); j++)
        {
            if((1<<j)&i)
            {
                vv.pb(j+1);
                sum+=a[j];
                sum%=200;
            }
        }

        if(!v[sum].empty())
        {
            cout<<"Yes\n";
            cout<<v[sum].size()<<" ";
            print(v[sum]);
            cout<<vv.size()<<" ";
            print(vv);
            return 0;
        }
        else v[sum]=vv;
    }
    cout<<"No\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <set>

using ll = long long;

int const nmax = 200000;
int v[1 + nmax * 2];

int main() {
  std::ios::sync_with_stdio(0);

  int n;
  std::cin >> n;
  for(int i = 1;i <= 2 * n; i++)
    std::cin >> v[i];
  std::multiset<int> myset;
  ll result = 0;
  for(int i = 1; i <= n; i++) {
    myset.insert(v[i]);
    myset.insert(v[2 * n - i + 1]);
    result += *myset.rbegin();
    std::multiset<int>::iterator it = myset.end();
    it--;
    myset.erase(it);
  }
  std::cout << result;
  return 0;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int IM = 2e9;
int dat[400004];

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

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

	int N = getint();
	dat[0] = -IM;
	ll kotae = -IM * ll(N);
	for (int i = N + 1; i > 1; i--) {
		dat[i] = getint();
		kotae += dat[i];
	}

	for (int i = 2; i < N + 2; i++) {

		int p = 2 + (dat[2] > dat[3]);
		int v = dat[i] - IM;
		while (v > dat[p]) {
			dat[p >> 1] = dat[p];
			p <<= 1;
			p += dat[p] > dat[p + 1];
		}
		dat[p >> 1] = v;

		int a = getint();
		kotae += a;
		p = i;
		v = a - IM;
		while (v < dat[p >> 1]) dat[p] = dat[p >> 1], p >>= 1;
		dat[p] = v;

		kotae -= dat[1];
	}

	co(kotae);

	Would you please return 0;
}


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

int main() {
    int arr[4];
    int a;
    for(int i=0;i<4;i++){
        cin>>a;
        arr[i]=a;
    }
    cout << *min_element(arr,arr+4) << endl;
    return 0;
}

// https://atcoder.jp/contests/abc185/tasks/abc185_a
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using str = string;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int ans = 100;
    rep(i, 4) {
        int a;
        cin >> a;
        ans = min(ans, a);
    }
    cout << ans << endl;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <fstream>
#include <numeric>
#include <tuple>
#include <ctime>
#include <random>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto& i : a)
#define foraj(a) for(auto& j : a)
#define forak(a) for(auto& k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0);
#define pb(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort((a).begin(), (a).end());
#define sortm(a, n) sort(a, a + n);
#define reversi(a) reverse((a).begin(), (a).end());
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define yes cout << "Yes\n";
#define no cout << "No\n";
#define ans(a) cout << a << '\n';
#define endl cout << '\n';
#define res(a, n) (a).resize(n);
#define read(a, n) (a).resize(n); fori(n) cin >> a[i];
#define print(a) for (auto i : a) cout << i << ' ';
#define clear(a) (a).clear();
//#define int long long
//#define double long double

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<int, pair<int, int>>> viii;
typedef pair<int, pair<int, int>> iii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;
typedef vector<bool> vb;
typedef set<int> si;
typedef vector<vector<ii>> vvii;
typedef vector<vector<iii>> vviii;
typedef vector<vector<llll>> vvllll;

const int INF = 2147483647;
const ll LONGINF = 9223372036854775807;
const ll MOD = 1e9 + 7;

string s;
list<char> help;

void solve()
{
    int n;
    cin >> n >> s;
    string est = "";
    fori(n) help.push_back(s[i]);
    auto i = help.begin();
    while (i != help.end())
    {
        est += *i;
        if (est.size() == 3)
        {
            if (est == "fox")
            {
                auto first = i, last = i;
                --first;
                --first;
                ++last;
                auto next = help.erase(first, last);
                if (next != help.begin()) --next;
                if (next != help.begin()) --next;
                i = next;
                est = "";
            }
            else
            {
                string temp = est;
                est = "";
                est += temp[1];
                est += temp[2];
                ++i;
            }
        }
        else ++i;
    }
    ans(help.size())
}

signed main()
{
    fast
    bool mult = false;
    if (mult)
    {
        int t;
        cin >> t;
        while (t--) solve();
    }
    else solve();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef double T;

T EPS = 1e-7;

int cmp(T x, T y = 0) {
	return (x <= y + EPS) ? (x + EPS < y) ? -1 : 0 : 1;
}

struct point {
    T x, y;
    int id;

    point(T x_ = 0, T y_ = 0, int id_ = -1): x(x_), y(y_), id(id_) {}

    point operator + (const point& b) const { return point(x + b.x, y + b.y); }
    point operator - (const point& b) const { return point(x - b.x, y - b.y); }
    point operator * (T c) { return point(x*c, y*c); }
    point operator / (T c) { return point(x/c, y/c); }
};

inline T escalar(point a, point b) {
    return a.x * b.x + a.y * b.y;
}

inline T vetorial(point a, point b) {
    return a.x * b.y - a.y * b.x;
}

T angle(point p, point q, point o) {
	point u = p - o, v = q - o;
	return atan2(vetorial(u, v), escalar(u, v));
}

point rot(point p, double a) {
    return {p.x*cos(a) - p.y*sin(a), p.x*sin(a) + p.y*cos(a)};
}

int n, nmatch[110];
point p1[110], p2[110], tmp;

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        p1[i] = point(x, y);
    }
    for(int i = n-1; i >= 0; i--)
        p1[i] = p1[i] - p1[0];
    for(int i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        p2[i] = point(x, y);
    }
    if(n == 1) {
        puts("Yes");
        return 0;
    }
    for(int i = 0; i < n; i++) {
        point dif = p1[0] - p2[i];
        for(int j = 0; j < n; j++) {
            if(j == i) continue;
            T ang = angle(p2[j]+dif, p1[1], p1[0]);
            int flag = 0;
            for(int k = 0; k < n; k++) {
                tmp = rot(p2[k] + dif, ang);
                for(int l = 0; l < n; l++) {
                    if(escalar(tmp - p1[l], tmp - p1[l]) < EPS) {
                        if(nmatch[l]++ == 0) flag++;
                    }
                }
            }
            if(flag == n) {
                puts("Yes");
                return 0;
            }
            memset(nmatch, 0, sizeof nmatch);
        }
    }
    puts("No");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll a, b;
    cin >> a >> b;
    cout << (a+b)/2 << " " << (a-b)/2 << endl;
    re0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
#define lin(x) ll x; cin>>x;
#define stin(x) string x; cin>>x;
#define yn(x)  if(x) {  cout<<"Yes"<<endl;   }    else {    cout<<"No"<<endl;   }
#define YN(x)  if(x) {  cout<<"YES"<<endl;   }    else {    cout<<"NO"<<endl;   }
#define co(x) cout<<x<<endl;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll mod=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
    return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
    return ((a > b) ? (a = b, true) : (false));
}
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}

int main() {
lin(N);
  lin(M);
  ll x=powmod(10,N,M*M);
  ll y=(x/M)%M;
  co(y);
}


#include <bits/stdc++.h>

typedef long long int ll;
typedef long double ld;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define re(i,a,n) for(i=a;i<=n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define mset(a,val) memset(a,val,sizeof(a));
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
#define PI 3.14159265
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
// Important header files
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int findMin(vector<int> arr, int n)
{
    // Calculate sum of all elements
    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += arr[i];

    // Create an array to store results of subproblems
    bool dp[n+1][sum+1];

    // Initialize first column as true. 0 sum is possible
    // with all elements.
    for (int i = 0; i <= n; i++)
        dp[i][0] = true;

    // Initialize top row, except dp[0][0], as false. With
    // 0 elements, no other sum except 0 is possible
    for (int i = 1; i <= sum; i++)
        dp[0][i] = false;

    // Fill the partition table in bottom up manner
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=sum; j++)
        {
            // If i'th element is excluded
            dp[i][j] = dp[i-1][j];

            // If i'th element is included
            if (arr[i-1] <= j)
                dp[i][j] |= dp[i-1][j-arr[i-1]];
        }
    }

    // Initialize difference of two sums.
    int diff = sum;

    // Find the largest j such that dp[n][j]
    // is true where j loops from sum/2 t0 0
    for (int j=sum/2; j>=0; j--)
    {
        // Find the
        if (dp[n][j] == true)
        {
            diff = sum-j;
            break;
        }
    }
    return diff;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   ll t,i,j,f,e,x,y,mid,z,w,d,c,b,h,a,k,q,p;
   ll t1,t2,t3,ans=0,tc,t4,m,l,n ;
   cin >> n >> m;
   vector<vector<pair<ll,pair<ll,ll>>>> adj(n+1);
   rep(i,m)
   {
      cin >> x >> y >> a >> b ;
      adj[x].pb({y,{a,b}});
      adj[y].pb({x,{a,b}});
   }
   vector<ll> dist(n+1,1e18);
   dist[1]=0;
   set<pair<ll,ll>> s;
   s.insert({0,1});
   while(!s.empty())
   {
    auto u=*s.begin();
    s.erase(s.begin());
    for(auto v:adj[u.se])
    {
        ll x = ceil(sqrt(v.se.se));
        if(u.fi>=x)
        {
          if(dist[v.fi]>u.fi+v.se.fi+(v.se.se)/(u.fi+1))
          {
            s.erase({dist[v.fi],v.fi});
            dist[v.fi]=u.fi+v.se.fi+(v.se.se)/(u.fi+1) ;
            s.insert({dist[v.fi],v.fi});

          }
        }
        else
        {
          t1=u.fi+v.se.fi+x-u.fi-1;
          //cout << t1 << endl ;
          t1+=(v.se.se)/x;
          //cout << t1 << endl ;
          if(dist[v.fi]>t1)
          {
            s.erase({dist[v.fi],v.fi});
            dist[v.fi]=t1 ;
            s.insert({dist[v.fi],v.fi});

          }
        }
    }
   }
   if(dist[n]==1e18) cout << -1 ;
   else cout << dist[n] ;

  return 0;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007

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...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ll gcd(ll x,ll y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}

class cmp      //comrootator for priority_queue
{               //declaration: priority_queue<int,vector<int>,cmp>
public:
    bool operator()(pair<ll,ll>& A, pair<ll,ll>& B)
    {
        // if(A.first == B.first)
        //     return A.second < B.second;
        return A.first > B.first;
    }
};

void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
}

unsigned int onesComplement(unsigned int n)
{
   // Find number of bits in the given integer
   int number_of_bits = floor(log2(n))+1;

   // XOR the given integer with poe(2,
   // number_of_bits-1 and print the result
   return ((1 << number_of_bits) - 1) ^ n;
}

bool comp1(pair<int,int> x,pair<int,int> y)
{
    return x.second<y.second;
}

const int N = 1e5 + 10;
struct node {
	int to;
	int c;
	int d;
};
vector<node> g[N];
void solve(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		g[a].push_back({b, c, d});
		g[b].push_back({a, c, d});
	}

	priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, cmp> pq;
	vector<ll> ans(n + 1, 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 10);
	ans[1] = 0;
	pq.push({0, 1});
	while(!pq.empty()) {
		auto e = pq.top();
		pq.pop();
		int from = e.second; ll cost = e.first;
		if(ans[from] < cost)
			continue;
		for(node to: g[from]) {
			ll min_cost = cost + 1LL * to.c + to.d / (cost + 1);
			int sqr = int(sqrt(to.d));
			for(int i = max(0, sqr - 3); i <= sqr + 3; ++i) {
				min_cost = min(min_cost,
				cost + i * 1LL + 1LL * to.c + to.d / (cost + i * 1LL + 1LL)
								);
			}
			if(ans[to.to] > min_cost) {
				ans[to.to] = min_cost;
				pq.push({min_cost, to.to});
			}
		}
	}

	if(ans[n] == 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 10) {
		cout << -1;
	}
	else
		cout << ans[n];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(15);
    // int t;
    // cin >> t;
    // while(t--){
    //     solve();
    // }
    solve();

}


#include <bits/stdc++.h>

using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second; debug("%s: %.5lf s\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count() / 1000.0), blockTime.second = false)

template <typename T>
std::string NumberToString(T Number)
{
    std::ostringstream ss;
    ss << Number;
    return ss.str();
} // Usages NumberToString(3)
template <typename T>
T StringToNumber(const string &Text)
{
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
} // StringToNumber<int>("3")

string StrCpy(string str, long long int start, long long int end)
{
    string temp = "";
    for (long long int i = start; i <= end; i++)
    {
        temp += str[i];
    }
    return temp;
}

#define ull unsigned long long int
#define ll long long int
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))

int solve() {

    ll x;
    cin >> x;
    while(x>=100){
        x = x - 100;
    }

    cout << 100 - x << endl;

    return 0;
}

int main()
{
   ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  /*
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
   */
   // time__("programm time")
    //{
        solve();
   // }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
   int a;
   cin>>a;
   cout<<100-a%100;

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 10, mod = 1e9 + 7;
void solve() {
    ll n; cin >> n;
    for (ll i = 1; i; ++i) {
        if (i * (i + 1 ) / 2 >= n) {
            cout << i ;
            return ;
        }
    }
}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    return 0;
}

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

const int MaxN=1e9;
char Nss[20];
int main(){
	while(scanf("%s",Nss)!=EOF){
		int i, L=strlen(Nss)-1;
		while(L>=0 and Nss[L]=='0')
			L-=1;
		for(i=0; i<=(L>>1) and Nss[i]==Nss[L-i]; i+=1);
		puts( (L==-1 or i>(L>>1))? "Yes": "No");
	}
}


// Author:   old_school
// Created:  16.01.2021 17:30:16

#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back
#define mp                make_pair
#define F                 first
#define S                 second
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define MOD               1000000007
#define tod               1
#define pi                3.1415926536
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];
#define bye               fflush(stdout)

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;

template <typename T>
bool mycomp(T x,T y){
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){
return x.second<y.second;
}

void solve(){
   lld n,k; cin>>n>>k;
   lld hash[n+5]={0};
   pls(n,a);
   itr(i,0,n-1) hash[a[i]]++;
   lld sumr=0;
   lld z=k,i=0;
   while(z!=0&&i<n){
   	  if(hash[i]>=z) ;
   	  else{
   	  	sumr+=(z-hash[i])*i;
   	  	z=hash[i];
   	  }
   	  i++;
   }
   cout<<sumr;
}
int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
      lld t=1; //cin>>t;
      while(t--){
            solve();
            cout<<endl;
      }
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define li long long
#define pii pair<int, int>
#define vi vector<int>
#define li long long

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

int main() {
	int tests;
	scanf("%d", &tests);
	forn(test, tests) {
		int l, r;
		scanf("%d%d", &l, &r);
		li ans = 0;
		if (2 * l <= r) {
			li len = r - 2 * l + 1;
			ans = len * (len + 1) / 2;
		}
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>
#include <algorithm>
#include <unordered_map>
#define ull unsigned long long
#define int long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
#define INF 1e18
#define all(x) (x).begin(), x.end()
#define int64_t 64
using namespace std;
typedef pair<int, int> pi;
const int MAX = 1e6 + 1;
// typedef vector<vector<ll>> matrix;
const ll PRIME = 1e9 + 7;
// typedef pair<int, pair<int, int>> ppi;
// const ll MAX = 1e6 + 1;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
char s[1505][1505];
int ans[1502][1502];
void solve()
{
    int h, w, n, m;
    cin >> h >> w >> n >> m;

    fr(i, n)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        s[a][b] = '.';
    }
    fr(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        s[a][b] = '#';
    }

    fr(i, h)
    {
        bool chk = 0;
        fr(j, w)
        {
            if (s[i][j] == '.')
                chk = 1;
            else if (s[i][j] == '#')
                chk = 0;
            if (chk)
                ans[i][j] = 1;
        }
        chk = 0;
        frd(j, w- 1)
        {
            if (s[i][j] == '.')
                chk = 1;
            else if (s[i][j] == '#')
                chk = 0;
            if (chk)
                ans[i][j] = 1;
        }
    }
    fr(j, w)
    {
        bool chk = 0;
        fr(i, h)
        {
            if (s[i][j] == '.')
                chk = 1;
            if (s[i][j] == '#')
                chk = 0;
            if (chk)
                ans[i][j] = 1;
        }
        chk = 0;
        frd(i, h - 1)
        {
            if (s[i][j] == '.')
                chk = 1;
            else if (s[i][j] == '#')
                chk = 0;
            if (chk)
                ans[i][j] = 1;
        }
    }
    int cnt=0;
    fr(i,h)
    {
        fr(j,w)
        {
            if(ans[i][j]==1)
            {

                cnt++;
            }
        }
    }
    cout<<cnt;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t;
    t = 1;
    // cin >> t;

    // int k=1;
    while (t--)
    {
        // cout << "Case " << k++ << ":\n";
        solve();
    }
}

#include <vector>
#include <iostream>
#include <utility>
#include <cstdio>
using namespace std;

#define EMPTY 0
#define BULB 1
#define BLOCK 2
#define LIGHT 3

int H,W,N,M;
vector<pair<int, int>> bulbs;
vector<vector<int>> grid;

int main() {
    cin >> H >> W >> N >> M;
    grid = vector<vector<int>>(H, vector<int>(W, EMPTY));
    int a, b, c, d;
    for(int i = 0; i < N; i++) {
        cin >> a >> b;
        bulbs.push_back({a-1, b-1});
        grid[a-1][b-1] = BULB;
    }
    for(int i = 0; i < M; i++) {
        cin >> c >> d;
        grid[c-1][d-1] = BLOCK;
    }

    // visited[i][j][index] grid[i][j]位置的灯的index方向是否被访问过
    vector<vector<vector<int>>> visited(H, vector<vector<int>>(W, vector<int>(4, 0)));

    // printf("H:%d, W:%d, N:%d, M:%d\n", H, W, N, M);
    // for(int i = 0; i < N; i++) {
    //     printf("%d %d\n", bulbs[i].first, bulbs[i].second);
    // }

    vector<int> dirs{0, 1, 0, -1, 0};
    int r, h, tr, th;
    // 循环每个灯，向上下左右扩展，直到扩展到block
    // 每次扩展时记录当前灯和扩展到的灯的方向是否访问过，便于缩小复杂度
    for(int i = 0; i < N; i++) {
        for(int index = 0; index < 4; index++) {
            r = bulbs[i].first;
            h = bulbs[i].second;
            if(visited[r][h][index]) {
                continue;
            }
            visited[r][h][index] = true;
            int tr = r + dirs[index];
            int th = h + dirs[index+1];
            while(tr >= 0 && tr < H && th >= 0 && th < W) {
                if(grid[tr][th] == BLOCK) {
                    break;
                }
                if(grid[tr][th] == BULB) {
                    visited[tr][th][index] = true;
                }
                if(grid[tr][th] == EMPTY) {
                    grid[tr][th] = LIGHT;
                }
                tr += dirs[index];
                th += dirs[index+1];
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(grid[i][j] == BULB || grid[i][j] == LIGHT) {
                ans++;
            }
        }
    }

    printf("%d", ans);
    return 0;
}


// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(false);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

template <int mod>
class ModInt {
 public:
  ModInt() : v(0) {}
  ModInt(int x) : v((x + mod) % mod) {}
  int value() const { return v; }
  const ModInt operator+(const ModInt &r) const {
    return ModInt(this->v + r.v);
  }
  const ModInt operator-(const ModInt &r) const {
    return ModInt(this->v + mod - r.v);
  }
  const ModInt operator*(const ModInt &r) const {
    return ModInt(this->v * r.v);
  }
  const ModInt operator/(const ModInt &r) const { return (*this * (~r)); }
  const ModInt operator^(int k) const { return ModInt(bpow(this->v, k)); }
  const ModInt operator~() const { return ModInt(bpow(this->v, mod - 2)); }
  bool operator==(const ModInt &r) const { return this->v == r.v; }
  bool operator!=(const ModInt &r) const { return this->v != r.v; }
  ModInt &operator+=(const ModInt &r) { return *this = *this + r; }
  ModInt &operator-=(const ModInt &r) { return *this = *this - r; }
  ModInt &operator*=(const ModInt &r) { return *this = *this * r; }
  ModInt &operator/=(const ModInt &r) { return *this = *this * (~r); }

 private:
  int v;
  int bpow(int a, int b) const {
    int ret = 1;
    while (b > 0) {
      if (b & 1) ret = (ret * a) % mod;
      a = (a * a) % mod;
      b >>= 1;
    }
    return ret;
  }
};
using Mint = ModInt<998244353>;
signed main() {
  int A, B, C;
  cin >> A >> B >> C;
  Mint a = Mint(A * (A + 1) / 2);
  Mint b = Mint(B * (B + 1) / 2);
  Mint c = Mint(C * (C + 1) / 2);
  cout << (a * b * c).value() << endl;
}


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<fixed<<setprecision(10)<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout << fixed << setprecision(15); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on

ll n;
ll msb(ll v) {
    // assert v > 0
    return 64 - __builtin_clzll(v);
}
// ダブリング: 各ノードから 2^i 回、根に向かって移動をして到達する場所 (-1は移動不可とする)
vector<ll> parent(200005);
vector<vector<ll>> depth(200005);
vector<ll> depth0(200005);
vector<ll> depthid(200005);
vector<vector<ll>> edgmap(200005);
void doubling_mv_to_root(vector<vector<ll>> &dbl) {
    ll logn = dbl.size();
    for (ll i = 0; i < logn; i++) {
        for (ll j = 0; j < n; j++) {
            if (i == 0) {
                dbl[i][j] = parent[j];
            } else if (dbl[i - 1][j] >= 0) {
                dbl[i][j] = dbl[i - 1][dbl[i - 1][j]];
            }
        }
    }
}
ll ancestor_at_depth(ll u, ll diff, vector<vector<ll>> &dbl) {
    ll logn = dbl.size();
    while (diff > 0) {
        // 2^i 回の移動をしてもdiffが0以上残る最大のi
        ll i = msb(diff) - 1;
        ll pow2i = (1ULL << i);
        diff -= pow2i;
        u = dbl[i][u];
    }
    return u;
}
void dfs(ll u, ll dep) {
    depth[dep].push_back(u);
    depthid[u] = -1 + depth[dep].size();
    depth0[u] = dep;
    for (auto v : edgmap[u]) {
        dfs(v, dep + 1);
    }
}
int main() {
    ioinit();
    cin >> n;
    for (ll i = 1; i < n; i++) {
        ll p;
        cin >> p;
        parent[i] = p - 1;
        edgmap[parent[i]].push_back(i);
    }
    ll q;
    cin >> q;
    vector<pll> queries(q);
    for (ll i = 0; i < q; i++) {
        ll u, d;
        cin >> u >> d;
        u--;
        queries[i] = {u, d};
    }

    dfs(0, 0);

    ll logn = 24;
    vector<vector<ll>> dbl(logn, vector<ll>(n, -1));
    doubling_mv_to_root(dbl);

    for (auto query : queries) {
        ll u = query.first;
        ll d = query.second;
        ll diff = d - depth0[u];
        if (diff == 0) {
            print(1);
            continue;
        }
        if (diff < 0) {
            print(0);
            continue;
        }

        ll k = depthid[u];
        ll mx = -10 * n - 10;
        {
            // diff回上に上がってdepthidがk以下になる最大
            ll right = depth[d].size() - 1;
            ll left = 0;
            while (left <= right) {
                ll mid = (left + right) / 2;
                ll did = depthid[ancestor_at_depth(depth[d][mid], diff, dbl)];
                if (did <= k) {
                    mx = max(mid, mx);
                    left = mid + 1;
                } else {
                    right = mid - 1;
                }
            }
        }
        ll mn = 10 * n + 10;
        {
            // diff回上に上がってdepthidがk以上になる最小
            ll right = depth[d].size() - 1;
            ll left = 0;
            while (left <= right) {
                ll mid = (left + right) / 2;
                ll did = depthid[ancestor_at_depth(depth[d][mid], diff, dbl)];
                if (did >= k) {
                    mn = min(mid, mn);
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }
        }
        ll ans = mx - mn + 1;
        if (ans < 0) ans = 0;
        print(ans);
    }
}

#include <bits/stdc++.h>
using namespace std;
#define deb(k) cerr << #k << ": " << k << "\n";
#define size(a) (int)a.size()
#define fastcin cin.tie(0)->sync_with_stdio(0);
#define st first
#define nd second
#define pb push_back
#define mk make_pair
#define int long long
typedef long double ldbl;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vector<int> vint;
#define MAXN 300100
#define MAXLG 20
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vint g[N];
int ans[N];
vector<pii>qr[N];
int f[N];
vint aux[N];

void dfs(int x, int p = -1, int d = 0){
	for(int v : g[x]){
		for(auto e : qr[v]){
			int i = e.nd, j = e.st;
			aux[j].pb(f[j]);
			f[j] = 0;
		}
		dfs(v, x, d+1);
		for(auto e : qr[v]){
			int i = e.nd, j = e.st;
			f[j] += aux[j].back();
			aux[j].pop_back();
		}
	}
	f[d]++;
	for(auto e : qr[x]){
		int i = e.nd, j = e.st;
		ans[i] = f[j];
	}
}

void solve(){
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		int x;
		cin>>x;
		g[x].pb(i);
	}
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int a,b;
		cin>>a>>b;
		qr[a].pb({b, i});
	}
	dfs(1);
	for(int i=0;i<q;i++) cout<<ans[i]<<"\n";

	// Have you read the problem again?
	// Maybe you understood the wrong problem
}

int32_t main(){
	fastcin;
	int t_ = 1;
	//cin>>t_;
	while(t_--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
//const lint MOD=998244353;
const lint MAX = 4000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#pragma GCC optimize("Ofast")
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

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

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

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

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }

    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }

    int main(){
       lint h,w,a,b;
       cin>>h>>w>>a>>b;
       lint t[h][w];
       vector<pair<P,P>> cd;
       rep(i,h){
           rep(j,w-1){
               cd.push_back({{i,j},{i,j+1}});
           }
       }
       rep(i,h-1){
           rep(j,w){
               cd.push_back({{i,j},{i+1,j}});
           }
       }
       lint aa=cd.size();
       lint g=1<<aa;
       lint ans=0;
       rep(bit,g){
           bool d[aa];
           fill(d,d+aa,false);
           lint count=0;
           rep(i,aa){
               if((1<<i)&bit){
                   d[i]=true;
                   count++;
               }
           }
           if(count!=a)continue;
           rep(i,h)rep(j,w)t[i][j]=0;
           rep(i,aa){
               if(d[i]){
                   t[cd[i].first.first][cd[i].first.second]++;
                   t[cd[i].second.first][cd[i].second.second]++;
               }
           }
           bool isp=true;
           rep(i,h)rep(j,w)if(t[i][j]>1)isp=false;
           if(isp)ans++;

       }
       cout<<ans<<endl;
      }

#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define MOD 998244353
//#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, j, n) for (int i = j; i < n; i++)
#define llrep(i, n) for (ll i = 0; i < n; i++)
using ll = long long;
typedef pair<ll, ll> P;

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

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

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

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

    return 0;
}