#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <unistd.h>
#include <stdlib.h>
#include <cassert>

using namespace std;
// using namespace atcoder;

// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<ll, vector<ll>> Pd;

const ll INF = 2e18;
const ll fact_table = 3200008;

priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = b; i >= (a); i--)

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll m = mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= m; b >>= 1;}(x *= a) %= m; b--;} return x;}
vec readvec(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/

bool icpc = false;
bool multicase = false;

ll n, m;
string s;

ll parent[500005], sizes[500005];

void init(ll n) {
    for (ll i = 0; i <= n; i++) {
        parent[i] = i;
    }
}
ll find(ll x) {
    if (parent[x] == x) {
        return x;
    } else {
        return parent[x] = find(parent[x]);
    }
}

void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y)return;
    if (sizes[x] < sizes[y])swap(x, y);

    parent[y] = x;
    sizes[x] += sizes[y];
}

bool same(ll x, ll y) {
    return find(x) == find(y);
}

ll size(ll x) {
    return sizes[find(x)];
}

ll a[200005], b[200005];
ll aimsize[200005];

bool solve() {
    cin >> n >> m;
    init(n + 10);
    rep(i, n) {
        cin >> a[i];
        sizes[i + 1] = a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    rep(i, m) {
        ll u, v;
        cin >> u >> v;
        unite(u, v);
    }
    for (int i = 1; i <= n; i++) {
        int par = find(i);
        aimsize[par] += b[i - 1];
    }
    bool ok = true;
    for (int i = 1; i <= n; i++) {
        int par = find(i);
        if (aimsize[par] != size(i)) {
            ok = false;
        }
    }
    Yes(ok);
    return true;
}

int main() {

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

    if (icpc) {
        while (solve());
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }

// solve();
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/modint>
//#include <atcoder/math>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c = a % i_7;
    if(c >= 0) return c;
    return c + i_7;
}
long long po(long a, long b){
    if(b == 0) return 1;

    long long z = po(a , b / 2);
    z = mod(z * z);
    if(b % 2 != 0) z = mod(a * z);
    return z;
}

bool prime_(int n){
    if(n == 1){
        return false;
    }else if(n == 2){
        return true;
    }else{
        for(int i = 2; i <= std::sqrt(n); i++) if(n % i == 0) return false;
        return true;
    }
}

long long gcd_(long long a, long long b){
    if(a < b) std::swap(a,b);
    if(a % b == 0) return b;
    else return gcd_(b, a % b);
}

long long lcm_(long long x, long long y){
    return (x / gcd_(x,y)) * y;
}

using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  //using namespace std;

  int n;
  cin>>n;
  string s, x;
  cin>>s;
  cin>>x;

  char dp[n][7];
  int nums[n];
  int p = 1;
  for(int i = n - 1; i >= 0; i--){
    int d = s[i] - '0';
    nums[i] = (d * p) % 7;
    p *= 10;
    p %= 7;
  }

  for(int i = n - 1; i >= 0; i--){
    for(int r = 0; r < 7; r++){
      if(i == n - 1){
        if(x[i] == 'A'){
          if(r != 0 || (r + nums[i]) % 7 != 0) dp[i][r] = 'A';
          else dp[i][r] = 'T';
        }else{
          if(r == 0 || (r + nums[i]) % 7 == 0) dp[i][r] = 'T';
          else dp[i][r] = 'A';
        }
        continue;
      }
      if(x[i] == 'A'){
        if(dp[i + 1][r] == 'A' || dp[i + 1][(r + nums[i]) % 7] == 'A') dp[i][r] = 'A';
        else dp[i][r] = 'T';
      }else{
        if(dp[i + 1][r] == 'T' || dp[i + 1][(r + nums[i]) % 7] == 'T') dp[i][r] = 'T';
        else dp[i][r] = 'A';
      }
    }
  }
  if(dp[0][0] == 'A') cout << "Aoki" << endl;
  else cout << "Takahashi" << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ignore ignore
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define in4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define inp(p) in2(p.F,p.S)
#define llin(a) cin >> a
#define llin2(a,b) cin >> a >> b
#define llin3(a,b,c) cin >> a >> b >> c
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twodread(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define prp(p) pr2(p.F,p.S)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llpr2(a,b) cout << a << " " << b << "\n"
#define llout(a) cout << a << "\n"
#define pinttwod(mat,i,j,n,m) rep(i,n){rep(j,m)pr(mat[i][j]);   lin;}
#define plltwod(mat,i,j,n,m)  rep(i,n){rep(j,m)llpr(mat[i][j]); lin;}
#define byes printf("YES\n")
#define bno printf("NO\n")
#define yes printf("Yes\n")
#define no printf("No\n")
#define lin printf("\n")
#define test(q) cout << "Case #" << q << ": "
// Iterator
#define rep(i,n) for(i=0;i<n;++i)
#define fone(i,n) for(i=1;i<=n;++i)
#define rrep(i,n) for(i=n-1;i>=0;--i)
#define lp(i,a,b) for(i=a;i<b;++i)
#define rlp(i,a,b) for(i=a;i>=b;--i)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// function
#define sz(x) (int)x.size()
#define inrange(i,a,b) (i>=a && i<=b)
#define FLUSH fflush(stdout)
#define precision(x) cout << setprecision(x) << fixed
#define remax(a,b) a=max(a,b)
#define remin(a,b) a=min(a,b)
#define middle() ((l+h)/2)
#define lchild(p) 2*p
#define rchild(p) 2*p+1
#define lseg l,m,2*p
#define rseg m+1,h,2*p+1
#define bhardo(mat,i,j,n,m,t) rep(i,n){rep(j,m)mat[i][j]=t;}
#define baselog2(n) __lg(n)
#define numberofbit(n) (32-__builtin_clz(n))
#define numberofbitll(n) (64-__builtin_clzll(n))
#define onbitcount(x)  __builtin_popcount(x)
#define onbitcountll(x)  __builtin_popcountll(x)
#define biton(mask,i)  ((mask>>i)&1)
#define bitoff(mask,i) (!((mask>>i)&1))
#define toggle(mask,i) (mask^=(1<<(i)))
#define raise(i) (1<<(i))
#define mul(p,q) ((ll)(p)*(ll)(q))
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define lii pair<ll,ll>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
// Constant
const double PI = acos(-1);
const double eps = (1e-9);
const ll INF = 2e18;
const int M = (1e9)+7;
//const int M= 998244353;
const int N = (1e2)+3;  // check the limit, man
/**
 Have you worked on Simplification of Idea?
 Ok! let's code, check whether it is correct or not?
*/
void solve()
{
    int n;
    in(n);
    out(max(n,0));
}
void starting()
{

}
int main()
{
    int t=1;
//    in(t);
    starting();
    while(t--)
        solve();
}

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, n) cout << 2 * i % n + 1 << " " << (2 * i + 1) % n + 1 << endl;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define ld long double

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define ff first
#define ss second

using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=4e18+10;

typedef pair<int, int> pii;

int power(int a, int b, int in_mod)
{
    int ans=1;
    int prod=a;
    while(b)
    {
        if(b%2)
            ans=(ans*prod)%in_mod;
        prod=(prod*prod)%in_mod;
        b/=2;
    }
    return ans;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}

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

int fact(int n,int in_mod){
    int f=1;
    for(int i=1;i<=n;i++) f=(f*i)%in_mod;
    return f;
}
int ncr(int n,int r,int in_mod){
    return (((fact(n,in_mod)*mod_inv(fact(r,in_mod),in_mod))%in_mod)*mod_inv(fact(n-r,in_mod),in_mod))%in_mod;
}

void solve()
{
    //write code here
    int n;
    cin>>n;
    vector<pair<int,string>> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i].second>>v[i].first;
    }
    sort(all(v));
    cout<<v[n-2].second<<endl;
}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed<<setprecision(10);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t=1;
    //cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((long double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}
/*
formats to remember:
1.vector<vector<int>> dp(n, vector<int>(m, 0));
--------------------------------------------------------------------------------------
1.do not use bitshift (1<<int) because it gives value in int and not in long long
2.check that for loops of i,j,k are properly declared
3.donot delete elements from map,set while looping in it
4.in a map's vector ,ie,map<int,vector<int>> mp,when you sort each vector in a loop it may not get sorted outside the scope of the loop so take care
*/

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <string.h>
#include <map>

using namespace std;
#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++)
#define all(A) A.begin(),A.end()
#define all2(A) A.rbegin(),A.rend()

int main(){
    int n;cin>>n;
    vector<tuple<int,string>> yama;
    rep(i,n){
        string a;
        int b;
        cin >> a >> b;
        yama.push_back(tie(b,a));
    }
    sort(yama.begin(),yama.end());

    cout << get<1>(yama[n-2]) << "\n";

}


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

typedef long long ll;

ll n,m,mod;

