#include <bits/stdc++.h>
#define debug(x) cout << "[" << #x << " = " << x << "] "
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

/*wa? coloca long long que passa;
testar casos, n = 0? n = 1?
dp: min(solve(l+1,r),solve(l,r-1))?
Uma resposta ótima pode ter tamanho 2?*/

void printa(string s, int cont){
    int n = s.size() / 2;
    if(cont & 1){
        for(int i = 0; i < n; i++)
            swap(s[i], s[i+n]);
    }

    cout << s << endl;
}

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

    int n;
    string s;
    cin >> n >> s;

    int q, cont = 0;
    cin >> q;

    while(q--){
        int t, a, b;
        cin >> t >> a >> b;

        if(t == 1){ //troca s[a] por s[b]
            if(a <= n && b <= n && (cont & 1) ){
                swap(s[a-1+n],s[b-1+n]);
            } else if(a > n && b > n && (cont & 1) ){
                swap(s[a-1-n], s[b-1-n]);
            } else {
                if(cont % 2 == 0)
                    swap(s[a-1], s[b-1]);
                else
                    swap(s[b-1-n], s[a-1+n]);
            }

        } else { //troca os n primeiros com os n ultimos
            cont++;
        }
    }

    printa(s, cont);

}

#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
void radd(int &a, int b)
{
	a=add(a,b);
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
void rmult(int &a, int b)
{
	a=mult(a,b);
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}

char b[2][2];
int a[2][2];
int c[2][2];
int dp[1111][2];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	if(n==2)
	{
		cout<<1<<'\n'; return 0;
	}
	cin>>b[0][0]>>b[0][1]>>b[1][0]>>b[1][1];
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			a[i][j]=b[i][j]-'A';
		}
	}
	if(a[0][1]==0)
	{
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				c[i][j]=(a[j^1][i^1]^1);
			}
		}
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				a[i][j]=c[i][j];
			}
		}
	}
	//assume A...B B
	if(a[1][1]==1)
	{
		cout<<1<<'\n'; return 0;
	}
	//assume B...A B
	if(a[1][0]==1)
	{
		dp[1][1]=1; //length 1, end with 0
		for(int i=2;i<=n;i++)
		{
			dp[i][0]=add(dp[i-1][0],dp[i-1][1]);
			dp[i][1]=dp[i-1][0];
		}
		cout<<dp[n][0]<<'\n';
	}
	else
	{
		//n>2
		cout<<modpow(2,n-3)<<'\n';
	}
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    A.push_back(x);
  }

  // Manhattan
  int64_t M = 0;
  for(int i = 0; i < N; i++){
    M += abs(A.at(i));
  }
  cout << M << endl;

  // Eucrid
  int64_t t = 0;
  double E = 0.00;
  for(int i = 0; i < N; i++){
    t += pow(A.at(i), 2);
  }
  E = sqrt(t);
  cout << fixed << setprecision(15);
  cout << E << endl;

  // Chebyshev
  for(int i = 0; i < N; i++){
    A.at(i) = abs(A.at(i));
  }
  sort(A.begin(), A.end());
  cout << A.at(N - 1) << endl;

  return 0;
}

#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
long long arr[100005];
int main(){

	int n;
	cin >> n;

	int i;
	long long ans = 0;
	for(i=0; i<n; i++){
		cin >> arr[i];
	}
	for(i=0; i<n; i++){
		if(arr[i]<0){
		ans += -arr[i];
	}else{
		ans += arr[i];
	}
}
	cout << ans << endl;

	long long ans1= 0;
	for(i=0; i<n; i++){
		ans1 += arr[i]*arr[i];
	}
	cout << fixed << setprecision(20) << sqrt(ans1) << endl;

	long long ans2=0;
	for(int i=0; i<n; i++){

		if(arr[i]>ans2 || (-arr[i]>ans2)){
			if(arr[i]<0){
				ans2 = -arr[i];
			}
			else{
				ans2 = arr[i];
			}
		}
}
	cout << ans2 << endl;

	return 0;
}


//#include <atcoder/all>
//using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define bit(n) (1LL<<(n))
#define FIX(d) fixed << setprecision(d)
using P = pair<int, int>;
using LP = pair<ll, ll>;
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 = 1e9;
const ll LINF = (1LL<<60);

unsigned int xor128(){
  static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
  unsigned int t = (x^(x<<11));
  x=y; y=z; z=w;
  return( w=(w^(w>>19))^(t^(t>>8)) );
}

int n;
int cx[200], cy[200], r[200];
int a[200], b[200], c[200], d[200];

ll score(){
  double sc = 0.0;
  REP(i,n){
    int area = (c[i]-a[i]) * (d[i]-b[i]);
    double tmp = 1.0 - (double)min(area,r[i])/max(area,r[i]);
    sc += 1e9 - 1e9*tmp*tmp;
  }
  return (ll)round(sc/n);
}

ll score_dx(int ind){
  int area = (c[ind]-a[ind]+1) * (d[ind]-b[ind]);
  double tmp = 1.0 - (double)min(area,r[ind])/max(area,r[ind]);
  tmp = 1e9 - 1e9*tmp*tmp;
  return (ll)round(tmp/n);
}

ll score_dy(int ind){
  int area = (c[ind]-a[ind]) * (d[ind]-b[ind]+1);
  double tmp = 1.0 - (double)min(area,r[ind])/max(area,r[ind]);
  tmp = 1e9 - 1e9*tmp*tmp;
  return (ll)round(tmp/n);
}

