#include<bits/stdc++.h>

#define vi             vector<int>
#define vb             vector<bool>
#define vs             vector<string>
#define vvi            vector<vector<int>>
#define vpi            vector<pair<int,int>>
#define pb             push_back
#define mp             make_pair
#define int            long long int
#define mod            1000000007
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define from(i,n)      for(int i=0;i<(int)n;i++)
#define from_j(i,j,n)  for(int i=j;i<(int)n;i++)
using namespace std;

int power(int n , int k) {
    if (k == 0)return 1;
    int temp = power(n, k / 2);
    temp = (temp * temp);
    if (k % 2) return (temp * n);
    return temp;
}
int fact(int x)
{
    int res = 1;
    for(int i=2;i<=x;i++)
        res = i*res;
    return res;
}

int choose(int n, int r)
{
    return fact(n)/(fact(r)*fact(n-r));
}

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

int lcm(int a, int b)
{
    int x = gcd(a, b);
    return abs(a*b) / x;
}

void print(vi z)
{
    for(auto x:z)
        cout<<x<<endl;
   // cout<<endl;
}

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

vi factors(int n)
{
	vi ans;
	ans.pb(1);
	if(n == 1)
		return ans;
	for(int i = 2;i*i<=n;i++)
	{
		if(n%i == 0)
		{
			if(n/i == i)
				ans.pb(i);
			else
			{
				ans.pb(i);
				ans.pb(n/i);
			}
		}
	}
	sort(ans.begin(), ans.end());
	ans.pb(n);
	return ans;
}

void solve()
{
    int n; cin>>n;
    print(factors(n));
}