ll qpow(ll a,ll n){
    ll res=1;
    while(n){
        if(n&1)res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

int main(){

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

    cin>>n>>m;
    mod=m*m;
    cout<<qpow(10,n)/m<<endl;

    return 0;
}

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cassert>
#include <numeric>
typedef long long ll;
#define FOR(i, a, b) for(int i=(a); i<(b);i++)
#define REP(i, n) for(int i=0; i<(n);i++)
#define ROF(i, a, b) for(int i=(b-1); i>=(a);i--)
#define PER(i, n) for(int i=n-1; i>=0;i--)
using namespace std;

class Mod {
public:
  ll var;
  ll MOD = 1e9 + 7;
  const int MaxIntPower = 60;
  Mod(ll v = 0) { var = v; }
  void operator = (ll r) { var = r % MOD; }
  void operator = (Mod r) { var = r.var; }
  Mod operator + (Mod r) { return (var + r.var) % MOD; }
  Mod operator - (Mod r) { return (var - r.var + MOD) % MOD; }
  Mod operator * (Mod r) { return (var * r.var) % MOD; }
  Mod operator / (Mod r) { return (var * r.Reverse().var) % MOD; }

  void operator += (Mod r) { var = (var + r.var) % MOD; }
  void operator -= (Mod r) { var = (var - r.var + MOD) % MOD; }
  void operator *= (Mod r) { var = (var * r.var) % MOD; }
  void operator /= (Mod r) { var = (var + r.Reverse().var) % MOD; }

  bool operator ==(const Mod& r) { return var == r.var; }
  bool operator <(const Mod& r) { return var < r.var; }
  bool operator !=(const Mod& r) { return var != r.var; }

  Mod Power(ll p) {
    if (var == 0 || var == 1) return var;
    //while (p < 0) p += MOD - 1;
    //p = p % (MOD - 1);
    ll bit = ll(1) << MaxIntPower;
    Mod ans = 1;
    ans.MOD = MOD;
    while (bit >= 1) {
      ans *= ans;
      if ((bit & p) != 0)
        ans *= var;
      bit = (bit >> 1);
    }
    return ans;
  }

  Mod Reverse() {
    ll a = var;
    ll b = MOD;
    ll u = 1;
    ll v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }

    Mod val;
    val.var = (u + MOD) % MOD;
    return val;
  }
};

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

  Mod x = 10;
  x.MOD = m * m;
  Mod ans = x.Power(n);

  cout << (ans.var / m) % m;
  return 0;
}


#include<iostream>
#include<utility>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define forn(i, x, n) for(int i = x; i < n; i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const bool DEBUG = 0;

void solve(){
    int n;
    cin>>n;
    int a[n];
    forn(i, 0, n) cin>>a[i], a[i] += 200;
    vector<int> f(401);
    forn(i, 0, n) f[a[i]]++;
    ll ans = 0;
    forn(i, 1, f.size()){
        forn(j, 0, i){
            ans += (i - j) * 1ll * (i - j) * f[i] * f[j];
        }
    }
    cout<< ans;

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
    //cin>>t;
	//while(t--) cout<<solve()<<'\n';
	while(t--) solve(), cout<<'\n';

}

#include <bits/stdc++.h>
typedef long long 		ll;
typedef long double 		ld;
#define endl 			"\n"
#define fi 			first
#define se 			second
#define Alkborough 			ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 2e18;
const ll MAX = 5e4 + 3;

int main(){

//cout<<fixed<<setprecision(15);

Alkborough
   int tc = 1; //cin>>tc;
    while(tc--){
        ll n; cin>>n;
        ll a[n]; for(int i = 0; i < n; i++)cin>>a[i];

        ll ans = 0;
        vector<ll> suf(n+1);
        for(int i = n-1; i >= 0; i--){
            suf[i] = suf[i+1] + a[i];
        }

        for(int i = 0; i < n; i++){
            ans += (n-1)*a[i]*a[i] - 2*a[i]*(suf[i+1]);
        }
        cout<<ans;
    }
return 0;
}


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

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

ll dp[1 << 18];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> XYZ[20];
	rep(i, M) {
		int x, y, z;
		cin >> x >> y >> z;
		XYZ[y].pb({ x, z });
	}

	dp[0] = 1;
	rep(i, 1 << N) {
		int c = __builtin_popcount(i);
		int OK = 1;
		for (auto p : XYZ[c]) {
			if (__builtin_popcount(i << 32 - p.first) > p.second) {
				OK = 0;
				break;
			}
		}
		if (!OK) {
			dp[i] = 0;
		}
		else {
			int tmp = i;
			for(int j = i + 1; j < (1 << N); j = tmp + 1) {
				dp[i | j] += dp[i];
				tmp |= j;
			}
		}
	}
	co(dp[(1 << N) - 1]);

	Would you please return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)
#define iter(x)  x.begin(),x.end()

int main()
{
    int n,m;
    cin>>n>>m;
    if(m==0)
    {
        int c=1;
        for(int i=1;i<=n;i++)
        {
            cout<<c<<" "<<c+1<<endl;
            c+=2;
        }
    }
    else if(m+2>n || m<0)
    {
        cout<<-1<<endl;
    }
    else
    {
        lli x=1000000000;
        int c=1;
        for(int i=m+2;i<=n;i++)
        {
            cout<<c++<<" "<<x--<<endl;
        }
        for(int i=1;i<=m+1;i++)
        {
            cout<<c<<" "<<c+1<<endl;
            c+=2;
        }

    }
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

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

    rep1(i,0,n-1){
        int ai;
        cin>>ai;

        sum += ai;
    }

    //db3(k,sum,n*m - sum);ln;

    if(n*m - sum > k){
        puts("-1");
        return 0;
    }else{
        cout <<max(0LL,n*m - sum)<<endl;
        return 0;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n,k,m,zbir=0;
    cin>>n>>k>>m;
    int a[n];
    for(int i=0;i<n-1;i++) {
        cin>>a[i];
        zbir+=a[i];
    }
    int average=m*n;
    int rezultat=average-zbir;
    if(rezultat<0) {
        cout<<"0";
        rezultat=2000000;
    }
    if(rezultat<=k) cout<<rezultat;
    if(rezultat>k) if(rezultat!=2000000) cout<<"-1"<<endl;
    return 0;
}


//Bulbul khan-420...
#include <bits/stdc++.h>
#include <cstring>
#define ll long long int
#define pb() push_back()
#define f(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
      ll t,a,b,c,d,i,j,k,l,n,m,x,y,z;
      cin>>n>>k;

      l=0;
     map<ll,ll>h;
     ll s[n+6];
    m=0;

    for(i=0;i<n;i++){
      cin>>a;
      m=max(m,a);
      h[a]++;
}
     for(i=0;i<=m+1;i++){
         a=h[i];

       if(a<k){
         b=k-a;
         l+=(b*i);
         k-=b;
}
       if(k==0)
         break;

   }
       cout<<l;

}

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

int main () {
    int N; cin >> N;
    vector<int> a(N); vector<int> b(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i) >> b.at(i);
    }
    double grad = 0;
    int ans = 0;
    for (int i = 0; i <= N-2; i++) {
        for (int j = N - 1; j > i; j--) {
            grad = (double)(b.at(i) - b.at(j)) / (a.at(i) - a.at(j));
            if (grad >= -1 && grad <= 1) ans++;
        }
    }
    cout << ans << endl;
}


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

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

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

    int n;
    cin >> n;

    ll ans = INF;
    REP(i, n) {
        ll a, p, x;
        cin >> a >> p >> x;
        if (a < x) {
            chmin(ans, p);
        }
    }
    if (ans == INF) ans = -1;
    COUT(ans);
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

ll mod_inverse(ll x){
  return mod_pow(x,MOD-2);
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

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

typedef vector<ll> vec;
typedef vector<vec> mat;

mat mul(mat &A,mat &B){
  mat C(A.size(),vec(B[0].size()));
  for(int i=0;i<A.size();i++){
    for(int k=0;k<B.size();k++){
      for(int j=0;j<B[0].size();j++){
        C[i][j]=(C[i][j]+(A[i][k]*B[k][j])%MOD)%MOD;
      }
    }
  }
  return C;
}

// C=pow(A,n)
mat pow(mat A,ll n){
  mat B(A.size(),vec(A.size()));
  for(int i=0;i<A.size();i++){
    B[i][i]=1;
  }
  while(n>0){
    if(n&1) B=mul(B,A);
    A=mul(A,A);
    n=(n>>1);
  }
  return B;
}

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

  int N,M,K;
  cin>>N>>M>>K;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  vector<int> X(M),Y(M);
  rep(i,M) cin>>X[i]>>Y[i];

  rep(i,M) X[i]--,Y[i]--;

  vector<vector<int>> g(N);
  rep(i,M){
    g[X[i]].push_back(Y[i]);
    g[Y[i]].push_back(X[i]);
  }

  mat P(N,vec(N,0));
  for(int i=0;i<N;i++){
    int deg=g[i].size();
    ll inv=mod_inverse(M);
    {
      ll coef=M-deg;
      mul(coef,inv);
      add(P[i][i],coef);
    }

    {
      ll coef=deg;
      mul(coef,inv);
      mul(coef,mod_inverse(2));
      add(P[i][i],coef);

      mul(coef,mod_inverse(deg));
      for(auto n:g[i]){
        add(P[i][n],coef);
      }
    }
  }

  mat C=pow(P,K);
  mat B(N,vec(1,0));
  rep(i,N) B[i][0]=A[i];

  B=mul(C,B);

  rep(i,N) cout<<B[i][0]<<"\n";

  return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<math.h>
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#define IOS ios::sync_with_stdio(false);cin.tie();cout.tie(0)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pll;
const int N=1e5+10;
const int mod=1e9+7;
double a[N],s[N];

int main()
{
    IOS;
    int n;
    cin>>n;
    double n1=n*1.0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        s[i]=s[i-1]+a[i];
    }
    double sum=0x3f3f3f3f;
    for(int i=1;i<=n;i++)
    {

        double w=a[i]/2;
        double w1=(s[n]-s[i])-(n-i-i)*w;
       /* if(n-i-i<0)
        {
            if(a[i+1]!=0)
                w=a[i+1]/2;
            w1=(s[n]-s[i])-(n-i-i)*w;
        }*/
        sum=min(sum,w1/n1);
        //printf("%.6lf\n",sum/n1);
    }
    printf("%.6lf",sum);
    return 0;
}