void init(){
  REP(i,n){
    a[i] = cx[i];
    b[i] = cy[i];
    c[i] = cx[i]+1;
    d[i] = cy[i]+1;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  REP(i,n) cin >> cx[i] >> cy[i] >> r[i];

  int ti = clock();
  init();
  ll mx = score();
  //cout << mx << endl;
  while(clock() - ti < 490 * CLOCKS_PER_SEC / 100){
    REP(loop, 300){
      int ind = xor128() % n;
      int xy = xor128() % 2;
      bool minus = false, plus = false;
      if(xy==0){
        REP(i,n){
          if(i==ind) continue;
          if(max(a[i],a[ind]-1)<min(c[i],c[ind]) && max(b[i],b[ind])<min(d[i],d[ind])){
            minus = true;
          }
          if(max(a[i],a[ind])<min(c[i],c[ind]+1) && max(b[i],b[ind])<min(d[i],d[ind])){
            plus = true;
          }
        }

        if(c[ind]<10000 && !plus){
          c[ind]++;
          if(!chmax(mx, mx+score_dx(ind))) c[ind]--;
        }else if(a[ind]>0 && !minus){
          a[ind]--;
          if(!chmax(mx, mx+score_dx(ind))) a[ind]++;
        }
      }else{
        REP(i,n){
          if(i==ind) continue;
          if(max(a[i],a[ind])<min(c[i],c[ind]) && max(b[i],b[ind]-1)<min(d[i],d[ind])){
            minus = true;
          }
          if(max(a[i],a[ind])<min(c[i],c[ind]) && max(b[i],b[ind])<min(d[i],d[ind]+1)){
            plus = true;
          }
        }
        if(d[ind]<10000 && !plus){
          d[ind]++;
          if(!chmax(mx, mx+score_dy(ind))) d[ind]--;
        }else if(b[ind]>0 && !minus){
          b[ind]--;
          if(!chmax(mx, mx+score_dy(ind))) b[ind]++;
        }
      }
    }
    //cout << mx << endl;
  }
  //cout << mx << endl;
  REP(i,n) cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << '\n';
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(int i=0;i<(n);i++)
#define f1(i,n) for(int i=1;i<=(n);i++)
#define f2(i,a,n) for(int i=(a);i<=(n);i++)
#define fr(i,n,a) for(int i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define nl "\n"

const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;
const ll LMXN = 1e14;
const int MOD = 1e9 + 7;
ll cs = 0;

void solve(){
    int n; cin >> n;
    ll ans1 = 0, ans3 = 0;
    double ans2 = 0;
    f0(i, n){
        ll a; cin >> a;
        ans1 += abs(a);
        ans2 += abs(a)*abs(a);
        ans3 = max(ans3, abs(a));
    }
    cout << fixed << setprecision(15);
    cout << ans1 << nl;
    cout << sqrt(ans2) << nl;
    cout << ans3 << nl;

}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //FIO;
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for(int i=int(n-1);i>=int(0);--i)
#define fore(i,a) for(auto &i:a)
#define all(x) x.begin(),x.end()
#define sz(x) ((int)(x).size())
#define bp(x) (__builtin_popcount((long long)(x)))
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define V vector
#define P pair<int,int>
#define TP tuple<int,int,int>
#define F first
#define S second
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 ll = long long;
using ld = long double;
using namespace std;
const int INF = 1001001001;
const ll INFL = 1001001001001001001;
const int MAX = 2e6+1;

int main() {
    ll a,b;cin>>a>>b;
    if(a>b)swap(a,b);
    ll ans=1;
    rep(i,2,b+1){
        if(ceil(1.0*a/i)*i+i<=b)ans=i;
    }

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

#include<cstdio>//JZM YYDS!!!
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define ll long long
#define MAXN 200005
#define uns unsigned
#define MOD 998244353ll
#define INF 0x7f7f7f7f
#pragma GCC optimize("O2")
using namespace std;
inline ll read(){
	ll x=0;bool f=1;char s=getchar();
	while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
	while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
	return f?x:-x;
}
ll x,y,p,q;
inline ll exgcd(ll a,ll b,ll&x,ll&y){
	if(b==0){x=1,y=0;return a;}
	ll res=exgcd(b,a%b,y,x);
	y-=a/b*x;return res;
}
signed main()
{
	for(int T=read();T--;){
		x=read(),y=read(),p=read(),q=read();
		ll md=(x+y)<<1,lim=md*(p+q)+1,ans=lim;
		ll b=p,a=p+q,K,f,g=exgcd(p+q,md,K,f);
		for(ll i=x;i<x+y;i++){
			ll c=((i-b)%md+md)%md,k=K;
			if(c%g!=0)continue;
			c/=g,k=(k*c%md+md)%(md/g);
			if((k*a+b)%md>=x&&(k*a+b)%md<x+y)ans=min(ans,k*a+b);
		}
		md=p+q,b=x,a=(x+y)<<1,g=exgcd((x+y)<<1,md,K,f);
		for(ll i=p;i<p+q;i++){
			ll c=((i-b)%md+md)%md,k=K;
			if(c%g!=0)continue;
			c/=g,k=(k*c%md+md)%(md/g);
			if((k*a+b)%md>=p&&(k*a+b)%md<p+q)ans=min(ans,k*a+b);
		}
		if(ans>=lim)printf("infinity\n");
		else printf("%lld\n",ans);
	}
	return 0;
}


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

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

	bool ok=true;
	rep(i, n) if(i!=p[i] && a[i]<=b[p[i]]) ok=false;
	if(!ok){
		cout<<(-1)<<endl;
		return 0;
	}

	vector<int> r(n);
	rep(i, n) r[p[i]]=i;

	vector<P> li;
	rep(i, n) li.push_back(P(b[i], i));
	sort(li.rbegin(), li.rend());
	vector<P> ans;
	for(auto t : li){
		int i=r[t.second];
		int j=p[i];
		if(i==j) continue;
		ans.push_back(P(i, j));
		swap(p[i], p[j]);
		swap(r[p[i]], r[p[j]]);
	}

	cout<<ans.size()<<endl;
	for(auto t : ans) cout<<(t.first+1)<<" "<<(t.second+1)<<endl;

	return 0;
}

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

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

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

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

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

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

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

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

/* sorry, this is the bare minimum :'( */
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second

int main(int argc, char const *argv[])
{
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  int n; cin >> n;
  vi a(n), b(n), p(n);
  for(int& x : a) cin >> x, x--;
  for(int& x : b) cin >> x, x--;
  for(int& x : p) cin >> x, x--;
  debug(a, b, p);
  vi host(n), to(n), what(n), from(n);
  set<ii> st;
  for(int i = 0; i < n; ++i) {
    from[p[i]] = i;
    to[i] = p[i];
    what[i] = b[p[i]];
    if(p[i] != i) {
      st.insert(ii(what[i], i));
    }
  }
  vector<ii> ans;
  while(st.size()) {
    debug(st);
    int y = st.begin() -> second;
    st.erase(st.begin());
    if(from[y] == y) continue;
    int x = from[y];
    if(what[x] >= a[x] or what[y] >= a[y]) {
      cout << "-1" << endl;
      exit(0);
    }
    ans.emplace_back(x+1, y+1);
    st.erase(ii(what[x], x));
    what[x] = what[y];
    st.insert(ii(what[x], x));
    to[x] = to[y];
    from[to[x]] = x;
  }
  cout << sz(ans) << "\n";
  for(ii& pa : ans) {
    cout << pa.fi << ' ' << pa.se << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define rep0(i,n) for ((i)=0;(i)<(n);(i)++)
using namespace std;
long long n,m,s,i;
vector<int> ans;
long long gcd(long long x,long long y){
	if(!y) return x;
	long long t=gcd(y,x%y);
	s+=x/y;return t;
}
void print(long long x,long long y){
	if(!x){
		while(y--)ans.push_back(2);
		return;
	}
	if(!y){
		while(x--)ans.push_back(1);
		return;
	}
	if(x>y){
		while(x>=y){
			ans.push_back(3);
			x-=y;
		}
	}
	else{
		while(x<=y){
			ans.push_back(4);
			y-=x;
		}
	}
	print(x,y);
}
int main(){
	srand(time(NULL));
	cin>>n;
	for(;;){
		m=(rand()+rand()*65536ll+rand()*65536ll*65536ll/*+rand()*65536ll*65536ll*65536ll*/)%n;
		s=0;
		long long g=gcd(n,m);
		if(s+g>130) continue;
		print(n,m);
		printf("%d\n",ans.size());reverse(ans.begin(),ans.end());
		rep0(i,ans.size())printf("%d\n",ans[i]);
		return 0;
	}
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

using ll=long long;
ll Fib[89];

int main(){
  Fib[0]=Fib[1]=1;
  for(int i=2;i<89;i++)Fib[i]=Fib[i-1]+Fib[i-2];

  ll n;cin>>n;
  vector<int> A;
  for(int i=88;i>=0;i--){
    if(n>=Fib[i]){
      A.push_back(i);
      n-=Fib[i];
    }
  }
  reverse(ALL(A));
  vector<int> ans;
  int now=0;
  for(int i=0;i<88&&now<A.size();i++){
    if(A[now]==i){
      ans.push_back(1+(i&1));
      now++;
    }
    ans.push_back(3+(i&1));
  }
  reverse(ALL(ans));
  cout<<ans.size()<<endl;
  for(int p:ans)cout<<p<<endl;
}


#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#define fi              first
#define se              second
#define mp              make_pair
#define all(x)          x.begin(), x.end()
#define For(it, x, y)	for(int it = x; it < y; it ++)
#define ios             ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define bug(str, x)     cerr << "# " << str << " : " << x << '\n'
#define here(x)         cerr << "here " << x << '\n'

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 2e5 + 10;
const int maxa = 2e5;
const int inf = 1e9;
int a[maxn];
bool visited[maxn];
vector<int> G[maxn];

void dfs(int v){
	visited[v] = true;
	for(int u : G[v]){
		if(!visited[u]){
			dfs(u);
		}
	}
}

int main(){
	ios;
	int n;
	cin >> n;
	For(i, 0, n){
		cin >> a[i];
	}
	For(i, 0, n / 2){
		G[a[i]].push_back(a[n - 1 - i]);
		G[a[n - 1 - i]].push_back(a[i]);
	}
	int cnt = 0;
	For(i, 1, maxa + 1){
		if(!visited[i]){
			dfs(i);
			cnt ++;
		}
	}
	cout << maxa - cnt;
}

#include <bits/stdc++.h>
#define f first
#define s second
#define all(vec) begin(vec), end(vec)
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<double, int> pdi;

const int N = 2e5+3;
vector<int> adj[N];
vector<bool> vis(N);
int cnt;
void dfs(int c){
    vis[c] = 1;
    cnt++;
    for(auto& i : adj[c]){
        if(!vis[i]){
            dfs(i);
        }
    }
}
void solve(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i <= n; i++){
//        if(a[i] == a[n-i+1])continue;
        adj[a[i]].pb(a[n-i+1]);
        adj[a[n-i+1]].pb(a[i]);
    }
    for(int i = 1; i < N; i++){
        if(!vis[i]){
            cnt = 0;
            dfs(i);
            ans += cnt-1;
        }
    }
    cout << ans << '\n';
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen("input.in", "r", stdin);
//    freopen("input.in", "w", stdout);
    int tc = 1;
//    cin >> tc;
    while(tc--)solve();
}


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

#define Fi first
#define Se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)
typedef tuple<int, int, int> t3;

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

int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%d", A + i);
	for(int i=1;i<=N;i++) scanf("%d", B + i);
	priority_queue <ll> pq;
	ll at = 0;
	for(int i=1;i<=N;i++) {
		if(i & 1) {
			at += B[i];
			pq.push(A[i] - B[i]);
		}
		else {
			at += A[i];
			pq.push(B[i] - A[i]);
		}
	}
	rep(i, N / 2) at += pq.top(), pq.pop();
	printf("%lld\n", at);
	return 0;
}

#include "bits/stdc++.h"

using namespace std;

const int mod = 1e9 + 7;

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

	long long dp[2] = {0}, cnt[2] = {0};

	cnt[1] = 1;

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

		auto x = dp[1];
		auto y = cnt[1];

		dp[1] = (dp[0] - cnt[0] * a) % mod;
		cnt[1] = cnt[0];

		dp[0] = (dp[0] + x + a * (y + cnt[0])) % mod;
		cnt[0] = (cnt[0] + y) % mod;
	}

	cout << ((dp[0] + dp[1]) % mod + mod) % mod << '\n';
}

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


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

ll INF = 1e18;
ll dp[101][101];

void init(int k){
	rep(i,k+1) rep(j,k) dp[i][j] = -INF;
	dp[0][0] = 0;
}

void update(int k, int a){
	for(int i=k-1; i>=0; --i) rep(j,k){
		int sk = (j + a) % k;
		dp[i+1][sk] = max(dp[i+1][sk], dp[i][j] + a);
	}
}

int main(){
	int n; ll x; cin>>n>>x;
	int A[n]; for(auto&a:A) cin>>a;
	ll ans = INF;
	for(int k=1; k<=n; ++k){
		init(k);
		for(int a:A) update(k, a);
		ll s = dp[k][x%k];
		if(s >= 0) ans = min(ans, (x-s)/k);
	}
	cout<< ans <<endl;
}


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

int main(){
  int N;
  cin >> N;
  unsigned long long a[N],a_max,b[N],b_max,c;
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  for(int i=0;i<N;i++){
    cin >> b[i];
  }
  c = a[0]*b[0];
  a_max=a[0];
  b_max=b[0];
  cout << c << endl;
  for(int i=1;i<N;i++){
    if(a_max < a[i]) a_max=a[i];
    if(c < a_max*b[i]) c = a_max*b[i];
    cout << c << endl;
  }
  return 0;
}

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

using namespace std;
#define  start     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define  int       long long
#define  ll        long long
#define  vi        vector<int>
#define  pb        push_back
#define  mod       1000000007
#define  all(v)    v.begin(),v.end()
#define  maxv(a)   *max_element(all(a))
#define  minv(a)   *min_element(all(a))
#define  sumv(a)    accumulate(all(a),0)
//#define  endl       '\n'

typedef tree< int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update > ordered_set;
//0 based index
//cout<<*X.find_by_order(1)<<endl; // iterator to the k-th element
// cout<<X.order_of_key(-5)<<endl;  // number of items in a set that are strictly smaller than our item

int gcd(int a,int b){
	return __gcd(a,b);
}
int lcm(int a,int b){
	return a*(b/gcd(a,b));
}
bool isprime(int n){
	if(n<=1)return false;
	for(int i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return true;
}

vector<int>divisor(int n)
{
	vector<int>v;
	for(int i=1;i*i<=n;i++){
		if(i*i==n)v.pb(i);
		else if(n%i==0){
			v.pb(i);
			v.pb(n/i);
		}
	}
	return v;
}

const int MX=1e6+123;
vector<int>fact[MX];
bool is_prime[MX];
vector<int>primes;

void sieve(int n){

	for(int i=3;i<=n;i+=2)is_prime[i]=1;
	for(int i=3;i*i<=n;i+=2){
		if(is_prime[i]==1){
			for(int j=i*i;j<=n;j+=(i+i)){
				is_prime[j]=0;
			}
		}
	}
	is_prime[2]=1;
	primes.pb(2);
	for(int i=3;i<=n;i++){
		if(is_prime[i]==1){
			primes.pb(i);
		}
	}
}

vector<int>primefactor(int n){

	vector<int>v;
	for(auto p:primes){
		if(1LL*p*p>n)break;
		if(n%p==0){
			while(n%p==0){
				v.pb(p);
				n/=p;
			}
		}
	}
	if(n>1)v.pb(n);
	return v;
}
int sumofDigit(int n)
{
    int sum=0;
	while(n!=0)
	{
		sum+=n%10;
		n/=10;
	}
	return sum;
}
bool isPalindrome(string s)
{
	int l=0;
	int h=s.size()-1;
	while(l<h)
	{
		if(s[l++]!=s[h--])
		{
			return false;
		}
	}
	return true;

}
int reverse(int x){
	int rev=0,rem;
	while(x!=0){
		rem=x%10;
		rev=rev*10+rem;
		x/=10;
	}
	return rev;
}

void solve(){
	int n;
	cin>>n;
	vi v(n);
	map<int,int>mp;
	for(int i=0;i<n;i++){
		cin>>v[i];
		mp[v[i]%200]++;
	}
	int ans=0;
	for(auto x:mp){
		ans+=(x.second*(x.second-1))/2;
	}
	cout<<ans<<endl;

}

signed main()
{
	start;
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}

}


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

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

#define all(x)						(x).begin(),(x).end()
#define X							first
#define Y							second
#define sep							' '
#define endl						'\n'
#define SZ(x)						ll(x.size())

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;

int n , A[MAXN] , ans[MAXN];
vector<pii> vec;
vector<int> stk;

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

	cin >> n;
	for(int i = 0 ; i < 2 * n ; i++){
		cin >> A[i];
		vec.push_back({A[i] , i});
	}
	sort(all(vec));
	for(int i = 0 ; i < n ; i++){
		ans[vec[i].Y] = 1;
	}
	for(int i = 0 ; i < 2 * n ; i++){
		if(SZ(stk) == 0 || ans[i] == ans[stk.back()]){
			cout << '(';
			stk.push_back(i);
		}
		else{
			cout << ')';
			stk.pop_back();
		}
	}

    return 0;
}
/*

*/

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define deb(x) cout << #x": " << (x) << endl;

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x){return __builtin_popcountll(x);}

 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

