//wtrl,everybody hangbeat me
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,int> mpci;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))
#define INF 1e9
#define PI acos(-1)

/*=====================================================================*/

string int_to_string(ll n)
{
	string s="";
	while(n)
	{
		ll now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
ll string_to_int(string s)
{
	ll n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
string turn(int n,int k)
{
	string s="";
	while(n)
	{
		s+=(char)(n%k+'0');
		n/=k;
	}
	reverse(s.begin(),s.end());
	return s;
}
const string turn16(int n)
{
	string s="";
	while(n!=0)
	{
		if(n%16>9)
		  s+=(char)('A'+n%16-10);
		else
		  s+=(char)('0'+n%16);
		n/=16;
	}
	reverse(s.begin(),s.end());
	return s;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
/*======================================================================*/
int main()
{
    std::ios::sync_with_stdio(false);
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  int n;
  cin>>n;
  cout<<(1<<n)-1<<endl;
  forn(i,1,(1<<n)-1)
  {
    forn(j,1,(1<<n))
	{
            cout<<(__builtin_popcount(i&j)&1?'A':'B');
    }
    cout<<endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;

//---整数pow  x^y----
ll powll(ll x, ll y){
  assert(y>=0);
  ll res = 1;
  while(y){
    if(y&1) res *= x;
    x *= x;
    y >>= 1;
  }
  return res;
}

//------------------------------------------------
struct Solver{
    int N,s;
    vvec(int) ans;

    void f(vec(int) a){
        ans.push_back(a);
        if(a[0]!=a[1]) return;

        vec(int) b1(s),b2(s);
        rep(i,s/2){
            b1[i] = a[i*2];
            b2[i] = a[i*2];
        }
        rep(i,s/2){
            b1[s/2+i] = a[i*2];
            b2[s/2+i] = -a[i*2];
        }

        f(b1);
        f(b2);
        return;
    }

    void solve(){
        cin >> N;
        s = powll(2,N);

        vec(int) a0(s,-1);
        rep(i,s/2) a0[i]=1;
        //ans.push_back(a0);
        f(a0);

        int K = ans.size();
        cout << K << endl;
        rep(ki,K){
            rep(i,s-1){
                if(ans[ki][i]==1) cout << "A";
                else cout << "B";
            }
            if(ans[ki][s-1]==1) cout << "A" << endl;
            else cout << "B" << endl;
        }
    }
};

int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define pii pair<int,int>
#define eps 1e-7
#define equals(a,b) (fabs(a - b) < eps)
#define fi first
#define se second
using namespace std;
typedef long long ll;

const int maxn = 1e6 + 5;
const ll MOD = 1e9 + 7;

ll rd(){
	ll x = 0;
	int f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		if(ch == '-')  f = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

struct PSegmentTree{
	struct Node{
		int l,r,d;
		Node *ls,*rs;
	};
	int a[maxn];
	Node pool[maxn * 30],*rt[maxn];
	int top;
	Node* build(int l,int r){
		Node *p = pool + (++top);
		p -> l = l,p -> r = r;
		if(l == r) {
			p -> d = a[l];
			return p;
		}
		int mid = l + r >> 1;
		p -> ls = build(l,mid);
		p -> rs = build(mid + 1,r);
		return p;
	}
	Node* copyNode(Node* rt){
		Node* p = pool + (++top);
		pool[top] = *rt;
		return p;
	}
	Node* change(Node* rt,int id,int x){
		Node* p = copyNode(rt);
		if(p -> l == p -> r) {
			p -> d = x;
			return p;
		}
		int mid = p -> l + p -> r >> 1;
		if(id <= mid) p -> ls = change(p -> ls,id,x);
		else p -> rs = change(p -> rs,id,x);
		return p;
	}
	int query(Node* rt,int id){
		if(rt -> l == rt -> r) {
			return rt -> d;
		}
		int mid = rt -> l + rt -> r >> 1;
		if(id <= mid) return query(rt -> ls,id);
		else return query(rt -> rs,id);
	}
};

struct Edge{
	int to;
	ll t,k;
};

int main(){
	int n = rd();
	int m = rd();
	int x = rd();
	int y = rd();
	x--;
	y--;
	vector<vector<Edge>> e(n);
	while(m--){
		int a = rd();
		int b = rd();
		int c = rd();
		int d = rd();
		a--;
		b--;
		e[a].push_back({b,c,d});
		e[b].push_back({a,c,d});
	}

	vector<ll> dis(n,1e18);
	dis[x] = 0;
	priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
	q.emplace(0,x);
	while(!q.empty()){
		ll d = q.top().fi;
		int u = q.top().se;
		q.pop();
		if(dis[u] != d) continue;
		for(auto v:e[u]) {
			ll tmp = ((d + v.k - 1) / v.k) * v.k + v.t;
			if(tmp < dis[v.to]) {
				dis[v.to] = tmp;
				q.emplace(tmp,v.to);
			}
		}
	}
	if(dis[y] == 1e18) cout << -1 << '\n';
	else cout << dis[y];
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define p_q priority_queue
#define m_p make_pair
#define pb push_back
#define ld long double
#define F first
#define S second
#define ull unsigned long long
#define mod 1000000007
#define md 998244353
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define int ll
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll qpow(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string iots(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int stoi(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n;
int val[100100];
vector<int>sons[100100];
int sz[100100];
void dfs(int u)
{
	val[u]=1;
	sz[u]=1;
	rep(i,sons[u].size())
	{
		dfs(sons[u][i]);
		sz[u]+=sz[sons[u][i]];
	}
	int sum=0;
	vector<int>vv;
	vv.clear();
	rep(i,sons[u].size())
	{
		int v=sons[u][i];
		if(sz[v]%2==0)
		{
			if(val[v]<0)
			{
				val[u]+=val[v];
			}
			else
			{
				sum+=val[v];
			}
		}
		else vv.pb(val[v]);
	}
	sort(vv.begin(),vv.end());
	if(vv.size()%2==0)
	{
		val[u]+=sum;
	}
	else
	{
		val[u]-=sum;
	}
	rep(i,vv.size())
	{
		if(i%2==0)
		{
			val[u]+=vv[i];
		}
		else
		{
			val[u]-=vv[i];
		}
	}
}
signed main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n-1)
	{
		int fa;
		cin>>fa;
		fa--;
		int u=i+1;
		sons[fa].pb(u);
	}
	dfs(0);
	cout<<(val[0]+n)/2<<endl;
	return 0;
}


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

#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 105;
int n;
pair<double,double> a[N];
pii dsu[N];
double dis[N][N];

int find(int x)
{
    if(dsu[x].F == x) return x;
    return dsu[x].F = find(dsu[x].F);
}

void merge(int x,int y)
{
    int p = find(x);
    int q = find(y);

    if(p == q) return;

    if(dsu[p].S > dsu[q].S) swap(p,q);

    dsu[q].S+=dsu[p].S;
    dsu[p].F = dsu[q].F;
}

//n is upper
//n+1 is lower

bool check(double r)
{
    f(i,n+2) dsu[i] = {i,1};

    f(i,n) f(j,n)
        if(dis[i][j] <= r ) merge(i,j);

    f(i,n) if(100 - a[i].S <= r) merge(i,n);
    f(i,n) if(a[i].S + 100 <= r) merge(i,n+1);

    return find(n) != find(n+1);
}

signed main()
{
    fast;

   cin >> n;

   f(i,n) cin >> a[i].F >> a[i].S;

   vector<double> go;

   f(i,n) f(j,n) dis[i][j] = sqrt(
     (a[i].F - a[j].F)*(a[i].F - a[j].F ) + (a[i].S - a[j].S)*(a[i].S - a[j].S));

   f(i,n) f(j,n) go.pb(dis[i][j]);
   f(i,n) go.pb((100 - a[i].S));
   f(i,n) go.pb((a[i].S + 100));

   double res = 0;

   for(auto x : go)
       if(check(x - 1e-9)) res = max(res,x);

   cout << fixed << setprecision(4) << res/2;
}

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=1e5+5;
int n,m,tp[N],a[N],b[N];
long long ans;

void GG(){
	write(-1);
	exit(0);
}

signed main(){
	read(n,m);
	for(int i=1;i<=n;i++) read(tp[i]),a[i]=tp[i]-tp[i-1]-1;a[n+1]=m-tp[n];
	for(int i=1;i<=n;i++) read(tp[i]),b[i]=tp[i]-tp[i-1]-1;b[n+1]=m-tp[n];n++;
	for(int i=1,j=1;i<=n;i++) if(b[i]){
		while(!a[j]) j++;
		int cur=0,l=j;
		while(j<=n&&cur<b[i]) cur+=a[j++];
		if(cur>b[i]) GG();
		ans+=max(i-l,0)+max(j-1-i,0);
	}
	write(ans);
}


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

int main() {
	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;
	vector<int>s;
	for (int i = 0; i < N; ++i) {
		if ('1' == S[i]) {
			s.push_back(i);
		}
	}
	vector<int>t;
	int tcount = 0;
	for (int i = 0; i < N; ++i) {
		if ('1' == T[i]) {
			t.push_back(i);
		}
	}
	if (t.size() % 2 != s.size() % 2) {
		cout << -1 << endl;
		return 0;
	}
	if (s.size() < t.size()) {
		cout << -1 << endl;
		return 0;
	}
	vector<int>newt;
	int j = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (j >= t.size()) {
			newt.push_back(s[i]);
			newt.push_back(s[i]);
			++i;
			continue;
		}
		if (s[i] < t[j]) {
			newt.push_back(s[i]);
			newt.push_back(s[i]);
			++i;
		}
		else {
			newt.push_back(t[j]);
			j++;
		}
	}
	if (j != t.size()) {
		cout << -1 << endl;
		return 0;
	}
	long long sumS = 0;
	for (int i = 0;i<s.size();++i) {
		sumS += s[i];
		//cout << s[i];
	}
	//cout << endl;
	long long sumT = 0;
	for (int i = 0; i <newt.size(); ++i) {
		sumT += newt[i];
		//cout << newt[i];
	}
	//cout << endl;
	cout << sumS - sumT << endl;
	return 0;
}

#include<bits/stdc++.h>
typedef long long LL;
typedef double dl;
#define opt operator
#define pb push_back
const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
void Chkmin(LL &x,LL y){
	if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
	if(y>x) x=y;
}
LL add(LL x,LL y){
	return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
	return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
	return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
	LL ret(1); while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
LL n,tot1,tot2;
LL a[maxn],b[maxn];
char s[maxn],t[maxn];
int main(){
	n=Read();
	scanf(" %s",s+1); scanf(" %s",t+1);
	for(LL i=1;i<=n;++i) if(s[i]=='1') a[++tot1]=i;
	for(LL i=1;i<=n;++i) if(t[i]=='1') b[++tot2]=i;
	if(tot1<tot2){
		puts("-1");
		return 0;
	}
	LL flag(1);
	LL j(1);
	LL ans(0);
	for(LL i=1;i<=tot2;++i){
		if(j>tot1){
			flag=0; break;
		}
		if(a[j]==b[i]){
			++j;
			continue;
		}
		if(a[j]<b[i]){
			if(j==tot1){
				flag=0; break;
			}
			ans+=(a[j+1]-a[j]);
			j+=2; --i;
			continue;
		}
		if(a[j]>b[i]){
			ans+=(a[j]-b[i]); ++j;
		}
	}
	if(!flag){
		puts("-1"); return 0;
	}
	if(j>tot1){
	    printf("%lld\n",ans); return 0;
    }
    if((tot1-j+1)&1){
    	puts("-1"); return 0;
	}
	for(LL i=j;i<=tot1;i+=2){
		ans+=(a[i+1]-a[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


#include <math.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
#define mod
using ll = long long;
using P = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
const ll INF = 1e18 + 1;
int main()
{
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 0, 10000)
  {
    string t = to_string(i);
    while (t.size() < 4)
      t.insert(t.begin(), '0');
    V<bool> used(10, false);
    bool j = true;
    rep(k, 0, 4)
    {
      if (s[t[k] - '0'] == 'x')
      {
        j = false;
        break;
      }
      used[t[k] - '0'] = true;
    }
    rep(k, 0, 10) if (s[k] == 'o') if (!used[k]) j = false;
    if (j)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

#include <stack>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <unordered_map>
/*#define cin(a) scanf("%d",&a)
#define llcin(a) scanf("%lld",&a)
#define fcin(a) scanf("%lf",&a)
#define cout(a) printf("%d",a)
#define cout_n(a) printf("%d\n",a)
#define cout_d(a) printf("%d ",a)
#define f2cout(a) printf("%.2f",a)
#define f2cout_n(a) printf("%.2f\n",a)
#define f2cout_d(a) printf("%.2f ",a)
#define llcout(a) printf("%lld",a)
#define llcout_n(a) printf("%lld\n",a)
#define llcout_d(a) printf("%lld ",a)*/
using namespace std;
typedef long long ll;
ll cnt;
int n;
string s[100];
int main()
{
    scanf("%d", &n);
    getchar();
    for (int i = 1; i <= n; i++)
        cin >> s[i];
    ll dpTrue[100], dpFalse[100];
    memset(dpTrue, 0, sizeof(dpTrue));
    memset(dpFalse, 0, sizeof(dpFalse));
    dpTrue[0] = dpFalse[0] = 1;
    for (int i = 1; i <= n;i++)
    {
        if(s[i]=="AND")
            dpTrue[i] = dpTrue[i - 1], dpFalse[i] = dpFalse[i - 1] * 2 + dpTrue[i - 1];
        else
            dpTrue[i] = dpTrue[i - 1] * 2 + dpFalse[i - 1], dpFalse[i] = dpFalse[i - 1];
    }
    cout << dpTrue[n];
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define f first
#define s second
void find(int N,vector<int>& a)
{
    int n=(N<<1);
    vector<bool> vis(n,1);
    vector<pi> val(n);
    for(int i=0;i<n;i++)
    val[i]=make_pair(a[i],i);
    sort(val.begin(),val.end());
    for(int i=0;i<N;i++)
    vis[val[i].s]=0;
    int cur=0;
    string res="";
    bool f=0;
    for(int i=0;i<n;i++)
    {
        if(cur==0 or vis[i]==f)
        {
            res.push_back('(');
            f=vis[i];
            ++cur;
        }
        else
        {
            res.push_back(')');
            --cur;
        }
    }
    cout<<res;
}
int32_t main()
{
    int n;
    cin>>n;
    vector<int> a(2*n);
    for(int i=0;i<2*n;i++)
    cin>>a[i];
    find(n,a);
    return 0;
}

#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 10005
#define ENDL putchar('\n')
#define LL long long
#define DB double
#define lowbit(x) ((-x) & (x))
LL read() {
	LL f = 1,x = 0;char s = getchar();
	while(s < '0' || s > '9') {if(s=='-')f = -f;s = getchar();}
	while(s >= '0' && s <= '9') {x=x*10+(s-'0');s = getchar();}
	return f * x;
}
int n,m,i,j,s,o,k;
int b[MAXN];
int main() {
	n = read();
	int ct = 0;
	for(int i = 1;i <= 10000;i ++) {
		if(i != 6 && i != 10 && i != 15) {
			int w = 0;
			if(i % 2 == 0) w ++;
			if(i % 3 == 0) w ++;
			if(i % 5 == 0) w ++;
			if(w > 1) b[++ ct] = i;
		}
	}
	for(int i = 1;i <= n-3;i ++) {
		printf("%d ",b[i]);
	}
	printf("6 10 15\n");
	return 0;
}


// Problem:
// 			E - Magical Ornament
//
//
// Contest: AtCoder - AtCoder Beginner Contest 190
// URL: https://atcoder.jp/contests/abc190/tasks/abc190_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

const int N = 1e5+7,M = 2 * N,CK = 20,INF = 0x3f3f3f3f;
int dist[CK][N],c[CK];
int edge[M],succ[M],ver[N],idx;
int f[1 << 17][CK];
void add(int u,int v)
{
	edge[idx] = v;
	succ[idx] = ver[u];
	ver[u] = idx++;
}

void bfs(int f)
{
	memset(dist[f],0x3f,sizeof dist[f]);
	queue<int> q;q.push(c[f]);dist[f][c[f]] = 0;
	while(!q.empty())
	{
		int u = q.front();q.pop();
		for(int i = ver[u];~i;i = succ[i])
		{
			int v = edge[i];
			if(dist[f][v] > dist[f][u] + 1)
			{
				dist[f][v] = dist[f][u] + 1;
				q.push(v);
			}
		}
	}
}

int main()
{
	memset(ver,-1,sizeof ver);
	int n,m;scanf("%d%d",&n,&m);
	forn(i,1,m)
	{
		int u,v;scanf("%d%d",&u,&v);
		--u;--v;
		add(u,v),add(v,u);
	}

	int k;scanf("%d",&k);
	forn(i,0,k - 1)	scanf("%d",&c[i]),--c[i];

	forn(i,0,k - 1)	bfs(i);

	memset(f,0x3f,sizeof f);
	forn(i,0,k - 1)	f[1 << i][i] = 1;

	forn(S,1,(1 << k) - 1)
	{
		forn(j,0,k - 1)	forn(i,0,k - 1)
		{
			if(f[S][j] == INF)	continue;
			if(!(S >> j & 1) || dist[j][c[i]] == INF || (S >> i & 1))	continue;
			f[S | (1 << i)][i] = min(f[S | (1 << i)][i],f[S][j] + dist[j][c[i]]);
		}
	}
	int res = INF;
	forn(i,0,k - 1)	res = min(res,f[(1 << k) - 1][i]);
	printf("%d",res == INF ? -1 : res);
	return 0;
}

#include <cstdio>
#include <cctype>
#include <cstring>
#define rr register
using namespace std;
const int N=100011;
struct node{int y,next;}e[N<<1];
int as[N],q[N],a[18],et=1,head,ans,tail,k,dis[18][N],n,m,dp[N<<1][18],two[18];
inline signed iut(){
	rr int ans=0; rr char c=getchar();
	while (!isdigit(c)) c=getchar();
	while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
	return ans;
}
inline void add(int x,int y){
    e[++et]=(node){y,as[x]},as[x]=et;
    e[++et]=(node){x,as[y]},as[y]=et;
}
inline signed min(int a,int b){return a<b?a:b;}
inline void bfs(int z,int st){
	q[head=tail=1]=st,dis[z][st]=1;
	while (head<=tail){
		rr int x=q[head++];
		for (rr int i=as[x];i;i=e[i].next)
		if (!dis[z][e[i].y]){
			dis[z][e[i].y]=dis[z][x]+1;
			q[++tail]=e[i].y;
		}
	}
}
signed main(){
	n=iut(); m=iut();
	for (rr int i=1;i<=m;++i) add(iut(),iut());
	k=iut(),memset(dp,42,sizeof(dp)),two[0]=1,ans=dp[0][0];
	for (rr int i=0;i<k;++i) bfs(i,a[i]=iut());
	for (rr int i=1;i<=k;++i) two[i]=two[i-1]<<1;
	for (rr int i=0;i<k;++i) dp[two[i]][i]=0;
	for (rr int i=3;i<two[k];++i){
		for (rr int j0=0;j0<k;++j0)
		    for (rr int j1=0;j1<k;++j1)
		        if (j0!=j1&&(i&(two[j0]|two[j1]))&&dis[j0][a[j1]])
		            dp[i][j0]=min(dp[i][j0],dp[i^two[j0]][j1]+dis[j0][a[j1]]-2);
	}
	for (rr int i=0;i<k;++i) ans=min(ans,dp[two[k]-1][i]);
	if (ans==dp[0][0]) return !printf("-1");
	return !printf("%d",ans+k);
}


#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)

int main(){
  ll k; cin >> k;
  string s, t;
  cin >> s >> t;
  vector<ll> card(10, k);
  rep(i, 4){
    ll x = s[i]-'0';
    ll y = t[i]-'0';
    card[x]--;
    card[y]--;
  }
  ll all = k * 9 - 8;
  ll all2 = all * (all-1);
  ll sum = 0;
  rep2(i, 1, 10){
    if (card[i] == 0) continue;
    rep2(k, 1, 10){
      if (card[k] == 0) continue;
      vector<ll> tvec(10, 0), avec(10, 0);
      rep(j, 4){
        ll x = s[j]-'0';
        ll y = t[j]-'0';
        tvec[x]++;
        avec[y]++;
      }
      tvec[i]++;
      avec[k]++;
      ll tp = 0;
      ll ap = 0;
      rep2(j, 1, 10){
        tp += j * pow(10, tvec[j]);
        ap += j * pow(10, avec[j]);
      }
      if (tp > ap){
        if(i==k) sum += card[i] * (card[k]-1);
        else sum += card[i] * card[k];
      }
    }
  }
  long double ans = (long double)sum / all2;
  cout << ans << endl;

  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<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

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

ll get(string str,char c){
	map<int,int> cnt;
	for(auto &x : str)cnt[x]++;
	cnt[c]++;
	ll res = 0;
	for(char act = '1'; act <= '9'; act++){
		ll tmp = act-'0';
		res += tmp*pow(10,cnt[act]);
	}
	return res;
}
int K;
ld asd(char c1,char c2,map<char,int> cnt){
	if(c1 != c2){
		ld tmp1 = ld(K-cnt[c1])/(9*K-8);
		ld tmp2 = ld(K-cnt[c2])/(9*K-8-1);
		return tmp1*tmp2;
	}
	ld tmp1 = ld(K-cnt[c1])/(9*K-8);
	ld tmp2 = ld(K-cnt[c2]-1)/(9*K-8-1);
	return tmp1*tmp2;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> K;
	string s1,s2; cin >> s1 >> s2;
	map<char,int> cnt;
	for(auto &x : s1)cnt[x]++;
	for(auto &x : s2)cnt[x]++;
	ld res = 0;
	for(char a = '1'; a <= '9'; a++){
		for(char b = '1'; b <= '9'; b++){
			cnt[a]++;
			cnt[b]++;
			if(cnt[a] <= K && cnt[b] <= K){
				ll r1 = get(s1,a);
				ll r2 = get(s2,b);

				cnt[a]--;
				cnt[b]--;

				if(r1 > r2){
					res += asd(a,b,cnt);
					//cout << a << ' ' << b << '\n';
					//debug(asd(a,b,cnt));
				}
			}else{
				cnt[a]--;
				cnt[b]--;
			}
		}
	}
	//debug(num,den);
	//ld res = num/den;
	cout << fixed << setprecision(15) << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
#define int long long
namespace run{
	const int MAX=1LL<<62;
	int X,Y,ans,num[109+9];
	int main(){
		X=read<int>(),Y=read<int>(),ans=max(X,Y);
		for(int i=0;i<=64;i++){
			int tmp=X,peg=1;
			for(int j=0;j<i;j++){
				tmp<<=1;
				if(tmp>MAX){peg=0;break;}
			}
			if(!peg) break;
			int del=abs(Y-tmp);
			for(int j=0;j<64;j++) num[j]=(del>>j&1);

			int g=i;
			for(int j=0;j<i;j++)
				if(num[j]==1){
					int k=j;
					while(k+1<i && num[k+1]) k++;
					g++;
					if(j^k){
						if(k+1<i) num[k+1]=1;
						else g++;
					}
					j=k;
				}
			g+=(del>>i),ans=min(ans,g);
		}
		cout<<ans<<endl;
		return 0;
	}
}
#undef int
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

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

int x, y;
map<int, int> dp;

int recurse(int n) {
	if (n <= x) {
		return abs(x - n);
	}
	if (n % 2 == 0) {
		if (dp[n / 2] == 0)
			dp[n] = recurse(n / 2) + 1;
		else
			dp[n] = dp[n / 2] + 1;
		dp[n] = min(dp[n], abs(x - n));
		return dp[n];
	}
	else {
		if (dp[n + 1] == 0)
			dp[n] = recurse(n + 1) + 1;
		else
			dp[n] = dp[n + 1] + 1;
		if (dp[n - 1] == 0)
			dp[n] = min(dp[n], recurse(n - 1) + 1);
		else
			dp[n] = min(dp[n], dp[n - 1] + 1);
		dp[n] = min(dp[n], abs(x - n));
		return dp[n];
	}
}

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

	cin >> x >> y;
	cout << recurse(y) << "\n";
	/*for (auto i : dp) {
		cout << i.first << " " << i.second << "\n";
	}*/
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define N 5114514
#define all(x) (x).begin(), (x).end()
const ll mod = 1000000007;
// const ll mod = 998244353;
const ll inf = 1000000000000000000;
void solve() {
    ll n;
    string s;
    cin >> n >> s;
    vector<ll> a(n + 1);
    ll k = inf;
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
        if (i) k = min(k, abs(a[i] - a[i - 1]));
    }
    cout << k << endl;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j <= n; j++) {
            cout << (a[j] + i) / k << ' ';
        }
        cout << endl;
    }
}

int main() {
    solve();
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

// index が条件を満たすかどうか
bool isOK(const vector<ll> &a, std::string S, ll index) {
  ll n = a[0] / index;
  ll m = a[0] % index;
  FOR(i, 1, a.size()) {
    ll x = a[i] / index;
    ll y = a[i] % index;
    if (S[i - 1] == '<') {
      if (n >= x) {
        return false;
      }
      if (n + 1 == x && m > y) {
        return false;
      }
    } else {
      if (n <= x) {
        return false;
      }
      if (n == x + 1 && m < y) {
        return false;
      }
    }
    swap(n, x);
    swap(m, y);
  }
  return true;
}

// 汎用的な二分探索のテンプレ
ll binary_search(const vector<ll> &a, std::string S) {
  ll ng = 100000;  //「index = 0」が条件を満たすこともあるので、初期値は -1
  ll ok = 1;       // 「index = a.size()-1」
                   // が条件を満たさないこともあるので、初期値は a.size()

  /* ok と ng のどちらが大きいかわからないことを考慮 */
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;

    if (isOK(a, S, mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

void solve(long long N, std::string S, std::vector<long long> A) {
  ll k = binary_search(A, S);
  cout << k << endl;
  vector<vector<ll>> v(N + 1);
  REP(i, N + 1) {
    ll n = A[i] / k;
    ll m = A[i] % k;
    REP(j, m) {
      v[i].push_back(n + 1);
    }
    REP(j, k - m) {
      v[i].push_back(n);
    }
  }
  REP(j, k) {
    REP(i, N + 1) {
      cout << v[i][j] << " ";
    }
    cout << endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::string S;
  std::cin >> S;
  std::vector<long long> A(N - 0 + 1);
  for (int i = 0; i < N - 0 + 1; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, S, std::move(A));
  return 0;
}


#include <bits/stdc++.h>

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

bool issame(int x, int y){
    if(x > y) swap(x, y);
    bool ret = true;
    while(x){
        if((x&1)^(y&1)) ret = false;
        x >>= 1, y >>= 1;
    }
    return ret;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N); rep(i, N) {cin >> A[i]; A[i] %= 200;}
    if(N >= 20){
        int states = (1 << 10);
        vector<int> resB(states), resC(states);
        rep(i, states){
            int val = i;
            ll acc = 0;
            rep(j, 10){
                if(val&1) (acc += A[j]) %= 200;
                val >>= 1;
            }
            resB[i] = acc;
        }
        rep(i, states){
            int val = i;
            ll acc = 0;
            rep(j, 10){
                if(val&1) (acc += A[j+10]) %= 200;
                val >>= 1;
            }
            resC[i] = acc;
        }

        rep(i, states){
            rep(j, states){
                if(i == 0 || j == 0) continue;
                if(resB[i] == resC[j]){
                    cout << "Yes" << endl;
                    int valB = i, valC = j;
                    cout << __builtin_popcount(valB) << " ";
                    rep(k, 10){
                        if(valB&1) cout << k+1 << " ";
                        valB >>= 1;
                    }
                    cout << endl;
                    cout << __builtin_popcount(valC) << " ";
                    rep(k, 10){
                        if(valC&1) cout << k+11 << " ";
                        valC >>= 1;
                    }
                    cout << endl;
                    return 0;
                }
            }
        }
    }
    else{
        int states = (1 << N);
        vector<int> res(states);
        rep(i, states){
            int val = i;
            int acc = 0;
            rep(j, N){
                if(val&1) (acc += A[j]) %= 200;
                val >>= 1;
            }
            res[i] = acc;
        }
        rep(i, states){
            rep(j, states){
                if(!issame(i, j) && res[i] == res[j]){
                    cout << "Yes" << endl;
                    int valB = i, valC = j;
                    cout << __builtin_popcount(valB) << " ";
                    rep(k, 10){
                        if(valB&1) cout << k+1 << " ";
                        valB >>= 1;
                    }
                    cout << endl;
                    cout << __builtin_popcount(valC) << " ";
                    rep(k, 10){
                        if(valC&1) cout << k+1 << " ";
                        valC >>= 1;
                    }
                    cout << endl;
                    return 0;
                }
            }
        }
        cout << "No" << endl;
    }
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int T; cin >> T;
    while(T--) {
        string s; cin >> s;
        int n = s.size();
        string t = "atcoder";
        if(s > t){
            cout << 0 << endl;
            continue;
        }
        bool ok = false;
        rep(i,n) {
            if(s[i] != 'a') ok = true;
        }
        if(!ok){
            cout << -1 << endl;
            continue;
        }
        int ans = INF;
        repr(i,1,n){
            if(s[i] > 't') {
                ans = min(ans,i-1);
            }
            else if(s[i] != 'a') {
                ans = min(ans,i);
            }
        }
        cout << ans << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define pii pair<ll, ll>
#define prdb(pranay) cout << fixed << setprecision(10) << pranay;
#define speed1 ios_base ::sync_with_stdio(false);
#define speed2 cin.tie(NULL);
#define speed3 cout.tie(NULL);

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

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        vector<ll> v(n);
        ll i, j;
        ll gcd;
        for (i = 0; i < n; i++)
            cin >> v[i];
        sort(v.begin(), v.end(), greater<ll>());
        gcd = v.back();
        for (i = 0; i < n - 1; i++)
            gcd = __gcd(gcd, v[i]);

        cout << gcd;
    }
}


#include <bits/stdc++.h>
/* #include <atcoder/all> */

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;
/* using namespace atcoder; */

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) {
    cin >> x.at(i);
    cin >> y.at(i);
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      double tmp = (double) (y.at(j) - y.at(i)) / (x.at(j) - x.at(i));
      if (tmp >= -1.0 && tmp <= 1.0) {
        res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool cmp(pair<ll,ll> a, pair<ll,ll> b){
	return (a.fi)*2 + a.se > (b.fi)*2 + b.se;

}

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

    int t=1;
    // cin>>t;
    while(t--){
    	int n;cin >> n;
    	vector<pii> a(n);
    	int ans = 0;
    	for(int i = 0;i < n; i++){
    		cin >> a[i].fi >> a[i].se;
    		for(int j = 0;j < i; j++){
    			if(abs(a[i].fi-a[j].fi) >= abs(a[i].se - a[j].se) )
    				ans++;
    		}
    	}
    	cout << ans;
    }
}


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

using ll = long long;

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

  int n;
  cin >> n;

  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s.at(i);

  vector<vector<ll>> dp(n + 1, vector<ll>(2)); // T, F
  dp[0][0] = dp[0][1] = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == "AND") {
      dp[i + 1][0] += dp[i][0];
      dp[i + 1][1] += dp[i][0] + dp[i][1] * 2;
    }
    else {
      dp[i + 1][0] += dp[i][0] * 2 + dp[i][1];
      dp[i + 1][1] += dp[i][1];
    }
  }

  cout << dp[n][0] << '\n';
}

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define forn(i,x1,n)     for(int i=x1; i<n; i++)
#define forit(it, m)    for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x1)      __builtin_popcountll(x1)
#define zrobits(x1)      __builtin_ctzll(x1)
#define mod             1000000007
// #define mod             998244353
#define inf             1e18
#define ps(x1,y)         fixed<<setprecision(y)<<x1
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x1)            int x1; cin>>x1; while(x1--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void zeus()
{
	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
}

int32_t main() {

	zeus();

	int n, q; cin >> n >> q;

	int a[n + 1];

	forn(i, 0, n) {
		cin >> a[i];
	}
	a[n] = 0;

	sort(a, a + n + 1);
	int diff[n];

	forn(i, 0, n) {
		diff[i] = a[i + 1] - a[i] - 1;
	}
	int prefixsum[n + 1];
	prefixsum[0] = 0;

	forn(i, 0, n) {
		prefixsum[i + 1] = prefixsum[i] + diff[i];
	}

	forn(i, 0, q) {
		int k; cin >> k;
		auto ind = lower_bound(prefixsum, prefixsum + n + 1, k) - prefixsum;
		cout << a[ind - 1] + k - prefixsum[ind - 1] << endl;
	}

}


#include <bits/stdc++.h>

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int it = *min_element(a.begin(), a.end());
    unordered_map<int, int> mp;
    auto add = [&](int x, int val) {
        if (x >= it)
            return;
        if (!mp.count(x))
            mp[x] = val;
        else
        {
            mp[x] = __gcd(val, mp[x]);
        }
    };
    for (int t : a)
    {
        for (int j = 1; j * j <= t; j++)
            if (t % j == 0)
            {
                add(j,t);
                add(t / j,t);
            }
    }
    int ans = 1;
    for (auto [i, j] : mp)
        if (i == j)
            ans++;
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    while (T--)
    {
        solve();
    }
}

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"

long long gcd(long long a, long long b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}
long long lcm(long long x, long long y) {
	return x * y / gcd(x, y);
}
map<long long, long long>mp;
//約数列挙
void calc(long long N) {
	for (long long i = 1; i <= sqrt(N); i++) {
		if (0 == N % i) {
			mp[i] = gcd(mp[i], N);
			if (N != i * i) {
				mp[N / i] = gcd(mp[N / i], N);
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<long long>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	long long minA = 1e18;
	rep(i, N) {
		minA = min(minA, A[i]);
	}
	rep(i, N) {
		calc(A[i]);
	}
	int ans = 0;
	for (auto p : mp) {
		if ((p.first <= minA) && (p.first == p.second)) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define MOD 998244353

int W[100],fact[1000];
int dp[2][10001][101];
int main() {
    int i;
    int N;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf("%d",&W[i]);

    int j,k;
    int sum = 0;
    dp[1][0][0] = 1;
    fact[0] = 1;
    for (i = 1; i < 1000; i++) fact[i] = ((LLI) i*fact[i-1]) % MOD;
    for (i = 0; i < N; i++) {
        int p = i & 1;
        sum += W[i];
        for (j = 0; j <= sum; j++) {
            for (k = 0; k <= i+1; k++) {
                dp[p][j][k] = dp[!p][j][k];
                if ((j-W[i] >= 0) && (k > 0)) {
                    dp[p][j][k] += dp[!p][j-W[i]][k-1];
                    if (dp[p][j][k] >= MOD) dp[p][j][k] -= MOD;
                }
            }
        }
    }
    LLI ans = 0;
    if (!(sum & 1)) {
        i = sum/2;
        for (j = 0; j <= N; j++) {
            ans += (((LLI) dp[(N-1) & 1][i][j]*fact[j]) % MOD)*fact[N-j];
            ans %= MOD;
        }
    }
    cout << ans << endl;

    return 0;
}

#pragma GCC optimize("O3")
// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

// using mint = modint998244353;
// ostream& operator<<(ostream& out, mint m){
//   out << m.val();
//   return out;
// }

const int P = 998244353;
void add(int &a,int b){
  a += b;
  if(a >= P)
    a -= P;
}
void sub(int &a,int b){
  a -= b;
  if(a < 0)
    a += P;
}
int mul(int a,int b){
  return a * b % P;
}
int n;
int res = 0;
vector<vector<int>> dp;
vector<int> t;
void add(int x){
  int pom = t[x];
  int a = SZ(dp);
  int b = SZ(dp[0]);
  vector<vector<int>> dp2(a + 1,vector<int>(b + pom));
  R(i,a)R(j,b){
    add(dp2[i + 1][j + pom], mul(dp[i][j], i + 1));
    if(j <= pom){
      add(dp2[a - i][pom - j], mul(dp[i][j], a - i));
    }else{
      add(dp2[i][j - pom], mul(dp[i][j], a - i));
    }
  }
//   debug(dp,pom,dp2);
  swap(dp,dp2);
}
void licz(int po,int ko){
  if(po + 1 == ko){
    debug(po,dp);
    R(i,SZ(dp)){
      R(j,min(SZ(dp[0]), t[po])){
        sub(res, dp[i][j]);
      }
    }
    debug(po,t[po],res);
    return;
  }
  int m = (po + ko) / 2;
  auto pam = dp;
  for(int i = po; i < m; i++)add(i);
  licz(m,ko);
  swap(dp,pam);
  for(int i = m; i < ko; i++)add(i);
  licz(po,m);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  t.resize(n);
  res = 1;
  R(i,n){
    cin >> t[i];
    res = mul(res, i + 1);
  }
  debug(res);
  dp.resize(1,vector<int>(1,1));
  licz(0,n);
  cout << res << "\n";
}


#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007

using namespace std;

ll power(ll a, ll b)
{

	ll ans = 1;
	if(b==0) return ans;
	while(b>0)
	{
		if(b%2==0)
		{
			a = (a*a)%mod;
			b/=2;
		}
		else
		{
			ans = (ans * a)%mod;
			b-=1;
		}
	}

	return ans;
}

int main()
{
	int n;
	cin>>n;
	char aa, ab, ba, bb;
	cin>>aa>>ab>>ba>>bb;

	if(n<=3) cout<<1;
	else if((bb=='B' && ab=='B')|| (aa == 'A' && ab =='A')) cout<<1;
	else if((ab=='B' && ba=='B') || (ab=='A' && ba=='A'))
	{
		int a[1001];
		a[2] = 1;
		a[3] = 1;
		for(int i = 4; i<1001; i++) a[i] = (a[i-1] + a[i-2])%mod;

		cout<<a[n];

	}
	else
	{
		cout<<power(2, n-3);
	}

}

#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
using ll = long long;
ll MOD = 1e9+7;

ll g(ll x){
	int ret = 1;
	for(int i = 0;i<x;i++){
		(ret*=2)%=MOD;
	}
	return ret;
}

ll f(ll x){
	ll ret;
	ll ret_1 = 1;
	ll ret_2 = 1;
	for(int i = 0;i<x-1;i++){
		(ret = ret_1 + ret_2)%=MOD;
		ret_2 = ret_1;
		ret_1 = ret;
	}
	return ret;
}
int main()
{
	int n;cin >> n;
	char c[4];
	for(int i = 0;i<4;i++)cin >> c[i];
	if(n<4){
	cout<<1<<endl;
	return 0;
	}
	ll ans;
	if(     c[0]=='A'&&c[1]=='A')                      ans=1;
	else if(           c[1]=='B'&&           c[3]=='B')ans=1;
	else if(           c[1]=='B'&&c[2]=='A'&&c[3]=='A')ans = g(n-3);
	else if(c[0]=='B'&&c[1]=='A'&&c[2]=='B')           ans = g(n-3);
	else if(           c[1]=='B'&&c[2]=='B'&&c[3]=='A')ans = f(n-2);
	else if(c[0]=='B'&&c[1]=='A'&&c[2]=='A')           ans = f(n-2);
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (ll i = (a); i <= (b); i+=x)
#define debug(x) cout <<" || "<< #x << " is= " << x <<endl; //use for debug
#define read(a) ll a; cin >> a;
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define pr         pair<long double,long double>
#define vpll       vector<pair<ll,ll>>
#define all(v)     v.begin(),v.end()
#define rall(v)    v.rbegin(),v.rend()  //reverse of above;
#define sz(container) int((container).size())
#define cut(x) {cout<<x<<"\n"; continue;}
#define setprec(x) cout << fixed << showpoint << setprecision(15)<<x<<"\n";
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl '\n';
#define mod 1000000007
#define mod1 998244353
#define pi 3.141592653589793238
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

//*s.find_by_order() ->returns an iterator to the k-th largest element (counting from zero);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
//sort(a+1,a+n+1,[](ll x,ll y){return abs(x)>abs(y);});
//sort(v.begin(), v.end(), greater<int>()); -> not sure work for first also if second are equal;
//q=lower_bound(all(v[a[i]]),i)-v[a[i]].begin()+1;
// s.substr(start_ind,length);
// vpll shift={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}} ->shift operator;
//bool comp(pr a,pr b){return a.second<b.second;} // use for differentiate order of comparision;
// cntbit(x) __builtin_popcount(x); -> no. of bits in given no.;

//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
const ll MAXN=2e7+5;
const ll inf=1e18+5;

int main()
{
  fast_io;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  //“Don’t wish it were easier. Wish you were better.” – Jim Rohn;
  ll n; cin>>n;
  long double a[10];
  FOR(i,1,4) cin>>a[i-1];

  long double h,k,x,y,radius;
  h=(a[0]+a[2])/2.0;
  k=(a[1]+a[3])/2.0;

  // shift p0 wrt h,k ant. clkwise;

  long double theta=2*pi/(n*1.0);
  //debug(theta);
  a[0]-=h,a[1]-=k;

  x=a[0]*cos(theta)-a[1]*sin(theta);
  y=a[0]*sin(theta)+a[1]*cos(theta);

  x+=h,y+=k;
  setprec(x); setprec(y);

 }

#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

typedef pair<int, int> PII;
const int N = 4e5 + 10;

PII a[N];
int b[N];
int stk[N], top;

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

    for(int i = 1; i <= 2 * n; i ++){
        scanf("%d", &a[i].first);
        a[i].second = i;
    }

    sort(a + 1, a + 1 + 2 * n);
    for(int i = 1; i <= n; i ++)
        b[a[i].second] = 1;

    for(int i = 1; i <= 2 * n; i ++)
        if(!top){
            printf("(");
            stk[++ top] = i;
        }
        else{
            if(b[i] == b[stk[top]]){
                printf("(");
                stk[++ top] = i;
            }
            else{
                printf(")");
                top --;
            }
        }

    return 0;
}


// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int n;
	cin>>n;
	vi x(n),y(n);
	rep(i,n)cin>>x[i]>>y[i];

	int m;
	cin>>m;
	vvi dp;
	// left, up, right, down
	dp.pb({0,0,2,1});

	rep(i,m){
		int q;
		cin>>q;
		vi t=dp.back();
		if(q==1){
			(t[2]+=1)%=4;
			(t[3]+=1)%=4;
			int nx=t[1],ny=-t[0];
			t[0]=nx;
			t[1]=ny;
		}else if(q==2){
			(t[2]+=3)%=4;
			(t[3]+=3)%=4;
			int nx=-t[1],ny=t[0];
			t[0]=nx;
			t[1]=ny;
		}else if(q==3){
			int a;cin>>a;
			if(t[2]==0||t[2]==2){
				(t[2]+=2)%=4;
				t[0]=2*a-t[0];
			}else{
				(t[3]+=2)%=4;
				t[0]=2*a-t[0];
			}
		}else{
			int a;cin>>a;
			if(t[2]==1||t[2]==3){
				(t[2]+=2)%=4;
				t[1]=2*a-t[1];
			}else{
				(t[3]+=2)%=4;
				t[1]=2*a-t[1];
			}
		}
		dp.pb(t);
	}

	int q;
	cin>>q;
	while(q--){
		int a,b;
		cin>>a>>b;b--;
		if(dp[a][2]==0||dp[a][2]==2)
			cout<<dp[a][0]+dx[dp[a][2]]*x[b]<<" "<<dp[a][1]+dy[dp[a][3]]*y[b]<<endl;
		else
			cout<<dp[a][0]+dx[dp[a][3]]*y[b]<<" "<<dp[a][1]+dy[dp[a][2]]*x[b]<<endl;
		 	// cout<<dp[a][1]+dx[dp[a][3]]*y[b]<<" "<<dp[a][0]+dy[dp[a][2]]*x[b]<<endl;
	}
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
// #define TEST_CASES
// #define ONLINE_JUDGE

#define test   \
  long long t; \
  cin >> t;    \
  while (t--)
#ifndef ONLINE_JUDGE
#define reach(x) cout << "\n\t\t" << x << "\n\n";
#define deb(x) cout << #x << " " << x << '\n';
#define deb2(x, y) cout << #x << " --> " << x << " || " << #y << " --> " << y << '\n';
#define deb4(a, b, c, d) cout << #a << " = " << a << ", " << #b << " = " << b << ", " << #c << " = " << c << ", " << #d << " = " << d << '\n';
#else
#define reach(x)         //
#define deb(x)           //cout << #x << " " << x << '\n';
#define deb2(x, y)       //cout << #x << " --> " << x << " || " << #y << " --> " << y <<'\n';
#define deb4(a, b, c, d) // cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<'\n';
#endif
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; i < n; i++)
#define boost()                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);                      \
  cout << fixed << setprecision(11);
#define MEM(a, val) memset(a, val, sizeof(a));
#define inputarr(a, n)        \
  for (int i = 0; i < n; ++i) \
  cin >> a[i]

const long long INF = LONG_LONG_MAX, MOD = 1e9 + 7;

typedef long long ll;
typedef long double ld;
using namespace std;

void solve()
{
  ll n, i, j;
  cin >> n;
  vector<ll> r, g, b;
  //logic start
  char ch;
  ll a;
  fo(i, 2 * n)
  {
    cin >> a >> ch;
    if (ch == 'R')
      r.push_back(a);
    else if (ch == 'G')
      g.push_back(a);
    else
      b.push_back(a);
  }
  ll gs = g.size();
  ll rs = r.size();
  ll bs = b.size();
  if (rs % 2 == 0 && gs % 2 == 0 && bs % 2 == 0)
  {
    cout << 0LL;
    return;
  }
  if (rs % 2 == 0)
  {
    swap(r, g);
  }
  else if (bs % 2 == 0)
    swap(b, g);
  rs = r.size();
  bs = b.size();
  sort(b.begin(), b.end());
  sort(r.begin(), r.end());
  // sort(b.begin(), b.end());
  ll ri = 0, bi = 0;
  ll ans = abs(r[0] - b[0]);
  for (ri = 0; ri < rs; ++ri)
  {
    ll ele = lower_bound(b.begin(), b.end(), r[ri]) - b.begin();
    // deb(ele);

    if (ele != bs)
      ans = min(ans, abs(r[ri] - b[ele]));
    if (ele != 0)
      ans = min(ans, abs(r[ri] - b[ele - 1]));
  }
  if (g.size())
  {
    ll res1 = abs(g[0] - r[0]), res2 = abs(g[0] - b[0]);
    for (ll x : g)
    {
      ll ele = lower_bound(b.begin(), b.end(), x) - b.begin();
      // deb(ele);
      if (ele != bs)
        res2 = min(res2, abs(x - b[ele]));
      if (ele != 0)
        res2 = min(res2, abs(x - b[ele - 1]));

      ele = lower_bound(r.begin(), r.end(), x) - r.begin();
      // deb(ele);
      if (ele != rs)
        res1 = min(res1, abs(x - r[ele]));
      if (ele != 0)
        res1 = min(res1, abs(x - r[ele - 1]));
    }
    ans = min(ans, res1 + res2);
  }
  cout << ans;
}

signed main()
{
#ifdef ONLINE_JUDGE
  boost()
#endif
#ifdef TEST_CASES
      test
#endif
  {
#ifdef TEST_CASES
    // reach("--------------------------------------------");
#endif
    solve();
#ifdef TEST_CASES
    cout << '\n';
    // reach("--------------------------------------------");
#endif
  }

  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007

ll read(){
   char C=getchar();
   ll N=0 , F=1;
   while(('0' > C || C > '9') && (C != '-')) C=getchar();
   if(C == '-') F=-1 , C=getchar();
   while('0' <= C && C <= '9') N=(N << 1)+(N << 3)+(C - 48) , C=getchar();
   return F*N;
}

ll n,p;

ll power(ll a,ll b){
   ll ans = 1;
   while(b){
       if(b & 1)ans = ans * a % mod;
       a = a * a % mod;
       b >>= 1;
   }
   return ans;
}

int main(){
   n = read();
   p = read();
   p -= 1;
   std::cout<<(p * power(p - 1,n - 1)) % mod<<std::endl;
}

  #include "bits/stdc++.h"
  using namespace std;
  typedef long long ll;
  typedef long double ld;
  typedef pair<int, int> ii;
  #define pb push_back
  #define T ll testx; cin>>testx; while(testx--)
  #define print(name) for(auto t:name){cout<<t<<" ";}cout<<endl;
  #define printii(name) for(auto t:name){cout<<t.first<<" "<<t.second<<endl;}
  #define mod 1000000007
  #define modx 998244353
  #define inf 2000000000000000000
  #define mem(name,val) memset(name,val,sizeof(name))
  #define f(n) for(ll i=0;i<n;i++)
  #define rep(i,a,n) for(ll i=a;i<n;i++)
  #define endl "\n"
  #define popcount(x) __builtin_popcountll(x)
  #define precise cout<<fixed<<setprecision(15)
  const long double pi = acos(-1);
  ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}
  ll modexp(ll x,ll n)
  {
      if(n==0)
          {return 1;}
      else if(n%2 == 0)
          {return modexp((x*x)%mod,n/2);}
      else
          {return (x*modexp((x*x)%mod,(n-1)/2))%mod;}
  }
  int main()
  {
     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
     #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
     #endif
     ll n,p;cin>>n>>p;
     ll res=modexp(p-2,n-1);
     res*=(p-1);
     res%=mod;
     cout<<res<<endl;
  }


#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*
bが入ったら、aの、それ未満を上書き。　それ以上は関係ない
aが入ったら、bの未満を上書き
BIT2つかな

*/
// BIT,index = 1 ~ (0を投げるととまる）
// https://atcoder.jp/contests/abc174/submissions/21572028
//indexにする・・・？ちょうたいへん

#define M 200010
ll dat1[M], dat2[M], dat3[M], dat4[M]; //34=累積いれとく？

void add(ll i, ll x, ll id){
  if (id==1)
    for(; i<M; i += i&-i) dat1[i] += x;
  if (id==2)
    for(; i<M; i += i&-i) dat2[i] += x;
  if (id==3)
    for(; i<M; i += i&-i) dat3[i] += x;
  if (id==4)
    for(; i<M; i += i&-i) dat4[i] += x;
}

ll sum(ll i, ll id){
  ll res = 0;
  if (id==1)
    for(; i>0; i -= i&-i) res += dat1[i];
  if (id==2)
    for(; i>0; i -= i&-i) res += dat2[i];
  if (id==3)
    for(; i>0; i -= i&-i) res += dat3[i];
  if (id==4)
    for(; i>0; i -= i&-i) res += dat4[i];
  return res;
}

ll rangesum(ll L, ll R, ll id){
  return sum(R, id) - sum(L-1, id);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  ll n, m, q;
  cin >> n >> m >> q;
  ll used[3][200010]; //t, x
  rep(i, 3) rep(j, 200010) used[i][j]=1;
  ll ans = n*m;
  add(1, n, 1); //1->0
  add(1, m, 2);
  add(1, n, 3); //1->0
  add(1, m, 4);
  //34が累積和
  ll T[200010];
  ll X[200010];
  ll Y[200010];
  map<ll, ll> mp1; // val->id
  map<ll, ll> mp2; // id->val
  set<ll> se;
  se.insert(1);
  rep(i, q){
    cin >> T[i] >> X[i] >> Y[i];
    Y[i]++;
    se.insert(Y[i]);
  }
  ll cnt = 1;
  for(auto v: se){
    mp1[v] = cnt++;
  }
  cnt=1;
  for(auto v: se){
    mp2[cnt++]=v;
  }
  rep(i, q){
    ll t=T[i];
    ll x=X[i];
    ll y=Y[i];
    ll z=used[t][x]; //val
    //まず除く
    ll zz=mp1[z];//id
    ans -= z*sum(zz, t^3); // もとあった値をなかったことに
    ans += sum(zz, (t^3)+2); // なかった場合の復元
    add(zz, -1, t);
    add(zz, -z, t+2);//累積
    used[t][x]=y;
    ll yy=mp1[y]; //id
    ans -= sum(yy, (t^3)+2);
    ans += y*sum(yy, (t^3));
    add(yy, 1, t);
    add(yy, y, t+2);
    cout << ans -n*m<< endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
ll N,M,Q;
map<ll,ll>mp;
map<ll,ll>mp1;
P dat[2][800005];
ll n;
void init(ll n_){
  n=1;
while(n<=n_)n*=2;
  for(ll i=0;i<2*n-1;i++){
  dat[0][i]=P(0,0);
    dat[1][i]=P(0,0);
  }
}
void update(ll j,ll k,ll a){
 ll m=mp1.at(k); k+=n-1;
dat[j][k].first+=a;dat[j][k].second+=a*m;
  while(0<k){
  k=(k-1)/2;
    dat[j][k].first=(dat[j][2*k+1].first+dat[j][2*k+2].first);
    dat[j][k].second=(dat[j][2*k+1].second+dat[j][2*k+2].second);
  }

}
P query(ll j,ll a,ll b,ll k,ll l,ll r){
if(a<=l&&r<=b)return dat[j][k];
  else if(b<=l||r<=a)return P(0,0);
  else{

  P val=query(j,a,b,2*k+1,l,(l+r)/2);
    P var=query(j,a,b,2*k+2,(l+r)/2,r);
    P p(val.first+var.first,val.second+var.second);
    return p;

  }

}
int main(){
  cin>>N>>M>>Q;
  set<ll>S;S.insert(0);
  vector<ll>T(Q);vector<ll>X(Q);vector<ll>Y(Q);
  for(ll q=0;q<Q;q++){
  cin>>T[q];cin>>X[q];X[q]--;cin>>Y[q];S.insert(Y[q]);
  }ll I=0;
  for(auto x:S){mp[x]=I;I++;}
  for(auto p:mp){mp1[p.second]=p.first;}vector<ll>A(N);vector<ll>B(M);ll ans=0;
  init(I);update(0,0,N);update(1,0,M);
    for(ll q=0;q<Q;q++){
 if(T[q]==1){
 ans-=query(1,0,mp.at(A[X[q]])+1,0,0,n).first*A[X[q]];
 if(A[X[q]]<Y[q]){
 ans-=query(1,mp.at(A[X[q]])+1,mp.at(Y[q])+1,0,0,n).second;
 }else if(Y[q]<A[X[q]]){
  ans+=query(1,mp.at(Y[q])+1,mp.at(A[X[q]])+1,0,0,n).second;
 }else{}
 ans+=query(1,0,mp.at(Y[q])+1,0,0,n).first*Y[q];update(0,mp.at(A[X[q]]),-1);
             update(0,mp.at(Y[q]),1);A[X[q]]=Y[q];
 }else{
  ans-=query(0,0,mp.at(B[X[q]])+1,0,0,n).first*B[X[q]];
 if(B[X[q]]<Y[q]){
 ans-=query(0,mp.at(B[X[q]])+1,mp.at(Y[q])+1,0,0,n).second;
 }else if(Y[q]<B[X[q]]){
  ans+=query(0,mp.at(Y[q])+1,mp.at(B[X[q]])+1,0,0,n).second;
 }else{}
 ans+=query(0,0,mp.at(Y[q])+1,0,0,n).first*Y[q];update(1,mp.at(B[X[q]]),-1);
             update(1,mp.at(Y[q]),1);B[X[q]]=Y[q];
 }cout<<ans<<endl;
  }

 return 0;
}


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

#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//insert,find_by_order,order_of_key,lower_bound,upper_bound;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

//////////////////////////////code//////////////////////////////

const int N = 200;

void solve()
{

      int ans = 1;

    int a , b;
    cin >> a >> b;

    for(int i = 1; i <= b ; i++)
    {
          int val1 = (a+i-1)/i;
          int val2 = val1 + 1;

        //  deb(i,val1,val2);

          if(i*val1 >= a && i*val2 <= b)
          {
              ans = max(ans,i);
          }
    }

    db(ans)

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

     #ifndef ONLINE_JUDGE
     freopen("INP.txt", "r", stdin);
     freopen("out.txt", "w", stdout);
     #endif

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

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values

#include<bits/stdc++.h>
using namespace std;
#define DONTSYNC ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--)  //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forll(a,start,end) for(long long a=start;a<end;a++)
#define forull(a,start,end) for(unsigned long long a=start;a<end;a++)
#define fi first
#define se second
typedef long long     ll;
typedef long double   ld;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vii;
typedef vector<pll>   vll;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
const double PI = acos(-1);

void solve(){
    /* code */
    int a,b; cin>>a>>b;
    int res=1;
    fori(gd,2,b+1){
        if(b/gd*gd-gd>=a) res=gd;
    }
    cout<<res<<endl;
}

int main()
{
    DONTSYNC;
    // TEST
    solve();
    return 0;
}


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

const int MAX_N = 2e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
void solve()
{
    int v, t, s, d;
    cin >> v >> t >> s >> d;
    if (d >= v * t && d <= v * s)cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif

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

#include <bits/stdc++.h>

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll r,x,y;
    cin >> r >> x >> y;

    ll ans = 1;

    if(r*r == x*x+y*y) {
        cout << 1 << endl;
        return 0;
    }
    if(r*r > x*x+y*y) {
        cout << 2 << endl;
        return 0;
    }

    while((ans*r*ans*r) < x*x+y*y){ ans++;}

    cout << ans << endl;

}


#include<bits/stdc++.h>
#define ll long long
#define mll map<ll,ll>
#define u_mll unordered_map<ll,ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define msll multiset<ll>
#define usll unordered_set<ll>
#define vll vector<ll>
#define vv vector
#define pqll priority_queue<ll, vll, greater<ll> ()>
#define pql priority_queue<ll>
#define MAX 19999999
#define ff first
#define ss second
#define pb push_back
#define srt(s) sort(s.begin(), s.end())
#define srtr(rs) sort(s.rbegin(), s.rend())
#define f(i,a,n) for(ll i = a; i < n; i++)
#define f1(i,a,n) for(ll i = a; i <= n; i++)
#define fr(i,a,n) for(ll i = n; i > a; i--)
#define abc int main
#define close_kor_taratari return 0
#define endl "\n"
#define testcase ll t; cin>>t; while(t--)
using namespace std;

bool isprime(ll n) {
    if(n < 2) return false;
    for(ll i = 2; i * i <= n; i++) {
        if(n % i == 0)
        {
            return false;
        }
    }
    return true;
}

bool perfect_sqr(ll n) {
    ll a = sqrt(n);
    return (a * a == n);
}

bool isfibo(ll n) {
    return perfect_sqr(5*n*n + 4) or perfect_sqr(5*n*n - 4);
}
bool Max(ll a, ll b) {
    return a > b;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll m, h;
  cin>>m>>h;
  if(h % m == 0) {
    cout<<"Yes";
  }
  else {
    cout<<"No";
  }
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

vector<ll> calc_all_sums(vector<ll> &v) {
  vector<ll> retv;
  int N = v.size();
  for (ull bits = 0; bits < (1ULL << N); bits++) {
    ll sum = 0;
    for (size_t i = 0; i < N; i++) {
      if ((bits & (1ULL << i)) != 0) {
        sum += v[i];
      }
    }

    retv.push_back(sum);
  }

  sort(ALL(retv));
  retv.erase(unique(ALL(retv)), retv.end());
  return retv;
}

ll solve(int N, ll T, vector<ll> &A) {
  int mid_N = N / 2;

  vector<ll> left_A{A.begin(), A.begin() + mid_N};
  vector<ll> right_A{A.begin() + mid_N, A.end()};

  vector<ll> left_sums = calc_all_sums(left_A);
  vector<ll> right_sums = calc_all_sums(right_A);

  ll retv = 0;
  for (auto &&l_sum : left_sums) {
    ll max_r_sum = T - l_sum;
    auto r_upper_itr = upper_bound(ALL(right_sums), max_r_sum);
    ll r_sum = (r_upper_itr != right_sums.begin() ? *(r_upper_itr - 1) : 0);
    ll sum = l_sum + r_sum;
    sum = (sum <= T ? sum : 0);
    retv = max(retv, sum);
  }

  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  ll T;
  cin >> N >> T;

  vector<ll> A(N, 0);
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }

  // main procedure
  ll ans = solve(N, T, A);

  // output
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define MOD1 998244353
#define ceil(x, y) ((x)%(y))==0? ((x)/(y)) : ((x)/(y)+1)
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in9.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int T=1;
    // cin >> T;
    FOR1(tt, T){
        // cout << "Case #" << tt << ": ";
        int x; cin >> x;
        cout << 100 - x % 100;
        cout << '\n';
    }
    return 0;
}

#include<cstdio>

using namespace std;

int main(){
	int n,a,sum=0;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		a>10 ? sum+=a-10:0;
	}
	printf("%d\n",sum);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t;
    cin >> t;
    vector<lli> v;
    for1(i, 0, t)
    {
        lli a;
        cin >> a;
        v.pb(a);
    }
    long double a2 = 0;
    lli a3 = 0, a1 = 0;
    for1(i, 0, t)
    {
        a1 += abs(v[i]);
        if (abs(v[i]) > a3)
        {
            a3 = abs(v[i]);
        }
        a2 += (long double)(v[i] * v[i]);
    }
    long double a4 = sqrtl(a2);
    cout << a1 << endl;
    cout << fixed << setprecision(15) << a4 << endl;
    cout << a3 << endl;
}

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

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    for(auto &e : A) cin >> e;

    long long m = 0;
    for(auto &e : A) m += abs(e);
    cout << m << '\n';

    double y = 0;
    for(auto &e : A) y += double(e) * e;
    y = sqrt(y);
    printf("%.15lf\n", y);

    long long c = 0;
    for(auto &e : A) c = max(c, abs(e));
    cout << c << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

int ppow(int x,int y,int mod)
{
    int res=1;
    while(y)
    {
        if(y&1)
            res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res;
}

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

    int n,m;
    cin>>n>>m;
    cout<<ppow(10,n,m*m)/m;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll modpow(ll a, ll n, ll m)
{
  ll ret = 1;
  while (n > 0)
  {
    if (n % 2 == 1) ret = ret * a % m;
    a = a * a % m;
    n /= 2;
  }
  return ret;
}

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

  ll X = modpow(10, N, M * M);
  ll Y = modpow(10, N, M);

  cout << mod(X - Y, M * M) / M << endl;
}


#pragma region shig_templates

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pairI2;
typedef pair<LL, LL> pairLL2;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
#define shig_for(i, a, b) for(int i = (a); i < (b); ++i)
#define shig_rep(i, n) shig_for(i, 0, n)
#define shig_forB(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define shig_repB(bit,n) shig_forB(bit,0,n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define tmp int temp = 0
#define str string s

template<class T> void COUT(T&& t){ cout << t << endl; }
template<class T,class... Ts>
void COUT(T&& t,Ts&&... ts){ cout << t << " "; COUT(ts...); }
void CIN() {}
template<class T,class... Ts> void CIN(T&& t,Ts&&... ts){ cin >> t; CIN(ts...); }

#pragma endregion

int main(){

    LL N;
    CIN(N);
    vector<VLL> C(N, VLL(N, 0));

    shig_rep(i, N){
        shig_rep(j, N){
            CIN(C[i][j]);
        }
    }

    vector<VLL> check(N, VLL(N, 0));

    shig_rep(i, N){
        shig_rep(j, N){
            if(j == 0)continue;
            check[i][j] = C[i][j-1] - C[i][j];
        }
    }

    shig_rep(i, N){
        if(i == 0)continue;
        shig_rep(j, N){
            if(check[i][j] != check[i-1][j]){
                COUT("No");
                return 0;
            }
        }
    }

    LL mum = numeric_limits<int>::max();
    int itr = -1;
    shig_rep(i, N){
        if(C[i][0] < mum){
            mum = min(mum, C[i][0]);
            itr = i;
        }
    }

    COUT("Yes");
    shig_rep(i, N){
        cout << (C[i][0] - mum) << " ";
    }

    cout << endl;

    shig_rep(j, N){
        cout << C[itr][j] << " ";
    }

    cout << endl;

    //COUT(N);
    //for(string& s : S) cin >> s;
    //cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

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

template <typename T, typename TT>
void print(T c, TT a,int n){

	vector<int> r;
	for(int i=0;i<n;i++)
		r.push_back(a[i][0] - c[0]);

	int mi = *min_element(r.begin(), r.end());

	if(mi<0){
		for(auto &x:r)	x+=abs(mi);
		for(auto &x:c)	x-=abs(mi);
	}

	cout<<"Yes\n";
	for(auto x:r)	cout<<x<<" ";
	cout<<"\n";
	for(auto x:c)	cout<<x<<" ";
	cout<<"\n";
}

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

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

	for(int i=0;i<n;i++){
		vector<int> c = a[i];
		int fail = 0;

		for(int j=0;j<n && !fail;j++){
			if(j==i)	continue;

			vector<int>temp(n);
			for(int k=0;k<n;k++){
				temp[k] = a[j][k] - c[k];
			}
			sort(temp.begin(), temp.end());
			if(temp[0] != temp.back()){
				fail = 1;
				break;
			}
		}

		if(!fail){
			print(c, a, n);
			return;
		}
	}
	cout<<"No\n";
}

signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
   	solve();
    return 0;
}


/*
  /^--^\
  \____/
 /      \ _____  _ __  __ ____  _     ____   ____  _____
|        || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_   _|
 \__  __/ |_|   |_|/_/\_\|____||____|\____)/__/\__\ |_|
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/
//#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#define int ll //__int128
#define double long double
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define For(i,a,b)    for(int i=a;i<=b;i++)
#define Fors(i,a,b,s) for(int i=a;i<=b;i+=s)
#define Forr(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define L(id) (id*2+1)
#define R(id) (id*2+2)
#define LO(x) (x&(-x))

#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair

#define MOD (int)(1000000007)
#define INF (int)(1e12)
#define EPS (1e-7)

#ifdef NYAOWO
#define debug(...) do{\
	cerr << __LINE__ <<\
	" : ("#__VA_ARGS__ << ") = ";\
	_OUT(__VA_ARGS__);\
	cerr << flush;\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
inline void USACO(const string &s) { cerr<<"USACO: "<<s<<"\n"; }
#else
#define debug(...)
inline void USACO(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
#endif
inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
inline int gcd(int a,int b) { return __gcd(a,b); }
inline int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p,const int &mod){
	int ans=1;
	while(p){
		if(p&1) ans=ans*b%mod;
		p/=2; b=b*b%mod;
	}
	return ans;
}
int fpow(int b,int p) { return fpow(b,p,MOD); }
template<typename T> inline void chmin(T &_a,const T &_b) { if(_b<_a) _a=_b; }
template<typename T> inline void chmax(T &_a,const T &_b) { if(_b>_a) _a=_b; }

int dis[1010][1010];
vector<int> adj[1010][26];

int32_t main(){
	NYA();
	//nachoneko so cute >/////<
	int n,m; cin>>n>>m;
	memset(dis,-1,sizeof(dis));
	priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> pq;
	//pair( dist , pair( s,t ) ) where s<=t
	For(i,1,n) pq.emplace(0,mkp(i,i));
	while(m--){
		int a,b; cin>>a>>b;
		char ch; cin>>ch;
		adj[a][ch-'a'].eb(b);
		adj[b][ch-'a'].eb(a);
		if(a>b) swap(a,b);
		pq.emplace(1,mkp(a,b));
	}
	while(!pq.empty()){
		int d=pq.top().F;
		int s=pq.top().S.F;
		int t=pq.top().S.S;
		pq.pop();
		if(dis[s][t]!=-1) continue;
		dis[s][t]=d;
		For(ch,0,25){
			for(auto &a:adj[s][ch]) for(auto &b:adj[t][ch]){
				int x=min(a,b),y=max(a,b);
				if(dis[x][y]==-1) pq.emplace(d+2,mkp(x,y));
			}
		}
	}
	cout<<dis[1][n]<<"\n";
	return 0;
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
typedef pair<int,pii> P;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
VII dist(1001,vector<ll>(1001,INF));
vector<vector<pii>> adj(1001);
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		char c;
		cin>>u>>v>>c;
		c-='a';
		adj[v].pb({u,c});
		adj[u].pb({v,c});
	}
	queue<pii>q;
	dist[1][n] = 0;
	q.push({1,n});
	while(!q.empty()){
		pii v = q.front();
		q.pop();
		for(pii x:adj[v.fi]){
			for(pii y:adj[v.se]){
				if(x.se == y.se && dist[x.fi][y.fi] == INF){
					dist[x.fi][y.fi] = dist[v.fi][v.se]+2;
					q.push({x.fi,y.fi});
				}
			}
		}

	}
	ll ans = INF;
	for(int i=1;i<=n;i++){
		ans = min(ans,dist[i][i]);
		for(pii x:adj[i]){
			ans = min(ans,dist[i][x.fi] + 1);
		}
	}
	if(ans == INF)ans = -1;
	cout<<ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define gt(a,b) get<b>(a)
#define endl '\n'
#define l_b lower_bound
#define u_b upper_bound
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
ll INF = 2147483647000000;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
bool compare(ll u,ll v)
{
    return v>u;
}

//unordered_map<long long, int, custom_hash> safe_map;
//oset<ar<int,2>>b,c; insert(),order_of_key(),find_by_order(return pointer);

ll prime[10000001];
ll freq[10000001];
ll co[10000001];
vector<ll> v[10000001];
int main()
{
    fastio
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll arr[n];
        unordered_map<ll,vector<ll>,custom_hash> sm;
        ll mn=INF;
        for(int i=0; i<n; i++) cin>>arr[i],mn=min(mn,arr[i]);
        set<ll> s;
        for(int i=0; i<n; i++)
        {
            for(int j=1; j*j<=arr[i]; j++)
            {
                if(arr[i]%j==0)
                {
                    if(arr[i]/j==j) sm[j].pb(arr[i]);
                    else sm[arr[i]/j].pb(arr[i]),sm[j].pb(arr[i]);
                }
            }
        }
        ll ans=0;
        for(auto it:sm)
        {
            ll gc=0;
            if(it.ff>=mn) continue;
            for(auto itt:it.ss)
            {
                gc=__gcd(gc,itt);
            }
            if(gc==it.ff) ans++;
        }
        cout<<ans+1<<endl;

        // for(auto it: s) cout<<it<<" ";

    }

}

/*
Description
@authors Magneto
@date    2020-10-12 10:59:53
@version 1.2.3
*/
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ll long long
#define l long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fr(i, a, b) for(int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define pf pop.front()
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " = " << x << endl;
#define lcm(a,b) a*b/__gcd(a,b)

using namespace std;

void solve()
{
l n;
cin>>n;
ll a[n];
for(l i=0;i<n;i++)
cin>>a[i];

ll ans= a[0];
for(l i=0;i<n;i++)
ans = __gcd(ans , a[i]);

cout<<ans<<endl;
}

int32_t main()
{
FAST
l T=1;
//cin>>T;
while(T--)
{
solve();
}
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstring>
#include <time.h>
#include <math.h>
#include <algorithm>
#include <random>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <chrono>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii > vii;
typedef vector<vector<ll> > vvi;
typedef vector<vvi > vvvi;
typedef vector<vector<pair<ll, ll> > > vvii;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,s,e) for(ll i=(s);i<(e);++i)
#define repr(i,s,e) for(ll i=(e);i>(s);--i)
#define io do { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } while (0)
#define endl '\n'
#define newl cout << '\n';

#define fill0(a) memset(a, 0, sizeof(a))
#define fill1(a) memset(a, -1, sizeof(a))

#define all(v) v.begin(), v.end()
#define bg begin()
#define ed end()
#define tr(it, v) for (auto it = v.bg; it != v.ed; it++)
#define prv(v) tr(it, v) { cout << *it << endl; }
#define prm(m) tr(it, m) { cout << it->first << " -> " << it->second << endl; }
#define scan(a, n) rep(i,0,n) cin >> a[i];
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define sumv(v) *accumulate(all(v), 0)
#define ub(a, x) upper_bound(all(a), x)
#define lb(a, x) lower_bound(all(a), x)

ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }
ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }
ll mid3(ll a, ll b, ll c) { return a + b + c - min3(a, b, c) - max3(a, b, c); }
ll ceil1(ll x, ll y) { if(x % y) return (x + y) / y; else return x / y; }

const ll MOD = 1e9+7;
const ll INF = 1e18;
const ll TE3 = 1005;
const ll TE5 = 200005;
const string YN[2] = {"NO", "YES"};

using namespace std;

ll n, m;
ll v[TE5];
ll vis[TE5];
ll ma[TE5];
vi a[TE5];
ll ans = -INF;

ll dfs(ll x,ll p) {
	if(p!=INF) {
		ans = max(ans, v[x] - p);
	}
	if(vis[x]) {
		ans = max(ans, ma[x] - p);
		return ma[x];
	}
	vis[x] = 1;
	ll op = p;
	p = min(p, v[x]);
	ll ret = v[x];
	for (ll ne : a[x])
	{
		ret=max(ret,dfs(ne, p));
	}
	if(op!=INF) {
		ans = max(ans, ma[x] - op);
	}
	return ma[x]=ret;
}

int main()
{
	io;
	cin >> n >> m;
	fill1(ma);
	rep(i, 0, n)
	{
		cin >> v[i];
	}
	rep(i,0,m) {
		ll x, y;
		cin >> x >> y;
		--x;
		--y;
		a[x].pb(y);
	}
	rep(i,0,n) {
		if(!vis[i]) {
			dfs(i, INF);
		}
	}
	cout << ans << endl;
	return 0;
}

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

vector<vector<int>> edge;
vector<int> v;
vector<int> d;

int dfs(ll now, ll pre, ll target) {
    int res = 0;
    int ma = -1, mi = 1000000;
    int dma = -1, dmi = 1000000;
    int cnt = 0;
    for (int nxt : edge[now]) {
        if (nxt == pre) continue;
        cnt++;
        res += dfs(nxt, now, target);
        mi = min(mi, v[nxt]);
        ma = max(ma, v[nxt]);
        dmi = min(dmi, d[nxt]);
        dma = max(dma, d[nxt]);
    }
    d[now] = dmi+1;
    bool put = false;
    if (cnt == 0) {
        return 0;
    }else if (cnt == 1) {
        if (mi >= 2*target) {
            v[now] = 0;
            put = true;
        }else {
            v[now] = mi+1;
        }
    }else {
        if (ma+dmi+2 <= 2*target+1) {
            v[now] = mi+1;
        }else if (ma+1 >= 2*target+1){
            v[now] = 0;
            put = true;
        }else {
            v[now] = ma+1;
        }
    }
    if (now == 0 && !put) {
        if (v[now] > target) put = true;
    }
    if (put) {
        res++;
        d[now] = 0;
    }
    return res;
}

int main() {
    int N, K;
    cin >> N >> K;
    edge.resize(N);
    v.resize(N);
    d.resize(N);
    for (int i = 0; i < N-1; i++) {
        int u, v;
        cin >> u >> v;
        u--;v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }

    ll l = 0, r = N;
    while (r-l > 1) {
        ll c = (l+r)/2;
        fill(v.begin(), v.end(), c+1);
        fill(d.begin(), d.end(), N*10);
        ll need = dfs(0, -1, c);
        //cout << need << endl;
        if (need <= K) r = c;
        else l = c;
    }
    cout << r << endl;

    return 0;
}


#include <iostream>

using namespace std;

string a;

bool Pal(int i , int j)
{
    while(i < j)
    {
        if(a[i] != a[j])
            return false;
        i++;
        j--;
    }
    return true;
}

int main()
{
    cin >> a;
    int i , j;
    i = 0;
    while(a[i] == '0'&& i < a.size())
        i++;
    j = a.size() - 1;
    while(a[j] == '0' && j >= 0)
        --j;
    if(Pal(i , j))
        cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

void yes(){
	cout << "Yes\n";
	exit(0);
}

void no(){
	cout << "No\n";
	exit(0);
}

bool isp(string s){
	fr(i,sz(s)/2) if(s[i]!=s[sz(s)-1-i]) return 0;
	return 1;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	ll n; cin >> n;
	if(n==0) yes();

	string s = to_string(n);

	while(s.back()=='0') s.pop_back();
	//prin(s);

	if(isp(s)) yes();
	no();
}


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

int main() {
  int64_t N;
  int64_t count=0;
  cin>>N;
  vector<int>data(200);
  for(int i=0;i<N;i++){
    int64_t a,z;
   cin>>a;
   z=a%200;
   data.at(z)++;
  }
  for(int i=0;i<200;i++){
   int64_t b,c;
   b=data.at(i);
   c=(b*(b-1))/2;
   count+=c;

 }
 cout<<count;
}

#include "bits/stdc++.h"
#pragma region header
using i32 = int;
using i64 = long long int;
using u32 = unsigned int;
using u64 = unsigned long long int;
using isize = ptrdiff_t;
using usize = size_t;

inline u64 popcount(const u64 v) {
#ifdef _MSC_VER
  return u64(__popcnt64(v));
#else
  return u64(__builtin_popcount(v));
#endif
}

class range {
  struct range_iterator {
    usize itr;
    constexpr range_iterator(const usize pos) noexcept : itr(pos) {}
    constexpr void operator++() noexcept { ++itr; }
    constexpr bool operator!=(const range_iterator& other) const noexcept {
      return itr != other.itr;
    }
    constexpr usize operator*() const noexcept { return itr; }
  };
  const range_iterator first, last;

 public:
  constexpr range(const usize first_, const usize last_) noexcept
      : first(first_), last(last_) {}
  constexpr range_iterator begin() const noexcept { return first; }
  constexpr range_iterator end() const noexcept { return last; }
};

template <class F>
class rec_lambda {
  F f;

 public:
  constexpr rec_lambda(F&& f_) : f(std::forward<F>(f_)) {}
  template <class... Args>
  constexpr auto operator()(Args&&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};

namespace cs_helper {
void zip_sort_renumber([[maybe_unused]] std::vector<usize>& order) {}
template <class T, class... Args>
void zip_sort_renumber(std::vector<usize>& order, std::vector<T>& head,
                       Args&&... args) {
  usize n = order.size();
  assert(n == head.size());
  std::vector<T> sorted_head(n);
  for (usize i = 0; i < n; ++i) sorted_head[i] = head[order[i]];
  head = std::move(sorted_head);
  zip_sort_renumber(order, args...);
}
}  // namespace cs_helper

template <class T, class... Args>
std::vector<usize> zip_sort(std::vector<T>& head, Args&&... args) {
  usize n = head.size();
  std::vector<std::pair<T, usize>> tmp(n);
  for (usize i = 0; i < n; ++i) tmp[i] = std::make_pair(head[i], i);
  std::sort(tmp.begin(), tmp.end());
  std::vector<usize> order(n);
  for (usize i = 0; i < n; ++i) order[i] = tmp[i].second;
  cs_helper::zip_sort_renumber(order, head, args...);
  return order;
}
#pragma endregion

void main_() {
  int N;
  std::cin >> N;
  std::array<u64, 200> cnt;
  for (auto& el : cnt) el = 0;
  for (usize i : range(0, N)) {
    usize A;
    std::cin >> A;
    --A;
    ++cnt[A % 200];
  }
  u64 ans = 0;
  for (usize i : range(0, 200)) ans += cnt[i] * (cnt[i] - 1) / 2;
  std::cout << ans << '\n';
  /* ----- ----- 08.05.2021 ----- ----- */
}

int main() { main_(); }