// author: Halit
#include <bits/stdc++.h>

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

  std::vector<int> a(n);
  for (int& el : a) {
    std::cin >> el;
  }

  constexpr double eps = 0.0000001;
  auto check = [&](double x) {
    long double compute = 0;
    for (int a_i : a) {
      compute += x + a_i - std::min(double(a_i), 2*x);
    }

    return compute / n;
  };

  double l = 0, r = 1e9+7;
  for (int i = 1;i <= 100; ++i) {
    double point_1 = (r-l)/3 + l;
    double point_2 = (r-l)/3 * 2 + l;

    if (check(point_2)-check(point_1) > eps) r = point_2;
    else l = point_1;
  }

  double ans = l;
  std::cout << std::fixed << std::setprecision(7) << check(ans);
}


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

ll power(ll N,ll P)
{
    if(N == 0)
        return(0);

    ll res = 1;

    while(P)
    {
        if(P%2)
            res = (res * N) % MOD;

        P = P/2;
        N = (N * N) % MOD;
    }

    return(res);
}

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

    ll N,P; cin>>N>>P;

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

    ll ans = P - 1;

    ans = (ans * power(P - 2, N - 1)) % MOD;

    cout<<ans<<endl;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;

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

int main(){
    ll n, p;
    cin >> n >> p;
    cout << mint(p - 1) * mint(p - 2).pow(n-1) << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE = 1e3+5;
#define PI 3.1415927

double ans[MAXSIZE][MAXSIZE];

typedef struct Point {
	int x, y;
} point;

int main() {
	int N;
	cin>>N;
	int cnt = 0;
	Point point[MAXSIZE];
	for(int i = 0; i < N; i++) {
		cin>>point[i].x>>point[i].y;
	}
	for(int i = 0; i < N-1; i++) {
		for(int j = i+1; j < N; j++) {
			ans[i][j] = (point[j].y-point[i].y)*1.0/(point[j].x-point[i].x);
			if(ans[i][j] >= -1 && ans[i][j] <=1) cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

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

#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vstr vector<string>
#define vvstr vector<vector<string>>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

ll T;
vll L,R;
vll ans;
int main(){

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

    cin >> T;
    L.resize(T);
    R.resize(T);
    rep(ti,T){
        cin >> L[ti];
        cin >> R[ti];
    }

    rep(ti,T){
        ll tL = L[ti];
        ll tR = R[ti];

        ll minV = tL * 2;
        ll maxV = tR;

        if(minV <= maxV){
            ll cntV = maxV - minV + 1;
            ans.push_back( cntV * (cntV+1) /2  );
        }else{
            ans.push_back(0);
        }
    }

    rep(ti,T) cout << ans[ti] << endl;

}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define X first
#define Y second
#define nl '\n'
#define AC return 0
#define pb(a) push_back(a)
#define mst(a,b) memset(a, b, sizeof a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a,b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 2e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f3f;
ll f[N], inv[N];

ll q_pow(ll a, ll k)
{
	ll s = 1;
	while(k)
	{
		if(k & 1)	s = s * a % mod;
		a = a * a % mod;
		k >>= 1;
	}
	return s;
}

ll C(ll n, ll m)
{
	return f[n] * inv[m] % mod * inv[n - m] % mod;
}

int main()
{
	IOS;
	int _;
	// cin>>_;
	_ = 1;
	while(_--)
	{
		ll n, m, k;
		cin>>n>>m>>k;
		if(m + k < n)
		{
			cout<<0<<nl;
			AC;
		}
		f[0] = inv[0] = 1;
		rep1(i, N-5)	f[i] = f[i-1] * i % mod;
		inv[N-5] = q_pow(f[N-5], mod - 2);
		for(int i = N - 6; i > 0; i--)
			inv[i] = inv[i+1] * (i + 1) % mod;

		ll ans = (C(n + m, m) - C(n + m, n - (k+1)) + mod) % mod;
		cout<<ans<<nl;
	}

	AC;
}

#include <bits/stdc++.h>
using namespace std;
const long long MOD=1000000007;
long long mod_pow(long long x,long long y){//x^yを返す//計算量は0(log(y))
  long long tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
int main(){
  #define int long long
  int H,W;
  cin>>H>>W;
  vector<string> vec(H);
  for(int i=0;i<H;i++){
    cin>>vec.at(i);
  }
  vector<vector<int>> ans(H,vector<int>(W));
  vector<vector<int>> right(H,vector<int>(W,0));
  vector<vector<int>> down(H,vector<int>(W,0));
  vector<vector<int>> slice(H,vector<int>(W,0));
  for(int i=1;i<H;i++){
    if(vec.at(i).at(0)=='#'){break;}
    down.at(i).at(0)=mod_pow(2,i-1);
  }
  for(int i=1;i<W;i++){
    if(vec.at(0).at(i)=='#'){break;}
    right.at(0).at(i)=mod_pow(2,i-1);
  }
  for(int i=1;i<H;i++){
    for(int j=1;j<W;j++){
      if(vec.at(i).at(j)=='#'){continue;}
      if(vec.at(i).at(j-1)=='.'){
        right.at(i).at(j)=2*right.at(i).at(j-1)+slice.at(i).at(j-1)+down.at(i).at(j-1);
        //if(i==0 && j-1==0){right.at(i).at(j)++;}
        right.at(i).at(j)%=MOD;
      }
      if(vec.at(i-1).at(j-1)=='.'){
        slice.at(i).at(j)=right.at(i-1).at(j-1)+2*slice.at(i-1).at(j-1)+down.at(i-1).at(j-1);
        if(i-1==0 && j-1==0){slice.at(i).at(j)++;}
        slice.at(i).at(j)%=MOD;
      }
      if(vec.at(i-1).at(j)=='.'){
        down.at(i).at(j)=right.at(i-1).at(j)+slice.at(i-1).at(j)+2*down.at(i-1).at(j);
        //if(i-1==0 && j==0){down.at(i).at(j)++;}
        down.at(i).at(j)%=MOD;
      }
      //cout<<i<<" "<<j<<"    "<<down.at(i).at(j)<<" "<<right.at(i).at(j)<<" "<<slice.at(i).at(j)<<endl;
    }
  }
  int a=down.at(H-1).at(W-1)+right.at(H-1).at(W-1)+slice.at(H-1).at(W-1);
  a%=MOD;
  cout<<a<<endl;
}


#include <bits/stdc++.h>
using i64 = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    std::cin >> n;
    std::vector<std::vector<int>> e(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    std::vector<int> dis(n), parent(n);
    auto bfs = [&](int s) {
        std::fill(dis.begin(), dis.end(), -1);
        parent[s] = -1;
        dis[s] = 0;
        std::queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int u = que.front();
            que.pop();
            for (auto v : e[u]) {
                if (dis[v] == -1) {
                    dis[v] = dis[u] + 1;
                    parent[v] = u;
                    que.push(v);
                }
            }
        }
        return std::max_element(dis.begin(), dis.end()) - dis.begin();
    };
    int u = bfs(0);
    int v = bfs(u);
    std::vector<int> son(n, -1);
    for (int i = v; i != u; i = parent[i]) {
        son[parent[i]] = i;
    }
    std::vector<int> E(n, -1);
    int cur = 0;
    std::function<void(int)> dfs = [&](int u) {
        E[u] = ++cur;
        for (auto v : e[u]) {
            if (v != son[u] && E[v] == -1) {
                dfs(v);
                cur++;
            }
        }
        if (son[u] != -1) {
            dfs(son[u]);
            cur++;
        }
    };
    dfs(u);
    for (int i = 0; i < n; i++) {
        std::cout << E[i] << " \n"[i == n - 1];
    }
    return 0;
}

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

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

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

bool vio;
char IO;
int rd(int res=0){
	bool f=0;
	while(IO=getchar(),IO<48||IO>57)
		f=IO=='-';
	do res=(res<<1)+(res<<3)+(IO^48);
	while(IO=getchar(),isdigit(IO));
	return f?-res:res;
}
const int M=1e6+10;
int nxt[M<<1],to[M<<1],hd[M],ecnt;
void Add(int a,int b){
	nxt[++ecnt]=hd[a],to[hd[a]=ecnt]=b;
}
int Mx,tp,bot,L[M],R[M],n;
void dfs(int x,int f,int d){
	static int tot;
	if(d>Mx)tp=x,Mx=d;
	L[x]=++tot;
	erep(i,x){
		int y=to[i];
		if(y==f)continue;
		dfs(y,x,d+1);
	}
	R[x]=tot;
}
bool FA(int a,int b){
	return L[a]<=L[b]&&L[b]<=R[a];
}
int nw=1,ans[M];
void redfs(int x,int f){
	ans[x]=nw;
	erep(i,x){
		int y=to[i];
		if(y==f||FA(y,tp))continue;
		nw++,redfs(y,x);
	}
	erep(i,x){
		int y=to[i];
		if(y!=f&&FA(y,tp))nw++,redfs(y,x);
	}
	nw++;
}
bool let;
int main(){
	cerr<<(&vio-&let)/1024.0/1024<<endl;
	rep(i,2,n=rd()){
		int a=rd(),b=rd();
		Add(a,b),Add(b,a);
	}
	Mx=0,dfs(1,0,0);
	bot=tp,Mx=0,dfs(tp,0,0);
	ans[1]=1;
	redfs(bot,0);
	rep(i,1,n)printf("%d ",ans[i]);
}


#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;
using namespace std;

// ----------------  modint ---------------------//

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const { //値をt乗する
    if (!t) return 1; // t == 0
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this; //*thisは元の値(t乗する対象)
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[2050][2050];
mint X[2050][2050];
mint Y[2050][2050];
mint Z[2050][2050];

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int h,w; cin >> h >> w;
        char s[h][w];
        rep(i,h){
                rep(j,w){
                        cin >> s[i][j];
                }
        }

        if(s[0][0] == '#' || s[h-1][w-1] == '#'){ cout << "0" << endl; return 0;}

        rep(i,2050)rep(j,2050){
                dp[i][j] = mint(0);
                X[i][j] = mint(0);
                Y[i][j] = mint(0);
                Z[i][j] = mint(0);
        }
        dp[0][0] = mint(1);

        rep(i,h)rep(j,w){
                if(i == 0 && j == 0) continue;
                if(s[i][j] == '#') continue;
                if(j>0) X[i][j] = X[i][j-1] + dp[i][j-1];
                if(i>0) Y[i][j] = Y[i-1][j] + dp[i-1][j];
                if(j>0 && i>0) Z[i][j] = Z[i-1][j-1] + dp[i-1][j-1];
                dp[i][j] = mint(X[i][j] + Y[i][j] + Z[i][j]);
        }

        cout << dp[h-1][w-1] << endl;

        return 0;
}

//a.9
#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define endll endl
#define endl '\n'
#define INF 1e18
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n'
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n'
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n'
#define output(container) for(auto x:container)cout<<x<<" ";cout<<'\n';
#define popcnt __builtin_popcountll
#define precise(x) fixed << setprecision(x)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
const ll mod=1000000007;
const ll maxN=50005;

ll ceill(ll a,ll b){return a/b+bool(a%b);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b, a % b);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x)%mod;x=(x*x)%mod;y>>=1;}return res;}
void bin(unsigned n,string &str){str="";if(n>1)bin(n>>1,str);str+=to_string(n&1);}
bool isPrime(ll n)
{
    if(n<=1)return false;else if(n<=3)return true;else if(n%2==0 || n%3==0)return false;
    for(ll i=5;i*i<=n;i=i+6){if(n%i==0 || n%(i+2)==0)return false;}return true;
}

vector<ll>primes;
void SieveOfEratosthenes()
{
    bool prime[maxN];primes.clear();
    memset(prime, true, sizeof(prime));
    for(ll i=2;i*i<maxN;i++)if(prime[i]==true)for(ll j=i*i;j<maxN;j+=i)prime[j]=false;
    for(ll i=2;i<maxN;i++)if(prime[i])primes.push_back(i);
}
//vector<ll>fact(maxN);
//void factpre(){fact[0]=1;for(ll i=1;i<maxN;i++)fact[i]=(fact[i-1]*1LL*i)%mod;}
//ll mul(ll a,ll b){return (a*1LL*b)%mod;}
//ll nCr(ll n,ll k){if(k>n)return 0;return mul(fact[n],power(mul(fact[k],fact[n-k]),mod-2));}

/*ll spf[maxN];
void sieve()
{
    spf[1]=1;for(ll i=2;i<maxN;i++)spf[i]=i;for(ll i=4;i<maxN;i+=2)spf[i]=2;
    for(ll i=3;i*i<maxN;i++){if(spf[i]==i)for(ll j=i*i;j<maxN;j+=i)if(spf[j]==j)spf[j]=i;}
}
vector<ll>getfacts(ll x){vector<ll>vec;while(x!=1)vec.push_back(spf[x]),x=x/spf[x];return vec;}*/

/*ll fen[maxN];
void update(ll i,ll val,ll n){i++;for(;i<=n;i+=i&-i)fen[i]+=val;}
ll get(ll i){i++;ll res=0;for(;i>0;i-=i&-i)res+=fen[i];return res;}*/

/*ll phi[maxN];
void Eul_Toi_phi_precompute()
{
    for(ll i=0;i<maxN;i++)phi[i]=i;
    for(ll i=2;i<maxN;i++)if(phi[i]==i){phi[i]=i-1;for(ll j=i+i;j<maxN;j+=i)phi[j]-=phi[j]/i;}
}*/
vector<vector<ll>>graph;
bool vis[2005];
ll subsz[2005];
void dfs(ll node)
{
    vis[node]=1;
    subsz[node]=1;
    for(ll child:graph[node])
    {
        if(vis[child]==0)dfs(child),subsz[node]+=subsz[child];
    }
}
void solve()
{
    ll n,m;cin>>n>>m;graph.clear();graph.resize(n+1);
    vector<ll>a(m);
    for(ll i=0;i<m;i++){ll b;cin>>a[i]>>b;graph[a[i]].push_back(b);}
    ll cnt=0;
    for(ll i=1;i<=n;i++)
    {
        memset(vis,0,sizeof vis);
        memset(subsz,0,sizeof subsz);
        dfs(i);
        ll t=subsz[i];
        //deb2(i,subsz[i]);
        cnt+=t;
    }
    cout<<cnt<<endl;
}
signed main()
{
    ios;
    ll tc=1; //cin>>tc;
    for(ll t=1;t<=tc;t++)
    {
        //CASE(t);
        solve();
    }
    //cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
}


#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;

ull gcd (ull a, ull b) {
  if(b == 0) return a;

  return gcd(b, a % b);
}

ull lcm (ull a, ull b){
  // バッファ溢れを抑えるために順番大事！！！
  return a / gcd(a, b) * b;
}

ull calcDigits(ull n, int count) {
  if(n < 10) return count + 1;

  return calcDigits(n/10, count+1);
}

int main () {
  ll n, a, b, res=0;
  cin >> n;

  for(ll i =0; i < n; ++i) {
    cin >> a >> b;

    if((b - a) % 2 == 1) {
      res += (a+b) * (b-a+1) /2;
    } else {
      res += (a+b-1) * ((b-a+1) / 2)  + b;
    }
  }

  cout << res << endl;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <math.h>
using namespace std;

#define nl <<endl
#define cy cout<<"Yes" nl
#define cn cout<<"No" nl
#define co(x) cout<<x nl
#define lp(i,a,b) for(i=a;i<b;i++)
#define lpe(i,a,b) for(i=a;i<=b;i++)

int main() {
    int i;
    unsigned long long n;
    cin>>n;
    long j,a,b,count=0;

    lp(i,0,n){
        cin>>a>>b;
        count+=(b-a+1)*(a+b)/2;
    }

    cout<<count nl;

    return 0;
}


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

int main()
{
    string S;
    cin >> S;
    int counter = 0;
    for(int i=0;i<9;i++)
    {
        if(S.at(i)=='Z')
        {
            if(S.at(i+1) == 'O')
            {
                if(S.at(i+2) == 'N')
                {
                    if(S.at(i+3) == 'e') counter++;
                }
            }
        }
    }
    cout << counter << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    int n=0,ans=0;
    while(s.find("ZONe",n)!=string::npos){
        n=s.find("ZONe",n)+4;
        ans++;
    }
    cout << ans << endl;

}


#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#define ll long long
#define pb push_back
#define forn(i,x,n) for(int i=x;i<=n;++i)
#define forr(i,x,n) for(int i=n;i>=x;--i)
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;
const int maxn=20000050;

struct node
{
	int v;int pos;
}aa[maxn],bb[maxn];

int n,s[maxn],a[maxn],b[maxn],c[maxn];

bool cmp(node a,node b)
{
	return a.v<b.v||a.v==b.v&&a.pos<b.pos;
}

int lowbit(int x)
{
	return (x&-x);
}

int query(int x)
{
	int ans=0;
	while(x)
	{
		ans+=s[x];
		x-=lowbit(x);
	}
	return ans;
}

void insert(int x)
{
	while(x<=n)
	{
		s[x]++;
		x+=lowbit(x);
	}
}

int main()
{
	cin>>n;
	forn(i,1,n)
	  {
	  	  cin>>a[i];
	  	  aa[i].v=a[i]+i;
	  	  aa[i].pos=i;
	  }
	forn(i,1,n)
	  {
	  	  cin>>b[i];
	  	  bb[i].v=b[i]+i;
	  	  bb[i].pos=i;
	  }
	sort(aa+1,aa+n+1,cmp);
	sort(bb+1,bb+n+1,cmp);
	bool flag=true;
	for(int i=1;i<=n;++i)
	  if(aa[i].v!=bb[i].v)flag=false;
	if(flag==false) cout<<-1<<endl;
	else
	{
		ll ans=0;
		forn(i,1,n)
		  c[aa[i].pos]=bb[i].pos;
		forn(i,1,n)
		{
			ans+=query(n)-query(c[i]);
			insert(c[i]);
		}
		cout<<ans<<endl;
	}
}

#include <bits/stdc++.h>
#define No return puts("-1"), 0
using namespace std;

typedef long long i64;
const int N = 2e5+10;
int n, m, a[N], b[N], c[N], to[N], bt[N];
vector<int> da[N], db[N];
void add(int x, int v=1) { for(; x <= n; x += x&-x) bt[x] += v; }
int ask(int x) { int y = 0; for(; x; x -= x&-x) y += bt[x]; return y; }

signed main() {
	cin >> n;
	for(int i = 1; i <= n; i ++) scanf("%d", &a[i]), a[i] += i, c[i] = a[i];
	for(int i = 1; i <= n; i ++) scanf("%d", &b[i]), b[i] += i;
	sort(c+1, c+1+n); m = unique(c+1, c+1+n) - c-1;
	for(int i = 1; i <= n; i ++) {
		a[i] = lower_bound(c+1, c+1+m, a[i]) - c;
		int p = lower_bound(c+1, c+1+m, b[i]) - c;
		if(c[p] != b[i]) No;
		da[a[i]].push_back(i), db[p].push_back(i);
	}
	for(int i = 1; i <= m; i ++) {
		if(da[i].size() != db[i].size()) No;
		for(int j = 0; j < da[i].size(); j ++)
			to[da[i][j]] = db[i][j];
	}
	i64 ans = 0;
	for(int i = n; i; i --) {
		ans += ask(to[i]);
		add(to[i]);
	}
	cout << ans << endl;
	return 0;
}


#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

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

int solve(vector<vector<ii>>& a, int s) {
  int n = SZ(a);
  priority_queue<ii, vector<ii>, greater<ii>> Q;
  vector<int> d(n, inf<int>);
  d[s] = 0;
  Q.push({d[s], s});
  bool first = true;
  while (!Q.empty()) {
    auto [dd, u] = Q.top();
    Q.pop();
    if (dd != d[u]) continue;
    // trace(dd, u);
    if (u == s) {
      if (first) {
        first = false;
        d[u] = inf<int>;
      } else {
        return dd;
      }
    }
    for (auto& [v, w] : a[u]) {
      if (d[v] > dd + w) {
        d[v] = dd + w;
        Q.push({d[v], v});
      }
    }
  }
  return -1;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<ii>> a(n);
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    --x; --y;
    a[x].push_back({y, z});
  }
  for (int i = 0; i < n; ++i) {
    int ret = solve(a, i);
    cout << ret << '\n';
  }
  return 0;
}

#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;
int n,m,e[2005][2005],Dis[2005][2005],vis[2005],dis[2005];
vector <pii > g[2005];
const int inf=0x3f3f3f3f;
void dij(int x)
{
	memset(vis,0,sizeof(vis));
	memset(dis,0x3f,sizeof(dis));
	dis[x]=0;
	priority_queue <pii > q;
	q.push(mp(0,x));
	while(!q.empty())
	{
		int u=q.top().se;
		q.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=0;i<g[u].size();i++)
		{
			int v=g[u][i].fi;
			if(vis[v]) continue;
			if(dis[u]+g[u][i].se<dis[v])
			{
				dis[v]=dis[u]+g[u][i].se;
				q.push(mp(-dis[v],v));
			}
		}
	}
	for(int i=1;i<=n;i++) if(i!=x) Dis[x][i]=dis[i];
}
int solve(int x)
{
	int ans=inf;
	for(int i=1;i<=n;i++)
	{
		if(x==i)
		{
			ans=min(ans,Dis[x][x]);
			continue;
		}
		int dist=Dis[x][i]+Dis[i][x];
		ans=min(ans,dist);
	}
	if(ans>=inf) return -1;
	else return ans;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) e[i][j]=Dis[i][j]=inf;
	while(m--)
	{
		int a,b,w;
		scanf("%d%d%d",&a,&b,&w);
		if(a==b) Dis[a][b]=min(Dis[a][b],w);
		else e[a][b]=min(e[a][b],w);
	}
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)
	{
		if(i==j) continue;
		if(e[i][j]!=inf) g[i].push_back(mp(j,e[i][j]));
	}
	for(int i=1;i<=n;i++) dij(i);
	for(int i=1;i<=n;i++) cout<<solve(i)<<endl;
	return 0;
}