int32_t main() {
    sync();

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

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

// Jai Shree Ram
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define max2(a,b) (a>b)?a:b
#define mi2(a,b) (a<=b)?a:b
#define fori(i,n) for(ll i=0;i<(ll)n;i++)
#define ford(i,n) for(ll i=n;i>=0;i--)
#define pll pair<ll,ll>
#define MOD 998244353
#define ff first
#define ss second
using namespace std;
#define MAX_LIMIT 1000001

// ll power(ll n, ll pow)
// {
//     n %= MOD;
//     long long int res = 1;
//     while (pow)
//     {
//         if (pow % 2)
//         {
//             res = ((res % MOD) * (n % MOD)) % MOD;
//         }
//         pow /= 2;
//         n = ((n % MOD) * (n % MOD)) % MOD;
//     }
//     res %= MOD;
//     return res;
// }

// void answer(ll ans)
// {
// 	cout<<"! "<<ans<<"\n";
// 	cout.flush();
// }
// ll query(ll l,ll r)
// {
// 	cout<<"? "<<l<<" "<<r<<"\n";
// 	cout.flush();
// 	ll rem;
// 	cin>>rem;
// 	return rem;
// }

void solve()
{

	ll a,b;
	cin>>a>>b;
	double d=(a-b)*100.0/a;
	cout<<setprecision(18)<<(double)d<<"\n";

}

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

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

    ll T;
    T=1;
    //cin>>T;
    //sievefun(1000004);
    fori(_,T)
    {
        solve();
    }

}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n,k,m;
    cin >> n >> k >> m;
    int sum = 0;
    rep(i,n-1) {
        int a;
        cin >> a;
        sum += a;
    }
    for (int i = 0; i <= k; i++)
    {
        if ((sum+i)/n >= m) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

#include <iostream>

using namespace std;

int main(){
  int n,k,m;
  cin >> n >> k >> m;
  int Score[n-1],sum=0;
  for(int i=0;i<n-1;i++){
    cin >> Score[i];
    sum += Score[i];
  }
  //主処理
  int  TargetScore = m*n;
  //すでに目標点を超えている場合
  if(TargetScore <= sum){
    cout << 0 << endl;
  }
  //下回っている場合
  else{
    if(TargetScore-sum <= k){
       cout << TargetScore-sum << endl;
    }
    else{
       cout << -1 << endl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using matrix = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
template<class in_chmax> void chmax(in_chmax &x, in_chmax y) {x = max(x,y);}
template<class in_chmin> void chmin(in_chmin &x, in_chmin y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll maxN = 110;

ll powmodp(ll x, ll n) {
    if (n==0) return 1;
    if (n%2) return x * powmodp(x,n-1) % mod;
    ll res = powmodp(x,n/2);
    return res * res % mod;
}

ll inv(ll x) {return powmodp(x,mod-2);}

matrix E(ll n) {
    matrix res(n,vector<ll>(n));
    rep(i,n) res[i][i] = 1;
    return res;
}

void addmodp(ll &x, ll y) {x = (x + y) % mod;}

matrix prodmatrix(matrix x, matrix y) {
    ll H = x.size(), W = y[0].size(), sz = y.size();
    matrix res(H,vector<ll>(W));
    rep(i,H) rep(j,W) rep(k,sz) {
        addmodp(res[i][j], x[i][k] * y[k][j] % mod);
    }
    return res;
}
vector<ll> prodmatrix(matrix A, vector<ll> x) {
    matrix X(x.size(),vector<ll>(1));//         |y1|   |A11    |   |x1|
    rep(i,x.size()) X[i][0] = x[i];  //         |y2| = |  A22  | * |x2|
    matrix Y = prodmatrix(A,X);      //         |y3|   |    A33|   |x3|
    vector<ll> y(Y.size());
    rep(i,Y.size()) y[i] = Y[i][0];
    return y;
}
vector<ll> prodmatrix(vector<ll> x, matrix A) {
    matrix X(1,vector<ll>(x.size()));//                               |A11    |
    rep(i,x.size()) X[0][i] = x[i];  // |y1, y2, y3| = |x1, x2, x3| * |  A22  |
    matrix Y = prodmatrix(X,A);      //                               |    A33|
    vector<ll> y(Y[0].size());
    rep(i,Y[0].size()) y[i] = Y[0][i];
    return y;
}

matrix powmatrix(matrix x, ll n) {
    if (n==0) return E(x.size());
    if (n%2) return prodmatrix(x,powmatrix(x,n-1));
    matrix res = powmatrix(x,n/2);
    return prodmatrix(res,res);
}

ll N, M, K;
vector<ll> A(maxN);
matrix mat(maxN,vector<ll>(maxN));
vector<ll> G[maxN];

int main() {
    cin >> N >> M >> K;
    rep(i,N) cin >> A[i];
    rep(i,M) {
        ll x, y; cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    rep(now,N) {
        ll n = G[now].size();
        ll p = n * inv(M) % mod, q = (1-p+mod) % mod;
        mat[now][now] = ((p * inv(2) % mod) + q) % mod;
        for (ll to : G[now]) {
            mat[now][to] = inv(M) * inv(2) % mod;
        }
    }
    vector<ll> res = prodmatrix(A,powmatrix(mat,K));
    rep(i,N) cout << res[i] << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define REPR(i,n) for (ll i = (n)-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = (m); i < (n); ++i)
#define FORR(i,m,n) for (ll i = (n)-1; i >= (m); --i)
#define FORE(x,xs) for (const auto& x : (xs))
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define STATE(s,n) for (int s = 0; s < (1 << (n)); s++)
#define SUB(t,s) for (int t = (s); --t&=(s);)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define UNIQ(v) sort(ALL(v)); v.erase(unique(ALL(v)),end(v))
#define CHMIN(x,y) x = min(x, (y))
#define CHMAX(x,y) x = max(x, (y))
#define BIT(x,i) (((x) >> (i)) & 1)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define RETURN(x) cout << (x) << endl; return

const ll MAX = 1<<20;

ll A, B;
vi PRIMES({2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71});

ll dp[77][MAX];

ll solve() {
    dp[0][0] = 1;
    FOR (i, A, B+1) {
        ll factor = 0;
        REP (ip, 20) if (i%PRIMES[ip] == 0) {
            factor |= (1 << ip);
        }
        REP (k, MAX) {
            dp[i-A+1][k] += dp[i-A][k];
            if ((k&factor) == factor) dp[i-A+1][k] += dp[i-A][k^factor];
        }
    }
    ll ans = 0;
    REP (k, MAX) {
        ans += dp[B-A+1][k];
    }
    return ans;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> A >> B;
    cout << solve() << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define lowbit(x) (x&-x)
#define reg register
#define mp make_pair
#define fir first
#define sec second
typedef long long LL;
typedef unsigned long long uLL;
const int INF=0x3f3f3f3f;
const int mo=1e9+7;
const int iv2=5e8+4;
const int lim=1000000;
const int jzm=1e6+7;
const int orG=3,invG=332748118;
const double Pi=acos(-1.0);
typedef pair<LL,LL> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
template<typename _T>
void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');}
int gcd(int x,int y){return !y?x:gcd(y,x%y);}
int add(int x,int y){return x+y<mo?x+y:x+y-mo;}
LL n,ans[2005],tot;pii f[2005];
pii solve1(pii tmp){return mp(tmp.fir+1LL,tmp.sec);}
pii solve2(pii tmp){return mp(tmp.fir,tmp.sec+1LL);}
pii solve3(pii tmp){return mp(tmp.fir+tmp.sec,tmp.sec);}
pii solve4(pii tmp){return mp(tmp.fir,tmp.sec+tmp.fir);}
void extend(LL id){
	tot=id;
	while(f[tot].fir+f[tot].sec<=n){
		if(f[tot].fir<=f[tot].sec)tot++,f[tot]=solve3(f[tot-1]),ans[tot]=3;
		else tot++,f[tot]=solve4(f[tot-1]),ans[tot]=4;
	}
}
LL check(LL id){return n-f[id].fir+id;}
void print(){
	while(f[tot].fir<n)++tot,f[tot]=solve1(f[tot-1]),ans[tot]=1;
	printf("%d\n",tot);for(int i=1;i<=tot;i++)printf("%d\n",ans[i]);
}
signed main(){
	read(n);f[1]=solve2(f[0]);ans[1]=2;f[2]=solve1(f[1]);ans[2]=1;tot=2;extend(tot);
	if(check(tot)<=130){print();return 0;}
	for(int i=3;i<=tot;i++){
		LL las=check(tot);pii ls=f[i];int lasway=ans[i];f[i]=solve1(f[i-1]);ans[i]=1;extend(i);
		if(check(tot)>=las)f[i]=ls,ans[i]=lasway,extend(i);
		//printf("%d:%lld %lld %lld %lld\n",i,f[i].fir,f[i].sec,check(tot),las);
		las=check(tot);ls=f[i];lasway=ans[i];f[i]=solve2(f[i-1]);ans[i]=2;extend(i);
		if(check(tot)>=las)f[i]=ls,ans[i]=lasway,extend(i);
		//printf("%d:%lld %lld %lld %lld\n",i,f[i].fir,f[i].sec,check(tot),las);
		las=check(tot);ls=f[i];lasway=ans[i];f[i]=solve3(f[i-1]);ans[i]=3;extend(i);
		if(check(tot)>=las)f[i]=ls,ans[i]=lasway,extend(i);
		//printf("%d:%lld %lld %lld %lld\n",i,f[i].fir,f[i].sec,check(tot),las);
		las=check(tot);ls=f[i];lasway=ans[i];f[i]=solve4(f[i-1]);ans[i]=4;extend(i);
		if(check(tot)>=las)f[i]=ls,ans[i]=lasway,extend(i);
		//printf("%d:%lld %lld %lld %lld\n",i,f[i].fir,f[i].sec,check(tot),las);
		if(check(tot)<=130){print();return 0;}
		//printf("nxt %lld %lld\n",f[i+1].fir,f[i+1].sec);
	}
	print();
	return 0;
}
/*
0 1
1 1
1 2
*/

#include <bits/stdc++.h>
#define Ri register int
#define ll long long
#define db double
#define FOR(i, j, k) for(Ri i = j; i <= k; i++)
#define DEC(i, j, k) for(Ri i = j; i >= k; i--)
using namespace std;

const int maxn = 2e5 + 100;
int n;
vector<int> g[maxn];
int mx, xm;

int d[maxn];
inline void dfs(int u, int fa) {
	d[u] = d[fa] + 1;
	if(d[u] > mx) mx = d[u], xm = u;
	for(Ri i = 0; i < g[u].size(); i++) {
		if(g[u][i] == fa) continue;
		dfs(g[u][i], u);
	}
}

bool f[maxn];
void tagi(int u) {
	if(!u) return;
	f[u] = 1;
	for(Ri i = 0; i < g[u].size(); i++) {
		if(d[g[u][i]] < d[u]) {
			tagi(g[u][i]);
			break;
		}
	}
}

int out[maxn];
int sol(int u, int fa, int w) {
	out[u] = ++w;
	int h = 0;
	for(Ri i = 0; i < g[u].size(); i++) {
		if(g[u][i] == fa) continue;
		if(f[g[u][i]]) {h = g[u][i]; continue;}
		w = sol(g[u][i], u, w) + 1;
	}
	if(h) w = sol(h, u, w);
	return w;
}

int main() {
	scanf("%d", &n);
	FOR(i, 2, n) {
		int x, y;
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	mx = 0, xm = 0;
	dfs(1, 0);
	int w = xm;
	mx = 0, xm = 0;
	dfs(w, 0);
	tagi(xm);
	sol(w, 0, 0);
	FOR(i, 1, n) printf("%d ", out[i]);
	return 0;
}


#include<cstdio>
using namespace std;
const int mod=998244353;
int n,m,k;
int res;
int pow(int x,int t)
{
	int r=1;
	while(t) {
		if(t&1) {
			r=1ll*r*x%mod;
		}
		t>>=1,x=1ll*x*x%mod;
	}
	return r;
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	if((n==1)||(m==1)) {
		res=pow(k,n==1?m:n);
	} else {
		for(int i=1;i<=k;++i) {
			res=(res+1ll*(pow(i,n)-pow(i-1,n))*pow(k-i+1,m))%mod;
		}
	}
	printf("%d\n",(res+mod)%mod);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
    #define author          "Sihare0riginals"
    #define ss              string
    #define lli             long long int
    #define ld              long double
    #define f               first
    #define s               second
    #define all(v)          v.begin(),v.end()
    #define I(a,i)          memset(a,i,sizeof(a));
    #define pb              push_back
    #define mp              make_pair
    #define L(i,start,end)  for(lli i=start;i<=end;i++)
    #define R(i,start,end)  for(lli i=start;i>=end;i--)
    #define ip(n)           cin>>n;lli ip[n+1];L(i,1,n)cin>>ip[i];
const lli LINF = 1e18,mod=998244353;
void Bl0ck_M0mb0();
lli power(lli a,lli b,lli m){ if(b==0) return 1; if(b==1) return a%m;
    lli t=power(a,b/2,m); t=(t*t)%m; if(b&1) t=(t*a)%m; return t;}

signed main()
{
    Bl0ck_M0mb0();
    lli t=1;
    //cin>>t;
    while(t--){
        lli n,m,k,ans=0;
        cin>>n>>m>>k;
        L(i,1,k)
        {
            lli val=(power(i,n,mod)-power(i-1,n,mod)+mod)%mod;
            //cout<<val<<" ";
            lli x=k-i+1;
            lli val1;
            if(n==1)
            val1=(power(x,m,mod)-power(x-1,m,mod)+mod)%mod;
            else if(m!=1)
                val1=power(x,m,mod);
            else
                val1=1;
            val*=val1;
            val%=mod;
            //cout<<x<<" "<<val<<endl;
            ans+=val;
            ans%=mod;
        }
        cout<<ans<<endl;
    }
    return 0;
}

void Bl0ck_M0mb0(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("ip.txt","r",stdin);
    freopen("op.txt","w",stdout);
    #endif
}
/*
#define dbg1D(i,start,end,arr) for(lli i=start;i<=end;i++) cout<<i<<"th : "<<arr[i]<<endl;
#define dbg2D(i,j,s1,e1,s2,e2,arr) for(lli i=s1;i<=e1;i++){cout<<i<<"th :";for(lli j=s2;j<=e2;j++)cout<<arr[i][j]<<" ";cout<<endl;}
#define M map<lli,lli> \n #define sz(s) s.size()-1
#define P pair<lli,lli>
#define V vector<lli>
lli dx[4]={-1, 0, 0, +1};
lli dy[4]={0, -1, +1, 0};
lli power(lli a,lli b,lli m){ if(b==0) return 1; if(b==1) return a%m;
    lli t=power(a,b/2,m); t=(t*t)%m; if(b&1) t=(t*a)%m; return t;}
lli modInverse(lli a, lli m) { return power(a, m-2, m); } */


#include <bits/stdc++.h>

#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 1e5 + 5;
const int ha = 1e9 + 7;
int f[MAXN],n;

inline void add(int &x,int y){
	x += y-ha;x += x>>31&ha;
}

int main(){
	f[0] = 1;f[1] = 2;FOR(i,2,MAXN-1) f[i] = (f[i-1]+f[i-2])%ha;
	int ans = 0;scanf("%d",&n);
	FOR(i,1,n){
		int x;scanf("%d",&x);
		if(i == 1) add(ans,1ll*x*f[n-1]%ha);
		else{
			add(ans,1ll*x*f[i-2]%ha*f[n-i]%ha);
			add(ans,ha-1ll*x*f[std::max(0,i-3)]%ha*f[std::max(0,n-i-1)]%ha);
		}
	}
	printf("%d\n",ans);
	return 0;
}
// f[i] = f[i-1]+f[i-2]


#include <bits/stdc++.h>

using namespace std;

typedef int int2;
#define int long long
#define pi pair<int, int>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
const int inf = 1e18;
const int B = 450;

int t;

int2 main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(2 * n);
    for (int i = 0; i < 2 * n; i++) {
        cin >> a[i];
    }
    map<int, vector<int>> locs;
    vector<pi> pairs;
    for (int i = n - 1; i >= 0; i--) {
        int e1 = a[i];
        int e2 = a[2 * n - 1 - i];
        pairs.eb(min(e1, e2), max(e1, e2));
    }
    int ans = 0;
    multiset<int> cur;
    for (int i = 0; i < n; i++) {
        int mn = pairs[i].f;
        int mx = pairs[i].s;
        ans += mx;
        if (!cur.empty() and *(cur.begin()) < mn) {
            ans += (mn - (*cur.begin()));
            cur.erase(cur.begin());
            cur.insert(mn);
        }
        cur.insert(mx);
    }
    cout << ans << "\n";
}

#include <bits/stdc++.h>
#define int long long int
#include <time.h>
using namespace std;
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector <int> v1;
    vector <int> v2;
    for(int i = 1;i<= n;i++){
        int z;
        cin>>z;
        v1.push_back(z);
    }
    reverse(v1.begin() , v1.end() );
    for(int i = 1;i<= n;i++){
        int z;
        cin>>z;
        v2.push_back(z);
    }
    priority_queue <int> q;
    for(int i = 0;i<n;i++){
        q.push(-v1[i] );
        q.push(-v2[i]);
        q.pop();
    }
    int ans = 0;
    while(q.size()){
        ans+= -q.top();
        q.pop();
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 998244353;
const ld PI = acos(-1);
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}

const int MAX = 510000;

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

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

inline ll ksm(ll a,ll b,const ll m=MOD) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = 1ll * ans * a % m;
        a = 1ll * a * a % m;
        b >>= 1;
    }
    return ans;
}

set<int> divisor(int n) {
    set<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.insert(i);
            if (i * i != n) ret.insert(n / i);
        }
    }
    // sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
    int n, ans=0;
    cin>>n;
    vector<int> A;
    set<int> B;
    rep(i,n){
        int l;
        cin>>l;
        A.push_back(l);
        set<int> C;
        C=divisor(l);
        B.insert(C.begin(),C.end());
    }

    for(auto i:B){
        bool flg=false;
        int ret=0;
        int flg2=0;
        rep(j,n){
            if(i>A[j]) {
                flg2 = 1;
                break;
            }
            if(A[j]%i==0){
                if(flg != true){
                    ret = A[j]/i;
                    flg=true;
                }
                else ret = __gcd(ret, A[j]/i);
            }
            }
        if(flg2==0&&ret==1)ans++;
        }

    co(ans);
}

#include<bits/stdc++.h>
#define LL unsigned long long
using namespace std;

const int N=5e5+100;
const LL P=1e9+7;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(LL x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

inline int gcd(int a,int b)
{
    return b>0 ? gcd(b,a%b):a;
}
void add(LL &x,LL y){
	x+=y;if(x>=P)x-=P;
}
LL qpow(LL x,LL y){
	LL re=1;
	while(y){
		if(y&1) re=re*x%P;
		x=x*x%P;y>>=1;
	}
	return re;
}
int n,ans;
int a[2010];
map<int,int> mp;
void add(int x,int y){
	int z=mp[x];
	if(z==x) return;
	z=gcd(z,y);
	mp[x]=z;
	if(z==x) ++ans;
	return;
}
int main(){
	int x;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	ans=0;
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=sqrt(a[i]);++j){
			if(a[i]%j==0){
				if(j<=a[1])add(j,a[i]);
				if(j*j!=a[i]&&(a[i]/j)<=a[1]) add(a[i]/j,a[i]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

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

template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
  return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}

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

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

int main() {
  int n;
  cin >> n;
  vector<double> a(n);
  for (auto& x : a) cin >> x;
  sort(a.begin(), a.end());
  trace(a);
  vector<double> pre(n + 1);
  for (int i = 0; i < n; ++i) pre[i + 1] = pre[i] + a[i];
  double ret = 1e300, cur;
  // 2x <= a[0]
  cur = pre[n] / n - a[0] / 2;
  ret = min(ret, cur);
  // 2x >= a[n - 1]
  cur = a[n - 1] / 2;
  ret = min(ret, cur);
  for (int i = 1; i < n; ++i) {
    // a[i - 1] <= 2x <= a[i]
    // n * x + pre[n] - pre[i] - (n - i) * x * 2;
    double x = 2 * i > n ? a[i - 1] / 2 : a[i] / 2;
    cur = (n * x + pre[n] - pre[i] - (n - i) * 2 * x) / n;
    ret = min(ret, cur);
  }
  cout << ret << '\n';
  return 0;
}

#include<iostream>
using namespace std;
double eps=1e-7;
double a[100005];
int n;
double gtval(double x){
	double sum=0;
	for(int i=1;i<=n;i++){
		sum+=x+a[i]-min(a[i],x*2);
	}
	return sum;
}
int main(){
	double mx=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mx=max(mx,a[i]);
	}
	double l=0,r=mx,ml,mr;
	while(r-l>eps){
		ml=((double(r-l)))/3.0+l;
		mr=((double(r-l)))/1.5+l;
		//cout<<l<<' '<<ml<<' '<<mr<<' '<<r<<endl;
		double v1=gtval(ml),v2=gtval(mr);
		if(v1<v2)r=mr;
		else l=ml;
	}
	printf("%.10lf",gtval(r)/n);
	return 0;
}


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

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

#define _USE_MATH_DEFINES
#include <math.h>

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

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

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

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

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

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

const long double eps = 1e-8;

i64 val(i64 a) {
    return (a * (a + 1) / 2) % smod;
}

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

    i64 a, b, c;
    cin >> a >> b >> c;

    i64 R = (val(a) * val(b)) % smod;
    R *= val(c);
    R %= smod;
    cout << R << endl;

    return 0;
}

#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
int n,m,a,b,c,d;
char s[1000002];
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
const int M=1e9+7;
inline void add(re int &x,re int y){(x+=y)>=M?x-=M:x;}
signed main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	printf("%lld",a*d-b*c);
}


#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
char s[N], t[N];
stack<int> S, T;
int main() {
	int n; long long ans = 0; scanf("%d", &n);
	scanf("%s%s", s + 1, t + 1);
	for (int i = 1; i <= n; i++) {
		if (t[i] == '1') T.push(i);
		if (s[i] == '1') {
			if (!S.empty())
				ans += i - S.top(), S.pop();
			else {
				if (T.empty()) S.push(i);
				else ans += i - T.top(), T.pop();
			}
		}
	}
	if (!S.empty() || !T.empty()) puts("-1");
	else printf("%lld\n", ans);
	return 0;
}

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
V<ll> p={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
int main(){
  ll a,b;
  cin>>a>>b;
  V<ll> dp((1<<20),0);
  dp[0]=1;
  V<ll> tmp={};
  for(ll i=a;i<=b;i++){
        ll v=0;
        for(int j=0;j<20;j++){
            if(i%p[j]==0)v+=(1ll<<j);
        }
        tmp.emplace_back(v);
  }
  int m=tmp.size();
  for(int i=0;i<m;i++){
      for(ll j=0;j<(1<<20);j++){
          if((j&tmp[i])>0)continue;
          dp[j|tmp[i]]+=dp[j];
      }
  }
  ll ans=0;
  for(int i=0;i<(1<<20);i++)ans+=dp[i];
  cout<<ans<<"\n";
}


#include <iostream>
using namespace std;
int main(void) {
    int a, b;
    cin >> a >> b;
    int bp = b - a;
    int p = bp;
    int d = a % p ? p - a % p : 0;
    while (d + p > bp) {
        p--;
        d = a % p ? p - a % p : 0;
    }
    cout << p << endl;
}

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

#define endl		'\n'
#define w(t)		int t;cin>>t;while(t--)
#define int			long long
#define fr(i,a,b)	for(int i=a;i<=b;i++)
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define pb 			push_back
#define ppb			pop_back
#define mp			make_pair
#define all(x)		x.begin(),x.end()
#define ff			first
#define ss			second
#define pii			pair<int,int>
#define vi			vector<int>
#define vvi			vector<vi>
#define pqi			priority_queue<int>
#define pqd			priority_queue<int,vi,greater<int>>
#define inf			1e18
#define mod			1000000007
#define PI 			3.14159265358979323846264338327950288419716939937510

int32_t main() {

	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int a,b;
	cin>>a>>b;
	int ans=-1;
	fr(i,1,b){
		int x=(b/i)*i;
		int y=((b/i)-1)*i;

		if(y>=a && y<x){
			ans=i;
		}
	}

	cout<<ans<<endl;

	return 0;
}


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

const int inf  = 1e18+9;
const int mod  = 1e9+7;
const int maxn = 2e5+8;

int n, m;

void solve() {
    int i, j;
    map<int, int> mp;
    cin >> n;
    for (int x = 3, i = 1; x < n; i++, x *= 3) mp[x] = i;
    for (int x = 5, i = 1; x < n; i++, x *= 5) if (mp.find(n - x) != mp.end()) return (void)(cout << mp[n - x] << " " << i << endl);
    cout << -1 << endl;
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}

#include <iostream>

using namespace std;

// a^p
uint64_t my_p(uint64_t a, int p)
{
    uint64_t ans = 1;
    for (int i = 0; i < p; ++i) { ans *= a;}

    return ans;
}

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

    for (int i = 1; i < 38; ++i)
    {
        for (int j = 1; j < 26; ++j)
        {
            uint64_t a = my_p(3, i) + my_p(5, j);
			if (a == N)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vv = vector<vi>;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

const ll mod = 1000000007;
const int INF = 100000000;
const double PI = acos(-1);

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<char> v;
    int ans = 0;
    rep(i, n)
    {
        if (s[i] == 'f')v.push_back(s[i]);
        else if (s[i] == 'o')v.push_back(s[i]);
        else if (s[i] == 'x')
        {
            if (v.size()  >= 2 && v[v.size() - 2] == 'f' && v[v.size() - 1] == 'o' )
            {
                ans++;
                v.pop_back();
                v.pop_back();
            }
            else v.clear();
        }
        else
        {
            v.clear();
        }

    }
    cout << n - 3 * ans << endl;
}

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

#define ll long long

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    string t = "";
    for (auto c : s) {
        t.push_back(c);
        while (t.size() >= 3 && t.substr(t.size() - 3, 3) == "fox") {
            for (int i = 0; i < 3; i++) t.pop_back();
        }
    }
    cout << t.size() << endl;
    return 0;
}


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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

    string x;
    cin >> x;
    string ans = x.substr(1, 2);
    ans += x[0];
    COUT(ans);
}

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

int main(){
	string s; cin >> s;

  	string ans = s.substr(1, s.size() - 1);

  	ans.push_back(s[0]);

  	cout << ans << endl;

  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()

struct P{int to,idx;};
vector<vector<P>> edge;
vector<int> a,b;
vector<string> ans;
const string R="->",L="<-";
vector<int> used;

bool dfs(int from,int idx,int goal,int num){
  used[idx]=num;
  for(P p:edge[idx]){
    if(idx==goal)return true;
    if((ans[p.idx]==R&&a[p.idx]!=idx)||(ans[p.idx]==L&&b[p.idx]!=idx))continue;
    if(p.to==from)continue;
    if(used[p.to]==num)continue;
    if(dfs(idx,p.to,goal,num)){
      if(ans[p.idx]=="#"){
        if(a[p.idx]==idx&&b[p.idx]==p.to)ans[p.idx]=R;
        else if(b[p.idx]==idx&&a[p.idx]==p.to)ans[p.idx]=L;
      }
      return true;
    }
  }
  return false;
}

signed main(){
  int n,m;cin>>n>>m;
  edge.resize(n);
  a.resize(m);
  b.resize(m);
  vector<int> c(n);
  REP(i,m)cin>>a[i]>>b[i];
  REP(i,m)a[i]--;
  REP(i,m)b[i]--;
  REP(i,n)cin>>c[i];
  used.resize(n,-1);
  ans.resize(m,"#");
  REP(i,m){
    if(c[a[i]]>c[b[i]]){
      ans[i]=R;
      edge[a[i]].push_back({b[i],i});
    }
    else if(c[a[i]]<c[b[i]]){
      ans[i]=L;
      edge[b[i]].push_back({a[i],i});
    }
    else{
      edge[a[i]].push_back({b[i],i});
      edge[b[i]].push_back({a[i],i});
    }
  }
  REP(i,m){
    if(ans[i]!="#")continue;
    if(dfs(b[i],a[i],b[i],2*i))ans[i]=L;
    else{
      dfs(a[i],b[i],a[i],2*i+1);
      ans[i]=R;
    }
  }
  REP(i,m)cout<<ans[i]<<endl;
}

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

struct edge{ int to, id, orientation; };
vector<vector<edge>> graph;
vector<int> ans;

void DFS(int v){
    for(edge e : graph[v]){
        if(ans[e.id] != 0) continue;

        ans[e.id] = e.orientation;
        DFS(e.to);
    }
}

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

    vector<int> a(m), b(m), c(n);
    for(int i=0; i<m; i++) cin >> a[i] >> b[i];
    for(int i=0; i<n; i++) cin >> c[i];

    graph.resize(n);
    ans.resize(m);
    for(int i=0; i<m; i++){
        a[i] -= 1;
        b[i] -= 1;

        graph[a[i]].push_back({b[i],i,+1});
        graph[b[i]].push_back({a[i],i,-1});

        if(c[a[i]] > c[b[i]]) ans[i] = +1;
        if(c[a[i]] < c[b[i]]) ans[i] = -1;
    }

    for(int i=0; i<n; i++) DFS(i);

    for(int i=0; i<m; i++){
        if(ans[i] == +1) cout << "->" << endl;
        if(ans[i] == -1) cout << "<-" << endl;
    }
    return 0;
}


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

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

    if(s.front() != s.back()) return 1;

    char a = s.front();
    for(int i = 1; i < n - 2; ++i) {
        if(s[i] != a && s[i + 1] != a) return 2;
    }

    return -1;
}

int main() {
    cout << solve() << '\n';
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#define re register
#define X first
#define Y second
#define mp std::make_pair
#define pb push_back
#define ohh(hhh...) fprintf(stderr,hhh)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> pii;
template<class T1> inline bool cmax(T1 &x,T1 y) {return x<y?(x=y,1):0;}
template<class T1> inline bool cmin(T1 &x,T1 y) {return x>y?(x=y,1):0;}
template<class T1> inline T1 dmax(T1 x,T1 y) {return x>y?x:y;}
template<class T1> inline T1 dmin(T1 x,T1 y) {return x<y?x:y;}
int n;
bool flag;
char s[100010];
int read()
{
	int x=0,w=0;
	char ch=0;
	while(ch<'0'||ch>'9') w|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int main()
{
	n=read();
	scanf("%s",s+1);
	if(s[1]!=s[n]) {printf("1\n");return 0;}
	for(re int i=2;i<n-1;i++) if(s[i]!=s[1]&&s[i+1]!=s[1]) flag=1;
	if(flag) printf("2\n");
	else printf("-1\n");
	return 0;
}


//                  //
//     Radmanシ     //
//                 //
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>

using namespace std;

//#define int long long

typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
#define F first
#define S second

const int maxn=2e5+5,maxlog=17;
int a[maxn],b[maxn],mark[maxn];
vector<int> v,yal[maxn];
map<int,int> mp;
int ans=0;

void dfs(int now)
{
   mark[now]=1;
   if(!b[a[now]])
   {
      b[a[now]]=1;
      v.push_back(a[now]);
      ans++;
   }
   for(int i=0;i<yal[now].size();i++)
   {
      int next=yal[now][i];
      if(mark[next])
         continue;
      dfs(next);
   }
}

int32_t main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0),cout.tie(0);
   int n;
   cin>>n;
   for(int i=1;i<=n;i++)
      cin>>a[i];
   for(int i=1;i<=n/2;i++)
   {
      yal[i].push_back(n-i+1);
      yal[n-i+1].push_back(i);
   }
   for(int i=1;i<=n;i++)
   {
      if(mp[a[i]])
      {
         yal[i].push_back(mp[a[i]]);
         yal[mp[a[i]]].push_back(i);
         mp[a[i]]=i;
      }
      mp[a[i]]=i;
   }
   for(int i=1;i<=n;i++)
   {
      if(mark[i])
         continue;
      dfs(i);
      while(v.size())
      {
         int l=v.back();
         v.pop_back();
         b[l]=0;
      }
      ans--;
   }
   cout<<ans<<endl;
   return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
#include <bitset>
#include <math.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define se second
#define INF 2e9
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())

class UnionFind{
private:
    vector<int> parent, setSize;
    int numSets;
public:
    UnionFind(int N){
        parent.assign(N, 0), setSize.assign(N, 1), numSets = N;
        for(int i = 0; i < N; i++){parent[i] = i;}
    }
    int findSet(int v){return (v == parent[v] ? v : parent[v] = findSet(parent[v]));}

    bool isSameSet(int v1, int v2){return (findSet(v1) == findSet(v2));}

    void unionSet(int v1, int v2){
        if(!isSameSet(v1, v2)){numSets--;
            v1 = findSet(v1);v2 = findSet(v2);
            if(setSize[v1] < setSize[v2]){swap(v1, v2);}
            parent[v2] = v1;
            setSize[v1] += setSize[v2];
        }
    }
    int numDisjointSets(){return numSets;}
    int sizeOfSet(int i){return setSize[findSet(i)];}
};

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

    int n;
    cin>>n;
    vector<int> in(n);
    for(int i = 0; i < n; i++){
        cin>>in[i];
    }
    int mxn = 2e5 + 5;
    UnionFind uf(mxn);

    for(int i = 0; i < n/2; i++){
        if(in[i] == in[n-i-1]) continue;
        if(in[i] != in[n-i-1]){
            uf.unionSet(in[i], in[n-i-1]);
        }
    }
    cout<<mxn - uf.numDisjointSets()<<endl;
    return 0;
}

// unordered_map<int, int> mp;
// int parent(int cur){
//     return (mp.count(cur) ? mp[cur] = parent(mp[cur]) : cur);
// }
// int main()
// {
//     ios_base::sync_with_stdio(0);
//     cin.tie(NULL);
//     cout.tie(NULL);

//     int n;
//     cin>>n;
//     vector<int> in(n);

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

//     int count = 0;
//     for(int i = 0; i < n/2; i++){
//         if(in[i] == in[n-i-1]) continue;

//         // if(mp.find(in[i]) != mp.end()) in[i] = mp[in[i]];
//         // if(mp.find(in[n-i-1]) != mp.end()) in[n-i-1] = mp[in[n-i-1]];
//         // // cout<<in[i]<<" "<<in[n-i-1]<<endl;
//         // if(in[i] != in[n-i-1]){
//         //     mp[in[i]] = in[n-i-1];
//         //     if(rmp.count(in[i])){
//         //         mp[rmp[in[i]]] = in[n-i-1];
//         //     }
//         //     rmp[in[n-i-1]] = in[i];
//         //     count++;
//         // }
//         in[i] = parent(in[i]);
//         in[n-i-1] = parent(in[n-i-1]);

//         if(in[i] != in[n-i-1]){
//             mp[in[i]] = in[n-i-1];
//             count++;
//         }
//     }
//     cout<<count<<endl;
//     return 0;
// }


#include<bits/stdc++.h>

	using namespace std;

	typedef long long ll;

	//ifstream in("cowsignal.in");
	//ofstream out("cowsignal.out");

	void solve(){
		map<ll, ll> cntJ;
		ll n;
		cin >> n;
		ll a[n], b[n], c[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 >> c[i];
			cntJ[b[c[i]-1]]++;
		}
		ll ans = 0;
		for (int i = 0; i < n; i++){
			ans += cntJ[a[i]];
		}
		cout << ans;
	}
 	//out << area(x1, y1, x2, y2) - iarea(x1, y1, x2, y2, xx1, yy1, xx2, yy2);
	int main(){
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
		ios_base::sync_with_stdio(0);
		cin.tie(0);
		cout.tie(0);
		solve();
	}

#include<bits/stdc++.h>

using namespace std;
typedef long long int lli;

#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define space ' '
#define kick(t) cout << "Case #" << t+1 << ":" << endl;

typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

template <typename T>
void input(vector<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
  for(auto x:arr) cout<<x<<" ";
  cout<<endl;
}

template <typename T>
void input_set(set<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}

lli mul(lli a, lli b) {
  return (a%MOD*b%MOD)%MOD;
}

lli power(lli a,lli b) {
  lli ans = 1;
  while(b > 0) {
    if(b&1)
      ans = mul(ans, a);
    a = mul(a,a);;
    b >>= 1;
  }
  return ans;
}
void solve(int testcase) {
    lli n;
    cin >> n;
    vector<lli> b;
    vector<lli> c;
    map<lli,lli> mp;
    lli ans=0;

    for(int i=0;i<n;i++){
      lli a;
      cin >> a;
      mp[a]++;
    }
    input(b,n);
    input(c,n);

    for(int i=0;i<n;i++){
      if(mp[b[c[i]-1]]){
        //cout << ans << endl;
        ans+= mp[b[c[i]-1]];
      }
    }

    cout << ans << endl;

}

int main() {

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

  lli testcases=1;
  //cin >> testcases;
  for(int testcase=0; testcase<testcases; testcase++) {
    solve(testcase);
  }
}


#include <iostream>
using namespace std;
int main(void){
    long long n, k;
    cin >> n >> k;

    for (int i = 0; i < k; i++){
        if (n % 200 == 0){
            n = n / 200;
        }
        else {
            string nn = to_string(n);
            nn += "200";
            n = stoll(nn);
        }
    }
    cout << n << endl;
}

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

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

template<typename T, size_t S>
T minval(const T(&vals)[S])
{
	T val = numeric_limits<T>::max();
	FOR_LT(i, 0, S) {
		val = min(val, vals[i]);
	}
	return val;
}

template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
	T val = numeric_limits<T>::min();
	FOR_LT(i, 0, S) {
		val = max(val, vals[i]);
	}
	return val;
}

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

	double a, b; cin >> a >> b;
	cout << (a - b) / a * 100.0 << endl;

	return 0;
}


#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod  1000000007
#define inf 900000000000000LL
#define M 200005

using namespace std;
int vis[400005];
int ar[400005];
int main()
{

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

    int n;
    cin >> n;
    int cnt = 0;
    for(int i=1;i<=n;i++)
    {
        int d = i;
        int f=1;
       while(d)
        {
            if(d%10==7)
            {
                f=0;
                break;
            }
            d/=10;
        }
        if(f==0)
        {
            cnt++;
            continue;
        }
        d = i;
        while(d)
        {
            if(d%8==7)
            {
                f=0;
                break;
            }
            d/=8;
        }
        if(f==0) cnt++;
    }
    cout << n-cnt << endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        bool ok = true;
        for (int x = i; ok && x; x /= 10) {
            ok &= (x % 10) != 7;
        }
        for (int x = i; ok && x; x /= 8) {
            ok &= (x % 8) != 7;
        }
        ans += ok;
    }
    cout << ans << '\n';
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
//#define MOD 998244353LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL;
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k;
  vi a(40,0),b(1048576),c(1048576);
  REP(i,n) cin>>a[i];

  REP(i,1048576){
    REP(j,20){
      if ((i>>j)%2==1)b[i]+=a[j];
    }
  }
  REP(i,1048576){
    REP(j,20){
      if ((i>>j)%2==1)c[i]+=a[j+20];
    }
  }

  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  REP(i,1048576){
    ll bb=b[i];
    if (k<bb)continue;
    if (k==bb){ans=k;break;}
    ll y=k-bb;
    //y未満の数の個数を求めたい
    auto Iter = lower_bound(c.begin(),c.end(), y);
    ll ynum=(Iter-c.begin());
    if (ynum==0){
      continue;
    }
    ans=max(c[ynum-1]+bb,ans);
    if (c[ynum]==y){ans=k;break;}
  }

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

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
    vector<map<int,int>> mp;

    UnionFind(int N) {
        r = vector<int>(N, -1);
        mp = vector<map<int,int>>(N);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (abs(-r[x]) > abs(-r[y])) swap(x, y);
        //xの集合の方が要素数が小さい
        for(auto p : mp[x]){
          mp[y][p.first] += p.second;
        }

        mp[x] = map<int,int>();
        r[y] += r[x];
        r[x] = y;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

};

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

  cout << a*d - b*c << endl;

}