lli poww(lli a, lli b){
	lli res =1;
	while(b){ if(b&1) res = res * a; a = a*a; b/=2; }
	return res;
}

template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- コーディングはここから！ ('-')7

void solve(){
	int n; cin>>n;
	cout<<100-(n%100)<<ENDL;

}

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


#include <bits/stdc++.h>
using namespace std;
#define int long long
int a,b,c,d;
signed main()
{
	cin>>a>>b>>c>>d;
	if(c*d<=b){cout<<-1;return 0;}
	cout<<ceil(1.0*a/(d*c-b));
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

//==============================AUTHOR:ZETPI=======================================//
#define int long long
#define fr(i,st,c)          for(int i=st;i<c;i++)
#define rfr(i,e,c)          for(int i=e;i>=c;i--)
#define i_output(f1)        cout<<(f1?"YES":"NO")<<endl;
#define F                   first
#define S                   second
#define pb                  push_back
#define print(n)            cout<<n<<endl
#define all(x)              x.begin(),x.end()
#define sortall(x)          sort(all(x))

#define thor                ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef vector<int>         vi;
typedef pair<int,int>       pi;
typedef map<int,int>        mpi;
typedef set<int>            st;

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

const int mod=1'000'000'007;

//============================COPYING PROHIBITED======================================//

void solve(){

   int a,b,c,d;
   cin>>a>>b>>c>>d;

   int cyan=a,red=0,cnt=0,f=-1;

   while(cyan>d*red && b<(c*d)){
    cyan+=b;
    red+=c;
    cnt++;
    f=1;
   }

   if(f==-1){
    print(-1);
    }
    else{
        print(cnt);
    }

}

signed main(){

    thor
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

    return 0;
}


/**
 *   Author:  Wasi Ur Rahman
 *   FROM RMSTU
**/
#include <bits/stdc++.h>
#define ll                     long long
#define boost                  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ticktock               cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n"
#define min3(a,b,c)            min(a,min(b,c))
#define min4(a,b,c,d)          min(d,min3(a,b,c))
#define max3(a,b,c)            max(a,max(b,c))
#define max4(a,b,c,d)          max(d,max3(a,b,c))
#define all(v)                 v.begin(),v.end()
#define revall(v)              v.rbegin(),v.rend()
#define pb                  	push_back
#define eb                     emplace_back
#define mk                     make_pair
#define setbits(x)             __builtin_popcountll(x)
#define zrobits(x)             __builtin_ctzll(x)
#define si(x)               	scanf("%d", &x)
#define sii(x, y)           	scanf("%d %d", &x, &y)
#define siii(x, y, z)       	scanf("%d %d %d", &x, &y, &z)
#define siiii(p,x, y, z)    	scanf("%d %d %d %d",&p, &x, &y, &z)
#define sll(x, y)           	scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       	scanf("%lld %lld %lld", &x, &y, &z)
#define read                	freopen("input.txt","r",stdin)
#define write               	freopen("output.txt","w",stdout)
#define println()          		cout << endl
#define no                      cout << "NO" << endl
#define yes                     cout << "YES" << endl
#define printi(x)           	printf("%d\n")
#define printii(x,y)        	printf("%d %d\n")
#define printiii(x,y,z)     	printf("%d %d %d\n")
#define printl(x)           	printf("%lld\n")
#define printll(x,y)        	printf("%lld %lld\n")
#define printlll(x,y,z)     	printf("%lld %lld %lld\n")
using namespace std;
/*************************************
*          A S S E M B L E           *
**************************************/
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
bool Prime(ll n){if(n <= 1)return false;for (ll i = 2; i<=sqrt(n); i++)if (n % i == 0)return false;return true;}
const int mod = 1e9+7;
ll add(ll a,ll b){if((a+=b)>=mod)a-=mod;return a;}
inline int dec(int a,int b){if((a-=b)<0)a+=mod;return a;}
ll mult(ll a,ll b){long long t=1ll*a*b;if(t>=mod)t%=mod;return t;}
ll power(ll a,ll b){ll out=1;while(b){if(b&1)out=mult(out,a);a=mult(a,a);b>>=1;}return out;}
ll modpow(ll a, ll n, ll mod){ll res=1;while(n>0){if(n&1) res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
ll modinverse(ll a,ll M){return modpow(a,M-2,M);}
int main(){
    boost;
    int n;
    cin >> n;
    vector<int> v(n);
    int arr[200001];
    memset(arr,0,sizeof(arr));
    for(int i = 0;i<n;i++)
    {
        cin >> v[i];
    }
    vector<int> ans;
    int m = 0;
    for(int i = 0;i<n;i++){
        arr[v[i]]++;
        if(arr[m] == 0)
            cout << m << endl;
        else{
            while(arr[m] != 0)
                m++;
            cout << m << endl;
        }
    }
}

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

// $ cp-batch NeqMin | diff NeqMin.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address NeqMin.cpp && ./a.out

/*

 10/10/2020

 5:06-

 */

const int MAX_N=1e6+1;
int P[MAX_N];
int N;

void solve() {
  VI viz(MAX_N,0);
  int res=0;
  REP(i,N) {
    viz[P[i]]=1;
    while(viz[res]==1) ++res;
    cout<<res<<endl;
  }
}

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

  cin>>N;
  REP(i,N) cin>>P[i];
  solve();

  return 0;
}


//
// Created by Anton Gorokhov
//

#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstddef>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <unordered_map>
#include <random>
#include <iomanip>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <cassert>
#include <bitset>
#include <deque>
#include <utility>

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ld double

using namespace std;

mt19937 rnd(time(nullptr));

inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

void solve() {
    int n;
    cin >> n;
    map<int, int> m;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        m[x]++;
    }
    int ans = (n * (n - 1)) / 2;
    for (auto i : m) {
        ans -= (i.second * (i.second - 1)) / 2;
    }
    cout << ans << '\n';
}

signed main() {
#ifdef lolipop
    freopen("input.txt", "r", stdin);
#else
    fastio();
#endif
    int T = 1;
//    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#define int long long
#define menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb emplace_back
#define pi pair<int, int>
#define BE(i) i.begin(),i.end()
#define fi first
#define se second
#define INF 2147483647
#define mkp make_pair
#define ist insert
#define mod 1000000007
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
using namespace std;
int min(int a, int b){return a < b ? a : b;}
int max(int a, int b){return a > b ? a : b;}
bool isprime(int k){bool is=1 ; for ( int i = 2 ; i <= sqrt(k) ; i++ ) if ( k % i == 0 ) is = 0 ; return is;}
const double PI=acos(-1);
int n;
pi p[66000];
pi dc(int l,int r,int lay)
{
    if (r-l==1) return p[l];
    int m=(l+r)/2;
    pi a=dc(l,m,1);
    pi b=dc(m,r,1);
    if (lay==0)
    {
        if (a.fi>b.fi) return b;
        else return a;
    }
    else
    {
        return (a.fi>b.fi?a:b);
    }
}
int32_t main()
{
	menhera_chan_is_mine
    cin >>n;
    n=(1<<n);
    for (int i=0;i<n;i++)
        cin >>p[i].fi,p[i].se=i;
    pi res=dc(0,n,0);
    cout <<res.se+1<<"\n";
	return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 4e5 + 5;
int C[3][3];
void pascal() {
    for(int i = 0;i < 3;i++) {
        C[i][0] = C[i][i] = 1;
        for(int j = 1;j < i;j++)
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 3;
    }
}
int ncrLucas(int n, int r, int p) {
    if(r == 0)
        return 1;
    int ni = n % p, ri = r % p;
    return (1ll * ncrLucas(n / p, r / p, p) * C[ni][ri]) % p;
}
int n, a[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    pascal();
    cin >> n;
    for(int i = 0;i < n;i++) {
        char c;
        cin >> c;
        if(c == 'B')
            a[i] = 0;
        else if(c == 'W')
            a[i] = 1;
        else
            a[i] = 2;
    }
    int ans = 0;
    for(int i = 0;i < n;i++)
        ans = (ans + (1ll * ncrLucas(n - 1, i, 3) * a[i]) % 3) % 3;
    if(n % 2 == 0)
        ans = (3 - ans) % 3;
    if(ans == 0)
        cout << 'B';
    else if(ans == 1)
        cout << 'W';
    else
        cout << 'R';
    return 0;
}

#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<int> P(n, -1);
    for (int i = 1; i < n; ++i) {
        cin >> P[i];
        --P[i];
    }
    vector<vector<int>> graph(n);
    for (int i = 1; i < n; ++i) {
        graph[P[i]].push_back(i);
    }

    int rt = 0;
    const int INF = 1 << 24;
    vector<int> dp(n, -INF);
    vector<int> sizes(n, 0);

    for (int i = n - 1; i >= 0; --i) {
        int u = i;
        sizes[u] = 1;

        long long res = 1;
        vector<vector<int>> ans(2);
        for (auto v : graph[u]) {
            sizes[u] += sizes[v];
            ans[(sizes[v] * 3) & 1].push_back(dp[v]);
        }
        for (auto& V : ans) {
            sort(V.begin(), V.end());
        }
        for (auto x : ans[0]) {
            if (x < 0) {
                res += x;
            }
        }
        int m = ans[1].size();
        // for (int i = 0, j = m - 1, t = 0; t < m; ++t) {
        //     if (t & 1) {
        //         res -= ans[1][j--];
        //     } else {
        //         res += ans[1][i++];
        //     }
        // }
        for (int j = 0; j < m; ++j) {
            if (j & 1) {
                res -= ans[1][j];
            } else {
                res += ans[1][j];
            }
        }
        if (m & 1) {
            for (auto x : ans[0]) {
                if (x > 0) {
                    res -= x;
                }
            }
        } else {
            for (auto x : ans[0]) {
                if (x > 0) {
                    res += x;
                }
            }
        }
        dp[u] = res;
    }
    assert((n + dp[rt]) % 2 == 0);
    cout << (n + dp[rt]) / 2 << '\n';

    return 0;
}


#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define rep(i,n) repi(i,0,n)
#define repi(i,a,n) for(ll i=a;i<(ll)n;++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define Show(val) cout<<(val)<<" "
#define Showln(val) cout<<(val)<<endl

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
// using P = pair<int, int>;
void YN(bool a) { cout << (a ? "Yes" : "No"); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

class UnionFind{
public:
  vector<int> p;		// 親
  vector<int> rank;	// サイズ・各集合の根のみ有効
  UnionFind(int n){
    p.resize(n, -1);
    rank.resize(n, 1);
  }
  int root(int x){
    if(p[x] == -1) return x;
    else return p[x] = root(p[x]); // 深さを 1 にしている
  }
  void unite(int x, int y){
    x = root(x); y = root(y);
    if(x == y)return;
    if(rank[x] > rank[y]) swap(x, y); // rankの小さいものを下につける
    // -> x <= y
    rank[y] += rank[x];
    p[x] = y;
  }
  // グループの数
  ll root_num() {
    ll num = 0;
    for(ll x : p) if (x < 0) num++;
    return num;
  }
  // グループごとに頂点をまとめる: O(N log N)
  map<int, vector<int>> groups(){
    map<int, vector<int>> ret;
    rep(i, p.size()) ret[root(i)].emplace_back(i);
    return ret;
  }
  //xが属すグループのサイズ
  int size(int x){ return rank[root(x)]; }
  bool same(int x, int y){ return (root(x) == root(y)); }
};

void solve()
{
  ll n, q, t, q1, q2;
  cin >> n >> q;

  vector<ll> cls(n);
  vector< map<ll, ll> > score(n, map<ll, ll>());

  rep(i, n) cin >> cls[i];
  rep(i, n) score[i][--cls[i]] = 1;

  UnionFind uf(n);
  rep(qi, q)
  {
    cin >> t >> q1 >> q2;
    q1--; q2--;
    if (t == 1)
    {
      if (uf.same(q1, q2)) continue;
      if (uf.size(q1) > uf.size(q2)) swap(q1, q2);

      // q1をq2にくっつける
      ll root1 = uf.root(q1);
      ll root2 = uf.root(q2);
      for(const auto& mp : score[root1])
      {
        score[root2][mp.first] += mp.second;
      }

      uf.unite(q1, q2);
    }
    else if (t == 2)
    {
      cout << score[uf.root(q1)][q2] << endl;
    }
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define all(v) (v).begin(),(v).end()
const  double pi = acos(-1.0);
const  double eps = 1e-12;
using namespace std;

const int N = 20;
const ll INF = 1e18;
int n, m;
ll pref[N][N];
ll dp[(1 << N)][2];
bool ok(int mask, int idPref){
    int kol = 0;
    for (int i = 0; i < n; i++){
        if (mask & (1 << i)){
            kol++;
        }
        if (pref[idPref][i + 1] < kol){
            return false;
        }
    }
    return true;
}
void solve(){
    cin >> n >> m;

    for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++){
            pref[i][j] = INF;
        }
    }

    for (int i = 1; i <= m; i++){
        int x, y, z;
        cin >> x >> y >> z;
        for (int j = 1; j <= x; j++){
            pref[j][y] = min((ll)z, pref[j][y]);
        }
    }
    dp[0][0] = 1;
    int now = 1;
    for (int pos = 0; pos < n; pos++){
        now = (now ^ 1);
        int nxt = (now ^ 1);

        for (int mask = 0; mask < (1 << n); mask++){
            dp[mask][nxt] = 0;
        }
        for (int mask = 0; mask < (1 << n); mask++){

            if (dp[mask][now] == 0){
                continue;
            }
            assert(__builtin_popcount(mask) == pos);
            for (int put = 0; put < n; put++){
                if (mask & (1 << put)){
                    continue;
                }
                int newMask = (mask | (1 << put));
                if (ok(newMask, pos + 1)){
                    dp[newMask][nxt] += dp[mask][now];
                    //cout << pos + 1 << " " << put + 1 << " " << mask << " " << newMask << " " << dp[mask][now] << " " << dp[newMask][nxt] << endl;
                }
            }
        }

            if (pos == n - 1){
                cout << dp[(1 << n) - 1][nxt] << endl;
                return;
            }
    }
}

int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(6);
    //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
    //freopen("exercise.in","r",stdin); freopen("exercise.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
        solve();
    }
}


#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")

using namespace std;

#define watch(x) cout << (#x) << " = " << (x) << endl
#define PI double(2 * acos(0.0))
#define ll long long
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define INF 1e15

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    for(int i = 0;i<n;i++){
        if(s[i] != '.'){
            cout << s[i];
        }else break;
    }
}

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