// ╔═══╗░░╔═══╗░░╔╗░╔╗╔═══╗╔═══╗╔╗░╔╗░
// ║╔═╗║░░║╔══╝░░║║░║║║╔═╗║║╔═╗║║║░║║░
// ║║░║║░░║╚══╗░░║╚═╝║║╚═╝║╚╝╔╝║║╚═╝║░
// ║╚═╝║░░║╔══╝░░║╔═╗║║╔═╗║╔═╝╔╝╚══╗║░
// ║╔═╗║╔╗║╚══╗╔╗║║░║║║╚═╝║║║╚═╗░░░║║░
// ╚╝░╚╝╚╝╚═══╝╚╝╚╝░╚╝╚═══╝╚═══╝░░░╚╝░

#include<bits/stdc++.h>

using namespace std;

#define int long long int
#define ll long long int
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define W(x) int x;cin>>x;while(x--)
#define fr(n) for(int i=n-1;i>=0;i--)
#define mp make_pair
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ps(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define vi vector<int>
#define deb(x) cout<<#x<<"="<<x<<endl;
#define all(a) (a).begin(),(a).end()
#define pii pair<int,int>
#define sortall(x) sort(all(x))
#define mk(arr,n,type)  type *arr=new type[n];
#define vpi vector<pair<int,int> >
#define setbits(x) __builtin_popcountll(x)
#define zerbits(x) __builtinctzll(x)
#define mod 1000000007
#define inf 1e18
#define sz(x) (int)x.size()
#define vs vector<string>
#define itr(a) for(auto it=a.begin();it!=a.end();it++)
#define f first
#define s second
#define INT_SIZE 32
int mpow(int exp, int base);
//I don't know what the funciton aeh() does but it speeds up my mess
void aeh()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
set<string>ans;
bool isValid(string s,vector<int>necc)
{
  for(int i=0;i<necc.size();i++)
  {
    int fl=0;
    for(int j=0;j<s.size();j++)
    {
      if(s[j]-'0'==necc[i])
      {
        fl=1;break;
      }
    }
    if(!fl){
      return false;
    }
  }
  return true;
}
void gen(vector<int>&poss,vector<int>&necc,int curr=0,string cur="")
{
  cur+=to_string(poss[curr]);

  if(cur.size()==4&&isValid(cur,necc))
  {
    sortall(cur);
    ans.insert(cur);
    return;
  }
  else if(cur.size()==4)return;
  for(int i=0;i<poss.size();i++)
  {

    gen(poss,necc,i,cur);
  }

}
bool shouldSwap(char str[], int start, int curr)
{
    for (int i = start; i < curr; i++)
        if (str[i] == str[curr])
            return 0;
    return 1;
}

// Prints all distinct permutations in str[0..n-1]
void findPermutations(char str[], int index, int n)
{
    if (index >= n) {
        ans.insert(str);
        return;
    }

    for (int i = index; i < n; i++) {

        // Proceed further for str[i] only if it
        // doesn't match with any of the characters
        // after str[index]
        bool check = shouldSwap(str, index, i);
        if (check) {
            swap(str[index], str[i]);
            findPermutations(str, index + 1, n);
            swap(str[index], str[i]);
        }
    }
}
int32_t main()
{
  //aeh();
  string s;cin>>s;
  vector<int>poss;
  vector<int>necc;
  fi(s.size())
  {
    if(s[i]=='o')
    {
      necc.pb(i);
      poss.pb(i);
    }
    if(s[i]=='?')
      poss.pb(i);
  }
  fi(poss.size())
  {
      gen(poss,necc,i);

  }
  for(auto it:ans){
    char str[it.size()+1];
    strcpy(str, it.c_str());

    findPermutations(str,0,it.size());
    // cout<<it<<endl;
  }
  cout<<ans.size();
}

int mpow(int base, int exp)
{
  base %= mod;
  int result = 1;
  while (exp > 0)
  {
    if (exp & 1)result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}

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

int A[200005], P[200005], F[200005];
vector<int> X;

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

    int n;
    cin >> n;

    for (int i=1; i<=n; i++) {
        cin >> A[i];
        P[ A[i] ] = i;
    }

    for (int i=n; i>=1; i--) {
        while (P[i] != i) {
            int indx = P[i];

            if (F[indx]) {
                cout << -1 << "\n";
                return 0;
            }

            F[indx] = 1;
            X.push_back(indx);

            int j = A[indx + 1];
            swap(A[indx], A[indx + 1]);
            P[i] = indx + 1;
            P[j] = indx;
        }
    }

    if (X.size() < n - 1) {
        cout << -1 << "\n";
        return 0;
    }

    for (auto x : X) {
        cout << x << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define M 1000000007
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());

  int a, b;
  cin >> a >> b;
  int req = 2 * a + 100;
  if (req - b >= 0)
    cout << req - b;
  else
    cout << 0;
  return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
	while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
	if (flag)	x = -x;
}
using namespace std;
const int P = 1e9 + 7;
inline ll quickpow(ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res * x % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
int n, m, A;
inline ll get_c(ll n, ll m) {
	if (n < 0 || m < 0 || n - m < 0)	return 0;
	ll res = 1;
	for (int i = 1; i <= m; ++i) res = res * (n - i + 1) % P;
	ll mu = 1;
	for (int i = 1; i <= m; ++i) mu = mu * i % P;
	return res * quickpow(mu, P - 2) % P;
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; ++i) {
		int x; read(x); A += x;
	}
	ll res = get_c(m + n, A + n);
	printf("%lld\n", (res % P + P) % P);
	return 0;
}


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int             long long int
#define ld              long double
#define ll              long long
#define INF             1000000000000000000
#define pb              push_back
#define mp              make_pair
#define all(x)          x.begin(),x.end()
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define sz(x)           (int)((x).size())
#define f1              first
#define s2              second
#define pii             pair<int,int>
#define bigprime        1000000007
#define MOD             1000000007
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        (a/gcd(a,b))*b
#define scanvec(a,n)      rep(i,0,n){cin>>a[i];}
#define printvec(a,n)     rep(i,0,n){cout<<a[i]<<endl;}
#define boost            ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef tree<int, null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update>PBDS;
//typedef tree<pair<int,int>, null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>PBDS;
/***************************************************/
//bool isPrime(int N){for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
//bool isvowel(char x){ return(x=='a' || x== 'e' ||x=='i' || x== 'o' || x=='u' );}
//int expo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
//int mod(int x){return (x%MOD + MOD)%MOD;}
//int modmul(int a, int b) {return ((a%MOD) * (b%MOD)) % MOD;}
//int modadd(int a, int b){return mod(mod(a) + mod(b));}
//int modsub(int a, int b){return((a%MOD) - (b%MOD) + MOD)%MOD;}
//vector<int> sieve(int n) {int*a = new int[n + 1](); vector<int> v; for (int i = 2; i <= n; i++)if (a[i] == 0) {v.pb(i); for (int j = 2 * i; j <= n; j += i)a[j] = 1;} return v;}
//int ceilval(int a,int b){return ((a/b) + ((a%b)!=0));}
//bool cmp(const pair<int,int> &a,const pair<int,int> &b){return a.f1>b.f1;}
//countsetbits(int n){return __builtin_popcount(n);}
/***************************************************/
void aim()
{
    int n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        sum+=i;
        if(sum>=n)
        {
            cout<<i<<endl;
            break;
        }
    }
}
signed main(){
boost
 //int t;cin>>t;while(t--){aim();}
//    cin.tie(NULL);
aim();
return 0;
}

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
using namespace std;
#define INFL 100000000000000000

