#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
using ll = long long;

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

// 小さい順(昇順)で約数をすべて列挙します。
vector<ll> allDivisors(ll n)
{

    vector<ll> result;

    for (ll i = 1; i <= n / i; ++i)
    {

        if (n % i == 0)
        {
            result.push_back(i);
            if (n / i != i)
            {
                result.push_back(n / i);
            }
        }
    }

    sort(result.begin(), result.end());

    return result;
}

int main()
{

    ll n;
    cin >> n;
    n *= 2;
    vector<ll> alld = allDivisors(n);
    ll count = 0;
    for (ll k : alld)
    {
        ll e = n / k;
        if ((e - k + 1) % 2 == 0)
        {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
#define P pair<ll,ll>
#define T tuple<int, int, int>
#define PP pair<P,P>
#define ALL(a) a.begin(), a.end()

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

    vi ans(n);
    ans[0] = 1;
    REP(i,1,n){
        int MAX = 0;
        i++;
        for (int j=1; j*j<=i; j++){
            if (i % j == 0){
                MAX = max(MAX, ans[j-1]);
                MAX = max(MAX, ans[i/j-1]);
            }
        }
        i--;
        ans[i] = MAX + 1;
    }

    rep(i,n){
        cout << ans[i];
        if (i < n - 1) cout << " ";
        else cout << endl;
    }
}


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

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<ll, ll>
#define vec vector<int>
#define mat vector<vec>

const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    ll n;
    cin >> n;
    vector<ll> fb;
    fb.push_back(0);
    fb.push_back(1);
    while(fb.back() < n){
        fb.push_back(fb[fb.size()-1] + fb[fb.size()-2]);
    }
    // cout << fb.size() << endl;
    // rep(i, fb.size()){
    //     cout << fb[i] << " ";
    // }cout << endl;
    vector<P> f;
    int t = 0;
    if(n != 1){
        t = upper_bound(fb.begin(), fb.end(), n)-fb.begin();
        n -= fb[t-1];
        f.push_back(P(fb[t-1], 0));
    }

    while(n > 1){
        int idx = upper_bound(fb.begin(), fb.end(), n)-fb.begin();
        idx--;
        ll num = fb[idx];
        n -= num;
        f.push_back(P(num, t-idx-1));
    }
    vec ans;
    int now = 0;
    // x, y, x, y...
    if(t % 2 == 1){
        rep(i, t-2){
            while(now < f.size() && f[now].second == i){
                if(i % 2 == 1){
                    ans.push_back(1);
                }else{
                    ans.push_back(2);
                }
                now++;
            }
            if(i % 2 == 0){
                ans.push_back(3);
            }else{
                ans.push_back(4);
            }
        }
    }else{
        rep(i, t-2){
            while(now < f.size() && f[now].second == i){
                if(i % 2 == 1){
                    ans.push_back(2);
                }else{
                    ans.push_back(1);
                }
                now++;
            }
            if(i % 2 == 0){
                ans.push_back(4);
            }else{
                ans.push_back(3);
            }
        }
    }
    if(n == 1) ans.push_back(1);

    // cout << "t = " << t << endl;
    // cout << f.size() << endl;
    // rep(i, f.size()){
    //     cout << f[i].first << ":" << f[i].second << " ";
    // }cout << endl;

    // ll x = 0, y = 0;
    // rep(i, ans.size()){
    //     if(ans[i] == 1){
    //         x++;
    //     }else if(ans[i] == 2){
    //         y++;
    //     }else if(ans[i] == 3){
    //         x += y;

    //     }else{
    //         y += x;
    //     }
    //     // cout << x << " " << y << endl;
    // }
    // cout << x << " " << y << endl;

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

}

#include<bits/stdc++.h>
using namespace std;
int n;
double f[200001];
int main()
{
	cin>>n;
	for(int i=n-1;i>=1;i--)
	{
		f[i]=1.0*((n-i)*(f[i+1]+1)+i)/(n-i);
	}
	printf("%.6lf",f[1]);
	return 0;
}


/*
  NAME : RISHABH SINGH
  INSTITUTION : DELHI TECHNOLOGICAL UNIVERSITY
*/
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int, int>
#define bi __builtin_inf()
#define ll long long
#define mp make_pair
#define ss second
#define pb push_back
#define ff first
#define speed_cubing ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define um unordered_map
#define us unordered_set
#define bp __builtin_popcount
#define ld long double
#define rep(n) for (int i = 0; i < n; i++)
#define pll pair<ll, ll>
#define mx = 1e18;
#define lb(v, val) (lower_bound(v.begin(), v.end(), val) - v.begin())
#define ub(v, val) (upper_bound(v.begin(), v.end(), val) - v.begin())
#define PI 3.1415926535
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
#define sz(v) (int)v.size()
#define endl '\n'
const int mod = 1e9+7;
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}
const int N = 5e5+5;

int32_t main(){

   speed_cubing

   char s,t;
   cin>>s>>t;

   if(s=='Y'){

     cout<<char(t-'a'+'A');

   }
   else
     cout<<t;

   return 0;
}

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

int main() {
    string t;
    char s;
    cin >> s >> t;
    if (s == 'Y') {
        for (int i = 0; i < t.size(); ++i) {
            t[i] = t[i] - 32;
        }
        cout << t << endl;
        return 0;
    } else {
        cout << t << endl;
        return 0;
    }
}


#include<bits/stdc++.h>
using namespace std;
int fa[400050],ring[400050],xd[400050];
int n,a,b,ans;
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-f;
        c=getchar();
    }
    while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}
void merge(int x,int y)
{
	int p=find(x),q=find(y);
	if(p==q)
	{
		ring[p]=1;
		return;
	}
	else
	{
		ring[p]=ring[q]=ring[p]|ring[q];
		fa[p]=q;
		xd[q]+=xd[p];
		xd[p]=0;
	}
	return;
}
int vis[400050];
int main()
{
	cin>>n;
	for(int i=1;i<=400000;i++) fa[i]=i,xd[i]=1;
	for(int i=1;i<=n;i++)
	{
		a=read();b=read();
		if(a>b) swap(a,b);
		merge(a,b);
	}
	for(int i=1;i<=400000;i++)
	{
		int p=find(i);
		if(ring[p]&&vis[p]==0) ans+=xd[p],vis[p]=1;
		else if(ring[p]==0&&vis[p]==0) ans+=xd[p]-1,vis[p]=1;
	}
	cout<<ans<<endl;
}

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

using namespace std;
//using namespace __gnu_pbds;
//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// ordered_set <int> s;
// s.find_by_order(k); // returns the (k+1)th smallest element
// s.order_of_key(k); //returns the number of elements in s strictly less than k

// numbers
#define MOD (1000000007)
//const int N=200000;
const long long int INF=1000000000000;
//shortforms
#define fast ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define sz(v) int(v.size())
#define ff first
#define ss second
#define pb push_back
#define pob() pop_back()
#define pf(a) push_front((a))
#define pof() pop_front()
#define nl '\n'
#define all(v) v.begin(),v.end()
//max and min and sum
#define maxv(a) *max_element(all(a))
#define minv(a) *min_element(all(a))
#define sumv(A,a) accumulate(all(A),a)
//for loops
#define fof(i,a,n) for(ll i=a;i<(n);i++)
#define fob(i,n,a) for(ll i=n;i>=a;i--)
//sorting
#define rev(a) reverse(all(a))
#define as(all,A) sort((A).begin(),(A).end())
#define ds(all,A,x) sort((A).begin(),(A).end(),greater<x>())
//permutations
#define nxtp(a,b) next_permutation(a,b);
//input
#define input(A,n) fof(i,0,n){cin>>A[i];}
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
#define mp(x,y) make_pair(x,y)
//output
#define de(a) cerr<<a<<" ";
#define dispve(A,a,n) fof(i,a,n){cout<<A[i]<<" ";}
#define dismp(m) for(auto x : m){ cout<<x.ff<<" "<<x.ss<<"\n"; }
// shortforms
typedef long long int ll;
#define int ll
//code begins
int n,m;

void solve(int c)
{
	cin>>n;
	if(n%2==1){
      cout<<"Odd";
      return;
    }
  	else if(n%4!=0){
      cout<<"Same";
    }
  	else{
      cout<<"Even";
    }
}

signed main()
{
	fast;
	int T=1;
	cin >> T;
	//cout<< fixed << setprecision(10);
	int cnt = 1;
	while(T--){
		solve(cnt);
		cnt++;
		cout<<nl;
	}
	return 0;
}


#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

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

typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

#define rep(i,start,end) for(ll i = start; i <= end; ++i)
#define rrep(i,end,start) for(ll i = end; i >= start; --i)
#define parr(a,n) rep(i,0,n-1){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) rep(i,0,n-1)cin >> a[i]
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define mset(a,x) memset(a, x, sizeof(a))
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)

// DEBUGGING
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

// Fast IO
void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
}

#define MOD 1000000007

//CODE
/*******************************************************/
#define MX 100000

ll n;

vvl gr(400001,vl());

bool vis[400001];
bool cycle = false;

int dfs(int i, int p = -1) {
  if (vis[i]) {
    cycle = true;
    return 0;
  }

  vis[i] = 1;

  int ans = 1;
  ll cntP = 0;
  for (auto j: gr[i]) {
    if (j == p && !cntP) {
      cntP++;
      continue;
    }
    ans += dfs(j,i);
  }

  return ans;
}

void solve() {
  cin >> n;
  // vector<pll> vp(n);
  ll u,v;

  mset(vis,0);

  rep(i, 0, n - 1) {
    cin >> u >> v;
    gr[u].pb(v);
    gr[v].pb(u);
  }

  ll ans = 0;

  rep(i,0,400000) {
    if (gr[i].size() == 0 || vis[i]) {
      continue;
    }

    cycle = false;
    ans += dfs(i);
    // debug(ans, cycle);
    if (!cycle) ans--;
  }

  cout << ans << "\n";

}