#include <iostream>

using namespace std;

int main()
{
    char a,b,c;
    cin>>a>>b>>c;
    cout<<b<<c<<a;
    return 0;
}

#include<stdio.h>
int main ()
{
    int g,j,i,h;
    scanf("%d %d\n%d %d",&g,&h,&i,&j);
    printf("%d",g*j-h*i);
    return 0;
}


#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;
    int A[110];
    for(int i = 0; i < N + 1; i++) {
        cin >> A[i];
    }
    int ans = 100000;
    for(int i = 0; i < N; i++) {
        ans = min(ans, abs(A[i] - A[i + 1]));
    }
    cout << ans << endl;
    for(int i = 0; i < ans; i++) {
        for(int j = 0; j < N + 1; j++) {
            if(j != 0) cout << " ";
            cout << (A[j] + i) / ans;
        }
        cout << endl;
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define lli long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define plli pair<lli,lli>
#define vi vector<int>
#define vlli vector<lli>
#define vpi vector<pii>
#define vplli vector<plli>
#define mi map<int,int>
#define mlli map<lli,lli>
#define forl(i,a,b) for(lli i=a;i<b;i++)
#define ford(i,a,b) for(lli i=a;i>=b;i--)
#define cout0(a) cout << a << endl
#define cout1(a) cout << a << " "
#define cout2(a,b) cout << a << " " << b << endl
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl

lli gcd(lli a,lli b)
{
    if(b>a)
    {
      lli t=a;
      a=b;
      b=t;
    }

    while(b!=0)
    {
      lli t = a;
      a = b;
      b = t%b;
    }

    return a;
}

bool sortbysec(const pair<lli,lli> &a,const pair<lli,lli> &b)
{
    return (a.first < b.first);
}

void dfs(vlli v[],lli s,lli depth[],lli isvisited[])
{
  forl(i,0,v[s].size())
  {
    lli t=v[s][i];
    if(!isvisited[t])
    {
      depth[t]=depth[s]+1;
      isvisited[t]++;
      dfs(v,t,depth,isvisited);
    }
  }
}

lli nCr(lli n,lli r)
{
  lli p = 1,k = 1;
  if (n-r < r) r = n - r;

  if (r != 0)
  {
    while (r)
    {
      p*=n;
      k*=r;

      lli m = __gcd(p, k);

      p/=m;
      k/=m;

      n--;
      r--;
    }
  }
  else p = 1;

  return p;
}

lli SieveOfEratosthenes(lli n)
{
  bool prime[n+1];
  memset(prime,true,n+1);
  forl(i,2,n+1)
    if(prime[i])
      for(lli j=2*i;j<n+1;j+=i)
        prime[i]=false;

  lli count=0;
  forl(i,2,n+1)
    if(prime[i]) count++;
  return count;
}

int main()
{
  fastio;
  // time_t start, end;
  // time(&start);

  lli q;
  // cin >> q;
  q = 1;
  while(q--)
  {
    lli h,w;
    cin >> h >> w;

    char grid[h+1][w+1];

    forl(i,1,h+1)
    {
      forl(j,1,w+1)
      {
        cin >> grid[i][j];
      }
    }

    lli starter[h+1][w+1];
    lli opponent[h+1][w+1];

    ford(j,w,1)
    {
      ford(i,h,1)
      {
        lli s_d = INT_MIN,s_r = INT_MIN, o_d = 0, o_r = 0;

        if(i==h && j==w)
        {
          starter[i][j] = 0;
          opponent[i][j] = 0;
        }
        else
        {
          if(i<h)
          {
            if(grid[i+1][j] == '+') s_d = 1+opponent[i+1][j];
            else s_d = -1+opponent[i+1][j];
            o_d = starter[i+1][j];
          }

          if(j<w)
          {
            if(grid[i][j+1] == '+') s_r = 1+opponent[i][j+1];
            else s_r = -1+opponent[i][j+1];
            o_r = starter[i][j+1];
          }

          if(s_d-o_d > s_r-o_r)
          {
            starter[i][j] = s_d;
            opponent[i][j] = starter[i+1][j];
          }
          else
          {
            starter[i][j] = s_r;
            opponent[i][j] = starter[i][j+1];
          }
        }
      }
    }

    if(starter[1][1] > opponent[1][1]) cout0("Takahashi");
    else if(starter[1][1] < opponent[1][1]) cout0("Aoki");
    else cout0("Draw");
  }

  // time(&end);
  // cout<<fixed<<double(end - start)<<setprecision(10)<<endl;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

ll n, Q;
vector<ll> G[200005];
ll a[200005], b[200005];
ll add[200005], ans[200005];
ll parent[200005];

void predfs(int v, int p)
{
	parent[v] = p;
	for(auto u : G[v]){
		if(u == p) continue;
		predfs(u, v);
	}
}

void dfs(int v, int p, ll s)
{
	s += add[v];
	ans[v] = s;
	for(auto u : G[v]){
		if(u == p) continue;
		dfs(u, v, s);
	}
}

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

	cin >> n;
	rep(i, 1, n-1){
		cin >> a[i] >> b[i];
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	predfs(1, 0);

	cin >> Q;

	ll t, e, x;
	ll sum = 0;
	rep(i, 1, Q){
		cin >> t >> e >> x;
		ll u = a[e], v = b[e];

		if(t == 1){
			if(parent[v] == u) sum += x, add[v] -= x;
			else add[u] += x;
		}
		else{
			if(parent[v] == u) add[v] += x;
			else sum += x, add[u] -= x;
		}
	}

	dfs(1, 0, 0);

	rep(i, 1, n) cout << ans[i] + sum << "\n";
	flush(cout);

	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
constexpr ll TEN(ll n){return n==0?1:10ll*TEN(n-1);}

constexpr ll inf = TEN(9)+5;
constexpr ll linf = 3*TEN(18);

struct UF {
    vi data;
    void init(int n)
    {
        data.resize(n);
        fill(all(data), -1);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (size(x) < size(y)) swap(x, y);
        data[x] += data[y];
        data[y] = x;
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x)
    {
        x = root(x);
        return -data[x];
    }
    bool is_root(int x)
    {
        return x == root(x);
    }
};

UF uf;
vector<int> G[200020];

signed main()
{
    int N, M; cin >> N >> M;
    vi a(N), b(N);
    vector<ll> asum(N), bsum(N);
    uf.init(N + 5);

    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];

    rep(i, M) {
        int c, d; cin >> c >> d;
        --c, --d;
        uf.unite(c, d);
    }

    rep(i, N) {
        asum[uf.root(i)] += a[i];
        bsum[uf.root(i)] += b[i];
    }

    bool f = true;
    rep(i, N) {
        if (asum[i] != bsum[i]) f = false;
    }

    cout << (f ? "Yes" : "No") << '\n';
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;
#define forn(a, e) for (i64 a = 0; a < (i64)(e); a++)
#define forr(a, s, e) for (i64 a = s; a < (i64)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using iip = pair<int, int>;
using llp = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
template<typename T, size_t N>
istream& operator>>(istream& is, array<T, N>& c) { for (auto& e : c) is >> e; return is; }

template<typename ...T>
istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

// const i64 INF = 2e18;
const int INF = 2e9;
const i64 M = 998244353;
const int MXB = 20;
using bin = bitset<MXB + 1>;
const double EPS = 1e-8;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    rande.seed(chrono::steady_clock::now().time_since_epoch().count());

    int n;
    while (read(n)) {
        llvec a(2 * n);
        read(a);

        vec<iip> pa(2 * n);
        forn(i, 2 * n) {
            pa[i] = {a[i], i};
        }

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

        ivec used(2 * n);

        forn(i, n) {
            used[pa[i].second] = true;
        }

        string res;
        int bal = 0;
        int last = 0;

        forn(i, 2 * n) {
            if (bal == 0) {
                last = used[i];
                res += '(';
                bal++;
            } else {
                if (used[i] == last) {
                    res += '(';
                    bal++;
                } else {
                    res += ')';
                    bal--;
                }
            }
        }

        cout << res << endl;
    }
}

#include<bits/stdc++.h>
#define M 400005
using namespace std;
int n;
pair<int,int> A[M],B[M],md;
int cnt[2];
char S[M];
int main(){
	scanf("%d",&n);n*=2;
	for(int i=1;i<=n;i++){
		scanf("%d",&A[i].first);
		A[i].second=i;
		B[i]=A[i];
	}
	sort(B+1,B+n+1);
	md=B[n/2];
	for(int i=1;i<=n;i++){
		int t=(A[i]<=md);
		if(cnt[!t]>0)S[i]=')',cnt[!t]--;
		else S[i]='(',cnt[t]++;
	}
	printf("%s\n",S+1);
	return 0;
}


#include<iostream>
#include<string>
using namespace std;

int main(){
    long long N;
    cin >> N;
    int ans = 0;
    for(long long i=1; ; i++){
        if(stoll(to_string(i)+to_string(i))<=N) ans += 1;
        else break;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	/*long long a,b,c;
	if(a==0 or a==1 or a==5 or a==6){
		cout<<a<<"\n";
	}else{

	}*/
	string memo;
	cin>>memo;
		long long th=memo.size();
	map<char,long long> save;
	long long sum=th,ans=0,con,k,i;

	for(i=th-1,con=0;i>=0;i--,con++){
		save[memo[i]]+=1;
		char aux=memo[i];
		if(i>0){
			long long lol=con,j=i;
			for(k=0;memo[i-1]==aux && i>=0;i--,k++){
				con+=1;
				if(k==0){
				ans+=con-save[aux];
				//cout<<con<<" "<<save[aux]<<" "<<i<<"\n";
				}
				save[aux]+=1;
			}
			if(k>0){
				save.clear();
				save[aux]=con+1;
			}

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

return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod=1000000007;
constexpr auto MOD=1000000000000000;
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
void syou(int a,double b){
    cout<<setprecision(a)<<b<<endl;
}
bool prime(int n){
    int cnt=0;
    for(int i=1;i<=sqrt(n);i++){
        if(n%1==0)cnt++;
    }
    if(cnt!=1) return false;
    else return n!=1;
}
struct UnionFind{
    vector<int> r;
    UnionFind(int N){
        r=vector<int>(N,-1);
    }
    int root(int x){
        if(r[x]<0) return x;
        return r[x]=root(r[x]);
    }
    bool unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(r[x]>r[y]) swap(x,y);
        r[x]+=r[y];
        r[y]=x;
        return true;
    }
    int size(int x){
        return -r[root(x)];
    }
};
struct Edge{
    int to;
    int weight;
};
vector<int> v;
int n=0,m=0,cnt=0,ans=0,aa[220000];
pair<int,int> pp[220000];
string s,ss[220000],sa;
queue<int> que;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>pp[i].first>>pp[i].second;
    }
    rep(i,n){
        rep(j,i){
            if(abs(pp[i].first-pp[j].first)>=abs(pp[i].second-pp[j].second)){
                cnt++;
            }
        }
    }
    cout<<cnt<<endl;
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, mm, ans = 0;
	cin >> nn >> mm;
	vector<int64> memo(nn, 0);
	string ss;
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> ss;
		for(int64 jj = 0;jj < mm;jj++)
		{
			if(ss[jj] == '1')
			{
				memo[ii] += (1ll << jj);
			}
		}
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		int64 tmp = bitset<21>(memo[ii]).count();
		if(tmp % 2 == 1)
		{
			ans++;
		}
	}
	cout << ans * (nn - ans) << endl;
	return 0;
}


/*
By: Anurag Rai
CF: Raag07
CC: call_me_raag
*/
#include<bits/stdc++.h>
#define FIO	   				std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(it, a, b)		for(int it = a; it < b; ++it)
#define all(X)				(X).begin(), (X).end()
#define int    				long long int
#define ff					first
#define ss					second
#define pb					push_back
#define sq(X)				(X) * (X)
#define mod    				1000000007
#define NUM					1000000
using namespace std;

// 1-D  <=>  2-D (N*M)
//  k   <->  [k / N, k % M]

int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int gcd(int a, int b) {	return b ? gcd(b, a % b) : a; }
bool comp(int a, int b) { return a > b; }
bool sortbySS(const pair<int, int> &A, const pair<int, int> &B) { return A.ss < B.ss; }

void solve() {
	// Write your code here

	string S;
	cin >> S;

	string res = "";

	for(int i = S.length(); i > 0; --i) {
		if(S[i-1] == '6')
			res += '9';
		else if(S[i-1] == '9')
			res += '6';
		else
			res += S[i-1];
	}

	cout << res << endl;
}

int32_t main() {
	FIO;

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

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

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define N 107
#define ldb long double
char s[N][N];
int g[N][N],cnt[N],n;
bool vis[N];
ldb f[N],cof[N];
void dfs(int v){
	cnt[v]++; vis[v]=1;
	for(int i=1;i<=n;i++)
		if(g[v][i]&&!vis[i])
			dfs(i);
}
int main(){
	//freopen("cpp.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for(int j=1;j<=n;j++)
			g[i][j]=s[i][j]-'0';
	}
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		dfs(i);
	}
	ldb ans=0;
	for(int i=1;i<=n;i++)
		ans+=1.0/cnt[i];
	printf("%.10Lf\n",ans);
	return 0;
}


#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)

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

inline int getRand(int L, int R) {
    if (L > R) swap(L, R);
    return (int)(rng() % (uint64_t)(R - L + 1) + L);
}

template<typename T1, typename T2>
ostream& operator << (ostream &os, pair<T1, T2> p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template<typename T>
ostream& operator << (ostream &os, vector<T> vec) {
    for (int i = 0; i < vec.size(); ++i) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}

void solve() {
    string s; cin >> s;

    int ans = 0;
    for (int i = 0; i < s.size()-3; ++i) ans += s.substr(i, 4) == "ZONe";
    cout << ans << "\n";
}

int32_t main() {
    fastIO();

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

    return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main(){
	int ans=0, i;
	string s;
	cin >> s;
	while ( s.find("ZONe")<s.size() ){
		i=s.find("ZONe");
		s.erase(i,4);
		ans++;
	}
	cout << ans;
}


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

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

unsigned char C[4000100];

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

	fread(C, 1, 4000100, stdin);
	int N = 0;
	char c = 0;
	auto ci = C;
	while ((c = *ci++) >= '0') N = N * 10 + c - '0';
	auto S = ci;
	rep(i, N) S[i] = (S[i] >> 3 ^ S[i]) & 3;
	N--;

	int k = 0;
	while (N > 0) {
		int K = 1;
		int tmp = N;
		while (tmp >= 3) {
			K *= 3;
			tmp /= 3;
		}

		rep(i, N - K + 1) {
			S[i] += S[i + K];
		}
		N -= K;
		k++;
		if (k % 6 == 0) rep(i, N + 1) S[i] %= 3;
	}

	int tmp = (S[0] % 3);
	if (tmp == 0) cout << 'R';
	else if ((tmp == 2) ^ (k & 1)) cout << 'B';
	else cout << 'W';

	Would you please return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400010;
char s[MAXN];
const int MOD = 3;
int cnt3[MAXN], pref_cnt3[MAXN];
int fac[MAXN];
int nck_brute (int n, int k) {
	long long ans = 1;
	for (int i = n; i > n - k; i--) ans *= i;
	for (int i = 1; i <= k; i++) ans /= i;
	return ans % 3;
}
int nck(int n, int k) {
	int cnt3_up = pref_cnt3[n] - pref_cnt3[n - k];
	int cnt3_down = pref_cnt3[k];
	if (cnt3_up > cnt3_down) {
		return 0;
	}
	return fac[n] * fac[n - k] * fac[k] % 3;
}
int main() {
	int n;
	scanf("%d", &n);
	fac[0] = 1;
	for (int i = 0; i < n; i++) {
		int p = 0, j = i;
		while (j > 0 && j % 3 == 0) {
			p += 1;
			j /= 3;
		}
		cnt3[i] = p;
		pref_cnt3[i] = (i > 0 ? pref_cnt3[i - 1] : 0) + cnt3[i];
		if (i > 0) {
			fac[i] = fac[i - 1] * j % 3;
		}
	}
	scanf("%s", s + 1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int val = s[i] == 'B' ? 0 : s[i] == 'R' ? 1 : 2;
		int c = nck(n - 1, i - 1);
		ans += c * (n % 2 == 0 ? (3 - val) : val);
	}
	ans %= 3;
	cout << "BRW"[ans] << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros

ll g(int N, int M, vector<ll>& H, vector<ll>& W, vector<ll>& lsum, vector<ll>& rsum, ll w, int idx){
    ll res = abs(H[idx] - w);
    res += lsum[idx / 2];
    res += rsum[(idx+1)/ 2];

    /*
    dbg("--");
    dbg(w);
    dbg(idx);
    dbg(res);
    */
    return res;
}

ll f(int N, int M, vector<ll>& H, vector<ll>& W, vector<ll>& lsum, vector<ll>& rsum, ll w){
    ll res = 1LL<<60;
    int idx = lower_bound(H.begin(), H.end(),w) - H.begin();
    if(idx%2==0) {
        if (idx < N) chmin(res, g(N, M, H, W, lsum, rsum, w, idx));
    }else{
        if (idx+1 < N) chmin(res, g(N, M, H, W, lsum, rsum, w, idx+1));
        if (idx-1 >=0) chmin(res, g(N, M, H, W, lsum, rsum, w, idx-1));
    }
    return res;
}

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

    vector<ll> H(N);
    rep(i, N) cin >> H[i];
    vector<ll> W(M);
    rep(i, M) cin >> W[i];

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

    vector<ll> diff1(N / 2), diff2(N/2);
    for(int i=0;i<N/2;i++){
        diff1[i] = abs(H[i*2] - H[i*2 + 1]);
        diff2[i] = abs(H[i*2+1] - H[i*2+2]);
    }

    vector<ll> lsum(N / 2 + 1), rsum(N / 2 + 1);
    for(int i=1;i<N/2+1;i++){
        lsum[i] = lsum[i - 1] + diff1[i-1];
    }
    for(int i=N/2-1;i>=0;i--){
        rsum[i] = rsum[i + 1] + diff2[i];
    }

    ll ans = 1LL<<60;
    for(auto w: W){
        ll res  = f(N,M,H,W,lsum,rsum,w);
        chmin(ans, res);
    }

    cout << ans << endl;
}

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

const int MAX = 2e5 + 10;
ll qian[MAX] , hou[MAX] , w[MAX] , h[MAX];
int N , M;
int main() {
	cin >> N >> M;
	register int i;
	for(i = 1;i <= N; ++i)
		cin >> h[i];
	for(i = 1;i <= M; ++i)
		cin >> w[i];
	sort(h + 1 , h + N + 1);
	for(i = 2; i <= N; i += 2)
		qian[i] = qian[i - 2] + abs(h[i] - h[i - 1]);
	for(i = N - 1; i >= 1; i -= 2)
		hou[i] = hou[i + 2] + abs(h[i + 1] - h[i]);
	ll ans = 1e18;
	for(i = 1; i <= M; ++i) {
		int pos = lower_bound(h + 1 , h + N + 1 , w[i]) - h;
		if(pos % 2 == 0) --pos;
		ans = min(ans , qian[pos - 1] + hou[pos + 1] + abs(h[pos] - w[i]));
	}
	printf("%lld\n" , ans);
	return 0;
}


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define unused [[maybe_unused]]
#define tempT template<class T>
#define pcnt(x) __builtin_popcountll(x)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define isin2d(i, j, h, w) (isin((i), 0, (h)) && isin((j), 0, (w)))
#define debug(x) cerr << #x << ": " << x << endl
#define ans_exit(x) { cout << (x) << endl; exit(0); }
#define ans_return(x) { cout << (x) << endl; return; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define r_rep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define reps(i, n, m) for (ll i = (ll)(n); i < (ll)(m); i++)
#define r_reps(i, n, m) for (ll i = (ll)(m) - 1; i >= (ll)(n); i--)
#define _dbgarr(a) {for(auto _e:(a)){cerr << _e << " ";} cerr << endl;}
#define printarr(a) {for(auto _e:(a)){cout << _e << " ";} cout << endl;}
#define debugarr(a) {cerr << #a << ": "; _dbgarr(a);}

using ll   unused = long long;
using ld   unused = long double;
using vl   unused = vector<ll>;
using vvl  unused = vector<vl>;
using vvvl unused = vector<vvl>;
using vstr unused = vector<string>;
using vb   unused = vector<bool>;
using lp   unused = pair<ll, ll>;
using lt   unused = tuple<ll, ll, ll>;
using lmap unused = map<ll, ll>;

unused constexpr ll MOD = 998244353;
unused constexpr ll INF = 1 << 29;
unused constexpr ll LINF = 1LL << 61;
unused constexpr double EPS = 1e-10;
unused constexpr int DX[8] = {0, 1, 0,-1, 1, 1,-1,-1};
unused constexpr int DY[8] = {1, 0,-1, 0, 1,-1, 1,-1};
unused inline bool bit(ll b, ll i) { return b & (1LL << i); }
unused inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; }
unused inline ll mod(ll a, ll m = MOD) { return (a % m + m) % m; }
unused inline void modadd(ll &a, ll b, ll m = MOD) { a = mod(a + b, m); }
unused inline ll floordiv(ll a, ll b) { return a / b - (a < 0 && a % b); }
unused inline ll ceildiv(ll a, ll b) { return floordiv(a + b - 1, b); }
tempT unused bool chmin(T &a, T b) { if(a > b) {a = b; return 1;} return 0; }
tempT unused bool chmax(T &a, T b) { if(a < b) {a = b; return 1;} return 0; }

int main() {
    ll h, w; cin >> h >> w;
    vstr field(h); rep(i, h) cin >> field[i];

    set<char> chars[h + w - 1];
    rep(i, h) rep(j, w) {
        chars[i + j].insert(field[i][j]);
    }

    ll ans = 1;
    rep(i, h + w - 1) {
        if(chars[i].count('B') && chars[i].count('R')) {
            ans_exit(0);
        } else if(chars[i].count('.') && chars[i].size() == 1) {
            ans = (ans * 2) % MOD;
        }
    }
    cout << ans << endl;
}

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

typedef tree<int, null_type, less<int>, rb_tree_tag,
    tree_order_statistics_node_update>  nds;
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int>>
#define vpci vector<pair<char,int>>
#define vpcc vector<pair<char,char>>
#define mi map<int,int>
#define mc map<char,int>
#define mpii map<pair<int,int>,int>
#define mpci map<pair<char,int>,int>
#define mpsi map<pair<string,int>,int>
#define ms map<string,int>
#define pii pair<int,int>
#define pc pair<char,char>
#define fbo find_by_order // (use *) value at  index in sorted array.
#define odk order_of_key  // tells index of element in array.
#define int long long int
#define double long double
#define inf 1e18
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define debug(x) cout<<x<<endl
#define debugc cout<<"!"<<endl
#define wt() int tt; cin>>tt;while(tt--)
# define f(x,a,b) for(int x = a; x <= b; x++)
# define fr(x,a,b) for(int x = b; x >= a; x--)
int max(int a,int b){return (a>=b)?a:b;}
int min(int a,int b){return (a<=b)?a:b;}
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int rnd(int limit)
{
    random_device rd;
    mt19937 gen(rd());
    uniform_int_distribution<> dis(1, limit);
    return dis(gen);
}
int modInverse(int a, int m)
{
    int m0 = m;
    int y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1) {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}
vpii p;
void factors(int n)
{
    int cnt=0;
    while (n % 2 == 0)
    {
        cnt++;
        n = n/2;
    }
    if(cnt)
    p.pb({2,cnt});
    cnt=0;
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        cnt=0;
        while (n % i == 0)
        {
            cnt++;
            n = n/i;
        }
        p.pb({i,cnt});
    }
    if (n > 2)
    p.pb({n,1});
}

int mod=1e9+7;
const int N=2e6;
int fact[N+1], ifact[N+1];
int power(int a,int b)
{
    if(b==0)
    return 1;
    int res=power(a,b/2);
    if(b&1)
    res = ((res%mod*res%mod)%mod*a)%mod;
    else
    res=(res%mod*res%mod)%mod;
    return res%mod;
}
void pre()
{
	fact[0]=1;
	f(i,1,N)
	fact[i]=((fact[i-1]%mod)*i)%mod;
	//inverse
	ifact[N]=power(fact[N],mod-2)%mod;;
	fr(i,1,N)
	ifact[i-1]=((ifact[i])*i)%mod;
}

int ncr(int n,int r)
{
	if(r>n)
	return 0;
	int ans=fact[n];
	ans=((ans%mod)*(ifact[n-r])%mod)%mod;
	ans=((ans%mod)*(ifact[r]%mod))%mod;
	return ans;
}

int npr(int n, int r)
{
	if(r>n)
	return 0;
	int ans=fact[n];
	ans=((ans%mod)*(ifact[n-r])%mod)%mod;
	return ans;
}
// In mathematics problem just always avoid floating precision errors(We can avoid it by multipling
//everyting with the number we are dividing) and also avoid mod on negative number mistakes(always add +mod)

// __gcd(x, y) = __gcd(x - y, x)

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    pre();
    int n, m, k;
    cin>>n>>m>>k;
    if( n > m + k)
    {
		cout<<"0"<<endl;
		return 0;
	}
    int ans = (ncr(n + m, n) - ncr(n + m, n - k - 1) + mod) % mod;
    cout<<ans % mod<<endl;
}


// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
#include <bits/stdc++.h>
#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

using namespace std;
using i64 = long long int;

i64 solve(int N, int M, const vector<i64> & A, const vector<i64> & B) {
    // TODO: edit here
    vector<vector<i64>> dp(N + 1, vector<i64>(M + 1));
    rep(i, N + 1) dp[i][0] = i;
    rep(i, M + 1) dp[0][i] = i;
    rep(i, N){
        rep(j, M){
            dp[i + 1][j + 1] = min({dp[i][j + 1] + 1, dp[i + 1][j] + 1, dp[i][j] + (A[i] == B[j] ? 0LL : 1LL)});
        }
    }
    return dp[N][M];
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int N, M;
    cin >> N;
    vector<i64> A(N);
    cin >> M;
    vector<i64> B(M);
    rep (i, N) {
        cin >> A[i];
    }
    rep (i, M) {
        cin >> B[i];
    }
    auto ans = solve(N, M, A, B);
    cout << ans << endl;
    return 0;
}


/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
bool flag[19999990];
int _prime[19999990];
void get_prime(int maxn)
{
    int i,j;
    for(i=2;i<=maxn;i++)
        if(!flag[i])
        {
            _prime[++_prime[0]]=i;
            for(j=i*i;j<=maxn;j+=i)
                flag[j]=true;
        }
}
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<a*2+100-b<<endl;
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << max(0, (2 * (a) + 100) - b) << '\n';
  return 0;
}


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

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

  ll n;
  cin >> n;
  vl v(2*n);
  rep(i, 2*n) cin >> v[i];

  pql pique;
  rep(i, n) {
    pique.push(v[n-1-i]);
    pique.push(v[n+i]);
    pique.pop();
  }
  ll ans = 0;
  while(!pique.empty()) {
    ans += pique.top();
    pique.pop();
  }
  cout << ans << newl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 200016