int main() {
	int n;
	cin >> n;
	int ans = 1;
	while(2*n > (ans+1)*ans) ans++;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define all(a)      (a).begin(),(a).end()

#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define REP(i,n) for(i=0;i<n;i++)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long   M = 1e9 + 7;

void c_p_c()
{
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mod(int x) {
	return (x % M + M) % M;
}
int  add(int a, int b)
{
	return mod(mod(a) + mod(b));
}
void solve()
{
	double x, y, a, b;
	cin >> x >> y >> a >> b;
	cout << fixed << setprecision(11);

	cout << x + (a * y - x * y) / (b + y);
}

int32_t main()
{

	c_p_c();

	FIO;

	int tt = 1;
	solve();

}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 998244353;

void solve() {
    ll x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    ld x = (x2 - x1) * y1 * 1.0;
    x = (ld)x / (y2 + y1);
    cout << fixed << setprecision(10) << x1 + x << "\n";
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    //cin >> t;
    for(ll i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N;
char S[200011];
char X[200011];

bool dp[200011][7];

void MAIN() {
    scanf("%d", &N);
    scanf("%s", S);
    scanf("%s", X);

    int ten = 1;
    dp[N][0] = true;

    for (int i=N; i--;) {
	int d = S[i] - '0';
	int add = 7 - (d * ten) % 7;
	add %= 7;

	if (X[i] == 'A') {
	    REP (t, 7) dp[i][t] = 1;

	    REP (t, 7) {
		if (!dp[i+1][t]) {
		    dp[i][(t+add) % 7] = 0;
		    dp[i][t] = 0;
		}
	    }
	} else {
	    REP (t, 7) {
		if (dp[i+1][t]) {
		    dp[i][(t+add) % 7] = 1;
		    dp[i][t] = 1;
		}
	    }
	}

	ten = ten * 10 % 7;
    }

    if (dp[0][0]) {
	puts("Takahashi");
    } else {
	puts("Aoki");
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int b = 7;

    int n;
    string s, x;
    cin >> n >> s >> x;

    vector<vector<int>> g(n, vector<int>(b)), h(n, vector<int>(b));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < b; j++) {
            g[i][j] = 10 * j % b;
            h[i][j] = (10 * j + s[i] - '0') % b;
        }
    }

    vector<vector<bool>> r(n + 1, vector<bool>(b, false));
    r[n][0] = true;

    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < b; j++) {
            if (x[i] == 'A') {
                r[i][j] = r[i + 1][g[i][j]] && r[i + 1][h[i][j]];
            } else {
                r[i][j] = r[i + 1][g[i][j]] || r[i + 1][h[i][j]];
            }
        }
    }

    cout << (r[0][0] ? "Takahashi" : "Aoki") << endl;
}


#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef long long int ll;
typedef unsigned long long int ull;

typedef long double lld;

using namespace std;
using namespace std::chrono;

const ll mod = 1'000'000'000ll + 7;
//const ll mod = 998'244'353ll;

const ll inf = 1'000'000'000'000'000'000ll;

const long double eps = 1e-15;

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    ll n;
    cin >> n;
    ll x = 0;
    ll R = n;
    while (1) {
        ll y = n / (1ll << x);
        if (!y) {
            break;
        }
        ll z = n - y * (1ll << x);
        R = min(R, x + y + z);
        x += 1;
    }

    cout << R << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef map<ll, ll> ml;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

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

  ll n, ans = INF;
  cin >> n;
  rep(b, 60) {
    ll q = 1LL << b;
    if(q <= n) chmin(ans, n/q + b + n%q);
  }
  cout << ans << newl;
  return 0;
}


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

