#include <bits/stdc++.h>

typedef long long ll;
#define llinf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define SZ(x) (int)x.size()
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back

using namespace std;

char s[1005], t[1005];

string atc = "0atcoder";

vector<int> vec[26];

int main() {
    int T;
    scanf("%d", &T);
    atc += 'a' - 1;
    while (T--) {
        scanf("%s", s + 1);
        int n = strlen(s + 1);

        if (n == 1) {
            if (s[1] == 'a') {
                printf("-1\n");
                continue;
            } else {
                printf("0\n");
                continue;
            }
        }

        int fg = 0;
        for (int i = 1; i <= min(n, 8); i++) {
            if (s[i] < atc[i]) break;
            else if (s[i] > atc[i]) {
                fg = 1;
                break;
            }
        }

        for (int i = 0; i < 26; i++) vec[i].clear();
        for (int i = 1; i <= n; i++) vec[s[i] - 'a'].pb(i);

        if (fg) {
            printf("0\n");
            continue;
        }

        int cnt = 1;
        for (int i = 25; i >= 0; i--) {
            for (int j = 0; j < SZ(vec[i]); j++) {
                t[cnt++] = 'a' + i;
            }
        }

        fg = 1;
        for (int i = 1; i <= min(n, 8); i++) {
            if (t[i] < atc[i]) {
                fg = 0;
                break;
            } else if (t[i] > atc[i]) break;
        }

        if (!fg) {
            printf("-1\n");
            continue;
        }

        int minn = inf;
        for (int i = 1; i <= min(n, 7); i++) {
            if (s[i] < atc[i]) {
                for (int j = atc[i] - 'a' + 1; j < 26; j++) {
                    if (!SZ(vec[j])) continue;
                    int pos = upper_bound(vec[j].begin(), vec[j].end(), i) - vec[j].begin();
                    if (pos == SZ(vec[j])) continue;

                    minn = min(minn, vec[j][pos] - i);
                }
                break;
            } else if (s[i] == atc[i]) {
                for (int j = atc[i] - 'a' + 1; j < 26; j++) {
                    if (!SZ(vec[j])) continue;
                    int pos = upper_bound(vec[j].begin(), vec[j].end(), i) - vec[j].begin();
                    if (pos == SZ(vec[j])) continue;
                    // printf("%d %d %d\n", j, vec[j][pos], i);
                    minn = min(minn, vec[j][pos] - i);
                }
            }
        }
        printf("%d\n", minn);

    }
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int dist[2000][2000];
bool done[26];
signed main(){
    int h,w;
    string a[2000];
    cin>>h>>w;
    pair<int,int>s,g;
    vector<pair<int,int>>pos[26];
    for(int i=0;i<h;i++){
        cin>>a[i];
        for(int j=0;j<w;j++){
            if(a[i][j]>='a'&&a[i][j]<='z')
                pos[a[i][j]-'a'].emplace_back(i,j);
            if(a[i][j]=='S')
                s=make_pair(i,j);
            if(a[i][j]=='G')
                g=make_pair(i,j);
        }
    }
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            dist[i][j]=mod;
    int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
    queue<pair<int,int>>que;
    que.push(s);
    dist[s.first][s.second]=0;
    while(!que.empty()){
        pair<int,int>p=que.front();
        que.pop();
        if(g==p){
            cout<<dist[g.first][g.second]<<endl;
            return 0;
        }
        if(a[p.first][p.second]>='a'&&a[p.first][p.second]<='z'&&!done[a[p.first][p.second]-'a']){
            done[a[p.first][p.second]-'a']=1;
            for(int i=0;i<pos[a[p.first][p.second]-'a'].size();i++){
                pair<int,int>np=pos[a[p.first][p.second]-'a'][i];
                if(dist[np.first][np.second]==mod){
                    dist[np.first][np.second]=dist[p.first][p.second]+1;
                    que.push(np);
                }
            }
        }
        for(int i=0;i<4;i++){
            pair<int,int>np=make_pair(p.first+dx[i],p.second+dy[i]);
            if(np.first<0||np.first>=h||np.second<0||np.second>=w)
                continue;
            if(a[p.first][p.second]>='a'&&a[p.first][p.second]<='z'&&a[p.first][p.second]==a[np.first][np.second])
                continue;
            if(a[np.first][np.second]=='#')
                continue;
            if(dist[np.first][np.second]==mod){
                dist[np.first][np.second]=dist[p.first][p.second]+1;
                que.push(np);
            }
        }
    }
    cout<<-1<<endl;
    return 0;
}


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

typedef long long ll;
const int N = 2e5 + 10;
int d[N], a[N];
ll f[N];
int n, m;

int h[N], e[N], ne[N], idx;
void add(int x, int y) {
	e[++idx] = y, ne[idx] = h[x], h[x] = idx;
}

int main()
{
	memset(h, -1, sizeof h);
	idx = 0;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for(int i = 1; i <= m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y);
		++d[y];
	}

	queue<int> q;
	for(int i = 1; i <= n; ++i) if(!d[i]) q.push(i);
	memset(f, 0x3f, sizeof f);
	ll res = -1e18;
	while(!q.empty()) {
		auto u = q.front(); q.pop();
		res = max(res, 1ll * a[u] - f[u]);
		f[u] = min(f[u], 1ll * a[u]);
		for(int i = h[u]; ~i; i = ne[i]) {
			int v = e[i];
			f[v] = min(f[v], f[u]);
			--d[v];
			if(!d[v]) q.push(v);
		}
	}

	printf("%lld\n", res);
}

// abc188e.cpp
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1000000009;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int>a(n);
    rep(i, n) cin >> a[i];
    vector<vector<int>>w(n);
    int x, y;
    rep(i, m) {
        cin >> x >> y;
        x--; y--;
        w[y].push_back(x);
    }
    vector<int>dp(n,INF);
    int ans = -INF;
    for(int i=1;i<n;i++) { // dp[1]から計算する
        int now = INF;
        for (int j : w[i]) {
            now = min(now, dp[j]);
            now = min(now, a[j]); // 町jに来るまでで最安値を調べる
        }
        dp[i] = now; // 町iに来るまでで金の最安値（町iを含まない）
        //cout << "dp[" << i << "]=" << dp[i] << endl;
        if(now!=INF) ans = max(ans, a[i] - now);
        //cout << "ans=" << ans << endl;
    }
    cout << ans << endl;
}
/*
2 1
1000000000 1
1 2

3 1
1 1000000000 1
2 3

*/


#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
#define SZ(v) ((int)(v).size())
typedef pair<int,int> pii;
#define ll long long
int n;
const int Maxv=1e5+5;
bool dp[Maxv];
int main(){
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cin>>n;
  	dp[0]=1;
  	int tot=0;
  	for(int i=1;i<=n;i++){
  		int x;cin>>x;
  		tot+=x;
  		for(int j=Maxv-1;j>=0;j--){
  			if(dp[j]&&j+x<Maxv){
  				dp[j+x]=1;
			  }
		  }
	  }
	vector<int>v;
	for(int i=0;i<Maxv;i++){
		if(dp[i]){
			v.push_back(i);
		}
	}
	if(tot%2==1)tot++;
	auto it=lower_bound(v.begin(),v.end(),tot/2);
	cout<<*it<<endl;
	return 0;
}

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

int main() {
	int n;
	cin>>n;
	vector<int>set(n);
	int sum = 0;
	int x1= 0 ,x2 = 0;
	for(int i=0;i<n;i++){
		cin>>set[i];
		sum+=set[i];
	}
	bool subset[n + 1][sum + 1];

    // If sum is 0, then answer is true
    for (int i = 0; i <= n; i++)
        subset[i][0] = true;

    // If sum is not 0 and set is empty,
    // then answer is false
    for (int i = 1; i <= sum; i++)
        subset[0][i] = false;

    // Fill the subset table in botton up manner
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= sum; j++) {
            if (j < set[i - 1])
                subset[i][j] = subset[i - 1][j];
            if (j >= set[i - 1])
                subset[i][j] = subset[i - 1][j]
                               || subset[i - 1][j - set[i - 1]];
        }
    }
    int mini = 1e8;
    int ans;
    for(int j=1;j<=sum;j++){
    	if(subset[n][j]){
    	//	cout<<j<<endl;
    		if(max(j,(sum-j))<mini){
    			mini = max(j,sum-j);
    			//mini = j-(sum-j);
    		}
    	}
    }
    cout<<mini<<endl;
    //cout<<max(ans,sum-ans)<<endl;

	return 0;
}


//pls work
#include <bits/stdc++.h>
#include <cmath>
#include <cctype>
#include <cstring>

#define fori(i, j, k, in) for (int i = j; i < k; i += in)
#define rfori(i, j, k, in) for (int i = j - 1; i >= k; i -= in)
#define rep(i, j) fori(i, 0, j, 1)
#define rrep(i, j) rfori(i, j, 0, 1)
#define sq(a) (a) * (a)
#define IAMSPEED std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define acci(n) ll n; cin>>n;
#define accia(n, a) ll n; cin>>n; ll a[n]; for(int i=0; i<n; i++) cin>>a[i];
#define pb push_back
#define mp make_pair

using namespace std;

typedef pair<int, int> pi;
typedef vector<int> vi;
typedef long long ll;

const int N = 5e+5, m = 1000000007;

//USE ll instead of int
//Don't use rep for dp!!