int main() {
  IO();
  int t = 1;

  // cin >> t;

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

/*******************************************************/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    map<ll, set<ll>> num;
    rep(i, n) {
        cin >> a[i] >> b[i];
        num[a[i]].insert(i);
        num[b[i]].insert(i);
    }
    queue<ll> q;
    for(auto x : num) {
        if (sz(x.second) == 1) {
            q.push(x.first);
        }
    }
    while(!q.empty()) {
        ll val = q.front(); q.pop();
        if (sz(num[val]) != 1) continue;
        ll idx = *num[val].begin();
        if (a[idx] != b[idx]) {
            ll nv = (a[idx] == val) ? b[idx] : a[idx];
            num[nv].erase(idx);
            if (sz(num[nv]) == 1) q.push(nv);
        }
    }
    ll ans = 0;
    for(auto x : num) {
        if (sz(x.second) > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<vector>
#define rg register
template<typename T>void read(rg T &x){
	x=0;rg int fh=1;
	rg char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=fh;
}
long long n,ans;
int main(){
	read(n);
	rg long long now=1;
	rg int cnt=0,num=0;
	while(1){
		if(n>=now*10-1){
			ans+=1LL*num*(now*10-now);
		} else {
			ans+=1LL*num*(n-now+1);
			break;
		}
		cnt++;
		now*=10;
		if(cnt%3==0) num++;
	}
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=double;
using vll=vector<ll>;
using vvll=vector<vector<ll>>;
#define FOR(i,a,b) for(ll i=a;i<(ll)b;++i)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define aa first
#define bb second
#define PB push_back
#define EQ(a,b) (fabs(a-b)<=(fabs(a+b)*EPS))
#define MOD ((ll)(1e9+7))
#define dbg cerr
#define out(n) cout << n << '\n'

//#define dbg if(0)cerr

int main(){
  ios::sync_with_stdio(0);cin.tie(0);
  vector<pair<ll,ll>> a = {{1e3 - 1, 0},{1e6 - 1, 1},{1e9 - 1, 2},{1e12 - 1, 3},{1e15 - 1,4},{1e18 - 1, 5}};
  ll n;
  cin>>n;
  ll res = 0;
  for (int i = 0; i < a.size(); ++ i) {
    res += min(a[i].aa,n) * a[i].bb;
    if (i > 0) res -= min(a[i-1].aa,n) * a[i].bb;
    if (a[i].aa > n) break;
  }
  out(res);

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using iPair = pair<int,int>;
using lPair = pair<ll, ll>;
using ivector = vector<int>;
using lvector = vector<ll>;
using istack = stack<int>;
using iqueue = queue<int>;
using ivv = vector<vector<int>>;
using lvv = vector<vector<ll>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
vector<iPair> dir = {{1,0}, {-1,0}, {0,1}, {0,-1}};
#define dump(x) cout << #x << " = " << (x) << endl
#define ALL(x) begin(x),end(x)
#define rep(i,s,e) for(ll i=(s), i_stop=(e); i<i_stop; ++i)
#define repRev(i,s,e) for(ll i=(e)-1, i_stop=(s); i>=i_stop; --i)
#define range(i,s,n) for(ll i=(s), i_stop=(s)+(n); i<i_stop; ++i)
#define rangeRev(i,s,n) for(ll i=(s), i_stop=(s)-(n); i>i_stop; --i)
#define foreach(x,container) for(auto &&x:container)
template<typename T> bool chmax(T& a, const T b) {if(a<b) {a=b;return true;} return false;}
template<typename T> bool chmin(T& a, const T b) {if(a>b) {a=b;return true;} return false;}
template<typename T> void printArr(vector<T> &arr){
    for(auto &x:arr) {cout << x << " ";} cout << endl;
}

// =====================================================>

/*

*/

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

    ivector cnt(n+1, 0);
    ivector a(n+1);
    range(i, 0, n) {cin>>a[i]; ++cnt[a[i]];}

    for(int i = 1; i <= n; ++i) {
        if(cnt[i] == 0) {cout<<"No"<<endl; return;}
    }
    cout << "Yes" << endl;
}

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

//Saptak_Roy_Turja
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]==s[1]&&s[0]==s[2]){
        cout<<"Won"<<endl;
    }
    else {
        cout<<"Lost"<<endl;
    }
}


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

template <class E> struct FenwickTree {
    int _n;
    std::vector<E> data;

    FenwickTree(int n) : _n(n), data(n) { }

    void add(int p, E x) {
        ++p;
        while (p <= _n) {
            data[p - 1] += x;
            p += p & -p;
        }
    }
    E sum(int r) const {
        E s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
    E sum(int l, int r) const {
        return sum(r) - sum(l);
    }
};

long long proc(
    std::vector<int>             &cur,
    int                          x,
    int                          y,
    FenwickTree<int>             &ftcnt0,
    FenwickTree<long long>       &ftsum0,
    const FenwickTree<int>       &ftcnt1,
    const FenwickTree<long long> &ftsum1,
    const std::vector<int>       &arr)
{
    int v = cur[x];
    long long dem = (long long)ftcnt1.sum(0, v) * arr[v];
    long long cre = (long long)ftcnt1.sum(0, y) * arr[y];
    long long adj = (long long)ftsum1.sum(y, v);

    ftsum0.add(v, -arr[v]);
    ftcnt0.add(v, -1);
    cur[x] = y;
    ftsum0.add(y, arr[y]);
    ftcnt0.add(y, 1);

    return cre + adj - dem;
}

int main(int argc, char **argv)
{
    int n, m, q;
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    std::cin >> n >> m >> q;
    std::set<int> s = { 0 };
    std::vector<int> ta(q), xa(q), ya(q);

    for (int i = 0; i < q; i++) {
        std::cin >> ta[i] >> xa[i] >> ya[i];
        xa[i]--;
        s.insert(ya[i]);
    }
    std::vector<int> arr(s.begin(), s.end());
    std::map<int, int> map;
    int ll = s.size();

    for (int i = 0; i < ll; i++) map.emplace(arr[i], i);

    FenwickTree<long long> ftsuma(ll);
    FenwickTree<long long> ftsumb(ll);
    FenwickTree<int>       ftcnta(ll);
    FenwickTree<int>       ftcntb(ll);
    std::vector<int> cura(n);
    std::vector<int> curb(m);
    ftcnta.add(0, n);
    ftcntb.add(0, m);
    long long sum = 0;

    for (int i = 0; i < q; i++) {
        int cy = map[ya[i]];
        sum += (ta[i] == 1) ? proc(cura, xa[i], cy, ftcnta, ftsuma, ftcntb, ftsumb, arr)
                            : proc(curb, xa[i], cy, ftcntb, ftsumb, ftcnta, ftsuma, arr);
        std::cout << sum << std::endl;
    }
    return 0;
}

// give up
#include <bitset>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <list>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <valarray>

// alias, using declaration
using llint = long long; using ldouble = long double;
template <class T = llint> using vector = std::vector<T>;
template <class T = llint> using deque = std::deque<T>;
template <class T = llint> using list = std::list<T>;
template <class T = llint, class U = llint> using umap = std::unordered_map<T, U>;
template <class T = llint, class U = llint> using ummap = std::unordered_multimap<T, U>;
template <class T = llint> using uset = std::unordered_set<T>;
template <class T = llint> using umset = std::unordered_multiset<T>;
template <class T = llint, class U = T> using pair = std::pair<T, U>;
template <class T = llint> using varray = std::valarray<T>;
template <class T = llint, class U = vector<T>, class V = std::less<class U::value_type>> using pqueue = std::priority_queue<T, U, V>;
using std::array; using std::bitset; using std::string; using std::tuple;

// constant
constexpr llint INF = 0x7FFFFFFFFFFFFFFF;
constexpr llint INVALID = 0x8000000000000000;

namespace io {
  // in
  template <class... T, size_t... S> auto in(std::index_sequence<S...>) {tuple<T...> t; (..., (std::cin >> std::get<S>(t))); return t;}
  template <class... T, size_t... S> auto in(std::index_sequence<S...>, size_t n) {tuple<vector<T>...> t{vector<T>(n)...}; for (size_t i = 0; i < n; i++) (..., (std::cin >> std::get<S>(t)[i])); return t;}
  template <size_t N, class T = llint, class... U> auto in() {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(); else return in<T, U...>(std::index_sequence_for<T, U...>());}
  template <size_t N, class T = llint, class... U> auto in(size_t n) {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(n); else return in<T, U...>(std::index_sequence_for<T, U...>(), n);}
  template <size_t N, class T = llint> auto in(size_t n, size_t m) {static_assert(N == 1); vector<vector<T>> v(n, vector<T>(m)); for (auto&& vi : v) for (auto&& vij : vi) std::cin >> vij; return std::make_tuple(v);}
  // out
  template <class T, class... U> void out(const T& a, const U&... b) {std::cout << a << (sizeof...(b) ? " " : "\n"); if constexpr (sizeof...(b)) out(b...);}
  template <class T, class U = const char*> void out(const vector<T>& a, U d = " ") {for (auto&& b : a) std::cout << b << (&b != &a.back() ? d : "\n");}
}

int main() {
  // input
  auto [N, M, Q] = io::in<3>();
  auto [T, X, Y] = io::in<3>(Q);

  // solve
  vector<> a(N + 1), b(M + 1);
  umap<> Z;
  {
    Z.emplace(0, 0);
    vector<> Y_ = Y;
    std::sort(Y_.begin(), Y_.end());
    for (llint i = 0; i < Q; i++) Z.emplace(Y_.at(i), i + 1);
  }
  constexpr llint ST_SIZE = 1 << 19;
  vector<pair<>> st_a(ST_SIZE), st_b(ST_SIZE);
  auto update = [&Z](vector<pair<>>& st, llint v, llint n) {
    for (llint i = (ST_SIZE >> 1) + Z.at(v); i > 0; i >>= 1) {
      st.at(i).first += n;
      st.at(i).second += v * n;
    }
  };
  auto culc_line = [&Z](const vector<pair<>>& st, llint v) {
    llint r = st.at((ST_SIZE >> 1) + Z.at(v)).second;
    for (llint i = (ST_SIZE >> 1) + Z.at(v); i > 1; i >>= 1) {
      r += i & 1 ? st.at(i ^ 1).first * v : st.at(i ^ 1).second;
    }
    return r;
  };
  update(st_a, 0, N);
  update(st_b, 0, M);
  vector<> result(Q);
  for (llint i = 0; i < Q; i++) {
    auto& t = (T.at(i) == 1 ? a : b).at(X.at(i));
    auto& st_x = T.at(i) == 1 ? st_a : st_b;
    auto& st_y = T.at(i) == 1 ? st_b : st_a;
    update(st_x, t, -1);
    result.at(i) = -culc_line(st_y, t);
    t = Y.at(i);
    update(st_x, t, 1);
    result.at(i) += culc_line(st_y, t);
  }
  for (llint i = 1; i < Q; i++) result.at(i) += result.at(i - 1);

  // output
  io::out(result, "\n");
}


	#include <bits/stdc++.h>
	#define ll long long int
	#define db double
	#define pb push_back
	#define mpr make_pair
	#define andl "\n"
	#define f first
	#define s second
	#define mset(x,y) memset(x,y,sizeof(x))
	#define fr(i,n) for(long long int i=0;i<n;i++)
	#define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++)
	#define mod 1000000007
	#define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0);
	#define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	using namespace std;

	// convert number to string to_string(x);
	// convert string to number stoi();

	// ll mulmod(ll x,ll y)
	// {
	//     return ((x%mod)*(y%mod))%mod;
	// }

	// ll ModInv(ll x, ll y)
	// {
	//     ll z = 1;
	//     while(y > 0)
	//     {
	//         if(y % 2 == 1)
	//             z = mulmod(z, x);
	//         x = mulmod(x, x);
	//         y /= 2;
	//     }
	//     return z;
	// }

	// ll ncr(ll n,ll r)
	// {
	//     return mulmod(fact[n],ModInv(mulmod(fact[n-r],fact[r]),mod-2));
	// }

	// ll pwr(ll n,ll m)
	// {
	//   if(n==1 || m==0)
	//     return 1;

	//   ll x=pwr(n,m/2);
	//   if(m%2==0)
	//     return x*x;
	//   else
	//     return n*x*x;
	// }

	// ll pwr(ll n,ll m,ll b)
	// {
	//   if(n==1 || m==0)
	//     return 1;

	//   ll x=pwr(n,m/2,b);
	//   if(m%2==0)
	//     return ((x%b)*(x%b))%b;
	//   else
	//     return ((n%b)*(((x%b)*(x%b))%b))%b;
	// }

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

		ll dp[31][31];

		fr(i,31)
		fr(j,31)
		{
			if(i==0 || j==0)
				dp[i][j]=1;
			else
				dp[i][j]=dp[i-1][j]+dp[i][j-1];
		}

		string s;

		while(a>0 && b>0)
		{
			if(dp[a-1][b]>=k)
				a--,s+='a';
			else
			{
				k-=dp[a-1][b];
				b--;
				s+='b';
			}
		}

		while(a--)
			s+='a';
		while(b--)
			s+='b';

		cout << s;

	  return ;
	}

	int main()
	{
	  fastio

	  ll t=1;
	  // cin >> t;

	  while(t--)
	    solve();

	  runtime
	}

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

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

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<ll,21> bt;
int N;
int A[606060];

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

	cin>>N;
	ll ret=0;
	FOR(i,N) {
		cin>>A[i];
		ret+=bt(N)-bt(A[i]);
		bt.add(A[i],1);
	}
	FOR(i,N) {
		cout<<ret<<endl;
		ret-=A[i];
		ret+=N-1-A[i];
	}

}

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