int main(){
    ll n,q;
    cin>>n>>q;
    ll arr[n];
    for(ll i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    vector <ll> total_elements(n,0);
    total_elements[0]=arr[0]-1;
    ll sum = total_elements[0];
    for(ll i=1;i<n;i++){
        total_elements[i]+=arr[i]-arr[i-1]-1+total_elements[i-1];
    }
    cout<<"\n";
    while(q--){
        ll k;
        cin>>k;
        if (total_elements[0]>=k){
            cout<<k<<"\n";
            continue;
        }
        else if (k>total_elements[n-1]){
            cout<<arr[n-1]+(k-total_elements[n-1])<<"\n";
            continue;
        }
        else{
            ll idx = lower_bound(total_elements.begin(),total_elements.end(),k)-total_elements.begin();
            cout<<arr[idx-1]+(k-total_elements[idx-1])<<"\n";
        }
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int n , q;
  cin >> n >> q;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  while (q--) {
    long long k;
    cin >> k;
    long long ok = (long long)(2e18);
    long long ng = 0;
    while (ok - ng > 1) {
      long long mid = (ok + ng) / 2;
      int it = upper_bound(a.begin() , a.end() , mid) - a.begin();
      if (mid - it >= k) ok = mid;
      else ng = mid;
    }
    cout << ok << endl;
  }
  return 0;
}


#include <iostream>

using namespace std;
void countPair(long long int arr[], long int n, int k)
{

    long int cnt = 0;

    for (long int i = 0; i < n; i++) {
        arr[i] = (arr[i] + k) % k;
    }

   long long  int hash[k] = { 0 };

    for (long int i = 0; i < n; i++) {
        hash[arr[i]]++;
    }

    for (long int i = 0; i < k; i++) {
        cnt += (hash[i] * (hash[i] - 1)) / 2;
    }

    cout << cnt << endl;
}

int main()
{
    long int n,k;
    cin>>n;
    long long int ar[n];
    for(int i=0; i<n; i++)
    {
        cin>>ar[i];
    }

    countPair(ar,n,200);

    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define F first
#define S second
#define sz(x) (int)x.size()
#define db(x) cout << #x << ": " << x << "\n";

bool mycomp (pair<ll,ll> a, pair<ll,ll> b) {
    return a.F * 2 + a.S > b.F * 2 + b.S;
}

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

    int n;
    cin >> n;
    vector<pair<ll,ll>> p(n);
    ll a = 0, t = 0;
    for (pair<ll,ll> & x : p) {
        cin >> x.F >> x.S;
        a += x.F;
    }
    sort(p.begin(), p.end(), mycomp);
    int i;
    for (i = 0; i < n && a >= t; i++) {
        t += p[i].F + p[i].S;
        a -= p[i].F;
    }
    cout << i << '\n';
}


#include <iostream>

using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    cout<<(k*(k+1)/2)*n+k*100*n*(n+1)/2;
    return 0;
}

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

int main(){
	int n,k;
	cin>>n>>k;
	int cnt=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			cnt+=(i*100+j);
		}
	}
	cout<<cnt;
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure
using namespace __gnu_pbds;              //Policy Based Data Structure
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; //Policy Based Data Structure
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int> >
#define mk(arr,n,type)  type *arr = new type[n]
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int             long long
#define ld              long double
#define nn              '\n'
#define w(t)            cin>>tc; while(tc--)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x,y)       cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define lb(v,x)         lower_bound(v.begin(),v.end(),x)  //returns address of number equal to or just greater than x ,else it is v.end() (i.e. not found)
#define ub(v,x)         upper_bound(v.begin(),v.end(),x)
#define all(x)          x.begin(), x.end()
#define fill(a, b)      memset(a, b, sizeof(a))
#define sortall(x)      sort(all(x))
#define tr(it,a)        for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define PI              3.1415926535897932384626
#define inf             1e18
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());  //Random Shuffler
typedef pair<int, int>   pii;
typedef vector<int>      vi;
typedef vector<pii>      vpii;
typedef vector<vi>       vvi;
typedef map<int, int>    mii;
typedef map<char, int>   mci;
typedef map<string, int> msi;
int mpow(int base, int exp);
int lcm(int a, int b);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
vi g[N];
// no of prime numbers in range : (70,19) , (1000,168) , (100000,1229) , (sqrt(10^9),3409)
//=======================