int x[N], y[N], f[N];

void inc(int n, int i)
{
    for (; i <= n; i += i&-i) ++f[i];
}

int get(int i)
{
    int res = 0;
    for (; i; i -= i&-i) res += f[i];
    return res;
}

int main()
{
    canhazfast();

    int n, p = 0;
    ll ans = 0;
    priority_queue<pii, vpii, greater<pii>> q;

    cin >> n;
    for (int i = n; i >= 1; --i) {
        cin >> x[i];
        ans += x[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> y[i];
        ans += y[i];
    }
    for (int i = 0; i < n; ++i) {
        while (p < n && get(p) >= p) {
            ++p;
            q.emp(x[p], p);
            q.emp(y[p], p);
        }
        pii u = q.top();
        q.pop();
        ans -= u.fir;
        inc(n, u.sec);
    }
    cout << ans << '\n';

    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

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

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'
 #define mod 1000000007
typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
//        ll ans=0;
//        for(ll i=b;i>=a+a;i--)
//        {
//            ll x=i-2*a +1;
//            ans+=x;
//        }
//        cout<<ans<<nl;
        ll ans=0;
        ll x=2*a;
        if(b>=x)
        {
            x=b-x+1;
            ans+=x*(x+1)/2;
        }
        cout<<ans<<nl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y))