#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define all(x) x.begin(), x.end()
const int inf = 1e4;

void solve() {
   int n, m, u, v;
   cin >> n >> m;
   vector <vector <bool>> adj(n + 1, vector <bool> (n + 1));
   vector <int> dp(1 << n, n + 1);
   dp[0] = 0;
   for (int i = 0; i < m; i++) {
      cin >> u >> v;
      adj[u][v] = true;
      adj[v][u] = true;
   }
   for (int k = 1; k < (1 << n); k++) {
      dp[k] = 1;
      for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
            if ((k >> i) & (k >> j) & 1)
               if (adj[i + 1][j + 1] == false)
                  dp[k] = inf;
         }
   }
   for (int i = 0; i < (1 << n); i++) {
      for (int j = i; j > 0; j = (j - 1) & i) {
         dp[i] = min(dp[i], dp[j] + dp[i ^ j]);
      }
   }
   cout << dp[(1 << n) - 1] << '\n';

}

int main() {
#ifndef ONLINE_JUDGE
   freopen("E:\\inp.txt", "r", stdin);      freopen("E:\\outp.txt", "w", stdout);
#endif
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
   solve();

   return 0;
}

#include<bits/stdc++.h>
using namespace std;
template<typename T>inline bool read(T&x){
x=0;char c=getchar();int f=1;while(!isdigit(c)&&(c!='-')&&(c!=EOF))c=getchar();
if(c==EOF)return 0;if(c=='-')f=-1,c=getchar();
while(isdigit(c)){x=(x<<1)+(x<<3)+(c&15);c=getchar();}x*=f;return 1;
}template<typename T,typename...Args>inline bool read(T&x,Args&...args){bool res=1;res&=read(x);res&=read(args...);return res;}
typedef long long LL;typedef unsigned long long u64;typedef unsigned u32;typedef long double LD;
#define il inline
#define pln putchar('\n')
#define For(i,a,b)  for(int i=(a),(i##i)=(b);i<=(i##i);++i)
#define Rep(i,n)    for(int i=0,(i##i)=(n);i<(i##i);++i)
#define Fodn(i,a,b) for(int i=(a),(i##i)=(b);i>=(i##i);--i)
const int M=1000000007,INF=0x3f3f3f3f;const long long INFLL=0x3f3f3f3f3f3f3f3fLL;
const int N=111;

/*********************数论*********************/
inline LL mul(LL a,LL b,LL p){const LL res=a*b-((LL)((LD)a*b/p)*p);return res<0?res+p:(res<p?res:res-p);}
inline LL fp(LL a,LL b,LL Mod){LL res=(Mod!=1);for(;b;b>>=1,a=a*a%Mod)if(b&1)res=res*a%Mod;return res;}
inline LL fpl(LL a,LL b,LL Mod){LL res=(Mod!=1);for(;b;b>>=1,a=mul(a,a,Mod))if(b&1)res=mul(res,a,Mod);return res;}
template<typename T>inline T gcd(T a,T b){while(b){T t=b;b=a%b;a=t;}return a;}template<typename T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<typename T>inline T exgcd(T a,T b,T&x,T&y){T m=0,n=1,t;x=1,y=0;while(b){t=m,m=x-a/b*m,x=t;t=n,n=y-a/b*n,y=t;t=b,b=a%b,a=t;}return a;}
inline LL Crt(LL a1,LL a2,LL mod1,LL mod2){LL u,v;const LL g=exgcd(mod1,mod2,u,v);if((a2-a1)%g)return -1;
const LL m12=abs(lcm(mod1,mod2)),res=(mul(mod1,mul(u,((a2-a1)/g),m12),m12)+a1)%m12;return res<=0?res+m12:res;/*求最小正数解还是非负解*/}
/*********************数论*********************/
LL n,m,k,d[N];
struct Mat{
	LL a[N][N];
	Mat(){memset(a,0,sizeof a);}
	void set(){for(int i=1;i<=n;++i)a[i][i]=1;}
	Mat operator*(const Mat&b)const{
		Mat res;
		for(int i=1;i<=n;++i)for(int k=1;k<=n;++k)for(int j=1;j<=n;++j)res.a[i][j]=(res.a[i][j]+(a[i][k]*b.a[k][j])%M)%M;
		return res;
	}
	Mat pow(LL b)const{
		Mat a=(*this),res;
		for(res.set();b;b>>=1,a=a*a)if(b&1)res=res*a;
		return res;
	}
};

LL a[N],mp[N][N];

LL im;

inline void init(){
	read(n,m,k);im=fpl(2ll*m,M-2,M);
	For(i,1,n)read(a[i]);
	For(i,1,m){
		int u,v;read(u,v);mp[u][v]=1;mp[v][u]=1;++d[u];++d[v];
	}
	For(i,1,n)mp[i][i]=mul((2ll*m-d[i]),im,M);
	For(i,1,n)For(j,1,i-1){
		if(mp[i][j]==0)continue;
		mp[i][j]=mp[j][i]=im;
	}
}
LL ans[N];
inline void solve(){
	Mat f;
	For(i,1,n)For(j,1,n)f.a[i][j]=mp[i][j];
	f=f.pow(k);
	For(i,1,n)For(j,1,n)ans[i]=(ans[i]+mul(a[j],f.a[j][i],M))%M;
	For(i,1,n)ans[i]=(ans[i]+M)%M;
	For(i,1,n)printf("%lld\n",ans[i]);
}
signed main(){
	init();solve();
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int h, w;
string s[2000];
int a[2000][2000];
bool used[2000][2000];
int dp[2000][2000];
int INF = 1e+6;

//高橋君 - 青木君
int dfs(int y, int x) {
	if (y == h - 1 && x == w - 1) return 0;
	if (used[y][x]) return dp[y][x];

	int res;
	int mul = (y + x) % 2 ? -1 : 1;
	int ret = (mul == 1) ? -INF : INF;

	if (x < w - 1) {
		res = mul * a[y][x + 1] + dfs(y, x + 1);
		if (mul == 1) ret = max(res, ret);
		else ret = min(res, ret);
	}
	if (y < h - 1) {
		res = mul * a[y + 1][x] + dfs(y + 1, x);
		if (mul == 1) ret = max(res, ret);
		else ret = min(res, ret);
	}
	used[y][x] = true;
	return dp[y][x] = ret;
}

signed main() {
	int i, j;

	cin >> h >> w;
	rep(i, h) cin >> s[i];

	rep(i, h) rep(j, w) dp[i][j] = -1;
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '-') a[i][j] = -1;
			else a[i][j] = 1;
		}
	}

	int res = dfs(0, 0);
	//cout << "res = " << res << endl;

	if (res > 0) cout << "Takahashi" << endl;
	else if (res == 0) cout << "Draw" << endl;
	else cout << "Aoki" << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ull unsigned long long
#define lld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define f first
#define s second
#define mk make_pair