int main() {
	string s; cin >> s;
	string ans = "";
	bool flg = true;
	for(char c : s) {
		if(c == '.') {
			flg = false;
		}
		if(flg) {
			ans += c;
		}
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int mod=998244353;
const int mex=200005;
#define ll long long
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++)
#define int long long
int bite[mex];
void update(int x,int vl)
{
    while(x<mex)
    {
        bite[x]+=vl;
        x+=x&-x;
    }
}
int query(int x)
{
    int sum=0;
    while(x)
    {
        sum+=bite[x];
        x-=x&-x;
    }
    return sum;
}

signed main()
{
    int n,m,w;
    cin>>n>>m>>w;
    int x[n+2];
    int y[m+2];
    fo(i,0,n+2)
    x[i]=m+1;
    fo(i,0,m+2)
    y[i]=n+1;
    fo(i,0,w)
    {
        int x1,y1;
        cin>>x1>>y1;
        x[x1]=min(x[x1],y1);
        y[y1]=min(y[y1],x1);
    }
    int ans=0;
    fo(i,1,x[1])
    {
        ans=ans+y[i]-1;
    }
    fo(i,1,y[1])
    ans=ans+x[i]-1;
    //cout<<ans<<endl;
    int y1=x[1];
    vector<int> v[n+3];
    fo(i,1,y1)
    {
        v[y[i]].pb(i);
    }
    fo(i,1,n+1)
    {
        if(i<y[1])
        update(x[i],1);
        fo(j,0,sz(v[i+1]))
        ans=ans-(query(mex-1)-query(v[i+1][j]));
    }
    cout<<ans<<endl;

}

#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;

class BIT {
    std::vector<long long> bit;
    long long size;
public:
    BIT() { }
    BIT(long long sz) { init(sz); }
    void init(long long sz) {
        bit = std::vector<long long>((size = sz) + 1);
    }
    long long sum(long long i) {
        LL s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(long long i, long long x) {
        while (i <= size) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

LL solve(long long H, long long W, long long M, std::vector<long long> X, std::vector<long long> Y) {
    LL right = W;
    vector<LL> min_height(W, H);
    vector<vector<LL>> blocks(H);
    for (LL i = 0; i < M; ++i) {
        min_height[Y[i]] = min(min_height[Y[i]], X[i]);
        if (X[i] == 0) {
            right = min(right, Y[i]);
        }
        blocks[X[i]].emplace_back(Y[i]);
    }
	LL ans = 0;
    for (LL i = 0; i < right; ++i) {
        ans += min_height[i];
    }
    BIT bit(W);
    vector<bool> used(W);
    for (LL i = right; i < W; ++i) {
        bit.add(i + 1, 1);
        used[i] = true;
    }
    for (LL i = 1; i < min_height[0]; ++i) {
        sort(blocks[i].begin(), blocks[i].end());
        LL right = blocks[i].empty() ? W : blocks[i][0];
        ans += bit.sum(right);
        for (auto j : blocks[i]) {
            if (!used[j]) {
                used[j] = true;
                bit.add(j + 1, 1);
            }
        }
    }
    return ans;
}

int main() {
#if DEBUG
    freopen("in_2.txt", "r", stdin);
#endif

    long long H, W, M;
    cin >> H >> W >> M;
    std::vector<long long> X(M), Y(M);
    for (int i = 0 ; i < M ; i++) {
        cin >> X[i] >> Y[i];
        --X[i]; --Y[i];
    }
    cout << solve(H, W, M, std::move(X), std::move(Y)) << endl;
	return 0;
}


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

// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint2 = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()

const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;
//const Int mod = 998244353;

typedef struct {
    int64_t to, weight;
} edge;

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

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (auto &e : v) {
        is >> e;
    }
    return is;
}

bool print_space_enable = false;
void print() {
    std::cout << '\n';
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    std::cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

template<class T>
vector<T> make_vec(size_t n, T val) {
    return vector<T>(n, val);
}

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

bool is_overflow(Int a, Int b) {
    return a > INF / b;
}

void solve() {
    Int k, n, m;
    cin >> k >> n >> m;
    vector<Int> a(k);
    cin >> a;
    vector<Int> b(k);
    for (Int i = 0; i < k; i++) {
        b[i] = (a[i] * m) / n;
    }
    Int sum = accumulate(all(b), (Int)0);
    if (sum > m) {
        priority_queue<pair<Int, Int>, vector<pair<Int, Int>>, greater<pair<Int, Int>>> q;
        for (Int i = 0; i < k; i++) {
            if (b[i] == 0) continue;
            q.push({abs(n * b[i] - m * a[i]), i});
        }
        for (Int i = 0; i < sum - m; i++) {
            pair<Int, Int> p = q.top();
            q.pop();
            b[p.second]--;
            if (b[p.second] == 0) continue;
            q.push({abs(n * b[p.second] - m * a[p.second]), p.second});
        }
    } else {
        priority_queue<pair<Int, Int>, vector<pair<Int, Int>>, greater<pair<Int, Int>>> q;
        for (Int i = 0; i < k; i++) {
            q.push({n * b[i] - m * a[i], i});
        }
        for (Int i = 0; i < m - sum; i++) {
            pair<Int, Int> p = q.top();
            q.pop();
            b[p.second]++;
            q.push({n * b[p.second] - m * a[p.second], p.second});
        }
    }
    print(b);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    //Int _t; cin >> _t; while (_t--) solve();
    return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

#undef _GLIBCXX_DEBUG
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *s) {return to_string(string(s));}
string to_string(bool b) {return b?"true":"false";}
string to_string(vector<bool> v) {
  string res = "{";
  for(int i = 0; i < int(v.size()); i++) {
    if(i) res += ", ";
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template<size_t N>
string to_string(bitset<N> v) {
  string res;
  for(size_t i = 0; i < N; i++) res += char('0' + v[i]);
  return res;
}
template<class A, class B>
string to_string(pair<A, B>);
template<class A, class B, class C>
string to_string(tuple<A, B, C>);
template<class A, class B, class C, class D>
string to_string(tuple<A, B, C, D>);
template<class A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x:v) {
    if(!first) res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template<class A, class B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template<class A, class B, class C>
string to_string(tuple<A, B, C> t) {
  return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}
template<class A, class B, class C, class D>
string to_string(tuple<A, B, C, D> t) {
  return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}
void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 822
#endif

//head

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vvi G(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].emplace_back(b);
  }
  queue<int> q;
  int ans = 0;
  rep(i, n) {
    vi check(n);
    check[i] = 1;
    ans++;
    q.emplace(i);
    while(not q.empty()) {
      int now = q.front();
      q.pop();
      for(auto ne:G[now]) {
        if(not check[ne]) {
          check[ne]++;
          ans++;
          q.emplace(ne);
        }
      }
    }
  }
  cout << ans << endl;
}


#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int A, B, W; cin >> A >> B >> W;
  long double w = W * 1000;
  int vmin = ceil(w/B);
  int vmax = floor(w/A);
  if (vmax >= vmin) cout << vmin << " " << vmax << endl;
  else              cout << "UNSATISFIABLE" << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long i = 0; i < n; i++)
int main() {
  int A, B, M;
  cin >> A >> B >> M;
  M *= 1000;
  int Q = M / A;
  int W = M / B;
  if(M % B != 0) W++;
  int U = 0, O = 0;
  for(int i = W; i <= Q; i++) {
    double T = i / 1.0;
    double R = M / T;
    if(U == 0) if(A <= R && R <= B) U = i;
    if(U != 0) if(A <= R && R <= B) O = i;
  }
  if(U == 0 && O == 0) cout << "UNSATISFIABLE" << endl;
  else cout << U << " " << O << endl;
}


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

const int MAX = 5010;
const int MOD = 998244353;

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

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

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

int main() {
  COMinit();

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

  if (M%2 == 1 || N == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<int64_t> dp(M+1,0);
  dp[0] = 1;
  for (int i = 2; i <= M; i += 2) {
    int sum = 0;
    for (int j = 0; j <= i; j += 2) {
      sum = (sum + (COM(N,j) * dp[(i-j)/2])%MOD )%MOD;
    }
    dp[i] = sum;
  }

  cout << dp[M] << endl;

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define rep(x, L, R) for(int x = (L), _x = (R); x <= _x; x++)
#define per(x, R, L) for(int x = (R), _x = (L); x >= _x; x--)
#define broken fprintf(stderr, "running on %s %d\n", __FUNCTION__, __LINE__)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define SZ(v) (int)(v).size()
#define ALL(x) (x).begin(), (x).end()
#define x first
#define y second
#define mp make_pair
#define pb push_back

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

typedef pair<int, int> par;
typedef long long LL;
typedef unsigned long long uLL;
typedef double db;
const int N = 5000 + 10, md = 998244353;
int n, m;
int fac[N], ifac[N];
int dp[N][N];
int qpow(int a, int b) {
	int res = 1;
	for(; b; b >>= 1, a = 1ll * a * a % md) if(b & 1) res = 1ll * res * a % md;
	return res;
}

int b(int n, int m) {
	if(n < m) return 0;
	return 1ll * fac[n] * ifac[m] % md * ifac[n - m] % md;
}

void initfac(int n) {
	fac[0] = 1;
	for(int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % md;
	ifac[n] = qpow(fac[n], md - 2);
	for(int i = n - 1; i >= 0; i--) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % md;
	return;
}

int main() {
	scanf("%d%d", &n, &m);
	initfac(n);
	dp[0][0] = 1;
	int now = 0;
	for(int i = 0, k = 1; k <= m; k <<= 1, i++) {
		for(int j = 0; j <= m; j++) {
			for(int l = 0; j + l * k <= m && l <= n; l += 2) {
				dp[i + 1][j + k * l] = (dp[i + 1][j + k * l] + 1ll * dp[i][j] * b(n, l) % md) % md;
//				cout << dp[i][j] << endl;
			}
		}
		now = i + 1;
	}
	printf("%d\n", dp[now][m]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
#define MOD 998244353
#define INF 1000000000
#define MAX 10000
using Graph=vector<vector<int>>;

int main(){
  int N;
  string S;
  string X;
  cin>>N>>S>>X;

  vector<vector<bool>> dp(N+1,vector<bool>(7,false));
  dp[N][0]=true;
  int res=1;
  for(int i=N-1;i>=0;i--){
    int d=S[i]-'0';
    if(X[i]=='T'){
      for(int j=0;j<7;j++){
        dp[i][j]=dp[i+1][j]|dp[i+1][(j+d*res)%7];
      }
    }else{
      for(int j=0;j<7;j++){
        if(dp[i+1][j]==false||dp[i+1][(j+d*res)%7]==false){
          dp[i][j]=false;
        }else{
          dp[i][j]=true;
        }
      }
    }
    res*=10;
    res%=7;
  }
  if(dp[0][0]==true){
    cout<<"Takahashi"<<endl;
  }else{
    cout<<"Aoki"<<endl;
  }
}

#include<bits/stdc++.h>
#define fort(i,a,b) for(long long i=a;i<=b;i++)
#define forn(i,a,b) for(long long i=a;i>=b;i--)
#define x first
#define y second
#define MP make_pair
#define pb push_back
#define ii pair<long long ,long long >
#define MT make_tuple
#define tp tuple
bool getbit(long long x,long long y)
{
    return (x>>y)&1;
}
void h10toh2()
{
    long long x,n;
    while(1)
    {
        std::cin>>x;
        if (x==-1) return;
        n=log2(x);
        forn(i,n,0)
        std:: cout<<((x>>i)&1);std::cout<<'\n';
    }
}
using namespace std;
long long A,B,C,D;
int main()
{
    //h10toh2();
    //freopen("codeforces.inp","r",stdin);
    //freopen("codeforces.out","w",stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>A>>B>>C>>D;
    if (D*C-B>0) cout<<A/(D*C-B)+(A%(D*C-B)!=0)<<'\n';else cout<<"-1\n";
}


#include <bits/stdc++.h>
#define arraysize(array) (sizeof(array)/sizeof(array[0]))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loopData(array) (cout << array[i] << " ")

using namespace std;

bool binarySearch(int arra[],int arraySize, int key){
    int startPoint, endPoint;
    int location;

    startPoint = 0;
    endPoint = arraySize - 1;

    while(startPoint <= endPoint){
        int midPoint = (startPoint + endPoint) / 2;

        if(arra[midPoint] == key){
            return true;
            break;
        }
        else if(arra[midPoint] < key){
            startPoint = midPoint + 1;
        }
        else
        {
            endPoint = midPoint - 1;
        }
    }
    return false;
}

void insert(int arra[], int arraySize, int position, int item){
    for(int i = arraySize - 1; i >= position-1; i--){
        arra[i+1] = arra[i];
    }
    arra[position-1] = item;
}

int main() {
    int M, H;

    cin >> M >> H;

    if(H % M == 0){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using pii = pair<int, int>;
using pll = pair<i64, i64>;
#define rep(i, n) for(i64 i = 0; i < n; i++)
#define per(i, n) for(i64 i = n - 1; i >= 0; i--)
#define REP(i, a, b) for(i64 i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec) {
    for (auto v : vec) { os << v << ' '; } os << '\n'; return os;
}
template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& pa) {
    os << '(' << pa.first << ',' << pa.second << ')'; return os;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
    cerr << " " << H; debug_out(T...);
}
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 i64 LINF = (1LL << 62) - 1;

void solve() {
    i64 n, k;
    cin >> n >> k;
    rep(i, k) {
        string s1 = to_string(n);
        string s2 = to_string(n);
        sort(rall(s1));
        sort(all(s2));
        n = stoll(s1) - stoll(s2);
    }
    cout << n << endl;
}

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


//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll
#define all(a) begin(a),end(a)

using namespace std;
using namespace __gnu_pbds;

using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
	cout<<w.size()<<en;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<en;
	if (fl) cout<<flush;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

template<class T>
vi compress(vector<T>&v)
{
	set<T> s;
	for (auto a: v) s.insert(a);
	vector<T> o(all(s));
	vi nv;
	for (int i=0;i<(int)v.size();++i) nv.pb(lower_bound(all(o),v[i])-o.begin());
	return nv;
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a,int base=10)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=base;
		k+=a[i]-'0';
	}
	return k;
}

template<class T>
void eras(vector<T>& a,T b)
{
	a.erase(find(a.begin(),a.end(),b));
}

string its(ll k,int base=10)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%base)+'0');
		k/=base;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return 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/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const int N=300010;
int n,a[N],b[N],p[N],pos[N];
bool bio[N];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
	cin>>n;
	for (int i=0;i<n;++i) cin>>a[i];
	for (int i=0;i<n;++i) cin>>b[i];
	for (int i=0;i<n;++i) cin>>p[i],--p[i],pos[p[i]]=i;
	for (int i=0;i<n;++i) if (p[i]!=i && a[i]<=b[p[i]])
	{
		cout<<-1<<en;
		exit(0);
	}
	vector<pii> re;
	for (int i=0;i<n;++i) if (!bio[i])
	{
		vi v;
		int z=i;
		do
		{
			bio[z]=1;
			v.pb(z);
			z=p[z];
		}
		while (z!=i);
		vector<pii> v1;
		for (auto x: v) v1.pb({b[x],x});
		sort(all(v1));
		reverse(all(v1));
		for (auto x: v1)
		{
			int po=pos[x.y],tre=x.y;
			if (po==tre) continue;
			re.pb({po,tre});
			swap(p[po],p[tre]);
			swap(pos[p[po]],pos[p[tre]]);
		}
	}
	cout<<re.size()<<en;
	for (auto a: re) cout<<a.x+1<<' '<<a.y+1<<en;
}

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<queue>
#define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i)
#define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i)
#define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i])
#define Li inline
#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
#define mpi(x,y) make_pair(x,y)
#define pi pair<int,int>
//#define int ll
#define DEBUG printf("%s %d\n",__FUNCTION__,__LINE__)
using namespace std;
typedef long long ll;
typedef double db;
template<typename T>
void read(T &x){
	x=0;char ch=getchar();bool f=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	x=f?-x:x;
}

const int N=2e5+7,P=1e9+7;
int n,m;
char s[N];
int a[N];
int f[20];
bool vis[20];int lst,cnt=0;

int add(int x,int y){
	x+=y;return x>=P?x-P:x;
}

signed main(){
	scanf("%s",s+1);int len=strlen(s+1);read(m);
	fs(i,1,len)if(isdigit(s[i]))a[i]=s[i]-'0';
	else a[i]=s[i]-'A'+10;
	f[0]=1;lst=a[1];f[1]=a[1]-1;
	fs(i,2,len){
		fn(j,16,2)f[j]=add((ll)f[j-1]*(16-j+1)%P,(ll)f[j]*j%P);
		f[1]=add(f[1],15);
		if(a[i]){
			if(!vis[lst])vis[lst]=true,++cnt;
			fs(j,0,a[i]-1)if(vis[j])f[cnt]=add(f[cnt],1);
			else f[cnt+1]=add(f[cnt+1],1);
			lst=a[i];
		}else if(!vis[0]){
			vis[0]=true;++cnt;
		}
	}
	//最后还要加1
	if(!vis[lst])vis[lst]=true,++cnt;
	if(vis[a[len]])f[cnt]=add(f[cnt],1);
	else f[cnt+1]=add(f[cnt+1],1);
	printf("%d\n",f[m]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,ans;
  string s;
  cin >> n >> s;
  ans=n;
  for(ll i=0;i<n-2;i++){
    if(s.at(i)=='f' && s.at(i+1)=='o' && s.at(i+2)=='x'){
      s=s.erase(i,3);
      n-=3;
      ans-=3;
      if(i>0){
        i-=2;
      }
      if(i>1){
        i--;
      }
    }
  }
  cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define al(a) a.begin(), a.end()
#define ral(a) a.rbegin(), a.rend()
#define sz(a) (int)a.size()

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  string ans;
  for (char c : s) {
    ans += c;
    // substr(最後の3文字前から最後まで)第一引数だけだと指定場所から最後まで
    if (sz(ans) >= 3 && ans.substr(sz(ans) - 3) == "fox") {
      //後ろから3文字消去方法
      ans.erase(ans.begin() + (sz(ans) - 3), ans.end());
    }
  }
  cout << sz(ans) << endl;
}

// stackの得意分野
// const string fox = "fox";
// int main() {
//   int n;
//   cin >> n;
//   string s;
//   cin >> s;
//   stack<char> st;
// //   cout << sz(st) << endl;
//   for (int i = 0; i < n; ++i) {
//     st.push(s[i]);
//     if (sz(st) >= 3 && s[i] == 'x') { // 2以上ではなく　既にpushなので3以上
//       string t;
//       for (int j = 0; j < 3; ++j) {
//         t = st.top() + t;
//         st.pop();
//       }
//       if (fox != t) {
//         for (int j = 0; j < 3; ++j) { st.push(t[j]); }
//       }
//       // stack不慣れ
//       //   char o = st.top();
//       //   st.pop();
//       //   char f = st.top();
//       //   st.pop();
//       //   if (o != 'o' || f != 'f') {
//       //     st.push(f);
//       //     st.push(o);
//       //     st.push(s[i]);
//       //   }
//     }
//   }
//   cout << sz(st) << endl;
// }

// fを数えとけばいい? ダメ　fofoxx　このパターン
// int main() {
//   int n;
//   cin >> n;
//   string s;
//   cin >> s;
//   int cntf = 0, ans = 0;
//   for (int i = 0; i < n; ++i) {
//     if (s[i] == 'f')
//       cntf++;
//     else if (s[i] == 'o' && cntf) { //文字列は配列外参照+1までは良いはず
//       if (s[i + 1] == 'x') {
//         cntf--;
//         i++;
//       }
//       else {
//         ans += cntf + 1;
//         cntf = 0;
//       }
//     }
//     else {
//       ans += cntf + 1;
//       cntf = 0;
//     }
//   }
//   if (s.back() == 'f') ans += cntf;
//   cout << ans << endl;
//   return 0;
// }


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

template< typename T >
T mod_pow(T x, T n, const T &p) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

int main() {
    ll n, m;
    cin >> n >> m;
    ll x = mod_pow(10ll, n, m*m);
    cout << x / m << endl;
}

#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

template<class L, class R>
ostream& operator<<(ostream &os, const pair<L,R> &input) {
    os << "(";
	os << input.first << "," << input.second;
	return os << ")";
}

template<class T>
ostream& operator<<(ostream &os, const vector<T> &input) {
    os << "[ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "]";
}

template<class T>
ostream& operator<<(ostream &os, const set<T> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "}";
}

template<class T>
ostream& operator<<(ostream &os, const unordered_set<T> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "}";
}

template<class T>
ostream& operator<<(ostream &os, const multiset<T> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "}";
}

template<class T>
ostream& operator<<(ostream &os, const unordered_multiset<T> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "}";
}

template<class L, class R>
ostream& operator<<(ostream &os, const map<L,R> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << "(" << elem.first << " , " << elem.second << ") ";
	}
	return os << "}";
}

template<class L, class R>
ostream& operator<<(ostream &os, const unordered_map<L,R> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << "(" << elem.first << " , " << elem.second << ") ";
	}
	return os << "}";
}

#define ll long long
const int MAXN = 500005;
const int INF = 1e9;
const int MOD = 998244353;

class TaskA {
private:
	int mod;
	int mul(int a, int b) {
		return (ll) a * b % mod;
	}
	int fastMod(int base, ll pot) {
		int ans = 1;
		while (pot) {
			if (pot & 1) {
				ans = mul(ans, base);
			}
			base = mul(base, base);
			pot/=2;
		}
		return ans;
	}

public:
	void solveOne(int it){
		ll n, m;
		cin >> n >> m;
		mod = m * m;
		int ans = fastMod(10, n);
		cout << (ans / m) % m << endl;

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	TaskA solver;
	solver.solve();
	return 0;
}


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

#define ll long long
#define ull unsigned long long
#define ld long double
#define ui unsigned int
#define ar array

#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
	read(h);
	read(t...);
}
template<class A> void read(vt<A>& x) {
	EACH(a, x)
		read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
	EACH(a, x)
		read(a);
}

string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b?"true":"false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vt<bool> v) {
	string res;
	FOR(sz(v))
		res+=char('0'+v[i]);
	return res;
}