void sol()
{
	int i, j, k, n, x, y, z, m, tc = 1;
	string s;
	// cin >> tc;
	while (tc--)
	{
		cin >> n;
		int a[n];
		int mn;
		fo(i, n)
		{
			cin >> a[i];
		}
		int ans = 0;
		fo(i, n)
		{
			mn = inf;
			Fo(j, i, n)
			{
				mn = min(mn, a[j]);
				x = mn * (j - i + 1);
				ans = max(ans, x);
			}

		}
		// int l = 0, r = n - 1;
		// int ans = 0;
		// while (l <= r)
		// {
		// 	mn = inf;
		// 	Fo(i, l, r + 1)
		// 	{
		// 		mn = min(mn, a[i]);
		// 	}
		// 	x = (r - l + 1) * mn;
		// 	ans = max(ans, x);
		// 	if (a[l] > a[r])
		// 		r--;
		// 	else
		// 		l++;
		// }
		cout << ans << nn;
	}
}

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

	sol();

	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = (result * base) % mod;
		base = (base * base) % mod;
		exp >>= 1;
	}
	return result;
}

int lcm(int a, int b)
{
	int g = __gcd(a, b);
	return a / g * b;
}

void ipgraph(int m) {
	int i, u, v;
	while (m--) {
		cin >> u >> v;
		g[u - 1].pb(v - 1);
		g[v - 1].pb(u - 1);
	}
}

void dfs(int u, int par) {
	for (int v : g[u]) {
		if (v == par) continue;
		dfs(v, u);
	}
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }

  ll ans=0;
  /*
  rep(i,n){
    for(ll j=i;j<n;j++){
      ll minimum=a[i];
      for(ll k=i;k<=j;k++){
        minimum = min(a[k],minimum);
      }
      //cout << i << " " << j << " " << minimum << endl;
      ans = max(ans,minimum*(j-i+1));
    }
  }
  */

  rep(i,n){
    ll res=a[i];
    ll minimum=a[i];
    for(ll j=i+1;j<n;j++){
      minimum = min(minimum,a[j]);
      res = max(res,minimum*(j-i+1));
    }
    ans = max(ans,res);
  }

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