/*----------------------DEBUGGER---------------------------*/
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.f); cerr << ","; _print(p.s); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
/*----------------------DEBUGGER---------------------------*/

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  int tt = 1;
  //cin >> tt;
  while (tt--)
  {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    if (n == 1) {
      cout << a[0];
      return 0;
    }
    ll dp[n][2];
    ll num[n][2];
    memset(dp, 0, sizeof(dp));
    memset(num, 0, sizeof(num));
    ll mod = 1e9 + 7;
    dp[1][0] = (a[0] + a[1]) % mod;
    dp[1][1] = (a[0] - a[1] + mod) % mod;
    num[1][0] = 1;
    num[1][1] = 1;
    for (int i = 2; i < n; i++)
    {
      dp[i][0] = (dp[i - 1][0] + (num[i - 1][0] * a[i]) % mod + dp[i - 1][1] + (num[i - 1][1] * a[i]) % mod) % mod;
      dp[i][1] = (dp[i - 1][0] - (num[i - 1][0] * a[i]) % mod + mod) % mod;
      num[i][0] = (num[i - 1][0] + num[i - 1][1]) % mod;
      num[i][1] = num[i - 1][0];
    }
    for (int i = 1; i < n; i++)
    {
      debug(dp[i][0]);
      debug(dp[i][1]);
    }
    cout << (dp[n - 1][0] + dp[n - 1][1]) % mod;
  }//while
}//main


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#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 eb emplace_back

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

void Main(){
    int n; cin >> n;
    set<int> st;
    rep3(i, 0, 200005) st.insert(i);
    rep(i, n){
        int p; cin >> p;
        if(st.find(p) != st.end()) st.erase(p);
        cout << *st.begin() << endl;
    }
    return;
}

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

// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii         pair<int,int>
#define psi         pair<string,int>
#define vi          vector<int>
#define vpii        vector<pii>
#define vvi         vector<vi>
#define sz(x)       (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n)     fixed<<setprecision(n)
#define ini(a, i)   memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;

#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
 cout << "[" << *it << ": " << a << "]\t";
 err(++it, args...);
}

// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

// Code from Here -------------------------------------------------------------------------------

void solver(){
    int n, p;
    cin >> n;
    int c = 0;
    map<int,int> mp;
    for(int i=0; i<n; i++){
        cin >> p;
        mp[p]++;
        while(mp[c]){
            c++;
        }
        cout << c << endl;
    }
}

signed main() {
    tezz

    int t=1;
    // cin >> t;
    while(t--){
        solver();
    }

    return 0;
}


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

int main(){
int64_t a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a==c&&b==d){cout<<0<<endl;}
  else if(a+b==c+d||a-b==c-d||abs(a-c)+abs(b-d)<=3){cout<<1<<endl;}
  else if((a+b-c-d)%2==0||abs(a-c)+abs(b-d)<=6||abs(a+b-c-d)<=3||abs(a-b-c+d)<=3)
          {cout<<2<<endl;}
  else{cout<<3<<endl;}
}

#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;

    r2 -= r1;
    c2 -= c1;

    ll rc = abs(c2 - r2);
    ll cr = abs(r2 - c2);

    if(r2 == 0 && c2 == 0){
        pr(0);
        return 0;
    }else if((abs(r2)+abs(c2)<=3) || (abs(r2)==abs(c2))){
        pr(1);
        return 0;
    }else{
        if((abs(r2)+abs(c2)<=6) ||  ((abs(r2)+abs(c2))%2)==0){
            pr(2);
            return 0;
        }
        for(int i = -3; i <=3 ; i++) for(int j = -3; j <=3 ; j++){
            if(abs(i)+abs(j) > 3) continue;
            ll tr = r2 - i;
            ll tc = c2 - j;
            if(abs(tr)==abs(tc)){
                pr(2);
                return 0;
            }
        }
    }
    pr(3);
}


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

const int P = 998244353;
//const int P = 1e9 + 7;
//const int P = 1e9 + 9;
int mul(const int &x, const int &y) { return 1ll * x * y % P; }
int qpow(int x, int y) {
	if (y < 0) {
		y += P - 1;
	}
	int r = 1;
	while (y) {
		if (y & 1) {
			r = mul(r, x);
		}
		x = mul(x, x);
		y /= 2;
	}
	return r;
}
int inc(const int &x, const int &y) {
	if (x + y >= P) {
		return x + y - P;
	} else {
		return x + y;
	}
}
int sub(const int &x, const int &y) {
	if (x < y) {
		return x - y + P;
	} else {
		return x - y;
	}
}

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

	int t;
	cin >> t;
	while (t--) {
		std::string s;
		cin >> s;
		int n = (int)s.size();
		std::string t = "atcoder";
		if (s > t) {
			cout << 0 << '\n';
			continue;
		}
		bool flag = true;
		for (int i = 0; i < n; i++) {
			if (s[i] != 'a') {
				flag = false;
			}
		}
		if (flag) {
			cout << -1 << '\n';
			continue;
		}
		int ans = n + 1;
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			std::string temp = s;
			for (int j = i; j >= 1; j--) {
				swap(temp[j], temp[j - 1]);
				++cnt;
				if (cnt >= ans) {
					break;
				}
				if (temp > t) {
					ans = cnt;
					break;
				}
			}
			cnt = 0;
			temp = s;
			for (int j = i; j < n - 1; j++) {
				swap(temp[j], temp[j + 1]);
				++cnt;
				if (cnt >= ans) {
					break;
				}
				if (temp > t) {
					ans = cnt;
					break;
				}
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#pragma region DEBUG
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef
tree<
  pair<int,int>,
  null_type,
  less<pair<int,int>>,
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
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
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
vector <lli> fact(MAX,1);
vector <lli> invfact(MAX,1);
lli n;
vector <lli> arr;
lli dp[3005][3005];
map <lli, vector<vector<lli> >> adj;
vector <lli> pre;
lli ctr = 0;
lli f(lli idx, lli head){
    if(head > n)
        return 0;
    if(idx == n+1)
        return 1;
   // debug("Yeet");

    if(dp[idx][head] != -1)
        return dp[idx][head];
    lli ans = 0;
    lli sum = 0;
    lli prefsum = pre[idx-1]%head;
    for(auto i : adj[head][prefsum]){
        if(i >= idx){
            if(i+1 == n+1){
                ans += 1;
            }
            else{
                ans += f(i+1,head+1);
                ans += f(i+1,head);
            }
            break;
        }
    }
    ans %= MOD;
    //debug(idx,head,ans);
    //debug(ans);
    return dp[idx][head] = ans;
}
void solve(){
    cin>>n;
    arr.resize(n);
    pre.resize(n+1,0);
    for(lli i = 0; i<=n+1; i++){
        for(lli j = 0; j<=n+1; j++){
            dp[i][j] = -1;
        }
    }
    for(lli i = 0; i<n; i++){
        cin>>arr[i];
        pre[i+1] = pre[i] + arr[i];
    }
    for(lli head = 1; head <=n; head++){
        adj[head].resize(head);
        lli sum = 0;
        adj[head][0].push_back(0);
        for(lli i = 0; i<n; i++){
            sum += arr[i];
            sum %= head;
            adj[head][sum].push_back(i+1);
        }
    }
  //  debug("Yoot");
    //debug(adj[1]);
    lli valx = f(1,1);
    cout<<valx<<endl;
}
int main(){
    /* freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout); */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   /*  for(lli i = 1; i<MAX-5; i++){
        fact[i] = i*fact[i-1]%MOD;
        invfact[i] = binpow(fact[i],MOD-2);
    } */
    lli t;
    t = 1;
    //cin>>t;
    lli p = 0;
    while(t--){
        p++;
        solve();
    }
}


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

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;

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

    ll a,b;
    cin >> a >> b;

    cout << (a+b)/2 << " " << (a-b)/2 << endl;
}

#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <regex>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using dl = long double;
using P  = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    ll sum = 0;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        sum += a;
        v[i] = a + a + b;
    }
    sort(v.begin(), v.end());
    int ans = 0;
    while (sum >= 0) {
        sum -= v.back();
        v.pop_back();
        ans++;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#include <math.h>
#define REP(i,a,b) for (int i=a; i<b; i++)
#define ALL(v) (v).begin(), (v).end()
#define FORE(i,a) for(auto &i:a)
using namespace std;
typedef long long ll;
const ll infl = 1LL << 60;
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; }
//#pragma GCC optimize ("-O3")
void _main(); int main() {cin.tie(0); ios::sync_with_stdio(false); _main(); }

void _main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i,0,N) cin >> A[i];

  ll ans = 0;
  ll every_sum = 0;
  ll sq_sum = 0;
  REP(i,0,N) {
    every_sum += A[i]*A[i];
    sq_sum += A[i];
  }

  ans = N*every_sum - sq_sum*sq_sum;

  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  ll N;
  cin >> N;
  vector<string> vec(N);
  rep(i, N) {
    cin >> vec.at(i);
    if(vec.at(i).at(0) != '!') {
      vec.at(i) = "!" + vec.at(i) + "&";
    }
  }
  ll co = -1;
  sort(vec.begin(), vec.end());
  rep(i, N - 1) {
    if(vec.at(i) != vec.at(i+1) && vec.at(i) + "&" == vec.at(i+1)) {
      co = i;
      break;
    }
  }
  if(co == -1) {
    cout << "satisfiable";
  }
  else {
    cout << vec.at(co).substr(1);
  }
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素  //遅延セグ木使うときは注意
#define S second //pairの二つ目の要素  //遅延セグ木使うときは注意
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;//10の18乗
#define yn {puts("Yes");}else{puts("No");}
#define dame { puts("-1"); return 0;}

int main() {
    ll a,b;
    cin >> a >> b;
    long double x=a;
    x*=b;
    x/=100;
    cout << fixed << setprecision(15);
    cout << x << endl;
}

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

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

using Graph = vector<vector<int>>;

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

	float ret = b / 100 * a;
	cout << ret << endl;

	return 0;
}


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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define VEC(n, x) VI n; n.resize(x); rep(i, x) cin >> n[i];
#define MAT(m, x, y) VVI m; m.resize(x); rep(i, x) m[i].resize(y);
#define out(x) cout << (x) << endl;

int main () {
  int N; cin >> N;
  VI x(N), y(N); rep(i, N) cin >> x[i] >> y[i];

  rep(i, N) rep(j, N) rep(k, N) {
    if (i == j || i == k || j == k) continue;

    if ((x[i] == x[j] && x[i] == x[k]) || (y[i] == y[j] && y[i] == y[k])) {
      out("Yes")
      return 0;
    }

    double a = (y[j] - y[i]) * (x[k] - x[i]) / (double)(x[j] - x[i]) + y[i];;
    if ((double)y[k] == a) {
      out("Yes")
      return 0;
    }
  }

  out("No");
  return 0;
}

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