template<class A> void write(A x) {
	cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
	write(h);
	write(t...);
}
template<class T> void write(const vt<T>& x) {
	EACH(a, x){
		write(a);
		write(' ');
	}
	write("\n");
}
void print() {
	write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
	write(h);
	if(sizeof...(t))
		write(' ');
	print(t...);
}

void DBG() {
	cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}

//Uncomment line when debugging, and comment out to remove all debug outputs directly
// #define _DEBUG

#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b,c,d;
	read(a,b,c,d);
	int den = c*d-b;
	if(den<=0)
		print(-1);
	else
	{
		int ans = (a+den-1)/den;
		cout<<ans<<"\n";
	}
}

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fs first
#define sd second
#define rept(x,n) for(int i=x;i<n;i++)
#define rrept(n,x) for(int i=n-1;i>=x;i--)
#define all(v) v.begin(),v.end()
#define mpit map<int,int>::iterator
#define stit set<int,int>::iterator
#define quit queue<int,int>::iterator
#define maxt(a,b,c) max(a,max(b,c))
#define mint(a,b,c) min(a,min(b,c))
#define rsort(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define printarr(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<"\n";
#define printvec(v) for(int i = 0;i<v.size();i++)cout<<v[i]<<" ";cout<<"\n";
using namespace std;
ll power(ll a,ll b){ll res = 1;while(b){if(b&1)res*=a;a*=a;b/=2;}return res;}
ll powerwithmod(ll a,ll b,ll mod){ll res = 1;while(b){if(b&1)res*=a;res%=mod;a*=a;a%=mod;b/=2;}return res;}
void sieve(vector<ll>&prime,ll n){ll candidate[n+1]={0};candidate[0]=1;candidate[1]=1;candidate[2]=0;
for(ll i = 4;i<=n;i+=2)candidate[i]=1;for(ll i = 3;i*i<=n;i+=2){if(candidate[i]==0){
for(ll j = i*i;j<=n;j+=i){candidate[j] = 1;}}}for(ll i = 2;i<=n;i++){if(candidate[i]==0)prime.pb(i);}}

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