#include <bits/stdc++.h>
using namespace std;
int read(){
	int sum=0,f=1;
	char s=getchar();
	while (s<'0' or s>'9'){
		if (s=='-')f=-1;
		s=getchar();
	}
	while (s>='0' and s<='9'){
		sum=sum*10+s-'0';
		s=getchar();
	}
	return sum*f;
}
stack<char>s;
int main(){
	int n=read();
	string s1;
	cin>>s1;
	int ans=n;
	for (int i=0;i<n;i++){
		s.push(s1[i]);
		while (s.size()>=3 and s.top()=='x'){
			s.pop();
			if (s.top()!='o'){
				s.push('x');
				break;
			}
			s.pop();
			if (s.top()!='f'){
				s.push('o');
				s.push('x');
				break;
			}
			s.pop();
			ans-=3;
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll n; cin >> n;
    string s; cin >> s;
    vector<char>v;
    for(ll i = 0; i < n; i++) {
        v.push_back(s[i]);
        if(v.size() >= 3) {
            if(v[v.size() - 1] == 'x' && v[v.size() - 2] == 'o' && v[v.size() - 3] == 'f') {
                ll g = 3;
                while(g--) v.pop_back();
            }
        }
    }

    cout << v.size() << endl;
    return 0;
}


#include <bits/stdc++.h>

#define ms(a,b) memset(a, b, sizeof(a))
#define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++)
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define m_p(a,b) make_pair(a, b)
#define lson l,mid,o << 1
#define rson mid + 1,r,o << 1 | 1
#define ls o << 1
#define rs o << 1 | 1
#define inf 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

inline bool isdigit(char& ch) {
	return ch >= '0' && ch <= '9';
}
template<class T>
void read(T &x) {
	x = 0;
	ll f = 1;char ch = getchar();
	for (;!isdigit(ch);ch = getchar())
		if (ch == '-') f = -1;
	for (; isdigit(ch);ch = getchar())
		x = (x << 1) + (x << 3) + ch - '0';
	x *= f;
}
template<class T>
inline void write(T x) {
	if (x == 0) {putchar('0');return ;}
	if (x < 0) {putchar('-');x = -x;}
	int _stk[65],_top = 0;
	for (;x;x /= 10) _stk[++_top] = x % 10 + 48;
	for (;_top;_top--)putchar(_stk[_top]);
}

namespace Union {
	vector<int>fa;
	void Assign(int n) {
		fa.assign(n, -1);
	}
	int root(int x) {
		if (fa[x] < 0)
			return x;
		return fa[x] == x ? fa[x] : fa[x] = root(fa[x]);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	void merge(int x, int y) {
		fa[root(x)] = root(y);
	}
}

using namespace Union;

int main () {
	int n;

	using P = pair<db, db>;
	using Edge = pair<db, pair<int, int>>;

	vector<P>pint;
	cin >> n;
	pint.resize(n);
	for (auto &[x, y] : pint)
		cin >> x >> y;
//	cout << pint.size();
	Assign(n + 2);
	int S  = n, T = n + 1;
	auto calc = [&](P a, P b) {return sqrt((a.fi-b.fi) * (a.fi-b.fi) + (a.se-b.se)*(a.se-b.se));};

	vector<Edge>edge;
	for (int i = 0; i < pint.size(); ++i) {
		edge.push_back({100+pint[i].se, {S, i}});
		edge.push_back({100-pint[i].se, {T, i}});
		for (int j = i + 1; j < pint.size(); ++j) {
			edge.pb({calc(pint[i], pint[j]), {i, j}});
		}
	}
	sort(edge.begin(), edge.end());
	db res = 0;
	for (auto E : edge) {
		merge(E.se.fi, E.se.se);
	//	cout << E.se.fi << " " << E.se.se << " " << E.fi<<endl;
		if (same(S, T)) {
			res = E.fi / 2.0;
			break;
		}
	}
	cout << fixed << setprecision(10) << res << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	int T; cin >> T;
	while(T--){
		string s; cin >> s;
		int N = si(s);
		if(s == string('a',N)){
			cout << -1 << endl;
			continue;
		}
		if(s[0] != 'a'){
			cout << 0 << endl;
			continue;
		}
		int j=-1;
		rep(i,N){
			if(s[i] != 'a'){
				j = i;
				break;
			}
		}
		string t = s;
		for(int i=j-1;i>=1;i--) swap(t[i],t[i+1]);
		if(t > "atcoder"){
			cout << j-1 << endl;
			continue;
		}
		cout << j << endl;
		continue;
	}
}


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

#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);//cout.precision(dbl::max_digits10);
#define pb(x) push_back(x)
#define mod 1000000007ll //998244353ll
#define vi vector<int>
#define v(x) vector< x >
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define repe(i,x,y) for(int i=x; i<=y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}

typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
lld pi=3.1415926535897932;

/*-----------------------------------------------------------*/

void solve(){
	int n,q;
	cin>>n>>q;
	int a[n];
	rep(i,0,n) cin>>a[i];
	sort(a,a+n);
	int b[n];
	b[0]=a[0]-1;
	rep(i,1,n){
		b[i]=b[i-1]+(a[i]-a[i-1]-1);
	}

	rep(i,0,q){
		int x;
		cin>>x;
		int ind = lower_bound(b,b+n,x)-b;
		if(ind!=n){
			cout<<a[ind]-(b[ind]-x+1)<<endl;
		}else{
			cout<<a[n-1]+(x-b[n-1])<<endl;
		}
	}
}

int32_t main(){
	IOS

	int t=1;
	// cin>>t;
	// while(t--)
	// if(solve())
	// cout<<"Yes"<<endl;
	// else
	// cout<<"No"<<endl;

	while(t--)
	solve();

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d[100001],v[100001],an[100001];
struct p
{
	long long q,w;
}m[100001];
bool cmp(p qq,p ww)
{
	return qq.q<ww.q;
}
int main()
{
	scanf("%lld%lld",&a,&b);
	for(int i=1;i<=a;i++)
	{
		scanf("%lld",&d[i]);
	}
	d[a+1]=2000000000000000000;
	for(int i=1;i<=b;i++)
	{
		scanf("%lld",&m[i].q);
		m[i].w=i;
	}
	sort(m+1,m+b+1,cmp);
	long long ll=1;
	for(int i=1;i<=b;i++)
	{
		while(d[ll]-ll<m[i].q) ll++;
		an[m[i].w]=m[i].q+ll-1;
	}
	for(int i=1;i<=b;i++)
	{
		printf("%lld\n",an[i]);
	}
	return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <math.h>
#include <fstream>

#include <complex>
#include <functional>
using namespace std;

#define rep(i, x) for (int i = 0; i < x; ++i)
#define repn(i, x) for (int i = 1; i <= x; ++i)

const static int n_query = 1000;
const static int INF = 100000000;

vector<pair<int, int>> QS(1000), QT(1000);
vector<int> length(1000, INF);

void naive(string& path, int si, int sj, int ti, int tj) {
  int di = ti - si;
  int dj = tj - sj;

  if (di >= 0) {
    rep(i, di) { path += 'D'; }
  } else {
    rep(i, -di) { path += 'U'; }
  }

  if (dj >= 0) {
    rep(i, dj) { path += 'R'; }
  } else {
    rep(i, -dj) { path += 'L'; }
  }
}

string solve(int si, int sj, int ti, int tj) {
  string path = "";
  naive(path, si, sj, ti, tj);
  return path;
}

void make_output(string filename, const string& path) {
  fstream file_out;

  file_out.open(filename, std::ios_base::out);
  if (!file_out.is_open()) {
    cout << "failed to open " << filename << '\n';
  } else {
    file_out << path << endl;
  }
}

int main() {
  rep(i, n_query) {
    int si, sj, ti, tj;
    cin >> si >> sj >> ti >> tj;
    QS[i] = make_pair(si, sj);
    QT[i] = make_pair(ti, tj);

    string path = solve(si, sj, ti, tj);
    cout << path << endl;
    // make_output("output_naive.txt", path);

    int b;
    cin >> b;
    length[i] = b;
  }
}

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

const ll N = 30;
const ll K = 1000;
struct query {
    ll si;
    ll sj;
    ll ti;
    ll tj;
};

// ローカル用
const int LOCAL = 0;
vector<vector<ll>> lhori;
vector<vector<ll>> lver;
vector<query> lqueries;
struct lscorefunc {
    ll a;
    double e;
};
vector<lscorefunc> lscorefuncs;
ll local_qid = 0;
void init_local() {
    lhori.resize(N, vector<ll>(N - 1));
    lver.resize(N - 1, vector<ll>(N));
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N - 1; j++) {
            cin >> lhori[i][j];
        }
    }
    for (ll i = 0; i < N - 1; i++) {
        for (ll j = 0; j < N; j++) {
            cin >> lver[i][j];
        }
    }
    for (ll i = 0; i < K; i++) {
        ll si, sj, ti, tj, a;
        double e;
        cin >> si >> sj >> ti >> tj >> a >> e;
        lqueries.push_back(query({si, sj, ti, tj}));
        lscorefuncs.push_back(lscorefunc({a, e}));
    }
}
ll response_local(string &s, query q) {
    ll i = q.si;
    ll j = q.sj;
    ll length = 0;
    for (char c : s) {
        if (c == 'D') {
            i = i + 1;
            length += lver[i - 1][j];
        } else if (c == 'U') {
            i = i - 1;
            length += lver[i][j];
        } else if (c == 'R') {
            j = j + 1;
            length += lhori[i][j - 1];
        } else if (c == 'L') {
            j = j - 1;
            length += lhori[i][j];
        }
    }
    return length;
}
query get_query_local() {
    query q = lqueries[local_qid];
    local_qid++;
    return q;
}
//

ll response(string &s, query q) {
    if (LOCAL) {
        return response_local(s, q);
    }

    cout << s << "\n";
    cout.flush();
    ll length = 0;
    cin >> length;
    return length;
}
query get_query() {
    if (LOCAL) {
        return get_query_local();
    }

    ll si, sj, ti, tj;
    cin >> si >> sj >> ti >> tj;
    return query({si, sj, ti, tj});
}

int main() {
    ioinit();
    if (LOCAL) {
        init_local();
    }
    for (ll task = 0; task < K; task++) {
        query q = get_query();
        string s;
        if (q.si > q.ti) {
            for (ll h = 0; h < (q.si - q.ti); h++) {
                s.push_back('U');
            }
        } else if (q.si < q.ti) {
            for (ll h = 0; h < (q.ti - q.si); h++) {
                s.push_back('D');
            }
        }
        if (q.sj > q.tj) {
            for (ll i = 0; i < (q.sj - q.tj); i++) {
                s.push_back('L');
            }
        } else if (q.sj < q.tj) {
            for (ll i = 0; i < (q.tj - q.sj); i++) {
                s.push_back('R');
            }
        }
        ll length = response(s, q);
    }
}


#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define MAXN 1000005
#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;

#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {
	while(L < R) cerr << *L << " \n"[next(L) == R], ++L;
}
void kout() {cerr << endl;}
template<class T1, class ... T2> void kout(T1 a, T2...e) {cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
int n, m;
struct edge {
	int to, cost;
};
vector<vector<edge>> mp;
vector<int> dis, vis;
int dikstra(int x, int y) {
	dis.assign(2 * n + 1, INF);
	vis.assign(2 * n + 1, 0);
//	print(2 * n + 1, dis.size());
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	dis[x] = 0; pq.push({0, x});
	while(pq.size()) {
		int cur = pq.top().second; pq.pop();
		if(vis[cur]) continue;
		vis[cur] = 1;
		for(auto i : mp[cur]) {
			if(dis[i.to] > dis[cur] + i.cost) {
				dis[i.to] = dis[cur] + i.cost;
				pq.push({dis[i.to], i.to});
			}
		}
	}
//	print(x, y, dis.size());
//	vprint(all(dis)), kout();
	if(dis[y] == INF) return -1;
	else return dis[y];
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	mp.assign(2 * n + 5, vector<edge>());
	rep(i, 1, n) {
		mp[i].push_back({i + n, 0});
	}
	rep(i, 1, m) {
		int a, b, c;
		cin >> a >> b >> c;
		mp[a + n].push_back({b, c});
	}
	rep(i, 1, n) {
		cout << dikstra(i + n, i) << "\n";
	}
	return 0;
}

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION cout << fixed << setprecision(20);

using namespace std;

void solve() {
    int n;
    cin >> n;
    string s;
    string x;
    cin >> s >> x;

    vector<vector<int>> dp(n, vector<int>(7, -1));

    function<int(int,int)> get = [&](int pos, int rem) {
        if (pos == n) return int(rem == 0);

        if (dp[pos][rem] == -1) {
            int ans1 = get(pos + 1, (rem * 10) % 7);
            int ans2 = get(pos + 1, (rem * 10 + (s[pos] - '0')) % 7);

            if (x[pos] == 'A') dp[pos][rem] = min(ans1, ans2);
            if (x[pos] == 'T') dp[pos][rem] = max(ans1, ans2);
        }

        return dp[pos][rem];
    };

    int ans = get(0, 0);

    if (ans) {
        cout << "Takahashi\n";
    } else {
        cout << "Aoki\n";
    }
}

int main() {
    FASTIO;
    PRECISION;

    int t = 1;
    // cin >> t;

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


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

#define MAX_HEIGHT 10000
#define MAX_WIDTH 10000

struct Ad {
  int x, y, r;
  int a, b, c, d, area;
  Ad(int x, int y, int r) : x(x), y(y), r(r) {
    a = x;
    b = y;
    c = x + 1;
    d = y + 1;
    area = 1; // (c - a) * (d - b)
  }
  void OutputPosition() {
    cout << a << " " << b << " " << c << " " << d << endl;
  }
  double GetScore() {
    double diff = (1 - (double)min(r, area) / (double)max(r, area));
    return 1 - diff * diff;
  }
};

double Solve(const vector<Ad*> ads, const int N) {
  double sum = 0;
  for (const auto& ad : ads) {
    ad->OutputPosition();
    sum += ad->GetScore();
  }
  cerr << "Score: " << (int)(1e9 * sum / N) << endl;
  return sum;
}

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

  int x, y, r;
  vector<Ad*> ads;
  for (int i = 0; i < N; i++) {
    cin >> x >> y >> r;
    ads.push_back(new Ad(x, y, r));
  }
  Solve(ads, N);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) v.begin(), v.end()
template<class T>bool chmax(T& a, const T& b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T& a, const T& b) { if (b<a) { a=b; return 1;} return 0;}

using pint = pair<int, int>;
const int MAX = 10000;
int n;
vector<vector<int>> xyr;
bool flgs[MAX][MAX];
vector<vector<int>> res;

void paintOut(int x, int y, int size) {
    x -= size, y -= size;
    size = 2 * size + 1;
    for (int i = y; i < y + size; ++i) {
        for (int j = x; j < x + size; ++j) {
            flgs[i][j] = 1;
        }
    }
}

int square(int sx, int sy, int r) {
    --sx, --sy; // upper left
    int len = 3;
    while (len*len <= r) {
        if (sy < 0 || sy + len >= MAX) return len/2 - 1;
        if (sx < 0 || sx + len >= MAX) return len/2 - 1;

        rep(i, len) if (flgs[sy+i][sx]) return len/2 - 1;
        rep(i, len) if (flgs[sy+len-1][sx+i]) return len/2 - 1;
        rep(i, len) if (flgs[sy+i][sx+len-1]) return len/2 - 1;
        rep(i, len) if (flgs[sy][sx+i]) return len/2 - 1;

        --sx, --sy, len += 2;
    }
    return len/2 - 1;
}

void solve() {
    rep(i, n) flgs[xyr[i][2]][xyr[i][1]] = 1;
    sort(all(xyr), [](auto& x, auto& y){return x[3] < y[3];});
    rep(i, n) {
        int x = xyr[i][1], y = xyr[i][2], r = xyr[i][3];
        flgs[y][x] = 0;
        int size = square(x, y, r);
        paintOut(x, y, size);
        res[xyr[i][0]] = {x-size, y-size, x+1+size, y+1+size};
    }
    rep(i, n) {
        rep(j, 4) {
            if (j) cout << " ";
            cout << res[i][j];
        }
        cout << endl;
    }
}

int main() {
    cin >> n;
    xyr.resize(n, vector<int>(4));
    rep(i, n) {
        xyr[i][0] = i;
        cin >> xyr[i][1] >> xyr[i][2] >> xyr[i][3];
    }
    res.resize(n, vector<int>(3));
    solve();
}