int n; vector<int> ans;

const int MAX=5e2+7;

int s[MAX],p[MAX];

void opt (int pos) {
	swap(p[s[pos]],p[s[pos+1]]);
	swap(s[pos],s[pos+1]);
	ans.push_back(pos);
	return;
}

void solve (int p1,int p2,int p3) {
	while (!(s[p1]<s[p2]&&s[p2]<s[p3])) {
		if (ans.size()%2==p1%2) opt(p2);
		else opt(p1);
	} return;
}

void solve () {

	scanf("%d",&n); ans.clear();
	for (int i=1;i<=n;i++)
		scanf("%d",&s[i]),p[s[i]]=i;

	if (n==1) { puts("0"); return; }
	if (n==2) {
		if (s[1]>s[2]) puts("1"),puts("1");
		else puts("0");
		return;
	}
	if (n==3) solve(1,2,3);

	const int odd=n&1?n-2:n-1;
	const int eve=n&1?n-1:n-2;

	for (int i=1;i<=n-3;i++) {
		rst:
		if (p[i]&1) {
			if (ans.size()%2==0)
				{ opt(odd); goto rst; }
			for (int t=p[i]-1;t>=i;t--)
				opt(t);
		} else {
			if (ans.size()%2==1)
				{ opt(eve); goto rst; }
			for (int t=p[i]-1;t>=i;t--)
				opt(t);
		}
	}

	solve(n-2,n-1,n);

	printf("%d\n",ans.size());
	for (auto cur:ans)
		printf("%d ",cur);
	printf("\n");

	return;

}

int main () {

	int T; scanf("%d",&T);
	while (T--) solve();

	return 0;
}


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