void solve()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll fir = c*d;
    ll sec = b;
    if(fir<=sec)
    {
        cout<<"-1\n";
    }
    else
    {
        cout<<(a + fir - sec - 1)/(fir-sec);
    }
}
signed main()
{
    speed;
    int t=1;
    //cin>>t;
    while(t--)
    {
         solve();
    }
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12);
  int n, d, h;
  cin >> n >> d >> h;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  long double lo = 0, hi = (long double) h;
  long double res;
  for (int i = 0; i < 100; i++) {
    long double mid = (lo + hi) / 2.0;
    long double slope = ((long double) h - mid) / (long double) d;
    bool ok = true;
    for (int j = 0; j < n; j++) {
      long double cur = slope * (long double) a[j] + mid;
      if (cur < (long double) b[j]) {
        ok = false;
      }
    }
    if (ok) {
      res = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << max((long double) 0, res) << '\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(arr,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
// lld sum=0;
// vector<int> visited(2001);
// vector<int>arr[2001];

// void dfs(int i){
//     visited[i]=1;
//     ++sum;
//     for(int x:arr[i]){
//         if(visited[x]){
//             continue;
//         }
//         dfs(x);
//     }
// }
void run(){
    int n;
    cin>>n;
    bitset<100001> dp;
    dp[0]=1;
    int sum=0;
    fors(i,n){
        int x;
        cin>>x;
        sum+=x;
        dp |= dp<<x;
    }
    // cout<<"sum: "<<sum/2<<endl;
    int temp = sum;
    for(int i=0;i<=sum;++i){
        if(dp[i]){
            temp = min(temp,max(i,sum-i));
        }
    }
    // cout<<"ans:"<<endl;
    cout<<temp<<endl;
}

int main(){
    fastio;
    // // file();
    int t=1;
    // cin>>t;
    for(int nr=0;nr<t;++nr){
        run();
    }
}


#include <iostream>
using namespace std;

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

    if(a==b){
        cout << c << endl;
    }else if(a==c){
        cout << b << endl;
    }else if(b==c){
        cout << a << endl;
    }else{
        cout << "0" << endl;
    }
}

//clear adj and visited vector declared globally after each test case
//check for long long overflow
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Incase of close mle change language to c++17 or c++14
#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 push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#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;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int a, b, c;
    cin>>a>>b>>c;
    cout<<21-a-b-c;
}


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

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int x= (a * d) - (c * b);

    cout << x;
    return 0;
}

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