int main()
{
    IAMSPEED
    int T = 1, cse = 0;
    // cin >> T;
    while (T--)
    {
        //cse++;
        //cout<<"Case #"<<cse<<": ";
        int h, w;
        cin>>h>>w;
        char c;
        int a[h+1][w+1];
        int dp[h+1][w+1];
        memset(a,0,sizeof(a));
        memset(dp,0,sizeof(dp));
        rep(i, h)
        {
            rep(j, w)
            {
                cin>>c;
                if(c=='+')
                    a[i][j] = 1;
                else
                    a[i][j] = -1;
            }
        }
        rrep(i, h)
        {
            rrep(j, w)
            {
                if(i==h-1&&j==w-1)
                    continue;
                else if((i+j)%2==0)
                {
                    if (i==h-1)
                    {
                        dp[i][j] = dp[i][j+1]+a[i][j+1];
                    }
                    else if (j==w-1)
                    {
                        dp[i][j] = dp[i+1][j]+a[i+1][j];
                    }
                    else
                    {
                        dp[i][j] = max(dp[i+1][j]+a[i+1][j], dp[i][j+1]+a[i][j+1]);
                    }
                }
                else
                {
                    if (i==h-1)
                    {
                        dp[i][j] = dp[i][j+1]-a[i][j+1];
                    }
                    else if (j==w-1)
                    {
                        dp[i][j] = dp[i+1][j]-a[i+1][j];
                    }
                    else
                    {
                        dp[i][j] = min(dp[i+1][j]-a[i+1][j], dp[i][j+1]-a[i][j+1]);
                    }
                }
            }
        }
        if(dp[0][0]==0)
            cout<<"Draw";
        else if(dp[0][0]>0)
            cout<<"Takahashi";
        else cout<<"Aoki";
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vec;
typedef vector<vec> grid;

int main() {
  int h, w;
  cin>>h>>w;
  grid dp(h+1, vec(w+1, -1));
  grid cell_score(h+1, vec(w+1, -1));

  vector<string> game(h);
  for (int i=0; i<h; ++i) {
    cin>>game[i];
  }
  for (int i=0; i<h; ++i) {
    for (int j=0; j<w; ++j) {
      if (game[i][j] == '+')
        cell_score[i][j] = 1;
      else
        cell_score[i][j] = -1;
    }
  }

  dp[h-1][w-1] = 0;

  for (int i=h-1; i>=0; --i) {
    for (int j=w-1; j>=0; --j) {
      if (i==h-1 && j==w-1) {
        continue;
      }
      int res = numeric_limits<int>::min();
      int temp_res;
      if ( i!= h-1) {
        temp_res = cell_score[i+1][j] - dp[i+1][j];
        res = max(res, temp_res);
      }
      if (j != w-1) {
        temp_res = cell_score[i][j+1] - dp[i][j+1];
        res = max(res, temp_res);
      }
      dp[i][j] = res;
    }
  }
  if (dp[0][0] > 0) {
    cout<<"Takahashi";
  }
  else if(dp[0][0] < 0) {
    cout<<"Aoki";
  }
  else {
    cout<<"Draw";
  }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}

// C

const int N=200050;
int p[N],pos[N];
int main(){
	int n=ri();
	ra(p,n);
	for(int i=1;i<=n;i++)pos[p[i]]=i;
	vector<int> ans;
	int mx=0;
	for(int i=1;i<=n;i++){
		int j=pos[i];
		if(j==i)continue;
		if(mx!=i-1)return 0*printf("-1\n");
		mx=j-1;
		while(j>i){
			ans.pb(j-1);
			swap(pos[p[j]],pos[p[j-1]]);
			swap(p[j],p[j-1]);
			j--;
		}
	}
	if(ans.size()!=n-1)return 0*printf("-1\n");
	for(int i:ans)printf("%i\n",i);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 2e5+5;

int n, a[sz], w[sz], bit[sz];

void add(int x) {
   while(x <= n) {
      bit[x]++;
      x += x & (-x);
   }
}

int quer(int x) {
   int ans = 0;
   while(x) {
      ans += bit[x];
      x -= x & (-x);
   }
   return ans;
}

int main() {
   cin >> n;
   for(int i=1; i<=n; i++) scanf("%d", &a[i]), w[a[i]] = i;

   int tot = 0;
   vector <int> res;
   for(int i=n; i; i--) {
      int x = quer(w[i]);
      if(x) tot += x, res.push_back(x);
      add(w[i]);
   }
   if(tot == n-1) {
      reverse(res.begin(), res.end());
      int s = 0;
      for(int x : res) {
         for(int i=s+x; i>s; i--) printf("%d\n", i);
         s += x;
      }
   }
   else puts("-1");
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N, L;
    cin >> N >> L;
    vl A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    ll k = 0, ans = 0, last = 0;
    rep(i, N){      // 右に走査
        if (i < last) A[i] = A[last] - (last - i);
        if (A[i] >= B[i] or B[i] == i + 1 or B[i] == L - (N - i - 1)) continue;
        chmax(k, i + 1);

        while (k < N and B[i] != A[k] - (k - i)) k++;
        if(k == N){
            cout << -1 << endl;
            return 0;
        }

        ans += k - i, last = k;
        A[i] = B[i];
    }

    k = N, last = N;
    repr(i, N){     // 左に走査
        if (i > last) A[i] = A[last] + (i - last);
        if (A[i] <= B[i] or B[i] == i + 1 or B[i] == L - (N - i - 1)) continue;
        chmin(k, i - 1);

        while (k >= 0 and B[i] != A[k] + (i - k)) k--;
        if(k == -1){
            cout << -1 << endl;
            return 0;
        }

        ans += i - k, last = k;
        A[i] = B[i];
    }

    rep(i, N){      // 端点
        if (A[i] == B[i]) continue;
        ans++;
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
constexpr int INF = 1e9, MOD = 1e9 + 7;
constexpr int64_t LINF = 5e18, LMOD = 998244353;
// #include <atcoder/all>
// using namespace atcoder;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int n, m;
int k;
int c[18];
vector<int> edge[100010];
int64_t dist[18][100010];

void f() {
	rep(i,k)rep(j,n) {
		dist[i][j] = INF;
	}
	for(int i = 0; i < k; ++i) {
		queue<int> que;
		dist[i][c[i]] = 0;
		que.push(c[i]);
		while(not que.empty()) {
			int from = que.front();
			que.pop();
			for(int to : edge[from]) {
				if(dist[i][from] + 1 >= dist[i][to]) continue;
				que.push(to);
				dist[i][to] = dist[i][from] + 1;
			}
		}
	}
}

int64_t dp[1 << 18][18];
int main() {
	cin >> n >> m;
	rep(i,m) {
		int a, b; cin >> a >> b;
		--a, --b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	cin >> k;
	rep(i,k) {
		cin >> c[i];
		--c[i];
	}
	f();
	rep(i,(1<<k))rep(j,k) dp[i][j] = INF;
	rep(i,k) {
		dp[1 << i][i] = 1;
	}
	for(int mask = 1; mask < (1 << k); ++mask) {
		for(int i = 0; i < k; ++i) {
			if(mask >> i & 1) {
				rep(j,k) {
					if(dist[i][c[j]] == INF) continue;
					dp[mask | (1 << j)][j] = min(dp[mask | (1 << j)][j], dp[mask][i] + dist[i][c[j]]);
				}
			}
		}
	}

	int64_t ans = INF;
	int ma = (1 << k) - 1;
	rep(i,k) {
		ans = min(ans, dp[ma][i]);
	}
	if(ans == INF) {
		cout << -1 << '\n';
	} else {
		cout << ans << '\n';
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <list>
#include <cassert>
#include <numeric>
#include <cstdint>
#include <queue>
#include <deque>

using ll = long long;
using ld = long double;
using namespace std;
using Graph = vector<vector<int>>;
using Priority = priority_queue<int>;

// typedef pair<int,int> P;
#define teisu 1000000007
#define MAX_WIDTH 60
#define MAX_HEIGHT 60
#define INF 1e16

ll N,A[100010],B[100010],C[100010];
map<ll,ll> link;
map<ll,ll> cnt;
int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
        cnt[A[i]]++;
    }
    for(int i=0;i<N;i++) {
        cin >> B[i];
    }
    for(int i=0;i<N;i++) {
        cin >> C[i];
        C[i]--;
        int index = B[C[i]];
        link[index]++;
    }

    ll ans = 0;
    for(int i=1;i<=N;i++){
        ans += cnt[i]*link[i];
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
typedef vector<int> vi;
#define all(x) x.begin(), x.end()
#define FIO     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define endl "\n"
#define pb push_back
#define mp make_pair
#define re(i,n)        for(int i=0;i<(n);i++)
#define re1(i, k, n) for (int i = k; k < n ? i <= n : i >= n; k < n ? i += 1 : i -= 1)
#define FORD(i,a,b)     for(int i=(a);i>=(b);i--)
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
#define mod 1000000007
//===================================DEBUG TEMPLATE=================================================
void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
	cerr << '{';
	__print(x.first);
	cerr << ',';
	__print(x.second);
	cerr << '}';
}
template <typename T>
void __print(const T &x)
{
	int f = 0;
	cerr << '{';
	for (auto &i : x)
		cerr << (f++ ? "," : ""), __print(i);
	cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
	__print(t);
	if (sizeof...(v))
		cerr << ", ";
	_print(v...);
}
//====================================DEBUG TEMPLATE==============================================

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

	int n;
	cin >> n;
	vi a(n + 1), b(n + 1), c(n + 1);
	re(i, n) {
		cin >> a[i + 1];
	}
	re(i, n) {
		cin >> b[i + 1];
	}
	re(i, n) {
		cin >> c[i + 1];
	}
	map<int, int> mp;
	re(i, n) {
		mp[b[c[i + 1]]]++;
	}
	int ans = 0;
	re(i, n) {
		auto it = mp.find(a[i + 1]);
		if (it != mp.end())
			ans += it->ss;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

const int M=1e9+7;

int T,n,a,b,ans;

int mo2(int x){
	return (x<0)?x+M:x;
}

int get_sum(int l,int r,int k,int t){
	int key1=l*k+t,key2=r*k+t;
	return 1ll*(key1+key2)*(r-l+1)/2%M;
}

int main(){
	scanf("%d",&T);
	while (T--){
		scanf("%d%d%d",&n,&a,&b);
		if (n<a+b){
			puts("0");
			continue;
		}
		ans=mo2((1ll*(n-b+1)*(a+b-1)-get_sum(0,a-1,-1,a-1)-get_sum(n-a-b+1,n-b,1,-(n-a-b+1)))%M);
		printf("%d\n",mo2((1ll*(n-a+1)*(n-a+1)%M*(n-b+1)%M*(n-b+1)-1ll*ans*ans)%M));
	}
	return 0;
}

    #include <bits/stdc++.h>
    typedef long long LL;
    #define SZ(X) ((int)(X).size())
    #define ALL(X) (X).begin(), (X).end()
    #define RALL(X) (X).rbegin(), (X).rend()
    #define REP(I, N) for (int I = 0; I < (N); ++I)
    #define REPP(I, A, B) for (int I = (A); I < (B); ++I)
    #define RI(X) scanf("%d", &(X))
    #define RII(X, Y) scanf("%d%d", &(X), &(Y))
    #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
    #define DRI(X) int (X); scanf("%d", &X)
    #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
    #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
    #define DRVI(N, X) VI X(N); for (int ___I=0; ___I<N; ___I++) scanf("%d", &(X[___I]))
    #define RS(X) scanf("%s", (X))
    #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
    #define MP make_pair
    #define PB push_back
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MS1(X) memset((X), -1, sizeof((X)))
    #define LEN(X) strlen(X)
    #define PII pair<int,int>
    #define VI vector<int>
    #define VL vector<long long>
    #define VPII vector<pair<int,int> >
    #define PLL pair<long long,long long>
    #define VPLL vector<pair<long long,long long> >
    #define F first
    #define S second

    using namespace std;

    int main(){
        DRII(h,w);
        DRII(n,m);
        vector<VI> v(h, VI(w,0));
        vector<pair<PII,int>> b;
        REP(i,n){
            DRII(x,y);
            x--;y--;
            v[x][y]=1;
            b.PB({{x,y},0});
        }
        REP(i,m){
            DRII(x,y);
            x--;y--;
            v[x][y]=-1;
        }

        int it=0;
        VI rv(h*w,0);
        int res=0;
        while (it<SZ(b)){
            int rr;
            if (b[it].S==0) rr=15;
            else rr=(1<<(b[it].S-1));
            if (rr^(rr&rv[b[it].F.F*w+b[it].F.S])){
                if (rv[b[it].F.F*w+b[it].F.S]==0) res++;
                rv[b[it].F.F*w+b[it].F.S]|=rr;
            }
            else{
                it++;
                continue;
            }
            if (b[it].S==0 or b[it].S==1){
                int x=b[it].F.F;
                int y=b[it].F.S;
                if (x+1<h and v[x+1][y]!=-1){
                    b.PB({{x+1,y},1});
                }
            }
            if (b[it].S==0 or b[it].S==2){
                int x=b[it].F.F;
                int y=b[it].F.S;
                if (y+1<w and v[x][y+1]!=-1){
                    b.PB({{x,y+1},2});
                }
            }
            if (b[it].S==0 or b[it].S==3){
                int x=b[it].F.F;
                int y=b[it].F.S;
                if (x>0 and v[x-1][y]!=-1){
                    b.PB({{x-1,y},3});
                }
            }
            if (b[it].S==0 or b[it].S==4){
                int x=b[it].F.F;
                int y=b[it].F.S;
                if (y>0 and v[x][y-1]!=-1){
                    b.PB({{x,y-1},4});
                }
            }
            it++;
        }
        printf("%d\n",res);

    }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define trace(...) debug(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void debug(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void debug(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " | ";
  debug(comma + 1, args...);
}
#define mp(x,y) make_pair(x,y)
const int INF=1000000000+5;
const int N=1e6+5;
const ll oo=1e18+5;
const ll mod=998244353;

ll gcd(ll a,ll b,ll& num1,ll& num2){
	if(b==0){
		num1=1;
		num2=0;
		return a;
	}
	ll x,y;
	ll g=gcd(b,a%b,x,y);
	num1=y;
	num2=x-y*(a/b);
	return g;
}

void solve(){
	ll n,s,k;
	cin>>n>>s>>k;
	//~ s+a*k==b*n
	//~ b*n-a*k=s;
	//~ s%gcd(n,k)==0
	//~ b*n/g-a*k/g=s/g
	//~ b'*n-a'*k=1
	ll num1,num2;
	ll g=gcd(k,n,num1,num2);
	if(s%g){
		cout<<-1<<endl;
		return;
	}
	num1*=s/g;
	num2*=s/g;
	n/=g;
	k/=g;
	if(num1>=0){
		ll w=num1/n;
		num1-=w*n;
		num1-=n;
		num1=-num1;
	}
	else{
		ll w=abs(num1)/n;
		num1+=w*n;
		num1=-num1;
	}
	cout<<num1<<endl;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FOR(i, a, b) for(int i = a; i < b; i++)
ll MOD = 1000000007;

ll power(ll base, ll n){
	if (n == 0) return 1;
	if (n == 1) return base;
	ll halfn = power(base, n/2);
	if (n % 2 == 0) return (halfn * halfn) % MOD;
	return (((halfn * halfn) % MOD) * base) % MOD;
}

ll inverse(ll n){
	return power(n, MOD-2);
}

int main(){
	ios::sync_with_stdio(false);
	int a, b, c; cin >> a >> b >> c;
	double dp[101][101][101];
	FOR(i, 0, 101){
		FOR(j, 0, 101){
			FOR(k, 0, 101){
				dp[i][j][k] = 0;
			}
		}
	}
	dp[99][99][99] = 1;
	for (int i = 99; i >= 0; i--){
		for (int j = 99; j >= 0; j--){
			for (int k = 99; k >= 0; k--){
			    if (i == 99 && j == 99 && k == 99){
			        dp[i][j][k] = 1; continue;
			    }
				if (a > 0) dp[i][j][k] += (dp[i+1][j][k] + 1) * i;
				if (b > 0) dp[i][j][k] += (dp[i][j+1][k] + 1) * j;
				if (c > 0) dp[i][j][k] += (dp[i][j][k+1] + 1) * k;
				dp[i][j][k] = dp[i][j][k] / (i+j+k);
			}
		}
	}
	cout << setprecision(18) << dp[a][b][c] << '\n';
	return 0;
}


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;

int main(){ _
  lli n; cin >> n;
  if(n == 1) {
    cout << 2 << ENDL;
    return 0;
  }
  lli ans = 0;
  lli cur = 0;
  fore(i, 1, 1e8) {
     cur += i;
     if(cur > n) break;
     lli x = n - cur;
     if(x % i == 0) ++ans;
  }
  cout << ans * 2LL << ENDL;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

bool ok (ll len, ll tot)
{
	ll tmp = tot / len;
	return (tmp + 1 - len) % 2 == 0;
}

int main()
{
	ll n; scanf("%lld", &n);

	n <<= 1;
	int cnt = 0;
	for (ll i = 1; i * i <= n; i++)
	{
		if (n % i) continue;
		cnt += ok(i, n);
		if (i * i != n) cnt += ok(n / i, n);
	}
	printf("%d\n", cnt);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lc (rt << 1)
#define rc ((rt << 1) | 1)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
#define PE(i, u) for (int i = head[u]; i != -1; i = edge[i].next)
typedef long long LL;
const int maxn = 1e6 + 20;
const int mod = 1e9 + 7;

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

LL cal(LL t){
    return t * (t + 1) % mod * y % mod;
}
int main(int argc, char const *argv[])
{
    y = qpow(2, mod - 2);
    int t;
    scanf("%d", &t);
    while(t--){
        LL n, a, b;
        scanf("%lld%lld%lld", &n, &a, &b);
        // printf("[%lld %lld %lld]\n", n, a, b);

        if(a > b) swap(a, b);
        // printf("[%lld %lld %lld]\n", n, a, b);
        LL num1 = (n - a + 1) * (n - a + 1) % mod, num2 = (n - b + 1) * (n - b + 1) % mod;
        // printf("num1 = %lld num2 = %lld\n", num1, num2);
        LL ans = num1 * num2 % mod;
        // printf("777ans = %lld\n", ans);
        ans = (ans - (b - a + 1) * (b - a + 1) % mod * num2 % mod + mod) % mod;
        // printf("88ans = %lld\n", ans);
        LL ma = min(a - 1, n - b);
        // printf("ma = %lld\n", ma);
        // printf("7777\n");
        LL res = cal(ma) * (b - a + 1) % mod * (n - b + 1) % mod;
        // printf("res = %lld\n", res);
        // printf("9999\n");
        if(n - b > a - 1){
            res = (res + (n - b - a + 1) * (a - 1) % mod * (b - a + 1) % mod * (n - b + 1) % mod) % mod;
        }
        // printf("res = %lld\n", res);
        ans = (ans - 4LL * res % mod + mod) % mod;

        ma = min(b + a - 1, n);
        LL mi = min(b + 1, ma);
        // printf("a = %lld\n", a);
        if(a != 1){
            // printf("ansans = %lld\n", ans);
            // printf("[ma = %lld mi = %lld]\n", ma, mi);
            LL num3 = (cal(ma - 1) - cal(mi - 2) + mod) % mod;
            // printf("num3 = %lld\n", num3);
            res = (n * n % mod * (ma - mi + 1) % mod * (ma - mi + 1) % mod - n * num3 % mod * (ma - mi + 1) % mod * 2LL % mod + num3 * num3 % mod + 10LL * mod) % mod;
            // printf("res = %lld\n", res);
            ans = (ans - 4LL * res % mod + mod) % mod;
        }

        printf("%lld\n", ans);
    }
    return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

LL sub(LL a, LL b) { return (a - b + kMod) % kMod; }
LL mul(LL a, LL b) { return a * b % kMod; }

LL solve() {
  LL N, A, B; cin >> N >> A >> B;
  if (N < A + B) return 0;

  LL all = mul(N - A + 1, N - B + 1);
  LL X3 = mul(N - A - B + 1, N - A - B + 2);
  LL X2 = sub(all, X3);
  LL X1 = mul(X2, X2);

  return sub(mul(all, all), X1);
}

int main() {
  int T; cin >> T;
  for (int i = 0; i < T; ++i) {
    std::cout << solve() << endl;
  }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    char s , t;
    cin >> s >> t;
    if(s == 'Y'  )cout << char (toupper(t)) << endl;
    else cout << t << endl;
}

#include<stdio.h>
#include<string.h>

int main(void){
    char S,T;
    S=fgetc(stdin);
    T=fgetc(stdin);
    scanf("%c",&T);
    if(S=='Y'){
        if(T=='a'){
            printf("A");
        }
        else{
            if(T=='b'){
                printf("B");
            }
            else{
                if(T=='c'){
                    printf("C");
                }
            }
        }
    }
    else{
        printf("%c\n",T);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MS(a, b) memset(a, b, sizeof(a))
#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define EREP(a, b) for (register int a = head[b]; a; a = edge[a].nxt)

inline int rd() {
    int x = 0; char c = getchar(); bool f = 0;
    while (c < '0' && c != '-') c = getchar();
    if (c == '-') f = 1, c = getchar();
    while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    return f ? -x : x;
}

const int SIZE = 2e5 + 100;

int n;

int head[SIZE], ecnt;
struct Edge {
	int v, nxt;
} edge[SIZE << 1];
void Add_Edge (int u, int v) {
	edge[++ecnt] = (Edge) { v, head[u] };
	head[u] = ecnt;
}

int dep[SIZE], F[SIZE];
int mx[SIZE][2];
int Len = -1, A, B;
void dfs (int u, int fa) {
	F[u] = fa;
	dep[u] = dep[fa] + 1;
	mx[u][0] = mx[u][1] = u;
	EREP (i, u) {
		int v = edge[i].v;
		if (v == fa) continue;
		dfs(v, u);
		if (dep[mx[v][0]] > dep[mx[u][0]])
			mx[u][1] = mx[u][0], mx[u][0] = mx[v][0];
		else if (dep[mx[v][0]] > dep[mx[u][1]])
			mx[u][1] = mx[v][0];
	}
	if (dep[mx[u][0]] + dep[mx[u][1]] - 2 * dep[u] > Len) {
		Len = dep[mx[u][0]] + dep[mx[u][1]] - 2 * dep[u];
		A = mx[u][0];
		B = mx[u][1];
	}
}
bool mark[SIZE];
int E;
int ans[SIZE];
void D (int u, int fa) {
	++E;
	ans[u] = E;
	EREP (i, u) {
		int v = edge[i].v;
		if (v == fa) continue;
		if (!mark[v]) D(v, u);
	}
	EREP (i, u) {
		int v = edge[i].v;
		if (v == fa) continue;
		if (mark[v]) D(v, u);
	}
	++E;
}

void _main () {
	n = rd();
	FOR (i, 1, n) {
		int u = rd(), v = rd();
		Add_Edge(u, v);
		Add_Edge(v, u);
	}
	dfs(1, 0);
	int T = A;
	while (A != B) {
		if (dep[A] < dep[B]) swap(A, B);
		mark[A] = 1;
		A = F[A];
	} mark[A] = 1;
	D(T, 0);
	REP (i, 1, n) printf ("%d ", ans[i]);
}

int main () {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
#endif
	_main();
	return 0;
}

#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set;

const int MAXN = 123;
int dp[MAXN][MAXN];
char s[MAXN];
int ds[MAXN];
int pw2[MAXN];

int vs(int a, int b) {
    if (a == 1) {
        return b != 2;
    } else if (a == 2) {
        return b != 3;
    }
    return b != 1;
}

int dfs(int n, int S, int N) {
    if (dp[n][S]) return dp[n][S];
    if (S == 1) {
        int a = ds[(n % N) + 1], b = ds[((n + 1) % N) + 1];
        return dp[n][S] = (vs(a, b) ? a : b);
    }
    int l = dfs(n, S - 1, N), r = dfs((n + pw2[S - 1]) % N, S - 1, N);
    return dp[n][S] = (vs(l, r) ? l : r);
}

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    scanf("%s", s + 1);
    for (int i = 1; i <= N; i++) {
        if (s[i] == 'R') ds[i] = 1;
        else if (s[i] == 'P') ds[i] = 2;
        else ds[i] = 3;
    }
    pw2[0] = (1 % N);
    for (int i = 1; i <= N; i++)
        pw2[i] = (pw2[i - 1] * 2) % N;
    char V[] = {0, 'R', 'P', 'S'};
    printf("%c\n", V[dfs(0, K, N)]);
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll dp[105][105][105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, X;
    cin >> N >> X;
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= N; j++) {
            for(int k = 0; k <= N; k++) {
                dp[i][j][k] = -INF;
            }
        }
    }
    for(int i = 0; i <= N; i++) {
        dp[0][i][0] = 0;
    }
    for(int t = 0; t < N; t++) {
        ll A;
        cin >> A;
        for(int i = t; i >= 0; i--) {
            for(int j = 1; j <= N; j++) {
                for(int k = 0; k < j; k++) {
                    if(dp[i][j][k] < 0) continue;
                    chmax(dp[i+1][j][(k+A)%j], dp[i][j][k] + A);
                }
            }
        }
    }
    ll ans = INF;
    for(int i = 1; i <= N; i++) {
        for(int j = 0; j < i; j++) {
            if(dp[i][i][j] < 0) continue;
            if(dp[i][i][j] > X) continue;
            ll delta = X - dp[i][i][j];
            if(delta % i != 0) continue;
            chmin(ans, delta / i);
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N;
ll X;
ll a[101];
ll dp[101][101][101];

int main() {
    cin >> N >> X;
    REP(i, N) cin >> a[i];

    ll ans = LLINF;

    FOR(k, 1, N+1) {
        REP(i,N+1)REP(j,k+1)REP(l,k) dp[i][j][l] = -LLINF;
        dp[0][0][0] = 0;

        REP(i, N) {
            REP(cnt, k + 1) {
                REP(r, k) {
                    if(dp[i][cnt][r] == -LLINF) continue;

                    // えらぶ
                    if(cnt < k) {
                        ll cost = 0;
                        if(a[i] + r >= k) {
                            cost++;
                            ll remain = a[i] - (k - r);
                            cost += remain / k;
                        }
                        int nxt_r = (a[i] + r) % k;
                        if((dp[i][cnt][r] + cost) * k + nxt_r <= X) {
                            chmax(dp[i+1][cnt+1][nxt_r], dp[i][cnt][r] + cost);
                        }
                    }

                    // えらばない
                    chmax(dp[i+1][cnt][r], dp[i][cnt][r]);
                }
            }
        }

        if(dp[N][k][X%k] == -LLINF) continue;

        chmin(ans, (X - X % k - dp[N][k][X%k] * k) / k);

    }

    assert(ans != LLINF);
    cout << ans << endl;
}


# include<bits/stdc++.h>

using namespace std;
# define l long long
# define db long double
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ' ' << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

#ifdef KRISHNAN_DEBUG
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

const bool MULTIPLE_TEST_CASES = false;

const l MOD=1e9+7;
const l N=1e5+5;
const l INF=1e12;
db PI = 3.141592653589793238;

void solve() {
	l n;
	cin>>n;
	l x0,y0;
	cin>>x0>>y0;
	l xn,yn;
	cin>>xn>>yn;

	db xmid = (db)(x0+xn)/2, ymid = (db)(y0+yn)/2;

	l xDiff = xn-x0, yDiff=yn-y0;
	dbg(xDiff, yDiff);
	db angle = acos((db)xDiff / (sqrtl(xDiff*xDiff + yDiff*yDiff)));
	dbg(angle, angle*180/PI);
	if(yDiff<0) {
		angle = 2*PI-angle;
	}
	dbg(angle, angle*180/PI);
	angle += 2*PI/n;
	dbg(angle, angle*180/PI);
	// angle = PI-angle;
	dbg(angle);
	db length = sqrtl(xDiff*xDiff + yDiff*yDiff) / 2;
	db X = xmid - length*cos(angle);
	db Y = ymid - length*sin(angle);
	cout.precision(15);
	cout<<X<<" "<<Y<<"\n";

	return;
}

int main(){
	io;
	int t=1;
	if (MULTIPLE_TEST_CASES) cin>>t;
	rep(i,0,t) {
		solve();
	}

	return 0;
}

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

#define ll              long long
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << " , " << #y << "=" << y << endl
#define _               ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

void solve()
{
    ll n, m;
    cin >> n;
    vector<pair<ll,ll>>v;

    for(int i=0 ; i<n ; i++)
    {
    	ll x,y;
    	cin >> x >> y;
    	v.push_back({x,y});
    }

    ll res = 0;

    for(int i=0 ; i<n ; i++)
    {
    	for(int j=i+1; j<n ; j++)
    	{
    		double slope = ((double)(v[i].second-v[j].second)/(double)(v[i].first-v[j].first));

    		if(slope >= -1 && slope <= 1) res++;
    	}
    }
    cout << res << '\n';
}

int main()
{_
    int t = 1;

    //cin >> t;

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

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
const long double PI = 3.141592653589793;

int main(){
    int n;
    cin >> n;
    int x0, y0, x2, y2;
    cin >> x0 >> y0;
    cin >> x2 >> y2;

    long double rx = (long double)(x0+x2)/2.0;
    long double ry = (long double)(y0+y2)/2.0;
    long double x01 = (long double)x0-rx;
    long double y01 = (long double)y0-ry;
    cerr << x01 << " " << y01 << endl;
    long double r = sqrt(x01*x01 + y01*y01);
    long double x1 = r*(x01/r*cos(PI*2.0/n)-y01/r*sin(PI*2.0/n));
    long double y1 = r*(y01/r*cos(PI*2.0/n)+x01/r*sin(PI*2.0/n));
    cout << fixed << setprecision(20) << x1+rx << " " << y1+ry << endl;
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

using D = long double;
const D PI = acos(-1.0);
const D EPS = 1e-10;
struct P {
  D x, y;
  P(D x=0, D y=0) : x(x), y(y) {}

  P& operator+=(const P& o) { x += o.x; y += o.y; return *this; }
  P& operator-=(const P& o) { x -= o.x; y -= o.y; return *this; }
  P& operator*=(const P& o) { return *this = {x*o.x - y*o.y, x*o.y + y*o.x}; }
  P& operator*=(const D& r) { x *= r; y *= r; return *this; }
  P& operator/=(const D& r) { x /= r; y /= r; return *this; }
  P operator-() const { return {-x, -y}; }

  D norm() const { return x*x + y*y; }
  D abs() const { return sqrt(norm()); }
  D arg() const { return atan2(y, x); }
  bool isZero() const { return std::abs(x) < EPS && std::abs(y) < EPS; }
  /** 象限 */
  int orth() const { return y >= 0 ? (x >= 0 ? 1 : 2) : (x < 0 ? 3 : 4); }
  static P polar(const D& rho, const D& theta = 0) { return {rho * cos(theta), rho * sin(theta)}; }
};
std::ostream &operator<<(std::ostream &os, P const &p) { return os << "(" << p.x << ", " << p.y << ")"; }
std::istream &operator>>(std::istream &is, P &p) { D a, b; is >> a >> b; p = P(a, b); return is; }
P operator+(const P& p, const P& q) { return P(p) += q; }
P operator-(const P& p, const P& q) { return P(p) -= q; }
P operator*(const P& p, const P& q) { return P(p) *= q; }
P operator*(const P& p, const D& r) { return P(p) *= r; }
P operator/(const P& p, const D& r) { return P(p) /= r; }
P operator*(const D& r, const P& p) { return P(p) *= r; }
P operator/(const D& r, const P& p) { return P(p) /= r; }
D crs(const P& a, const P& b){ return a.x*b.y - a.y*b.x; }
D dot(const P& a, const P& b){ return a.x*b.x + a.y*b.y; }

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  int x0 = nextLong();
  int y0 = nextLong();
  int xN2= nextLong();
  int yN2 = nextLong();
  P a = P(x0, y0);
  P b = P(xN2, yN2);
  P m = (a + b) / 2.0;
  P v = a - m;
  P r = P(cos(2.0 * PI / N), sin(2.0 * PI / N));
  P ans = m + v * r;
  printf("%.10f %.10f\n", (double)ans.x, (double)ans.y);
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


//#define NDEBUG

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class F> class rec_lambda {
  F f;

public:
  rec_lambda(F &&f) : f(std::move(f)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); }
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}
constexpr char eoln = '\n';
template <class T> T ceildiv(const T &l, const T &r) {
  return l / r + (l % r != 0 ? 1 : 0);
}

} // namespace n91

#include <numeric>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize n = scan<usize>();
  std::vector<u32> a(n), b(n);
  std::vector<usize> p(n), inv(n);
  for (auto &e : a) {
    std::cin >> e;
  }
  for (auto &e : b) {
    std::cin >> e;
  }
  for (auto &e : p) {
    std::cin >> e;
    --e;
  }

  for (const usize i : rep(0, n)) {
    if (a[i] <= b[p[i]] && p[i] != i) {
      std::cout << "-1" << eoln;
      return;
    }
  }

  for (const usize i : rep(0, n)) {
    inv[p[i]] = i;
  }

  std::vector<std::pair<usize, usize>> ans;

  std::vector<usize> idx(n);
  std::iota(idx.begin(), idx.end(), usize(0));
  std::sort(idx.begin(), idx.end(),
            [&](usize l, usize r) { return b[l] > b[r]; });
  for (const usize i : idx) {
    if (p[i] == i) {
      continue;
    }
    const usize j = inv[i];
    std::swap(inv[p[i]], inv[p[j]]);
    std::swap(p[i], p[j]);
    ans.emplace_back(i, j);
  }
  std::cout << ans.size() << eoln;
  for (const auto &e : ans) {
    std::cout << e.first + 1 << " " << e.second + 1 << eoln;
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}

//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 998244353LL;
// static const ll MOD = (1LL << 61LL) - 1LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#ifdef LOCAL_ENV
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define DUMP(x)
#define DEBUG(x)
#endif

#define MAX_VALUE 9223372036854775807LL

template <ull N, class T, class... Args, std::enable_if_t<N == 0, int> = 0>
auto make_multiple_vector(Args... args) {
    return T(args...);
}

template <ull N, class T, class... Args, std::enable_if_t<N != 0, int> = 0>
auto make_multiple_vector(ull size, Args... args) {
    using value_type = std::decay_t<decltype(make_multiple_vector<N - 1, T>(args...))>;
    return vector<value_type>(size, make_multiple_vector<N - 1, T>(args...));
}

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

	vector<ll> as(n), bs(n), ps(n);
	REPD(i, 0, n) cin >> as[i];
	REPD(i, 0, n) cin >> bs[i];
	REPD(i, 0, n) cin >> ps[i], --ps[i];

	vector<pair<ll, ll>> results;
	vector<bool> is_visited(n, false);
	REPD(i, 0, n) {
		if (is_visited[i]) continue;

		ll begin_idx = i, curr_idx = i;
		vector<ll> idxs;
		ll cnt = 0, min_cnt;
		ll min_val = MAX_VALUE;
		do {
			if (as[curr_idx] <= bs[ps[curr_idx]] && curr_idx != ps[curr_idx]) RET(-1);
			idxs.emplace_back(curr_idx);
			if (bs[ps[curr_idx]] < min_val) {
				min_val = bs[ps[curr_idx]];
				min_cnt = cnt;
			}
			++cnt;
			is_visited[curr_idx]= true;
			curr_idx = ps[curr_idx];
		}
		while (curr_idx != begin_idx);

		REPD(j, 1, idxs.size()) {
			results.emplace_back(idxs[min_cnt] + 1LL, idxs[(min_cnt - 1LL + idxs.size()) %  idxs.size()] + 1LL);
			min_cnt = (min_cnt - 1LL + idxs.size()) %  idxs.size();
		}
	}

	cout << results.size() << endl;
	REPI(res, results) cout << res.first << " " << res.second << endl;

	return 0;
}

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

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}


#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

ll N;
ll i3[100];
ll i5[100];

bool res(ll r, ll &b) {
  while(i5[b] > r) b--;
  if (i5[b] == r) return true;
  b++;
  return false;
}

int main()
{

  int A,B;
  int max3, max5;

  i3[0] = 1;
  for (max3=1; i3[max3-1] < 1000000000000000000LL; max3++) {
    i3[max3] = i3[max3-1]*3;
  }
  max3--;
  i5[0] = 1;
  for (max5=1; i5[max5-1] < 1000000000000000000LL; max5++) {
    i5[max5] = i5[max5-1]*5;
  }
  max5--;

  B = max5;

  cin >> N;

  for (A=1; i3[A] < N; A++) {
    for (B=max5; B>0 ; B--) {
//printf("i3[%d](%lld) + i5[%d](%lld) = %lld\n", A, i3[A], B, i5[B], i3[A] + i5[B]);
      if (i3[A] + i5[B] == N) {
        printf("%d %d\n", A, B);
        return 0;
      }
      if (i3[A] + i5[B] < N) break;
    }
  }

  printf("-1\n");

  return 0;
}

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

long long power(long long a,long long x){
    return x?x%2?power(a,x-1)*a:(long long)power(a,x/2)*power(a,x/2):1;
}

long long N,A,B;
int main(){
    cin>>N;
    for(B=1LL;power(5LL,B)<=N;B++){
        //cout<<B<<" : "<<power(5LL,B)<<endl;
        long long t=N-power(5LL,B);
        if(t==0LL)continue;
        //cout<<t<<endl;
        for(A=0LL;t%3LL==0LL;A++)t/=3LL;
        if(t==1LL&&A>0LL){cout<<A<<" "<<B<<endl;return 0;}
    }
    cout<<-1<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

int fa[N], a[N], sz[N], n;

int find(int rt) {
  return rt == fa[rt] ? rt : fa[rt] = find(fa[rt]);
}

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i < N; i++) {
    fa[i] = i, sz[i] = 1;
  }
  for (int i = 1; n - i + 1 > i; i++) {
    int u = find(a[i]), v = find(a[n - i + 1]);
    if (u != v) {
      fa[u] = v;
      sz[v] += sz[u];
    }
  }
  int ans = 0;
  for (int i = 1; i < N; i++) {
    if (fa[i] == i) {
      ans += sz[i] - 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

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

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

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

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

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

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

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const ll mod = 1e9+7;
ll mul(ll a,ll b){return ((a%mod)*(b%mod))%mod;}
ll sum(ll a,ll b){return ((a%mod)+(b%mod))%mod;}
ll sub(ll a,ll b){return ((a%mod)-(b%mod))%mod;}
ll power(ll a,ll b){
	ll res = 1;
	while(b){
		if(b&1)res = mul(res,a);
		b >>= 1;
		a = mul(a,a);
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	vii A(N);
	forn(i,0,N){
		ll a,b; cin >> a >> b;
		ll sum = a+b;
		A[i].fi = sum;
		A[i].se = a;
	}
	sort(all(A),[&](ii a,ii b){
		ll s1 = a.fi+a.se;
		ll s2 = b.fi+b.se;
		return s1 < s2;
	});
	ll tot = 0;
	forn(i,0,N)tot += A[i].se;
	int res = 0;
	ll act = 0;
	forr(i,N-1,0){
		act += A[i].fi;
		tot -= A[i].se;
		if(act > tot)break;
		res++;
	}
	cout << res+1 << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 205
using namespace std;
int n,a[maxn],c[maxn][maxn],bj[maxn],tot;
void dfs(int x,int sum,int ct,int last,int num)
{
	if(sum==num)
	{
		++tot;
		cout<<endl<<ct<<" ";
		for(int i=1;i<=last;i++)if(bj[i])printf("%d ",i);
		return ;
	}
	if(x==last+1)return ;
	dfs(x+1,sum,ct,last,num);
	if(tot==2)return ;
	bj[x]=1;
	dfs(x+1,(sum+a[x])%200,ct+1,last,num);
	bj[x]=0;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		a[i]%=200;
	}
	c[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=199;j++)c[i][j]=c[i-1][j];
		for(int j=0;j<=199;j++)
		{
			c[i][j]+=c[i-1][(j-a[i]+400)%200];
			if((c[i][j]>=2&&j!=0)||(c[i][j]>=3&&j==0))
			{
				cout<<"YES";
				dfs(1,0,0,i,j);
				return 0;
			}
		}
	}
	cout<<"NO";
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007, pi = 3.1415926535;
    string s1, s2;
    char moji;

    cin >> a;
    vector<long long> v(a);
    vector<vector<long long>> dou(200);
    for(int i=0;i<a;i++)
    {
        cin >> b;
        b%=200;
        v.at(i)=b;
    }
    for(int i=1;i<pow(2,min(8LL,a));i++)
    {
      m=0;
        vector<int> bit(8,false);
        for(int j=0;j<8;j++)
        {
            long long div=pow(2,j);
            bit.at(j)=(i/div)%2;
            if(bit.at(j))
            {
                m+=v.at(j);
            }
        }
        m%=200;
        if(dou.at(m).size())
        {
            cout << "YES" << endl;
            cout << dou.at(m).size() << ' ';
            for(auto x:dou.at(m))
            cout << x+1 << ' ';
            cout << endl;
            cout << count(bit.begin(),bit.end(),true) << ' ';
            for(int j=0;j<8;j++)
            {
                if(bit.at(j))
                {
                    cout << j+1 << ' ';
                }
            }
            cout << endl;
            return 0;
        }
        else
        {
            for(int j=0;j<8;j++)
            {
                if(bit.at(j))
                {
                    dou.at(m).push_back(j);
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1000005;
struct node{
	int c,id,val;
}s[N];
bool cmp1(node a,node b){return a.val<b.val;}
bool cmp2(node a,node b){return a.id<b.id;}
int st[N],top;
int main(){
	int n;
	scanf("%d",&n);n<<=1;
	for(int i=1;i<=n;i++) scanf("%d",&s[i].val),s[i].c=0,s[i].id=i;
	sort(s+1,s+n+1,cmp1);
	for(int i=n/2+1;i<=n;i++) s[i].c=1;
	sort(s+1,s+n+1,cmp2);
	int nl=-1;
	for(int i=1;i<=n;i++){
		if(nl==-1) nl=s[i].c,putchar('('),st[++top]=s[i].id;
		else if(s[i].c==nl) putchar('('),st[++top]=s[i].id;
		else putchar(')'),st[top--]=0;
		if(!top) nl=-1;
	}
	putchar('\n');
}

//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define ld double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp tuple<LL,LL,LL>
#define setl pair<LL,LL>
#define micro 0.000001

using namespace std;

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

#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#else
#define AT
#define AE
#define ce(t)
#endif

pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,-1}, {-1,1} , {-1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } };

const int max_v = 2e5 + 7;
const int max_k = 5e2 + 7;
const int bsz = (1ll << 10) + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
LL mod = 998244353;
template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; };

int main()
{
#ifdef OHSOLUTION
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; ci(n);

	vector<LL> va(n);
	vector<LL> vb(n);

	fa(i, 0, n) ci(va[i]);
	fa(i, 0, n) ci(vb[i]);

	unordered_map<LL, vector<int>> xh;
	fd(i, n-1, -1) va[i] += i,xh[va[i]].push_back(i);

	LL d = 0;
	LL ans = 0;
	vector<LL> arr(n+1);

	auto upd = [&](int i)
	{
		++i;
		for (; i<=n; i += i & -i) ++arr[i];
	};

	auto qur = [&](int i)
	{
		++i;
		LL ret = 0;
		for (; i; i -= i & -i)ret += arr[i];
		return ret;
	};

	fa(i, 0, n)
	{
		if (xh[vb[i] + d].empty())
		{
			co(-1);
			return 0;
		}

		int t = xh[vb[i] + d].back();

		xh[vb[i] + d].pop_back();

		ans += t - qur(t);
		upd(t);
		++d;
	}

	co(ans);

	return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    vector<pair<ll,ll>> v;
    ll a_value =0;
    rep(i,n){
        cin >> a[i] >> b[i];
        a_value+=a[i];
        v.push_back({ 2*a[i]+b[i],a[i]});
    }
    sort(v.begin(),v.end());

    int vsize = v.size();

    ll b_value = 0;
    ll count =0;
    for(int i=vsize-1;i>=0;i--){
        a_value-=v[i].second;
        b_value+=v[i].first-v[i].second;
        count ++;
        if(b_value > a_value){
            break;
        }
    }

    cout << count << endl;

    /*
    for (auto V : v) {
        cout << V.first << " " << V.second << endl;

    }*/
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}

#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(begin(container)), (end(container))

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif

constexpr ll mod = 998244353;

int main()
{
	inp(ll, a, b, c);

	ll sa = a * (a + 1) / 2 % mod;
	ll sb = b * (b + 1) / 2 % mod;
	ll sc = c * (c + 1) / 2 % mod;
	ll sbc = sb * sc % mod;
	ll sabc = sa * sbc % mod;

	otp(sabc);

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <limits.h>
#include <limits>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sstream>
using namespace std;
const int N = 1e6 + 10;
const int M = 1e4 + 5;
int siz = 0;
long long n;
long long arr[N];
int sol[M];
bool res[N];
int freq[10];
int cnt[N];

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	double a, b, m=100, am;
	cin >> a >> b;
	if (a == 0 || b == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	am = m / a;
	cout << b / am << endl;
	return 0;
}

// omae wa mou shindeiru

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

#define ff              first
#define ss              second
#define float           double
#define ll              long long
#define int             long long
#define pb              push_back
#define ppb             pop_back
#define pf              push_front
#define ppf             pop_front
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define uniq(v)         (v).erase(unique(all(v)),(v).end())
#define endl            "\n"

#define pii             pair<int,int>
#define pll             pair<ll, ll>
#define vi              vector<int>
#define vl              vector<ll>
#define vpii            vector<pii>
#define vpll            vector<pll>
#define vvi             vector<vi>
#define vvl             vector<vl>

#define rep(i,a,b)      for(int i=a;i<b;i++)
#define tr(it, l)       for(auto it = l.begin(); it != l.end(); it++)
#define max(a, b)       ((a < b) ? b : a)
#define min(a, b)       ((a > b) ? b : a)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mem1(a)         memset(a,-1,sizeof(a))
#define mem0(a)         memset(a,0,sizeof(a))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)

#define PI              3.1415926535897932384626433832795
#define eps             1e-9
#define mod             1000000007
#define inf             1e18

mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;}
template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;}
template<typename T>
using pbds = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;

void runtime()
{
    float a,b;
    cin >> a >> b;
    float ans = (a*b)/100;
    cout << ps(ans,8);
}

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

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

    int TESTS = 1; // one input
    // cin >> TESTS;
    while (TESTS--) {
        runtime();
        cout << "\n";
    }
    return 0;
}


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

#define LL long long
int n, x[20], y[20], z[20]; LL dp[(1<<17)+1][20];

int dis(int i, int j) {return abs(x[i]-x[j]) + abs(y[i]-y[j]) + max(0, z[j]-z[i]);}

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

    cin >> n;
    for(int i = 0; i <= (1<<17); i++) for(auto &j : dp[i]) j = 1e9;
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i];
    dp[0][0] = 0;

    for(int i = 1; i < (1 << n); i++)
        for(int j = 0; j < n; j++)
            if((i >> j) & 1)
                for(int k = 0; k < n; k++)
                    dp[i][j] = min(dp[i][j], dp[i - (1<<j)][k] + dis(k, j));
    cout << dp[(1<<n)-1][0];
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

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

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

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
ll dp[19][1<<18];
vector<pair<int,int> > q[20];
int main(){
    int n,m;
    cin >> n >> m;

    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        x--;y--;
        q[x].push_back(MP(y,z));
    }
    dp[0][0] = 1;
    rep(i,n){
        rep(j,1<<n){
            rep(k,n){
                if((j>>k)&1){

                }else{
                    dp[i+1][j^(1<<k)] += dp[i][j];
                }
            }
        }
        for(auto x:q[i]){
            int mask = (1<<(x.first+1)) - 1;
            rep(j,1<<n){
                if(__builtin_popcount(mask & j) > x.second){
                    dp[i+1][j] = 0;
                }
            }
        }
    }
    cout << dp[n][(1<<n)-1] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[4];
    for(int i=0;i<4;i++)
    cin>>a[i];

sort(a, a + 4);

  if (a[0] + a[3] == a[1] + a[2] || a[0] + a[1] + a[2] == a[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}

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

int main(){
    int v,t,s,d;
    cin >> v >> t >> s >> d;
    cout << ((d < v * t || d > v * s)?"Yes":"No");
}


#line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;

// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

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

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

vector< int > calc(int n, vector< int > ps) {
  vector< int > res;
  for (auto &p : ps) {
    p--;
  }

  // v : 0-indexed
  auto find_idx = [&](int v) {
    range(i, 0, n) {
      if (ps[i] == v) return i;
    }
    return -1ll;
  };

  int k = 0;

  auto swap_check = [&](int i) {
    return ((i & 1) == (k & 1));
  };

  auto swap_query = [&](int i) {
    // if ((i + k) % 2 != 0) return;
    swap(ps[i], ps[i + 1]);
    k++;
    res.emplace_back(i + 1);
  };

  rrange(v, 0, n) {
    int idx = find_idx(v);
    if (idx == v) continue;

    while (not swap_check(idx)) {
      if (idx == (k&1) + 1) idx--;
      swap_query(k & 1);
    }

    range(i, idx, v) {
      swap_query(i);
    }
  }

  if (ps[n-2] != n-2) {
    swap_query(n-2);
  }

  return res;
}

void solve() {
  int t = input();
  while (t--) {
    int n = input();
    vector< int > ps(n);
    cin >> ps;
    auto as = calc(n, ps);
    cout << as.size() << endl;
    cout << as << endl;
  }
}

signed main() {
  solve();
}

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

typedef unsigned long long ull;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;

#define pb push_back
#define pi 3.1415

const lli MOD= 1e9+7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n;cin>>n;
    vi A(n),B(n);
    for(auto &a:A)
        cin>>a;

    for(auto &b:B)
        cin>>b;

    cout<<max(0,*min_element(B.begin(),B.end())-*max_element(A.begin(),A.end())+1)<<"\n";
    return 0;
}


#include <iostream>
using namespace std;
#include <vector>
#include <set>
#include<string>
#include <algorithm>
#include <cmath>
#include <climits>
typedef long long ll;
typedef unsigned long long ull;

//AtCoder Begginer Contest 201 C
int main(void)
{
	int n;
	cin >> n;

	vector<ll> a(n);

	for (auto& x : a)
	{
		cin >> x;
	}

	ll min = LONG_MAX -1 ;

	ll max_i = (1 << (n - 1) ) - 1; //2の(n-1)乗-1

	for (ll i = 0; i <= max_i; i++)
	{
		vector<bool> s(n - 1);
		int count_s = 0; //仕切りの数

		for (int j = 0; j < n - 1; j++)
		{
			s[j] = (i >> j) & 1;
			count_s += s[j];
		}

		ll xorall = 0;
		ll or_tmp = 0;
		for (int j = 0; j < n; j++)
		{
			or_tmp |= a[j];

			bool bRun_xor = false;
			if (j < n - 1)
			{
				if (true == s[j])
				{
					bRun_xor = true;
				}
			}
			else
			{
				bRun_xor = true;
			}

			if (true == bRun_xor)
			{
				xorall ^= or_tmp;
				or_tmp = 0;
			}

		}

		min = std::min(xorall, min);

	}

	cout << min;

	return 0;
}

#include <bits/stdc++.h>
typedef long long LL;
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define RALL(X) (X).rbegin(), (X).rend()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRVI(N, X) VI X(N); for (int ___I=0; ___I<N; ___I++) scanf("%d", &(X[___I]))
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    string t;
    cin>>s>>t;
    VI a;
    VI b;
    REP(i,n){
        if (s[i]=='1') a.PB(i);
        if (t[i]=='1') b.PB(i);
    }
    int st=SZ(b);
    int ss=SZ(a);
    bool isok=true;
    int i=0;
    int j=0;
    LL ops=0;
    if (st>ss or st%2!=ss%2) isok=false;
    //cout<<isok<<endl;
    while (i<ss and j<st){
        //cout<<i<<" "<<j<<" "<<a[i]<<" "<<b[j]<<endl;
        if (b[j]>a[i]){
            if (i==ss-1) {isok=false; break;}
            else ops+=a[i+1]-a[i];
            i+=2;
        }
        else{
            ops+=a[i]-b[j];
            i++; j++;
        }
    }
    //cout<<isok<<endl;
    if (j<st) {isok=false;}
    while (i<ss){
        if (i==ss-1) {isok=false; break;}
        else ops+=a[i+1]-a[i];
        i+=2;
    }

    if (isok) cout<<ops<<"\n";
    else cout<<"-1\n";
}


//   g++ cpp.cpp && ./a.out

#define mod 1000000007

#include<iostream>
#include<vector>

using namespace std;

typedef long long ll;

int main(){

	int n;

	cin >> n;

	int max = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
		if (a[i] > max)
			max = a[i];
	}

	int ans;
	int cmax = 0;
	for (int i = 2; i <= max; i++)
	{
		int c = 0;
		for (int j = 0; j < n; j++)
		{
			if(a[j]%i==0)
				c++;
		}
		if(c>cmax){
			cmax = c;
			ans = i;
		}
	}

	cout << ans << endl;

	return 0;

}

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

signed  main(){
	int N, i, ans = 0;
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		int A;
		scanf("%d", &A);
		ans += max(A - 10, 0);
	}
	printf("%d\n", ans);
	return 0;
}


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

long long int mod = 1000000007;

void solve(){

	int n;
	cin>>n;
	string s;
	cin>>s;
	int l=0;
	string a,b;
	a = s.substr(0,n);
	b = s.substr(n,n);

	int q;
	cin>>q;

	while(q--){
		int t,x,y;
		cin>>t>>x>>y;
		x--;
		y--;
		if(t==1){
			if(l==0){
				char t;
				if(x<n) t = a[x];
				else t = b[x-n];

				if(x<n) if(y<n) a[x]=a[y]; else a[x]=b[y-n];
				else if(y<n) b[x-n]=a[y]; else b[x-n]=b[y-n];

				if(y<n) a[y]=t;
				else b[y-n]=t;
			}
			if(l==1){
				char t;
				if(x<n) t = b[x];
				else t = a[x-n];

				if(x<n) if(y<n) b[x]=b[y]; else b[x]=a[y-n];
				else if(y<n) a[x-n]=b[y]; else a[x-n]=a[y-n];

				if(y<n) b[y]=t;
				else a[y-n]=t;
			}
		}

		if(t==2) l = 1-l;
	}

	if(l==0) cout<<a<<b<<endl;
	else cout<<b<<a<<endl;

	return;
}

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

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

	for(long long int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}

    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "talltree"
#define pll pair<ll, ll>
#define pii pair<pll, pll>
#define fi first
#define se second
#define ull unsigned long long

using namespace std;
const ll mod = 1e9+7;
const ll N = 2e5+5;

ll n, m, t, ans, k, a[N], b[N], tong,  cnt, q, c[N];
pll d[N][62];
vector<pll> adj[N];

string s[N];
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
void dfs(ll u, ll p)
{
    for(int i = 0; i < 60; i ++)d[u][i].se = 1;
    for(pll v : adj[u])
    {
        if(v.se == p)continue;
        dfs(v.se, u);
        for(int i = 0; i < 60; i ++)
        {
            if((v.fi >> i) & 1)swap(d[v.se][i].fi, d[v.se][i].se);
            ans = (ans + pw(2, i) * ((d[v.se][i].fi * d[u][i].se % mod + d[u][i].fi * d[v.se][i].se % mod) % mod ) % mod) % mod;
            d[u][i].fi += d[v.se][i].fi;
            d[u][i].se += d[v.se][i].se;
        }
    }
}
void sol()
{
    cin >> n;
    for(int i = 1; i < n; i ++)
    {
        ll x, y, w;
        cin >> x >> y >> w;
        adj[x].pb({w, y});
        adj[y].pb({w, x});
    }
    dfs(1, 0);
    cout << ans;
}
int main()
{
    if(fopen(task".inp", "r")){
       freopen(task".inp", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
3 5
1 2 3 3 1
4 3 2 5 3
2 6 6 2 5
1 2 2 2
2 1 3 3
3 2 3 3
3 5 1 3
*/


// #include<iostream>
// #include<bits/stdc++.h>
// #include<vector>
// #include<algorithm>
// #include<string>
// #include<cmath>
// #include<iomanip>
// #include<numeric>
// #include<set>
// // #include<pair>
// #include<cctype>

/**** BE SPECIFIC WITH YOUR GOAL ******/
/**** TRY TO DRY RUN YOUR CODE AS YOU CAN ****/

#include<bits/stdc++.h>
#include<iostream>

using namespace std;

#define rep(i,a,b) for(int i=a; i<b; i++)
#define repp(i,a,b) for(int i=a; i>=b; i--)

#define ll long long

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define vi vector<ll>
#define vpi vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define setpre cout<<fixed<<setprecision(10)
#define sumv(a) accumulate(all(a),0)
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979

const int N = 1000005;
ll modd = 998244353;
vector<bool> isprime(N);
vector<int> primes;
void seive(){
    isprime[0]=false;
    isprime[1]=false;
    for(int i=2; i<=1e6; i++){
        isprime[i] = true;
    }
    for(int i=2; i*i<=1e6; i++){
        if(isprime[i]){
            for(int j=i*i; j<=1e6; j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2; i<1e6; i++){
        if(isprime[i]){
            primes.pb(i);
        }
    }
}
/*** START YOUR CODE USING ABOVE SHORTS ***/

vector<ll> v[25];
ll vis[25];
ll lvl[25];
ll col[25];
ll dfs(ll ind){
    ll ret = 1;
    vis[ind] = 0;
    for(ll x:v[ind]){
        if(lvl[x] != 0 && lvl[x] != lvl[ind]+1){
            if(col[x] == col[ind]){
                ret = 0;
            }
            continue;
        }
        lvl[x] = lvl[ind]+1;
        ll temp = 0;
        rep(i,1,4){
            if(i == col[ind]) continue;
            col[x] = i;
            temp += dfs(x);
            col[x] = 0;
        }
        ret *= temp;
    }
    return ret;
}
void Reverse_Matrix(){
    ll n,m; cin>>n>>m;
    // cout<<n<<" "<<m<<endl;
    rep(i,0,n+1){
        vis[i] = 1;
        lvl[i] = 0;
        col[i] = 0;
    }
    rep(i,0,m){
        int x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    ll ans = 1;
    rep(i,1,n+1){
        if(vis[i]){
            lvl[i] = 1;
            col[i] = 1;
            ans *= 3 * dfs(i);
            // cout<<i<<" ";
        }
        // cout<<endl;
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // seive();
    int TEST = 1;

    // cin>>TEST;

    while(TEST--){
        Reverse_Matrix();
    }
}

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

// @author: sharad_sharma

#define ll                long long
#define ld                long double
#define mod               1000000007
#define inf               1e18
#define pb                push_back
#define all(n)            n.begin(),n.end()
#define loop(i,a,b)       for(int i=(a);i<=(b);i++)
#define logarr(arr)       for(int z=(0);z<(arr.size());z++) cout<<(arr[z])<<" ";cout<<endl;
#define deb(x)            cout << #x << " = " << x << endl
#define debu(x, y)        cout << "( " << #x << ", " << #y << " ) = ( " << x << ", " << y << " )" << endl

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

int N = 25;
vector<vector<int>> adj(N);
vector<int> visited(N, 0);
vector<int> col(N, 0);
vector<int> level(N, 0);

// i want to search exhaustively
int dfs(int i, int p) {
	//if(visited[i]) return 1;
	level[i] = level[p] + 1;
	visited[i] = 1;
	int ret = 1;

	for(auto u: adj[i]) {
		//if(u == p) continue;	// this is not enough if their level is same then it must return 0
		if(level[u] != 0 && level[u] != level[i] + 1) {
			if(col[u] == col[i]) {
				// this should not be allowed
				return 0;
			}
			continue;
		}

		int tem = 0;
		for(int c=1; c<4; c++) {
			if(col[i] == c) continue;
			col[u] = c;
			tem += dfs(u, i);
			col[u] = 0;
		}
		ret *= tem;
	}
	return ret;
}

int32_t main(int32_t argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();

	// Write your code here....
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	int ans = 1LL;

	for(int i=0; i<n; i++) {
		if(visited[i]) continue;
		// let's say we colour Red on i so, it's edges is either blue or green
		col[i] = 1;	// let's say Red is 1
		level[i] = 0;
		int dd = dfs(i, i);
		ans = ans*3LL*dd;
	}
	cout << ans << "\n";

	#ifndef ONLINE_JUDGE
	  clock_t end = clock();
	  cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
	#endif
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define pf push_front

using namespace std;
typedef long long int lli;
lli n,k,m,t,a,b,l,r,h,u,temp1,temp2,x,y,temp,q,d,mod=1e9+7,w,p,c,z;

lli MOD =998244353;

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

    cin>>a>>b>>c;

    lli sigA = (((a%MOD)*((a+1)%MOD))/2)%MOD;
    lli sigB = (((b%MOD)*((b+1)%MOD))/2)%MOD;
    lli sigC = (((c%MOD)*((c+1)%MOD))/2)%MOD;

    lli ans = ((sigA%MOD * sigB%MOD)%MOD * sigC%MOD)%MOD;

    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll>   vl;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define fr(i,n) for(i=n-1;i>=0;i--)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
const double pi=3.141592653;
const ll infi=1000000001;
const ll MOD=1000000007;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";

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

// void dfs(vl v[],ll node,ll hai[]){
//     hai[node]=1;
//     for(auto i:v[node]){
//         if(hai[i]==0){
//             dfs(v,i,hai);
//         }
//     }
// }

// ll con(vl v[],ll hai[],ll sz){
//     ll count=0;
//     for(int i=1;i<sz;i++){
//         if(hai[i]==0){
//             count++;
//             dfs(v,i,hai);
//         }
//     }
    // return count;
// }

// void gcde(int a,int b,int *x,int *y){
//     if(a==0){
//         *x=0;
//         *y=1;
//         return;
//     }
//     int x1,y1;
//     gcde(b%a,a,&x1,&y1);

//     *x=y1-(b/a)*x1;
//     *y=x1;
// }

// ll recur(vl v,ll in,ll m,ll n){
//     if(in==-1)  return 1000000000001;
//     ll d,e,c;
//     d=max(m/v[in],n*v[in]);
//     c=recur(v,in-1,m/v[in],n*v[in]);
//     e=recur(v,in-1,m,n);
//     return min(c,min(e,d));
// }

// ll bexpo(ll a,ll p){
//     ll x=1;
//     while(p){
//     if(p&1){
//         x=(x*a)%mod;
//     }
//     a=(a*a)%mod;
//     p>>=1;
//     }
//     return x;
// }
// int dx[8]{-1,0,0,1,-1,-1,1,1};
// int dy[8]{0,-1,1,0,-1,1,-1,1};

int main() {
    fastio
    int t=1;
    // cin>>t;
    ll n,m,i,l,d,bank,s,k,j,x,y,ans,q;

    while(t--){ans=0;
        ll a,b,c;
        cin>>a>>b>>c;
        // ll a[n];
        // f(i,n)  cin>>a[i];
        x=(a*(a+1))/2;
        x%=mod;
        a=b;
        y=(a*(a+1))/2;
        y%=mod;
        a=c;
        s=(a*(a+1))/2;
        s%=mod;
        ans=(((x*y)%mod)*s)%mod;

        cout<<ans<<endl;
    }

	return 0;
}


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

char standard[3]={'1','1','0'};
const ll N=1e10,M=2e5+100;
int n,t;
string s;
char a[M];

bool check(){
	int pos1=a[1],pos2=a[2];
	if(pos1=='1'){
		if(pos2=='1'){
			for(rei i=3;i<=n;++i)
			    if(a[i]!=standard[(i-1)%3]) return false;
		}
		if(pos2=='0'){
			for(rei i=3;i<=n;++i)
			    if(a[i]!=standard[(i)%3]) return false;
		}
	}
	if(pos1=='0'){
		if(pos2=='1'){
			for(rei i=3;i<=n;++i)
			    if(a[i]!=standard[(i-2)%3]) return false;
		}
		if(pos2=='0'){
			return false;
		}
	}
	return true;
}

int main(){
	cin>>n;
	int pos;
	getchar();
	for(rei i=1;i<=n;++i){
	    a[i]=getchar();
	}
	if(!check()){
		cout<<0<<endl;
		return 0;
	}
	if(n==1){
		if(a[1]=='1')
			cout<<N*2<<endl;
		else
		    cout<<N<<endl;
		return 0;
	}
	if(n==2){
		if(a[1]=='0') cout<<N-1<<endl;
		else cout<<N<<endl;
		return 0;
	}
	if(!(n%3)){
		if(a[1]=='1'&&a[2]=='1'&&a[3]=='0')
		    cout<<N-n/3+1<<endl;
		else
		    cout<<N-n/3<<endl;
		return 0;
	}
	if((n%3)==1){
		cout<<N-n/3<<endl;
		return 0;
	}
	if(a[1]=='0')
		cout<<N-n/3-1<<endl;
	else
	    cout<<N-n/3<<endl;
	return 0;
}

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

signed main() {
  int n;
  string s = "110";
  string t;
  cin >> n >> t;

  int ans = 1e10;
  if (t == "1") {
    cout << ans * 2 << '\n';
    return 0;
  } else if (t == "11" || t == "10") {
    cout << ans << '\n';
    return 0;
  }

  int m = 3;
  int cnt = 1;
  int need = n+2;
  while(m < need) {
    m+=3;
    s += "110";
    cnt++;
  }

  int mod = -1;
  for (int i = 0; i <= 2; i++) {
    if (s.substr(i,n) == t) mod = i;
  }
  if (mod == -1) {
    cout << 0 << '\n';
    return 0;
  }

  if (mod == 0) {
    ans = ans - cnt + 2;
  } else {
    ans = ans - cnt + 1;
  }
  cout << ans << '\n';
}


#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<>()で降順
#include <map>

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;
using ll = long long int;

int main(){
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> c(n);
    rep(i,n) c[i] = i + 1;
    sort(ALL(a));
    sort(ALL(c));
    if(a==c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

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

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

	int ans = -1;
	for(int left = 0; left < n; ++left) {
		int min_app = vec[left];
		for(int right = left; right < n; ++right) {
			min_app = min(min_app, vec[right]);
			ans = max((right - left + 1) * min_app, ans);
		}
	}

	cout << ans << "\n";

}


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

void f(const int& a,const int& b) {

	if (a>b) {
		cout << ">";
	}
	else if(a<b){
		cout << "<";
	}
	else {
		cout << "=";
	}

}

int main(void) {
	int A,B,C;
	cin >> A >> B >> C;
	C = C % 2;

	if (A < 0) {  //A-
		if (B < 0) { //B-
			if (C == 0) {
				f(A*(-1),B * (-1));
			}
			else {
				f(A, B);
			}
		}
		else { //B+
			if (C == 0) {
				f(A * (-1), B);
			}
			else {
				f(A, B);
			}
		}
	}
	else { //A+
		if (B < 0) { //B-
			if (C == 0) {
				f(A , B * (-1));
			}
			else {
				f(A, B);
			}

		}
		else { //B+
			f(A, B);
		}

	}

	return 0;
}

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

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

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

/*-----------------------------------------------------------*/
char getChar(int a,int b){
	if(a==b) return '=';
	if(a<b) return '<';
	if(a>b) return '>';
	return '$';
}

char solve(){
	int a,b,c;
	cin>>a>>b>>c;
	if(c%2==0) return getChar(abs(a),abs(b));
	else return getChar(a,b);
}

int32_t main(){
	IOS

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

	while(t--)
	cout<<solve()<<endl;

	return 0;
}