int main(){
    string s; cin >> s;
    int n = s.size();
    int ans = 0;
    for(int i = 1; i <= (n-1)/2; i++){
        ans += 9*pow(10,i-1);
    }
    if(n%2 == 0){
        string sl = s.substr(0,n/2);
        string sr = s.substr(n/2);
        ans += stoi(sl)-pow(10,n/2-1)+1;
        if(sl > sr) ans--;
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
using namespace std;
void solve()
{
    ull MAX = 1e18;//((ull)1)<<60;
    //cerr<<MAX<<endl;
    ull n;
    cin>>n;
    vector<ull> P3, P5;
    ull z = 3;
    while(z<MAX) {
        P3.push_back(z);
        z*=3;
    }
    z = 5;
    while(z<MAX) {
        P5.push_back(z);
        z*=5;
    }
    for(int i=0; i<P3.size(); ++i)
        for(int j=0; j<P5.size(); ++j)
            if(P3[i]+P5[j] == n){
                cout<<(i+1)<<" "<<(j+1)<<endl;
                return;
            }
    cout<<-1<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int T = 1;
    //cin>>T;
    while(T--)
        solve();

	return 0;
}


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

// 二次元幾何は複素数で考えると楽になるかもしれない

using C = complex<double>;
C inC() {
  double x, y;
  cin >> x >> y;
  return C(x, y);
}

int main() {
  int n;
  cin >> n;
  C s = inC();
  C t = inC();

  C o = (s + t) / 2.0;
  double PI = acos(-1);
  double rad = 2 * PI / n;
  C r(cos(rad), sin(rad));
  C ans = o + (s - o) * r;

  printf("%.10f %.10f\n", ans.real(), ans.imag());
  return 0;
}

#include <iostream>
using namespace std;
int main()
{
    int a,b,temp1[3],temp[3];
    cin>>a>>b;
    temp[0]=a%10;
    a=a/10;
    temp[0]+=a%10;
    a=a/10;
    temp[0]+=a%10;
    a=temp[0];

    temp[1]=b%10;
    b=b/10;
    temp[1]+=b%10;
    b=b/10;
    temp[1]+=b%10;
    b=temp[1];
    if(a>=b)
    cout<<a;
    else if(b>a)
   cout<<b;
}


#include<iostream>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

using namespace std;
typedef long long ll;

const int MAXN=1e5+5;

int ok(int n, int base) {
    while(n) {
        if(n%base == 7) return 0;
        n/=base;
    }
    return 1;
}
int main() {
    FAST;
    int n; cin>>n;
    int ans=0;
    for(int i=1;i<=n;++i) {
        if(ok(i, 8) && ok(i, 10)) ++ans;
    }
    cout<<ans<<endl;
}

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

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

  cout << N - 1;
}


#include <bits/stdc++.h>

#define ll long long
#define endl '\n'

using namespace std;

void solve(){
   ll s,p;
   cin>>s>>p;
   for(ll i = 1;i*i<=p;i++){
       if(p % i == 0){
           if(i + p/i == s){
               cout<<"Yes";
               return;
           }
       }
   }
   cout<<"No";
}

int main(){
    int t = 1;
    while(t--)
        solve();
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

int main() {
  ll s,p;cin >> s >> p;

  if(1+p == s){
    cout << "Yes" << endl;
    return 0;
  }

  bool isok = false;
  for(ll n=1;n*n<=p; n++){
    if(p%n == 0){
      ll m = p/n;
      if(n+m == s) isok = true;
    }
  }
  if(isok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

void solve() {
    int h, w;
    cin>>h>>w;
    vector<string> grid(h);
    for(auto &i : grid) {
        cin>>i;
    }
    vector<vector<int>> dp(h, vector<int> (w, -1e9));
    for(int i=h-1; i>=0; i--) {
        for(int j=w-1; j>=0; j--) {
            if(i+1<h) {
                int option=-dp[i+1][j];
                if(grid[i+1][j]=='+') {
                    option++;
                } else {
                    option--;
                }
                dp[i][j]=max(dp[i][j], option);
            }
            if(j+1<w) {
                int option=-dp[i][j+1];
                if(grid[i][j+1]=='+') {
                    option++;
                } else {
                    option--;
                }
                dp[i][j]=max(dp[i][j], option);
            }
            if(i==h-1 && j==w-1) {
                dp[i][j]=0;
            }
        }
    }
    string ans="Takahashi";
    if(dp[0][0]<0) {
        ans="Aoki";
    } else if(dp[0][0]==0) {
        ans="Draw";
    }
    cout<<ans<<endl;
    return;
}

int main() {
#ifdef bipinpathak
    (void)!freopen("input.txt", "r", stdin);
    (void)!freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    auto start=clock();
    int t = 1;
    //cin>>t;
    for(int i=0; i<t; i++) {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    double used= (double) (clock()-start);
    used=(used*1000)/CLOCKS_PER_SEC;
    cerr<<fixed<<setprecision(2)<<used<<" ms"<<endl;
    return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e12;
#define D long double
#define NeedForSpeed ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int MOD = 1000000007;
#define fi first
#define se second
#define endl '\n'
// random_device rd;
// mt19937 rng(rd());
// int getRand(int l,int r){ // get random number in the range [l,r]
//   uniform_int_distribution<int> uid(l,r);
//   return uid(rng);
// }
const int N = 1e5 + 10;
int n , m ;
vector<string> a;
int dp[2001][2001][2]={0};
bool vis[2001][2001][2] = {0};

int rec(int i , int j , int z){
   if(i==n-1 && j==m-1)return 0;
   int & ans = dp[i][j][z];
   if(vis[i][j][z])return ans;
   vis[i][j][z] = 1;
   if(z==0){
     ans = -inf;
     if(j+1 < m) ans = max(ans,rec(i,j+1,1)+(a[i][j+1]=='+')-(a[i][j+1]=='-'));
     if(i+1 < n) ans = max(ans,rec(i+1,j,1)+(a[i+1][j]=='+')-(a[i+1][j]=='-'));
   }else{
     ans = inf;
     if(j+1 < m) ans = min(ans,rec(i,j+1,0)-(a[i][j+1]=='+')+(a[i][j+1]=='-'));
     if(i+1 < n) ans = min(ans,rec(i+1,j,0)-(a[i+1][j]=='+')+(a[i+1][j]=='-'));
   }
   return ans;
}

void go(){
   cin >> n >> m ;
   a.resize(n);
   for(int i = 0 ; i < n ; i++)cin >> a[i];
   memset(dp,-1,sizeof(dp));
   int ans = rec(0,0,0);
   if(ans > 0)cout << "Takahashi" << endl;
   else if(ans < 0)cout << "Aoki" << endl;
   else  cout << "Draw" << endl;
}

signed main() {
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        NeedForSpeed
        int t = 1;
        cout << fixed << setprecision(12) ;
        // cin >> t;
        while(t--){
            // cout << "Case #" << cases << ": ";
            go();
        }

}


#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n,m;
	cin >> n;
	vector<vector<int>> x(n);
	rep(i, n){
      	rep(j, n) {
			cin >> m;
          	x[i].push_back(m);
        }
	}
  	if(n==1) {
    	cout << "Yes" << endl;
      	cout << x[0][0] << endl << 0 << endl;
      	return 0;
    }
  	vector<int> hor(n-1);
  	vector<int> ver(n-1);
  	long long a=0, b=0, minA=0, minB=0;
  	rep(i, n-1) {
    	hor[i] = x[0][i+1] - x[0][i];
      	ver[i] = x[i+1][0] - x[i][0];
      	a += hor[i];
      	b += ver[i];
      	if(a<minA) minA=a;
      	if(b<minB) minB=b;
    }
  	rep(i, n-1) {
    	rep(j, n-1) {
        	if(x[i+1][j+1] - x[i+1][j] != hor[j]) {
            	cout << "No" << endl;
            	return 0;
            }
        	if(x[i+1][j+1] - x[i][j+1] != ver[i]) {
            	cout << "No" << endl;
            	return 0;
            }
        }
    }
	cout << "Yes" << endl;
    int A, B;
  	if(minB<0 && minB < minA) {
      A = -minB;
  	  B = x[0][0] - A;
    } else if(minA<0) {
      B = -minA;
      A = x[0][0] - B;
    } else {
    	A = x[0][0]/2;
      B = x[0][0] - A;
    }

  cout << A;
	rep(i, n-1) {
      	A += ver[i];
      	cout << " " << A;
    }
  	cout << endl << B;
  	rep(i, n-1) {
      	B += hor[i];
      	cout << " " << B;
    }
  	cout << endl;
}

/**
 * author: said_v15
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

typedef long long  ll;

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++)
#define pb push_back
#define sc second
#define f first
#define kek cout<<"\n";
#define fla cout<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end())
// #define int ll

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int MAXN = 200100;
const int INF = 1e8;
const ll LL_INF=1e18;
const double pi=3.1415926535;

int divide(int a, int b)
{
          return (a+b-1)/b;
}

int32_t main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 fast;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";

 int questions=1;
 // cin>>questions;
 while(questions--)
 {
          string s;
          cin>>s;
          int ans=INF;
          int n=s.size();
          for(int i=0;i<(1<<n);i++)
          {
                    int sum=0;
                    int cnt=0;
                    bool ok=false;
                    for(int j=0;j<n;j++)
                    {
                              if(i&(1<<j))
                              {
                                  sum+=(s[j]-'0');
                                  cnt++;
                                  ok=true;
                              }
                    }
                    if(ok && sum%3==0)
                    {
                              ans=min(ans, n-cnt);
                    }
          }
          if(ans==INF) cout<<-1;
          else cout<<ans;

 }

 // !!! LOOK AT NUMBER OF QUESTIONS IN A PROBLEM !!! (cin>>questions)

  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;

}


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

int a[100010], b[100010];
map <int, vector <int> > all;
map <int, int> cnt, sum;

int main () {
	int n, L; scanf("%d%d", &n, &L);
	a[0] = 0, a[n + 1] = L + 1;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i <= n + 1; i++) {
		all[a[i] - i].push_back(i);
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &b[i]);
		b[i] -= i;
		if (!all.count(b[i])) {
			printf("-1\n");
			return 0;
		}
		vector <int> &tmp = all[b[i]];
		int pos = lower_bound(tmp.begin(), tmp.end(), i) - tmp.begin();
		int p = 0x3f3f3f3f;
		if (pos != tmp.size()) {
			if (abs(p - i) > abs(tmp[pos] - i)) p = tmp[pos];
		}
		if (pos) {
			pos--;
			if (abs(p - i) > abs(tmp[pos] - i)) p = tmp[pos];
		}
		if (p > i) cnt[b[i] * 2]++, sum[b[i] * 2] = max(sum[b[i] * 2], abs(p - i));
		else if (p < i) cnt[b[i] * 2 + 1]++, sum[b[i] * 2 + 1] = max(sum[b[i] * 2 + 1], abs(p - i));
	}
	for (map <int, int> :: iterator it = cnt.begin(); it != cnt.end(); it++) {
		int x = it->first;
		ans += sum[x];
	}
	printf("%lld\n", ans);
	return 0;
}

/*
 * @Author: zhl
 * @LastEditTime: 2021-02-13 22:14:39
 */
#include<bits/stdc++.h>
using namespace std;

const int N = 2e3 + 10;
typedef long long ll;

char mp[N][N];
int n,m;
vector<int>G[N];
int fa[N];
int find(int a){
    return a == fa[a] ? a : fa[a] = find(fa[a]);
}
void merge(int a,int b){
    a = find(a);b = find(b);
    if(a != b)fa[a] = b;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n;i++)scanf("%s",mp[i] + 1),fa[i] = i;

    merge(1,n);

    for(int j = 1;j <= m;j++){
        for(int i = 1;i <= n;i++){
            if(mp[i][j] == '#')G[j].push_back(i);
        }
        int sz = G[j].size();
        if(G[j].empty())continue;

        for(int ii = 1;ii < sz;ii++){
            merge(G[j][ii], G[j][0]);
        }
        if(j == 1 or j == m)merge(G[j][0],1);
    }

    set<int>rt;
    for(int i = 1;i <= n;i++)rt.insert(find(i));

    int ans = rt.size() - 1;

    for(int i = 1;i <= m;i++)fa[i] = i;
    merge(1,m);

    for(int i = 1;i <= n;i++){
        G[i].clear();
        for(int j = 1;j <= m;j++){
            if(mp[i][j] == '#')G[i].push_back(j);
        }
        int sz = G[i].size();
        if(G[i].empty())continue;

        for(int ii = 1;ii < sz;ii++){
            merge(G[i][ii], G[i][0]);
        }
        if(i == 1 or i == n)merge(G[i][0],1);
    }
    rt.clear();
    for(int i = 1;i <= m;i++)rt.insert(find(i));
    cout << min(ans,int(rt.size()) - 1) << endl;

}


// abc203_c
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e15)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N, K;
    cin >> N >> K;
    vector<P> AB(N);
    REP(i, N) cin >> AB[i].first >> AB[i].second;
    sort(ALL(AB));

    ll now = 0;
    REP(i, N){

        ll d = AB[i].first - now;

        if (K >= d){
            K += AB[i].second - d;
            now += d;
        } else {
            now += K;
            K = 0;
            break;
        }
    }
    now += K;
    print(now);

    return 0;
}

/* code by savagecarol */
#include <bits/stdc++.h>
using namespace std;

/* predefined value */
#define yes() cout << "YES"
#define no() cout << "NO"
#define one() cout << "1"
#define zero() cout << "0"
#define ll long long int
#define mp make_pair
#define fi first
#define se second
#define pb push_back

/* loops */
#define inp(i,n,arr) for(ll i=0 ; i<n ; i++) cin >> arr[i]
#define out(i,n,arr) for(ll i=0 ; i<n ; i++) cout << arr[i] << " "
#define loop(i,n) for(ll i=0;i<n;i++)
#define arrs(i,n,arr,sum) for(ll i = 0 ; i < n ; i++) sum = sum + arr[i];
#define arrmax(i , n , arr , maxx) for(ll i = 1 ; i < n;i++) maxx = max(maxx , arr[i]);
#define arrmin(i , n , arr , minn) for(ll i = 0 ; i < n;i++) minn = min(minn , arr[i]);

/* typedef */
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll mod = 1e9 + 7;
/* power function */
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int countSetBits(int n){
    unsigned int count = 0;
    while (n) {
        n &= (n - 1);
        count++;
        }
    return count;
}
int powerOfTwo(int n){
        return n && (!(n & (n-1)));
    }
/*code*/
void solve()
{
    ll n , k;
    cin >> n >> k;
    vector<pair<ll , ll>> a;
    ll x, y;
    for(ll i = 0 ; i < n;i++)
    {
        cin >> x >> y;
        a.push_back({x , y});
    }
    sort(a.begin(), a.end());
    ll i = 0;
    while(i < n)
    {
        if(k>=a[i].first)
            {
                k=k+a[i].second;
                i++;
            }
        else  break;
    }
    cout << k;
}
int main()
{
    solve();
	return 0;
}


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

int main() {
    int N, max = 0;
    bool sin = true;
    cin >> N;
    int a[N];
    for (int i=0; i<N; i++){
        cin >> a[i];
        if (max < a[i])
            max = a[i];
        if (i>0 && a[i-1] != a[i])
            sin = false;
    }

    if (sin){
        cout << a[0] << endl;
        return 0;
    }

    int k = max / 2;
    int count = 0;
    while(true){
        for (int i=0; i<N; i++){
            if (a[i] % k != 0){
                count += 1;
                break;
            }
        }
        if (count == 0){
            cout << k << endl;
            return 0;
        }
        k -= 1;
        count = 0;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//(double)clock() / CLOCKS_PER_SEC;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    set<int> s;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        s.insert(x);
    }
    while(s.size()>1)
    {
        auto it=s.end();
        it--;
        int v=(*it);
        int mini=*(s.begin());
        s.erase(v);
        s.insert(v-mini);
    }
    cout<<(*s.begin())<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(c%2==0)
	{
		if(abs(a)>abs(b)) cout<<">";
		if(abs(a)==abs(b)) cout<<"=";
		if(abs(a)<abs(b)) cout<<"<";
	}
	else
	{
		if(a>b) cout<<">";
		if(a==b) cout<<"=";
		if(a<b) cout<<"<";
	}
	return 0;
}

/*
    author : aryan57
    created : 13-June-2021 17:33:20 IST
*/
#include <bits/stdc++.h>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
// const int32_t M = 998244353;
const long double pie = acos(-1);

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

    if(c%2==0)
    {
        if(abs(a)==abs(b))
        {
            cout<<"=";
            return;
        }
        if(abs(a)>abs(b))
        {
            cout<<">";
            return;
        }
        if(abs(a)<abs(b))
        {
            cout<<"<";
            return;
        }
    }

    if(a<0 && b>=0)
    {
        cout<<"<";
        return;
    }
    if(a<0 && b<0)
    {
        if(abs(a)==abs(b))
        {
            cout<<"=";
            return;
        }
        if(abs(a)>abs(b))
        {
            cout<<"<";
            return;
        }
        if(abs(a)<abs(b))
        {
            cout<<">";
            return;
        }
    }

    if(a>=0 && b>=0)
    {
        if(abs(a)==abs(b))
        {
            cout<<"=";
            return;
        }
        if(abs(a)>abs(b))
        {
            cout<<">";
            return;
        }
        if(abs(a)<abs(b))
        {
            cout<<"<";
            return;
        }
    }
    if(a>=0 && b<0)
    {
        cout<<">";
        return;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    // cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOG();
    }
    return 0;
}
//	parsed : 13-June-2021 17:33:16 IST


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

void solve(int _rot){
   // printf("Case #%d: ",_rot);
   int n;
   cin>>n;
   vector<int> a(n);
   rep(i,0,n)cin>>a[i];
   if(n==2){
      if(a[0]!=1){
         puts("1\n1");
      }
      else{
         puts("0");
      }
      return;
   }

   map<int,int> pos;
   rep(i,0,n)pos[a[i]]=i;
   vector<int> res;
   auto process=[&](int i){
      res.push_back(i+1);
      swap(a[i],a[i+1]);
      swap(pos[a[i]],pos[a[i+1]]);
   };

   bool flip=1;
   rep(i,0,n-3){
      int from=pos[i+1];
      if(flip+(from&1)==1){ //not match
         int to;
         if(from>=n-2){
            to=i/2*2;
            if(!flip)to++;
            if(to<i)to+=2;
            if(to==from or to==from-1)to+=2;
         }
         else{
            to=n/2*2;
            if(!flip)to++;
            while(to>=n-1)to-=2;
            if(to==from or to==from-1)to-=2;
         }
         process(to);
         flip^=1;
      }
      {
         while(from>i){
            process(from-1);
            from--;
            flip^=1;
         }
      }
   }
   for(;;){
      int from;
      if(flip)from=n/2*2-2;
      else from=n/2*2-1;
      if(from==n-1)from-=2;
      process(from);
      if(a[n-3]==n-2 and a[n-2]==n-1 and a[n-1]==n)break;
      flip^=1;
   }

   cout<<res.size()<<'\n';
   for(auto& x:res)cout<<x<<'\n';
}

int main(){
   int t; scanf("%d",&t);
   rep(rot,0,t)solve(rot+1);
   return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    vector<int> inv(n);
    rep(i,n){
        inv[a[i]] = i;
    }
    vector<int> res;
    int k = 0;
    rep(i,n){
        while(k!=n&&inv[k]==k){
            k++;
        }
        if(k==n)break;
        res.push_back(inv[k]-1);
        int id = inv[k]-1;
        swap(a[id],a[id+1]);
        inv[a[id]] = id;
        inv[a[id+1]] = id+1;
    }
    bool ok = 1;
    rep(i,n){
        if(a[i]!=i)ok = 0;
    }
    if(ok&&(int)res.size()==n-1){
        rep(i,n-1){
            cout << res[i]+1 << "\n";
        }
    }else{
        cout << -1 << endl;
    }
    return 0;
}


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

typedef long long LL;
const int N = 100010;
int a[N], b[N], c[N], d[N];
int n, l;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> l;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];
    a[n + 1] = l + 1;
    b[n + 1] = l + 1;
    for (int i = 0; i <= n; i++) {
        c[i] = a[i + 1] - a[i] - 1;
        d[i] = b[i + 1] - b[i] - 1;
    }

    LL ans = 0;
    for (int i = 0, j = 0; i <= n; i++) {
        if (d[i]) {
            while (j <= n && c[j] == 0) j++;
            int l = j, s = 0;
            while (j <= n && s < d[i])
                s += c[j++];
            if (s != d[i]) {
                puts("-1");
                return 0;
            }
            ans += max(i - l, 0) +  max(j - 1 - i, 0);
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ll = long long;
const int inf = 1e9+5;
const ll INF = 1e18+5;
const int nax = 2e5+500;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<vector<int>> g(h+1, vector<int> (w+1));
	for(int i=1;i<=h;i++) {
		for(int j=1;j<=w;j++) {
			char ch;
			cin >> ch;
			g[i][j] = (ch == '+'?1:-1);
		}
	}
	vector<vector<int>> dp(h+2, vector<int> (w+2));
	for(int i=h;i>=1;--i) {
		for(int j=w;j>=1;--j) {
		if(i == h && j == w) dp[i][j] = 0;
			else if((i + j) % 2 == 0) {
					dp[i][j] = -(1 << 30);
					if(i + 1  <= h) dp[i][j] = max(dp[i][j], dp[i+1][j] + g[i+1][j]);
					if(j + 1 <= w) dp[i][j] = max(dp[i][j], dp[i][j+1] + g[i][j+1]);
			} else {
					dp[i][j] = (1 << 30);
					if(i+1 <= h) dp[i][j] = min(dp[i][j], dp[i+1][j] - g[i+1][j]);
					if(j+1 <= w) dp[i][j] = min(dp[i][j], dp[i][j+1] - g[i][j+1]);
			}
		}
	}
	if((h == 1 && w == 1) || dp[1][1] == 0) cout << "Draw";
	else cout << (dp[1][1] > 0 ? "Takahashi":"Aoki");

}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//turn on extra precision
//#pragma GCC target("fpmath=387")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout << (#x) << " is : " << (x) << newl

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vi dirx = {0,0,1,-1};
vi diry = {1,-1,0,0};
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122) return char(x-32);
    if( 65 <= int(x) && int(x) <= 90) return x;
    return -1;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122) return x;
    if( 65 <= int(x) && int(x) <= 90) return char(x+32);
    return -1;
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57) return int(x-'0');
    if(97 <= int(x) && int(x) <= 122) return int(x-96);
    if(65 <= int(x) && int(x) <= 90) return int(x-64);
    return -1;
}
bool isect (int l1, int r1, int l2, int r2){ return max(l1,l2) <= min(r1,r2); }
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1%MOD;
    else if(num2==1)return num1%MOD;
    else{
        ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template

int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

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

    string s; cin >> s;
    string res = "";
    for(auto i : s) {
        if(i == '.') break;
        res += i;
    }
    cout << res << newl;

    return 0;
}