#define long long long
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vs vector<string>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define FORs(i,a,b,c) for (int i = a; i < b; i+=c)
#define DPMOD 1000000007

int main() {
    // freopen("input.txt", "r", stdin);

    int a; cin >> a;
    int b; cin >> b;
    int c; cin >> c;
    int d; cin >> d;
    cout << a*d - b*c << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, k; cin >> n >> k;
  const int LIM = 3010;
  const long long MOD = 998244353;
  long long dp[LIM][LIM];
  // dp[i][j] = number of multisets that leave
  //            i elements to choose and j is the remaining sum
  for(int i = 0; i<LIM; ++i) {
    for(int j = 0; j<LIM; ++j) {
      dp[i][j] = 0;
    }
  }
  dp[n][k] = 1;
  for(int i = n; i>0; --i) {
    for(int j = LIM-1; j>0; --j) {
      int ways = dp[i][j];
      for(int k = 0; ; ++k) {
        int next_remaining = j*(1<<k)-1;
        if(next_remaining >= LIM) {
          break;
        }
        if(next_remaining >= 0) {
          dp[i-1][next_remaining] = (dp[i-1][next_remaining] + ways) % MOD;
        }
      }
    }
  }

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

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

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

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

int main() {
lin(X);
  if(X%100==0) {
co(100);
  }
  else {
    ll aa=X%100;
    co(100-aa);
  }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vl;
typedef vector<pii> vpii; typedef vector<pll> vpll;
#define FOR(n) for(int i=0;i<n;++i)
#define FOR1(n) for(int i=1;i<=n;++i)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll gcd(ll a, ll b) { return a % b ? gcd(b, a % b) : b; }
const ll mod = 1e9 + 7; const ll inf = 0x3f3f3f3f;
ll qpow(ll a, ll b) { ll t = 1; while (b != 0) { if (b & 1)t = (t * a) % mod; a = (a * a) % mod; b >>= 1; }return t; }
void re(vi& a) { for (auto& t : a)cin >> t; }void re(vl& a) { for (auto& t : a)cin >> t; }
void pr(vi& a) { for (auto& t : a)cout << t << " "; cout << endl; }
void pr(vl& a) { for (auto& t : a)cout << t << " "; cout << endl; }

signed main() {
	int n;
	cin >> n;
	vi a(n), b(n);
	FOR(n)cin >> a[i] >> b[i];
	int ans = inf;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i != j)ans = min(ans, max(a[i], b[j]));
			else ans = min(ans, a[i] + b[j]);
		}
	}
	cout << ans;
}