#define chmax(x,y) x = max((x),(y))
#define popcount(x) __builtin_popcount(x)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

void solve(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    rep(i,n) --p[i];

    random_device seed_gen;
    mt19937_64 rnd(seed_gen());
    uniform_int_distribution<int> dist_a(0, n-2);

    int m = 0;
    vector<int> ans;
    while(1){
        bool change = false;
        rep(i,n-1){
            if(abs(i-m)%2==0 && p[i] > p[i+1]){
                swap(p[i],p[i+1]);
                ans.push_back(i);
                change = true;
                ++m;
                break;
            }
        }

        bool ok = true;
        rep(i,n) if(p[i] != i) ok = false;
        if(ok) break;

        if(!change && !ok){
            int ind = n-2;
            if(abs(ind-m)%2==1) ind--;
            swap(p[ind],p[ind+1]);
            ans.push_back(ind);
            ++m;
        }
    }

    cout << m << endl;
    rep(i,m) cout << ans[i]+1 << " ";
    cout << endl;
    return;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include <iostream>

using namespace std;

int main() {
    int n;
    cin>>n;
    if(n%2==0){
        cout<<"White";
    }
    else{
        cout<<"Black";
    }

    return 0;
}

//BY: YASH JAIN, CF: yashjain0333
#include <bits/stdc++.h>
using namespace std;
#define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define rall(v) v.rbegin(),v.rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define deb(x) cout<<#x<<": "<<x<<endl;
#define debn(x) cout<<#x<<": "<<x<<"  ";
#define MOD 998244353
#define INF 1e18
#define ll long long
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define int long long
#define N 100
#define mod 998244353
#define sq(x) ((x)*(x))
typedef vector<int> vi;
ll gcd(ll a, ll b) {if (!b)return a; return gcd(b, a % b);}
ll power(ll x, ll y, ll p = INF) {ll res = 1; x %= p; while (y > 0) {if (y & 1)res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}

void solve() {
    int n; cin >> n;
    if (n % 2) cout << "Black";
    else cout << "White";
}

int32_t main() {

#ifndef ONLINE_JUDGE
    // for geting input form input.txt
    freopen("input.txt", "r", stdin);
    // for wrting output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    May_the_fork_be_with_you
    int t = 1;
    // cin >> t;
    cout << fixed << setprecision(12);
    while (t--) {
        solve();
    }

    cerr << "Time Taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <climits>
#include <cctype>
#define rg register
#define Fo(i,a,b) for(int i=(a);i< (b);++i)
#define Fr(i,a,b) for(int i=(a);i<=(b);++i)
#define Fl(i,a,b) for(int i=(a);i>=(b);--i)
#define Fill(x,n) memset((x),(n),sizeof(x))
using namespace std;
typedef long long ll;
typedef unsigned int uint;
const int MX=300;
int N;
/*
const uint A[]=
{
	0b11001001,
	0b10101010,
	0b10011100,
	0b11000110,
	0b10100101,
	0b10010011,
	0b11110000
};
*//*
const uint A[]=
{
	0b10011100,
	0b10101010,
	0b11001001,
	0b10010011,
	0b10100101,
	0b11000110,
	0b11110000
};*/

char A[MX][MX];

void solve(int N)
{
	if(N==1){A[0][0]=1;return;}
	solve(N-1);
	int x=1<<(N-1),y=x-1;
	Fo(i,0,y)Fo(j,0,x)
		A[y+i][j]=A[i][j];
	Fo(i,0,y)Fo(j,0,x)
		A[i][x+j]=A[y-1-i][j];
	Fo(i,0,y)Fo(j,0,x)
		A[y+i][x+j]=A[i][x+j]^1;
	Fo(j,0,x)A[y+y][j]=1;
//	Fo(i,0,(1<<N)-1){Fo(j,0,1<<N)printf("%d",A[i][j]);printf("\n");}
}

/*
int check(int N)
{
	int x=1<<N;
	int y=x-1;
	int z=-1;
	Fo(i,0,x)Fo(j,0,x)if(i!=j)
	{
		int cnt=0;
		Fo(k,0,y)if(A[k][i]==A[k][j])++cnt;
		printf("%d\n",cnt);
		if(z==-1)z=cnt;
		else if(z!=cnt)return 0;
	}
	return 1;
}
*/
/*
int main()
{
	solve(5);
	int res=check(5);
	printf("%d\n",res);
	return 0;
}
*/
int main()
{
	scanf("%d",&N);
	solve(N);
	int x=1<<N,y=x-1;
	printf("%d\n",y);
	Fo(i,0,y)Fo(j,0,x)A[i][j]+='A';
	Fo(i,0,y)printf("%s\n",A[i]);
}

#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, po[8];
vector<string> s[8];

int main() {
    ci(n);
    po[0] = 1;
    rep(i, n - 1) po[i + 1] = 2 * po[i] + 1;
    s[0].epb("AB");
    rep(i, n - 1) {
        rep(j, po[i]) {
            string tmp1, tmp2;
            for (auto &c: s[i][j]) {
                tmp1.append(2, c);
                tmp2.append(1, c);
                tmp2.append(1, 'A' + (c - 'A' + 1) % 2);
            }
            s[i + 1].epb(tmp1);
            s[i + 1].epb(tmp2);
        }
        string tmp;
        rep(j, po[i] + 1) tmp.append("AB");
        s[i + 1].epb(tmp);
    }
    co(po[n - 1]);
    rep(i, po[n - 1]) co(s[n - 1][i]);
    return 0;
}