#include <bits/stdc++.h>

#define Vanya Unstoppable

#define int long long

#define pb push_back
#define ll long long
#define pii pair<int, int>
#define all(a) a.begin(), a.end()

#define TESTS 0

typedef long double ld;

using namespace std;

void solve() {
    string a;
    cin >> a;
    int n = a.size();
    for (int i = 0; i < n; ++i) {
        if (a[i] == '.') break;
        cout << a[i];
    }
//    int pos = n;
//    for (int i = 0; i < n; ++i) {
//        if (a[i] == '.') pos = i;
//    }
//    int to = pos - 1;
//    int ans = 0, t = 1;
//    while (to >= 0) {
//        ans += (a[to] - '0') * t;
//        t *= 10; --to;
//    }
//    bool f = false;
//    for (int i = pos + 1; i < n; ++i) {
//        int to = a[i] - '0';
//        int del = 5 - to;
//        if (del == 1) {
//            f = true;
//        } else {
//            if (del >= 0) {
//                ++ans;
//                break;
//            } else {
//                break;
//            }
//        }
//    }
}

signed main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int q = 1;
#if TESTS
    cin >> q;
#endif

    while (q--) {
        solve();
    }
}


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

int main(){
    int n, ans = 0;
    cin >> n;
    int sum = 0;
    for(int i = 1; 1;++i){
	if(sum >= n){
	    ans = i - 1;break;
	}
	sum+=i;
    }
    cout << ans << '\n';
}

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i;++i)if(i*(i+1)/2>=n){printf("%d",i);return 0;}
	return 0;
}


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

#define co(n) cout<<n<<endl;
const double eps=1e-10,pi=3.1415926535898;
const int mod=1e9+7,maxn=410;
int T,n,m,k,x,y;
long long dp[maxn][maxn];

void init() {
	for (int i=0;i<maxn;++i) {
		dp[i][0] = dp[i][i] = 1;
	}
	for (int i=2;i<maxn;++i) {
		for (int j=1;j<i;++j) {
			dp[i][j] = dp[i-1][j]+dp[i-1][j-1];
		}
	}
}

int main(int argc, char const *argv[]) {
	init();
	T = 1;
	//scanf("%d", &T);
	for (int _=1;_<=T;++_) {
		long long ans=0;
		scanf("%d", &n);
		printf("%lld\n", dp[n-1][11]);
	}
	return 0;
}

/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
clock_t clk;
clk = clock();
if(clock() - clk > CLOCKS_PER_SEC * 0.9)
      T
W     L
A C M E R
  E L   E
    E
*/

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;   typedef pair<int,int>pint;
using vll=vector<ll>;   using vs=vector<string>;
#define b2e(v)v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]

class var { public: ll min,max,ct,sum,dif,result; };
int main() {
    const ll cut=11;
    ll l; cin>>l;

    ll val, sum = 1;
    for (ll i = 1; i <= cut; i++) {
        sum *= l-i;
        sum /= i;
    }
    cout << sum << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll maxn=200005;

const ll mod=998244353;
const ll INF64 = ll(1e18);
const ll max2=10500000;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
vector<ll> adj_row[52],adj_column[52];
ll vis_r[52],vis_c[52];
ll dfs(ll p,vector<ll> adj[],ll vis[])
{
	vis[p]=1;
	ll i;
	ll x=1;
	for(i=0;i<adj[p].size();++i)
	{
		if(vis[adj[p][i]]==0)
		{
			x+=dfs(adj[p][i],adj,vis);
		}
	}
	return(x);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
//long long tt = clock();
#endif
ios_base::sync_with_stdio(NULL);  cin.tie(0); cout.tie(0);
ll n,c,i,j,k;
cin>>n>>c;
ll a[n][n];
for(i=0;i<n;++i)
{
	for(j=0;j<n;++j)
		cin>>a[i][j];
}
ll fact[52];
fact[0]=1;
for(i=1;i<=n;++i)
{
	fact[i]=(fact[i-1]*i)%mod;
}

for(i=0;i<n;++i)
{
	for(j=i+1;j<n;++j)
	{ll sum=0;
		for(k=0;k<n;++k)
			sum+=(a[i][k]+a[j][k]<=c);

		if(sum==n)
		{
			adj_column[i].push_back(j);
			adj_column[j].push_back(i);
		}
	}

}
for(i=0;i<n;++i)
{
	for(j=i+1;j<n;++j)
	{ll sum=0;
		for(k=0;k<n;++k)
			sum+=(a[k][i]+a[k][j]<=c);
		if(sum==n)
		{//cout<<i<<" "<<j<<"\n";
			adj_row[i].push_back(j);
			adj_row[j].push_back(i);
		}
	}

}
//return(0);
ll ans=1;
for(i=0;i<n;++i)
{
	if(vis_c[i]==0)
	{
		ll x=dfs(i,adj_column,vis_c);

		ans=(ans*fact[x])%mod;
	}
	if(vis_r[i]==0)
		{ll x=dfs(i,adj_row,vis_r);
			//cout<<x<<" "<<i<<"\n";
		//return(0);
			ans=(ans*fact[x])%mod;
		}
}
cout<<ans;

return(0);
}

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

using namespace std;

constexpr ll MOD = 1e9+7;

long long powmod(long long x,long long n){
    long long ret=1;
    while(n>0){
        if(n&1){
            ret*=x;
            ret%=MOD;
            n-=1;
        }else{
            x*=x;
            x%=MOD;
            n>>=1;
        }
    }
    return ret;
}

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    ll m; cin >> m;
    vector<ll> a(n);
    ll sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 1;
    for(ll i=1;i<=n+sum;i++){
        ans *= (n+m+1-i)%MOD;
        ans %= MOD;
        ans *= powmod(i,MOD-2);
        ans %= MOD;
    }
    cout << ans  << endl;

    return 0;
}
// g++ main.cpp -o a.out && ./a.out


#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>