//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int N = 2441;

using namespace std;
int  n , m , value;
ll a[ N ][ N ] , ro[ N ] , col[ N ] , mod = 1e9+7 ;

map <ll,ll> dia;

char ch;

int main(){
fcin;
	cin >> n >> m ;
	for(int i = 0 ; i < n ; i++) {
		for(int j = 0 ; j < m ; j++) {
			cin >> ch;
			a[i][j] = (ch == '.');
		}
	}

	ll ans = 0;

	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){

			if(!a[i][j]) {
				dia[i-j] = 0;
				ro[i] = 0;
				col[j] = 0;
				continue;
			}
			if(!i && !j) {
				dia[0] = 1;
				col[j] = 1;
				ro[i] = 1;
			}
			else {
				value = dia[ i - j ] % mod;
				value += col[j] % mod; value %= mod;
				value += ro[i] % mod; value %= mod;
				dia[i - j] += value; dia[i-j] %= mod;
				col[j] += value; col[j] %= mod;
				ro[i] += value; ro[i] %= mod;
				if(i == n - 1 && j == m - 1) ans = value;
			}
		}
	}

	cout << ans << "\n";
	return 0;
}


#include <iostream>
using namespace std;
int x;
int main() {
    cin >> x;
    int now = 1;
    while (now <= 33) {
        if (now <= x && now * 100 >= x) {
            cout << now << endl;
            exit(0);
        }
        now = now + 1;
    }
}

//Update : 2021.5.7
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii ;
typedef pair<long long,long long> pll;
//#define endl '\n'
/*Debugger
#define tpc template<class c
#define ckt(x) tpc> typename enable_if<sizeof ptb<c>(0) x 1, debug&>::type
#define rpt return *this
#define dop debug& operator <<
tpc> struct rge { c b, e; };
tpc> rge<c> range(c x, c y) { return rge<c>{x, y}; }
tpc> auto ptb(c* x) -> decltype(cerr << *x, 0);
tpc> char ptb(...);
struct debug {
	#ifdef LOCAL
		~debug() {cerr << "\u001b[0m\n";}
		debug() {cerr << "\u001b[92m";}
		ckt(!=) operator <<(c x) { cerr << boolalpha << x; rpt; }
		ckt(==) operator <<(c x) { rpt << range(x.begin(), x.end()); }
		tpc, class b> dop(pair<c,b> x) { rpt << "(" << x.first << ", " << x.second << ")"; }
		tpc> dop(rge<c> r) { *this << "{";
			for(auto it = r.b; it != r.e; ++it) *this << ", "+2*(it==r.b) << *it; rpt << "}";
		}
	#else
		tpc> dop(const c&) {rpt;}
	#endif
};
#define watch(...) "[" << #__VA_ARGS__ " = " << (__VA_ARGS__) << "] "
//调试工具*/

ull M = 1e9+7; //998244353; 1e9+9;
const int N = 100005; //105; 455; 1005; 200005; 300005; 4000005;
ll n,m,k,a,b,p,q,r,t;
//ll A[];
string s;

void input(){
	cin>>b;
}
void solve(){
	input();
	cout<<(b+99)/100<<endl;
}
void TC(){
	int tc=1;
	//cin>>tc;
	for(int t=1;t<=tc;t++){
		//cout<<"Case #"<<t<<":";
		solve();
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(0);
	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	//system(""); //Buat menyalakan warna pada debugger
 	TC();
}
/*

*/


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

  string s;
  cin>>s;
  int n = s.size();
  string ans;
  for(int i = n - 1; i >= 0; i--){
    if(s[i] == '6') ans.push_back('9');
    else if(s[i] == '9') ans.push_back('6');
    else ans.push_back(s[i]);
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define int int64_t

using namespace std;

const int LG=2e5+5;

int a[LG], viz[LG];

vector<int> v[LG];

void dfs(int nod)
{
    viz[nod]=1;
    for (auto el:v[nod])
        if (!viz[el])
            dfs(el);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    map<int,int> m;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    int ans=m.size();
    for (int i=1;i<=n/2;i++)
    {
        int f=a[i];
        int s=a[n+1-i];
        if (f!=s)
        {
            v[f].push_back(s);
            v[s].push_back(f);
        }
    }
    for (int i=1;i<=n;i++)
    {
        if (!viz[a[i]])
        {
            dfs(a[i]);
            ans--;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1005];
int b[1100][1100];
int c[1100];
void gmin(int x)
{
	for(int i=2;i<=x;i++)
	{
		if(x%i==0) b[x][++c[x]]=i;
	}
}
inline int read()
{
	char ch=getchar();
	int x=0,f=1;
	while(ch>'9'||ch<'0')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch<='9'&&ch>='0')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		//a[i]=read();
		scanf("%d",&a[i]);
	}
	int maxx=-1,maxd;
	for(int i=1;i<=n;i++)
	{
		gmin(a[i]);
		for(int k=1;k<=c[a[i]];k++)
	 {
	 	int cnt=0;
		for(int j=1;j<=n;j++)
		{
			if(a[j]%b[a[i]][k]==0) cnt++;
			if(cnt>maxx)
			{
				maxx=cnt;
				maxd=b[a[i]][k];
			}
		}
	 }
	}
	printf("%d",maxd);
	return 0;
}

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


#include <iostream>

using namespace std;

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

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

int main()
{
   int N;
   cin >> N;
   int64_t arrlcm = 1;
   for(int i = 2; i <= N; i++){
       arrlcm = lcm(i,arrlcm);
   }
   cout << arrlcm + 1 << endl;
   return 0;
}

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

#define rep(i,_l,_r) for(signed i=(_l),_end=(_r);i<=_end;++i)
#define fep(i,_l,_r) for(signed i=(_l),_end=(_r);i>=_end;--i)
#define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i])
#define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i])
#define print(x,y) write(x),putchar(y)
//#define debug(...) do {cerr<<__LINE__<<" : ("#__VA_ARGS__<<") = "; Out(__VA_ARGS__); cerr<<flush;} while(0)
//template <typename T> void Out(T x) {cerr<<x<<"\n";}
//template <typename T,typename ...I> void Out(T x,I ...NEXT) {cerr<<x<<", "; Out(NEXT...);}

template <class T> inline T read(const T sample) {
    T x=0; int f=1; char s;
    while((s=getchar())>'9'||s<'0') if(s=='-') f=-1;
    while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar();
    return x*f;
}
template <class T> inline void write(const T x) {
    if(x<0) return (void) (putchar('-'),write(-x));
    if(x>9) write(x/10);
    putchar(x%10^48);
}
template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;}
template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;}
template <class T> inline T fab(const T x) {return x>0?x:-x;}
template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;}
template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;}
template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;}

typedef pair <int,int> pii;

const int maxn=2e5+5;

set <pii> s;
int n;
long long c[maxn];
set <pii> :: iterator it;

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

void add(int x,int k) {
	while(x<=n) c[x]+=k,x+=lowbit(x);
}

long long ask(int x) {
	long long r=0;
	while(x) r+=c[x],x-=lowbit(x);
	return r;
}

int main() {
	n=read(9); long long ans=0;
	rep(i,1,n) s.insert(make_pair(read(9)+i,i));
	rep(i,1,n) {
		int x=read(9); it=s.lower_bound(make_pair(x+i,0));
		if(it==s.end() || (it->first)!=x+i) return puts("-1"),0;
		long long tmp=ask(it->second);
		add(1,1),add(it->second,-1);
		ans+=tmp+(it->second)-i;
		s.erase(it);
	}
	print(ans,'\n');
	return 0;
}