using namespace std;
using lint = long long;

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

    vector<lint> cnt(2, 0);
    while (n--) {
        string s;
        cin >> s;
        ++cnt[count(s.begin(), s.end(), '1') % 2];
    }

    cout << cnt[0] * cnt[1] << "\n";
}

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

    solve();

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<ll>r, g, b;
	rep(i, 0, 2 * n) {
		ll a;
		char c;
		cin >> a >> c;
		if (c == 'R') r.push_back(a);
		else if (c == 'G') g.push_back(a);
		else b.push_back(a);
	}
	sort(r.begin(), r.end());
	sort(g.begin(), g.end());
	sort(b.begin(), b.end());
	ll rg = 1e16, rb = 1e16, bg= 1e16;
	if (g.size() != 0) {
		rep(i, 0, r.size()) {
			ll v = r[i];
			int pos = lower_bound(g.begin(), g.end(), v) - g.begin();
			if(pos != g.size())rg = min(rg, abs(v - g[pos]));
			if (pos != 0) rg = min(rg, abs(v - g[pos - 1]));
		}
	}
	if (b.size() != 0) {
		rep(i, 0, r.size()) {
			ll v = r[i];
			int pos = lower_bound(b.begin(), b.end(), v) - b.begin();
			if(pos != b.size())rb = min(rb, abs(v - b[pos]));
			if (pos != 0) rb = min(rb, abs(v - b[pos - 1]));
		}
	}
	if (g.size() != 0) {
		rep(i, 0, b.size()) {
			ll v = b[i];
			int pos = lower_bound(g.begin(), g.end(), v) - g.begin();
			if(pos != g.size())bg = min(bg, abs(v - g[pos]));
			if (pos != 0) bg = min(bg, abs(v - g[pos - 1]));
		}
	}
	if (r.size() % 2 == 0 && g.size() % 2 == 0 && b.size() % 2 == 0) cout << 0 << endl;
	else if (r.size() % 2 == 0) {
		ll ans = min(bg, rg + rb);
		cout << ans << endl;
	}
	else if (g.size() % 2 == 0) {
		ll ans = min(rb, rg + bg);
		cout << ans << endl;
	}
	else {
		ll ans = min(rg, rb + bg);
		cout << ans << endl;
	}
}


#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
//#define LOCAL_TEST
#define init_val 2500
template<class T>int chmin(T&a,const T&b){if(b<a){a=b;return 1;}return 0;}
//----------def struct st----------
struct st
{
	int fif;
	int fis;
	int se;
	bool operator<(const st&st1)const{return se<st1.se;};
	bool operator>(const st&st1)const{return se>st1.se;};
};
//----------global args----------
int si,sj,ti,tj,A;double E;
vector<vector<vector<st>>>G(30,vector<vector<st>>(30));
//----------def input----------
#ifdef LOCAL_TEST
void input()
{
	int h,v;
	rep(i,30)rep(j,29)
	{
		cin>>h;
		G[i][j].push_back(st{i,j+1,init_val});
		G[i][j+1].push_back(st{i,j,init_val});
	}
	rep(i,29)rep(j,30)
	{
		cin>>v;
		G[i][j].push_back(st{i+1,j,init_val});
		G[i+1][j].push_back(st{i,j,init_val});
	}
}
#else
void input()
{
	rep(i,30)rep(j,29){G[i][j].push_back(st{i,j+1,init_val});G[i][j+1].push_back(st{i,j,init_val});}
	rep(i,29)rep(j,30){G[i][j].push_back(st{i+1,j,init_val});G[i+1][j].push_back(st{i,j,init_val});}
}
#endif
//----------def solve----------
#ifdef LOCAL_TEST
void in_a_e(){cin>>A>>E;}
#else
void in_a_e(){cin>>A;}
#endif
void solve()
{
	cin>>si>>sj>>ti>>tj;
	vector<vector<int>>dist(30,vector<int>(30,1LL<<60));dist[si][sj]=0;
	vector<vector<P>>prev(30,vector<P>(30,{-1,-1}));
	priority_queue<st,vector<st>,greater<st>>pq;
	pq.push(st{0,si,sj});
	while(!pq.empty())
	{
		auto[d,v1,v2]=pq.top();
		pq.pop();
		if(d>dist[v1][v2])continue;
		for(auto e:G[v1][v2])if(chmin(dist[e.fif][e.fis],dist[v1][v2]+e.se))
		{
			prev[e.fif][e.fis]={v1,v2};
			pq.push(st{dist[e.fif][e.fis],e.fif,e.fis});
		}
	}
	vector<P>keiro;
	for(P cur={ti,tj};cur!=(P){-1,-1};cur=prev[cur.first][cur.second])keiro.push_back(cur);
	reverse(keiro.begin(),keiro.end());
	int keirosize=keiro.size();
	for(int i=1;i<keirosize;i++)
	{
		if(keiro[i-1].first-keiro[i].first<0)cout<<'D';
		else if(keiro[i-1].first-keiro[i].first>0)cout<<'U';
		if(keiro[i-1].second-keiro[i].second<0)cout<<'R';
		else if(keiro[i-1].second-keiro[i].second>0)cout<<'L';
	}
	cout<<endl;
	in_a_e();
	for(int i=1;i<keirosize;i++)
	{
		for(auto&it:G[keiro[i].first][keiro[i].second])
		{
			if(it.fif==keiro[i+1].first&&it.fis==keiro[i+1].second)
			{
				if(it.se==init_val)it.se=A/keirosize;
				else it.se=(it.se+A/keirosize)/2;
			}
		}
	}
}
//-----------main-----------
main()
{
	input();
	rep(i,1000)solve();
}

#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template<typename T> void dbg_a(const T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;}
typedef long long ll;
//#define int long long

#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define rep(i,a) for(int i = 0;i<(int)a;i++)
#define All(x) x.begin(),x.end()
#define all(x) x.begin() + 1,x.end()

//const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 6,M = 1<<18 + 6;
const int mod = 1e9 + 7;

void solve(){
    int n; cin>>n;
    ll lb = -INF,ub = INF,add = 0;
    For(i,1,n){
        ll a,t;
        cin>>a>>t;
        if(t == 1) {
            lb += a;
            ub += a;
            add += a;
        }
        else if(t == 2){
            lb = max(lb,a);
            ub = max(ub,a);
        }
        else{
            lb = min(lb,a);
            ub = min(ub,a);
        }
    }
    auto clamp = [&](ll val,ll mi,ll mx)->ll{
        if(val < mi) return mi;
        if(val > mx) return mx;
        return val;
    };
    int q; cin>>q;
    while(q--){
        ll x; cin>>x;
        cout<<clamp(x + add,lb,ub)<<"\n";
    }
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    solve();
    return 0;
}


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

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

  bool flag = false;

  vector<ll> a(MAX, 0);
  rep(i, n){
    ll s, t, p;
    cin >> s >> t >> p;
    a[s] += p;
    a[t] -= p;
  }
  rep(i, MAX){
    a[i+1] += a[i];
    if(a[i] > w) flag = true;
  }

  if(flag) cout << "No" << endl;
  else cout << "Yes" << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll b,c;
	scanf("%lld%lld",&b,&c);
	ll cnt=0;
	if(b<=0){
		cnt=c+1;
		c--;
		if(b==0)cnt--;
		if(c>0&&b<0)cnt+=min(-2*b-1,c-1);
	}else {
		cnt=c+(c==1?1:0);
		cnt+=min(2*b-1,c-1);
	}printf("%lld\n",cnt);
}


/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */
#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

/** faster solution */
const int MAXN = 70;
ll C[MAXN + 1][MAXN + 1];

const bool init_nCr=[]() {
    C[0][0] = 1;
    for (int n = 1; n <= MAXN; ++n) {
        C[n][0] = C[n][n] = 1;
        for (int k = 1; k < n; ++k)
            C[n][k] = C[n - 1][k - 1] + C[n - 1][k];
    }
    return true;
}();

ll nCr(int n, int k) {
    return C[n][k];
}

/* aaaabbbb
 * aaababbb
 * aaabbabb
 * ...
 * aabaabbb
 * aabababb
 * ...
 * aababbba
 * Number of strings of len x with A 'a' is nCr(x,A)
 * So we check the prefixes until we found the right one.
 */
void solve() {
    cini(a);
    cini(b);
    cini(k);

    int cnt=a+b;

    string ans;
    for(int i=0; i<cnt; i++) {
        int num=nCr(a+b-1, a-1);    /* consider first letter a */
        if(b>0 && (a==0 || num<k)) {
            k-=num;
            ans.push_back('b');
            b--;
        } else {
            ans.push_back('a');
            a--;
        }
    }
    cout<<ans<<endl;
}

signed main() {
    solve();
}

/*
{
######################
#       Author       #
#        Gary        #
#        2021        #
######################
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
//inline int read(){
//    int x=0;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){
//        ch=getchar();
//    }
//    while(ch>='0'&&ch<='9'){
//        x=(x<<1)+(x<<3)+(ch^48);
//        ch=getchar();
//    }
//    return x;
//}
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MAXN=200000+233;
vector<int> g[MAXN];
int n;
mp fr;
int depth[MAXN],rest[MAXN],cnt;
void dfs(int now,int dis=0,int pre=0){
	check_max(fr,II(dis,now));
	for(auto it:g[now]) if(it!=pre){
		dfs(it,dis+1,now);
	}
}
void dfs2(int now,int pre=0){
	for(auto it:g[now]) if(it!=pre){
		depth[it]=depth[now]+1;
		dfs2(it,now);
	}
	for(auto it:g[now]) if(it!=pre){
		check_max(depth[now],depth[it]);
	}
}
bool cmp(int A,int B){
	return depth[A]<depth[B];
}
void dfs3(int now,int pre=0){
	rest[now]=++cnt;
	vector<int> ord;
	for(auto it:g[now]) if(it!=pre) ord.PB(it);
	sort(ALL(ord),cmp);
	for(auto it:ord) dfs3(it,now),++cnt;
}
int main(){
	scanf("%d",&n);
	rb(i,1,n-1){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].PB(v);
		g[v].PB(u);
	}
	fr=II(-1,-1);
	dfs(1);
	int tmp=fr.SEC;
	fr=II(-1,-1);
	dfs(tmp);
	int root=fr.SEC;
	dfs2(root);
	dfs3(root);
	rb(i,1,n) printf("%d ",rest[i]);
	return 0;
}