#include<bits/stdc++.h>

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

class UnionFind {
public:
    vector<int> par, rnk;

    void init(int n) {
        for (int i = 0; i < n; i++) par.push_back(i);
        rnk.resize(n, 0);
    }

    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rnk[x] < rnk[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rnk[x] == rnk[y]) rnk[x]++;
        }
    }

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

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

    UnionFind UF;
    UF.init(200005);

    int ans = 0;
    rep(i, int((n+1)/2)) {
        if (i * 2 + 1 != n) {
            int x = a[i], y = a[n - i - 1];
            if (!UF.same(x, y)) {
                UF.unite(x, y);
                ans++;
            }
        }
    }

    cout << ans << endl;
}

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

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
        return false;
    }
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

template<typename...args>inline bool read(int &a,args&...x){
    return (read(a),read(x...));
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

const int N=200010;

int n,a[N],ans;
bool vis[N];
vector<int> g[N];

void dfs(int x){
    if(!vis[x]) return;
    vis[x]=false;

    for(auto y:g[x]){
        dfs(y);
    }
}

signed main(){
    read(n);

    for(int i=1;i<=n;i++){
        read(a[i]);
        if(!vis[a[i]]){
            vis[a[i]]=true;
            ans++;
        }
    }

    int l=1,r=n;

    while(l<r){
        g[a[l]].push_back(a[r]);
        g[a[r]].push_back(a[l]);
        l++,r--;
    }

    for(int i=1;i<=N;i++){
        if(vis[i]){
            ans--;
            dfs(i);
        }
    }

    writeln(ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int64_t a=0;a<b;a++)
#define sor(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define ll int64_t
#define mod 1000000007
#define vl vector<int64_t>
int64_t rui(int64_t n,int64_t x){
int64_t i,s,ans;
i=0;
ans=1;
vector<int64_t> vec(100);
while(x>0){
  vec.at(i)=x%2;
  x=x/2;
  i++;
}
s=n;
for(int64_t j=0;j<100;j++){
  if(vec.at(j)==1){ans=(ans*s)%998244353;}
   s=(s*s)%998244353;
}
return ans;
}

int main() {
  ll h,w,k,a,b,p,t,q;
  t=998244353;
  char c;
  cin>>h>>w>>k;
  vector<vector<ll>> da(h, vector<ll>(w));
  vector<vector<ll>> ans(h+1, vector<ll>(w+1));
  fo(i,k){
   cin>>a>>b;
    a--;
    b--;
    cin>>c;
    if(c=='R'){da.at(a).at(b)=1;}
    else if(c=='D'){da.at(a).at(b)=2;}
    else if(c=='X'){da.at(a).at(b)=3;}
  }
  ans.at(0).at(0)=1;
  fo(i,h){
    fo(j,w){
      p=ans.at(i).at(j);
      if(da.at(i).at(j)==0){
        if(p%3==0){q=p/3*2;}
        if(p%3==1){q=(p+t)/3*2;}
        if(p%3==2){q=(p+t*2)/3*2;}
        ans.at(i+1).at(j)+=q;
        ans.at(i).at(j+1)+=q;}
      else if(da.at(i).at(j)==1){ans.at(i).at(j+1)+=p;}
      else if(da.at(i).at(j)==2){ans.at(i+1).at(j)+=p;}
      else if(da.at(i).at(j)==3){ans.at(i+1).at(j)+=p;
                           ans.at(i).at(j+1)+=p;}
      if(ans.at(i+1).at(j)>=t){ans.at(i+1).at(j)=(ans.at(i+1).at(j))%t;}
      if(ans.at(i).at(j+1)>=t){ans.at(i).at(j+1)=(ans.at(i).at(j+1))%t;}
    }
  }
  cout<<((ans.at(h-1).at(w-1))*rui(3,(h*w)-k))%t<<endl;
}

//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const ll p = 998244353;
const int maxn = 5005+10;
ll fac[maxn];
ll Pow(ll x,ll d){
	ll tans = 1;
	if(d == 0)return 1%p;
	ll a = Pow(x,d/2);
	tans = a*a%p;
	if(d%2)tans = tans*x%p;
	return tans%p;
}
char G[maxn][maxn];
ll f[maxn][maxn];
void add(ll & x,ll y){
	x = (x + y)%p;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll inv3 = Pow(3,p-2)%p;
	int n,m,k;
	cin >> n >> m >> k;
	for(int i = 1;i <= k;i++){
		int x,y;char s;
		cin >> x >> y >> s;
		G[x][y] = s;
	}
	f[1][1] = 1;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++)if(i != 1 or j != 1){
			if(i > 1){
				char u = G[i-1][j];
				if(u == 'X' or u == 'D')add(f[i][j],f[i-1][j]);
				if(!u)add(f[i][j],f[i-1][j]*inv3%p*2%p);//2/3
			}
			if(j > 1){
				char u = G[i][j-1];
				if(u == 'X' or u == 'R')add(f[i][j],f[i][j-1]);
				if(!u)add(f[i][j],f[i][j-1]*inv3%p*2%p);
			}
		}
	}
	cout << f[n][m]*Pow(3,n*m-k)%p;
	return 0;
}


#include <bits/stdc++.h>

const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>

typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
    x %= MOD;
    x += MOD;
    x %= MOD;
}

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

struct COMB{
    vl fact, fact_inv, inv;
    void init_nCk(long long SIZE) {
        fact.resize(SIZE + 5);
        fact_inv.resize(SIZE + 5);
        inv.resize(SIZE + 5);
        fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
        for(long long i = 2; i < SIZE + 5; i++) {
            fact.at(i) = fact.at(i - 1)*i%MOD;
            inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
            fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
        }
    }
    long long nCk (long long n, long long k) {
        assert(!(n < k));
        assert(!(n < 0 || k < 0));
        return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
    }
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}

void Main() {
    LCIN(N);
    ll n = (1 << N);
    vector<pair<ll, ll> > A(n/2), B(n/2);
    for(int i = 0; i < n/2; i++) {
        cin >> A.at(i).first;
        A.at(i).second = i + 1;
    }
    for(int i = 0; i < n/2; i++) {
        cin >> B.at(i).first;
        B.at(i).second = i + 1 + n/2;
    }
    sort(A.rbegin(),A.rend());
    sort(B.rbegin(),B.rend());
    if(A.at(0).first > B.at(0).first) cout << B.at(0).second << endl;
    else cout << A.at(0).second << endl;

}

int main() {
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

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(char c) {
	string s;
	s += c;
	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...);
}

void testcase(){
	int n;
	cin >> n;
	n = 1 << n;
	vector<int> a(n),org(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		org[i] = a[i];
	}
	vector<int> b;
	bool alt = true;
	int ans = -1;
	while(true){
		n = max(a.size(),b.size());
		if(n == 2){
			ans = (a.size() == 2 ? min(a[0],a[1]) : min(b[0],b[1]));
			break;
		}
		if(alt){
			for(int i = 0; i < n; i+= 2){
				b.pb(max(a[i],a[i+1]));
			}
			a.clear();
		}
		else{
			for(int i = 0; i < n; i+= 2){
				a.pb(max(b[i],b[i+1]));
			}
			b.clear();
		}
		//debug((alt ? b : a));
		alt = !alt;
	}
	for(int i = 0; i < (int)org.size(); i++){
		if(org[i] == ans){
			cout << i+1;
			break;
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define MOD 1000000007

int main() {
    int a, b; cin >> a >> b;
    cout << (a - b) / (double)a * 100 << endl;
    return 0;
}

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

int main()
{
  double A, B;
  cin >> A >> B;

  double ans = B / A;
  ans = 1.0 - ans;
  ans *= 100.0;
  cout << fixed << setprecision(20) << ans << endl;

  return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ps(x,y)   fixed<<setprecision(y)<<x
using namespace std;
int check, cnt, n;
ll k;
ll mat[9][9];
void ways(int bits, ll curr, int last) {

    if (bits == check) {
        ll temp = curr + mat[last][0];
        if (temp == k) {
            cnt++;
            // cout << "prices ->" << temp << endl;
        }
        return;
    }

    for (int i = 0; i < n; i++)
    {
        if (!((1 << i)&bits)) {
            int temp = (1 << i) | bits;
            ll mv = curr + mat[last][i];
            ways(temp, mv, i);
        }
    }
}
void solve()
{
    cin >> n >> k;
    check = (1 << n) - 1;
    cnt = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> mat[i][j];
        }
    }
    ways(1, 0LL, 0);
    cout << cnt << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // scanf("%d",&t);
    while (t--) {
        solve();
    }

}

#include<bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2")
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define req(i,a,b) for(int i=(a);i>=(b);--i)
#define rep_(i,a,b) for(int i=(a);i<(b).size();++i)
#define F(a) rep(a,1,n)
#define M(a,b) memset(a,b,sizeof a)
#define DC int T;cin>>T;while(T--)
#define ll long long
#define Z(a,b) sort(a+1,a+b+1)
using namespace std;
const unsigned _mod=998244353;
const unsigned mod=1e9+7;
const ll infi=0x3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
void rd(auto &x){x=0;int f=1;char ch=getchar();while(ch<48||ch>57){if(ch==45)f=-1;ch=getchar();}while(ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();x*=f;}
ll ksm(ll x,ll y=mod-2,ll m=mod){ll ret=1;while(y){if(y&1)ret=ret*x%m;y>>=1ll;x=x*x%m;}return ret;}
ll qpow(ll x,ll y){ll ret=1;while(y){if(y&1ll)ret=ret*x;y>>=1ll;x=x*x;}return ret;}
/*
    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
*/
int h,w,fa[2010],s,t;
char c;
unordered_map<int,bool> mp;
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline void merge(int x,int y){fa[find(x)]=find(y);}
int main()
{
    cin>>h>>w;
    rep(i,1,h+w) fa[i]=i;
    merge(1,h+1),merge(1,h+w),merge(h,h+1),merge(h,h+w);
    rep(i,1,h) rep(j,1,w) cin>>c,c=='#'&&(merge(i,h+j),1);
    rep(i,1,h) s+=!mp[find(i)],mp[find(i)]=1;
	mp.clear();
	rep(i,h+1,h+w) t+=!mp[find(i)],mp[find(i)]=1;
	cout<<min(s,t)-1<<'\n';
    return 0;
}


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

ll h, w, n, m, a[500010], b[500010], c[100010], d[100010];
ll ans;
int mp[2000][2000];
void run(int T) {
    cin >> h >> w >> n >> m;
    rep(i, 1, n) {
        cin >> a[i] >> b[i];
        mp[a[i]][b[i]] = 3;
        ans++;
    }
    rep(i, 1, m) {
        cin >> c[i] >> d[i];
        mp[c[i]][d[i]] = 2;
    }
    rep(i, 1, n) {
        for(int j = a[i] - 1; j && mp[j][b[i]] < 2; j--) {
            if(!mp[j][b[i]]) ans++;
            mp[j][b[i]] = 1;
        }
        for(int j = a[i] + 1; j <= h && mp[j][b[i]] < 2; j++) {
            if(!mp[j][b[i]]) ans++;
            mp[j][b[i]] = 1;
        }
        for(int j = b[i] - 1; j && mp[a[i]][j] < 2; j--) {
            if(!mp[a[i]][j]) ans++;
            mp[a[i]][j] = 1;
        }
        for(int j = b[i] + 1; j <= w && mp[a[i]][j] < 2; j++) {
            if(!mp[a[i]][j]) ans++;
            mp[a[i]][j] = 1;
        }
    }
    cout << ans << endl;

}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    int T = 1;
    //cin >> T;
    rep(i, 1, T) run(i);
}


#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++)
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 itos(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;
}
string s;
bool ok(string s)
{
	rep(i,s.size()/2)if(s[i]!=s[s.size()-i-1])return 0;
	return 1;
}
bool f=0;
int main()
{
	ios::sync_with_stdio(0);
	cin>>s;
	fore(i,s.size()-1,0)
	{
		if(s[i]!='0')
		{
			s=s.substr(0,i+1);
			f=1;
			break;
		}
	}
	if(ok(s)||f==0)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}
//特判判全
//循环边界
//精度足够
//注意初值

#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower)
#define upper_string(s) transform(all(s),s.begin(),::toupper)
#define len(s) (int)s.size()
#define F first
#define S second
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
const int MOD=1e9+7;
void solve()
{
int n;
cin>>n;
cout<<n-1;
}
int main()
{
//code
fastio
int t=1;
//cin>>t;
while(t--)
{
solve();
cout<<endl;
}
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

std::set<int> s;

int main(void){
	int n,i,p;
	for(i=0; i<200002; ++i){
		s.insert(i);
	}
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> p;
		s.erase(p);
		std::cout << *s.begin() << std::endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
const ll mod=1000000007;
inline int roundup(int a, int b) { return (((a + (b -1)) / b)); }
inline ll powmod(ll x, ll y) {ll res=1; for(ll i=0;i<y;i++){ res=res*x%mod; } return res;}
using namespace std;

signed main(void) {
    cout << fixed << setprecision(15);
    ll n, x[100000], m=0, c=0, u_sq=0;
    cin >> n;
    rep(i, n) {
        cin >> x[i];
    }
    rep(i, n) {
        c = max(c, abs(x[i]));
        m += abs(x[i]);
        u_sq += abs(x[i])*abs(x[i]);
    }
    cout << m << '\n' << sqrt(u_sq) <<'\n' << c << '\n';
    return 0;
}


#include <cstdio>
#include <cctype>
using namespace std;

const int max_n = 200000;
int a[max_n], wa[max_n], ps[max_n], wa_cnt = 0;
bool us[max_n] = {};

#define gc getchar
inline int read()
{
	int c = gc(), t = 1, n = 0;
	while (isspace(c)) { c = gc(); }
	if (c == '-') { t = -1, c = gc(); }
	while (isdigit(c)) { n = n * 10 + c - '0', c = gc(); }
	return n * t;
}
#undef gc

int main()
{
	int n;

	n = read();
	for (int i = 0; i < n; i++)
	{
		a[i] = read() - 1;
		ps[a[i]] = i;
	}

	for (int i = 0; i < n; i++)
	{
		if (ps[i] == i)
			continue;

		for (int j = ps[i] - 1; j >= i; j--)
		{
			ps[a[j]]++, a[j+1] = a[j];
			wa[wa_cnt++] = j + 1;
			if (us[j] || wa_cnt >= n)
			{
				puts("-1");
				return 0;
			}
			us[j] = true;
		}

		a[i] = ps[i] = i;

		/*
		for (int i = 0; i < n; i++)
			fprintf(stderr, "%d ", a[i]);
		putc('\n', stderr);
		*/
	}

	if (wa_cnt != n - 1)
	{
		puts("-1");
	//	fprintf(stderr, "%d\n", wa_cnt);
		return 0;
	}

	for (int i = 0; i < wa_cnt; i++)
		printf("%d\n", wa[i]);

	return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
int N,P[500];
vector<int> ans;
void f(int a){
  ans.push_back(a);
  swap(P[a],P[a+1]);
}
signed main(){
  int T; cin>>T;
  while(T--){
    cin>>N;
    for(int i=0;i<N;i++) cin>>P[i],P[i]--;
    ans.clear();
    for(int i=0;i<N-2;i++){
      int d=i;
      for(;P[d]!=i;d++);
      if(d==i)continue;
      if(d%2==ans.size()%2){
        if(d-i>=2){
          if(i%2==ans.size()%2) f(i);
          else f(i+1);
        }
        else if(N-d>2){
          f(d);
          f(d+1);
          f(d);
          d+=2;
        }
        else{
          f(d);
          f(d-1);
          d++;
        }
      }
      for(int j=d-1;j>=i;j--) f(j);
    }
    if(P[N-2]!=N-2){
      if(ans.size()%2==N%2)f(N-2);
      else{
        f(N-3);
        f(N-2);
        f(N-3);
        f(N-2);
        f(N-3);
      }
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i]+1;
      if(i+1!=ans.size())cout<<' ';
    }
    cout<<endl;
    assert(ans.size()<=N*N);
  }
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>

#define LL long long
#define Maxn 200005

using namespace std;

LL read() {
	LL x = 0, f = 1;
	char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while('0' <= c && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}

int n, q, fa[Maxn], siz[Maxn];
map <int, int> S[Maxn];

#define IT map <int, int> ::iterator

int find(int x) {
	if(fa[x] == x) return x;
	else return find(fa[x]);
}

int main() {
	n = read(); q = read();
	int c;
	for(int i = 1; i <= n; ++i) {
		c = read(); fa[i] = i; siz[i] = 1;
		S[i][c] = 1;
	}
	int opt, x, y;
	for(int i = 1; i <= q; ++i) {
		opt = read(); x = read(); y = read();
		if(opt == 1) {
			int anx = find(x), any = find(y);
			if(anx == any) continue;
			if(siz[anx] < siz[any]) swap(anx, any);
			fa[any] = anx;
			siz[anx] += siz[any];
			for(IT it = S[any].begin(); it != S[any].end(); ++it) S[anx][(*it).first] += (*it).second;
		}
		if(opt == 2) {
			int anx = find(x);
			printf("%d\n", S[anx][y]);
		}
	}
	return 0;
}


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

vector<vector<int>> dp;
vector<vector<bool>> visited;
vector<string> a;
int h, w;

int f(int i, int j){
    if(visited[i][j]) return dp[i][j];
    else{
        visited[i][j] = true;
        if((i+j)%2 == 1){
            dp[i][j] = 1001001001;
            if(i+1 < h) dp[i][j] = min(dp[i][j], f(i+1, j));
            if(j+1 < w) dp[i][j] = min(dp[i][j], f(i, j+1));
            dp[i][j] += (a[i][j] == '+') ? 1: -1;
        }else{
            dp[i][j] = -1001001001;
            if(i+1 < h) dp[i][j] = max(dp[i][j], f(i+1, j));
            if(j+1 < w) dp[i][j] = max(dp[i][j], f(i, j+1));
            if(i != 0 || j != 0) dp[i][j] += (a[i][j] == '-') ? 1: -1;
        }
    }
    return dp[i][j];
}

int main(){
    cin >> h >> w;
    a = vector<string>(h);
    for(auto &p: a) cin >> p;

    dp = vector<vector<int>>(h, vector<int>(w, -1));
    visited = vector<vector<bool>>(h, vector<bool>(w, false));
    visited[h-1][w-1] = true;
    dp[h-1][w-1] = (a[h-1][w-1] == '+') ? 1: -1;
    if((h+w)%2 == 0) dp[h-1][w-1] *= -1;
    if(h == 1 && w == 1) dp[h-1][w-1] = 0;
    if(f(0, 0) > 0) cout << "Takahashi" << endl;
    else if(f(0, 0) < 0) cout << "Aoki" << endl;
    else cout << "Draw" << endl;
    return 0;
}

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

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

using namespace std;

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

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

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

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


#include<bits/stdc++.h>
clock_t __t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 111111
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-__t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	ll mul(ll x,ll y){ull s=1.0*x/mod*y;ll res=1ull*x*y-s*mod;return (res%mod+mod)%mod;}
}
using namespace my_std;

int n,L;
ll a[sz];
ll b[sz];

map<ll,int>mn,mx;

int main()
{
	file();
#define GG return puts("-1"),0
	read(n,L);
	rep(i,1,n) read(a[i]);
	rep(i,1,n) read(b[i]);
	a[0]=b[0]=0,a[n+1]=b[n+1]=L+1;
	rep(i,0,n+1) if (!mn.count(a[i]-i)) mn[a[i]-i]=mx[a[i]-i]=i; else mx[a[i]-i]=i;
	ll ans=0;
	for (int l=0,r;l<=n+1;l=r+1)
	{
		if (b[l]<=a[l]) { r=l; continue; }
		if (!mn.count(b[l]-l)) GG;
		for (r=l;r<=n&&b[r+1]==b[r]+1;++r);
		ans+=mn[b[l]-l]-l;
	}
	for (int r=n+1,l;r>0;r=l-1)
	{
		if (b[r]>=a[r]) { l=r; continue; }
		if (!mx.count(b[r]-r)) GG;
		for (l=r;l&&b[l-1]==b[l]-1;--l);
		ans+=r-mx[b[r]-r];
	}
	cout<<ans;
	return 0;
}

#include<iostream>
#include<list>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}
pair<int,int> tpt(vector<vector<pair<int,int>>>& tp,pair<int,int> p,
                  vector<string>& mp){
  char c=mp[p.first][p.second];
  if(not ('a'<= c and c<= 'z')) return {-1,-1};
  int a=c-'a';
  if(tp[a][0]==p) return tp[a][1];
  return tp[a][0];
}
int q(vector<vector<pair<int,int>>>& tp,pair<int,int> p,
                  vector<string>& mp){
  char c=mp[p.first][p.second];
  if(not ('a'<= c and c<= 'z')) return 0;
  if(tp[c-'a'].size()<=1) return 0;
  return 1;
}

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

int main(){
  int h,w; cin >>h >>w;
  vector<string> mp(h); rep(i,h) cin >>mp[i];
  vector<vector<pair<int,int>>> tp(26);
  list<pair<int,int>> que;
  vector<vector<int>> te(h,vector<int>(w,-1));
  rep(i,h){
    rep(j,w){
      if('a'<= mp[i][j] and mp[i][j]<='z'){
        tp[mp[i][j]-'a'].push_back({i,j});
      }
      if(mp[i][j]=='S'){
        que.push_back({i,j});
        te[i][j]=0;
      }
    }
  }

  auto illegal
    =[&](pair<int,int> p){
       int f=p.first,s=p.second;
       if(f<0 or s<0 or f>=h or s>=w) return 1;
       if(mp[f][s]=='#') return 1;
       if(te[f][s]>=0) return 1;
       return 0;
     };

  while(que.size()){
    auto p=*que.begin();
    que.pop_front();
    int f=p.first,s=p.second;
    int cnt=te[f][s];
    if(mp[f][s]=='G'){
      print(te[f][s]);
      return 0;
    }
    auto t=tpt(tp,p,mp);
    if(q(tp,p,mp)){
      int a=mp[f][s]-'a';
      for(auto q:tp[a]){
        if(p==q) continue;
        if(te[q.first][q.second]>=0) continue;
        if(df)print(q);
        que.push_back(q);
        te[q.first][q.second]=cnt+1;
      }
      tp[a].clear();
    }
    rep(i,4){
      pair<int,int> t={f+dx[i],s+dy[i]};
      if(illegal(t)) continue;
      if(df)print(t);
      que.push_back(t);
      te[t.first][t.second]=cnt+1;
    }
    if(df)print("que",que);
  }
  print(-1);
}


#include<bits/stdc++.h>
using namespace std;
inline long long read()
{
	long long sum=0,naga=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')naga=-1;ch=getchar();}
	while(ch<='9'&&ch>='0')sum=sum*10+ch-'0',ch=getchar();
	return sum*naga;
}
inline void write(long long X)
{
	if(X<0)putchar('-'),X=-X;
	if(X>9)write(X/10);
	putchar(X%10+'0');
}
typedef pair<int,int>ss;
priority_queue <ss,vector<ss>,greater<ss> >q;
const long long N=1e6+5,M=5e6+5,INF=1e15;
long long head[N],n,m,s,cnt,dis[N],a,b;
bool vis[N];
struct point
{
	int u,v,w;
}edge[M];
inline void dijkstra()
{
	while(!q.empty())
	{
		ss mmp=q.top();
		int u=mmp.second;vis[u]=0,q.pop();
		for(register int i=head[u];i!=0;i=edge[i].u)
		{
			int V=edge[i].v;
			if(dis[V]>dis[u]+edge[i].w)
			{
				dis[V]=dis[u]+edge[i].w;
				if(vis[V]==0)vis[V]=1,q.push(ss{dis[V],V});
			}
		}
	}
}
inline void addedge(int u,int v,int w)
{
	edge[++cnt].u=head[u],edge[cnt].v=v,edge[cnt].w=w,head[u]=cnt;
//	edge[++cnt].u=head[u+n],edge[cnt].v=v,edge[cnt].w=w,head[u+n]=cnt;
}
int ww,id[1009][1009];
int main()
{
	a=read(),b=read();n=a*b;
	for(register int i=1;i<=a;i++)
		for(register int j=1;j<=b;j++)
			id[i][j]=(i-1)*b+j;
	for(register int i=1;i<=a;i++)
		for(register int j=1;j<b;j++)
		{
			ww=read();
			addedge(id[i][j],id[i][j+1],ww);
			addedge(id[i][j]+n,id[i][j+1],ww);
			addedge(id[i][j+1],id[i][j],ww);
			addedge(id[i][j+1]+n,id[i][j],ww);
		}
	for(register int i=1;i<a;i++)
		for(register int j=1;j<=b;j++)
		{
			ww=read();
			addedge(id[i][j],id[i+1][j],ww);
			addedge(id[i][j]+n,id[i+1][j],ww);
		}
	for(register int i=1;i<=a;i++)
		for(register int j=1;j<=b;j++)
			if(i!=1)addedge(id[i][j],id[i-1][j]+n,2);
	for(register int i=1;i<=a;i++)
		for(register int j=1;j<=b;j++)
			if(i!=1)
			{
				addedge(id[i][j]+n,id[i-1][j]+n,1);
				addedge(id[i][j]+n,id[i-1][j],1);
			}
	s=1;
	for(register int i=1;i<=n*2;i++)dis[i]=INF;
	q.push(ss{0,s}),dis[s]=0,vis[s]=1;
	dijkstra();
	write(dis[n]),putchar(' ');
}

#include <bits/stdc++.h>

using namespace std;

#define st first
#define nd second
#define pb push_back
#define cl(x,v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int, pii> piii;
typedef pair<ll,ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector <vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 2e5+5;

int cost = 0;
vector <piii> edges;
vector <pii> adj[N];

int par[N], sz[N], vis[N];

int find (int a) { return par[a] == a ? a : par[a] = find(par[a]); }

void unite (int a, int b) {
    if ((a = find(a)) == (b = find(b))) return;
    if (sz[a] < sz[b]) swap(a, b);
    sz[a] += sz[b];
    par[b] = a;
}

void dfs(int u){
    for(auto v: adj[u]){
        if(!vis[v.nd]){
            if(vis[u] == v.st) vis[v.nd] = (v.st == 1 ? 2 : 1);
            else{
                vis[v.nd] = v.st;
            }
            dfs(v.nd);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin  >> n >> m;
    for(int i=1;i<=m;i++){
        int u,v,c;
        cin >> u >> v >> c;
        edges.pb({c,{u,v}});
    }
    for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;
    sort(edges.begin(),edges.end());
    for(auto e : edges){
        if(find(e.nd.st) != find(e.nd.nd)){
            adj[e.nd.st].pb({e.st,e.nd.nd});
            adj[e.nd.nd].pb({e.st,e.nd.st});
            //cout << e.nd.nd << " " << e.nd.st << "\n";
            unite(e.nd.st, e.nd.nd);
        }
    }
    vis[1] = 1;
    dfs(1);
    for(int i=1;i<=n;i++) cout << vis[i] << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
const int maxn=2e5+10;
int n,m,t,is,cnt,ans;
string p;
int sum[10],q[150];
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(2);
    memset(q,0,sizeof(q));
    memset(sum,0,sizeof(sum));
    int c=0;
    for(int i=104;;i+=8){
        if(i>=1000)break;
        q[c++]=i;
    }
    // for(int i=0;i<c;i++)cout<<q[i]<<"\n";
    // return 0;
    cin>>p;
    bool is=false;
    for(int i=0;i<p.length();i++)++sum[p[i]-'0'];
    if(p.length()==1&&(p[0]-'0')%8==0)is=true;
    else if(p.length()==2){
        int g=(p[0]-'0')+(p[1]-'0')*10;
        if(g%8==0)is=true;
        g=(p[1]-'0')+(p[0]-'0')*10;
        if(g%8==0)is=true;
    }
    else {
        for(int i=0;i<c;i++){
            int a=q[i]%10,b=q[i]/10%10,c=q[i]/100;
            --sum[a],--sum[b],--sum[c];
            if(sum[a]>=0&&sum[b]>=0&&sum[c]>=0){
                is=true;
                break;
            }
            ++sum[a],++sum[b],++sum[c];
        }
    }
    cout<<(is?"Yes":"No")<<"\n";
    return 0;
    //good job!
}

#include <bits/stdc++.h>
const int N = 200005, P = 1e9 + 7;
char s[N]; int n, K, c[16], fac[20], ifac[20];
int qpow(int a, int b) {
	int t = 1;
	for (; b; b >>= 1, a = 1LL * a * a % P)
		if (b & 1) t = 1LL * t * a % P;
	return t;
}
int idx(char c) {
	if (isdigit(c)) return c - '0';
	else return c - 'A' + 10;
}
int C(int n, int m) {
	if (m > n || m < 0) return 0;
	return 1LL * fac[n] * ifac[m] % P * ifac[n - m] % P;
}
int f(int m, int n) {
	// K - m
	int k = K - m, ans = 0;
	if (n < k) return 0;
	for (int i = 0; i <= k; i++) {
		ans = (ans + 1LL * C(k, i) * qpow(P - 1, k - i) % P * qpow(i + m, n)) % P;
	}
	return 1LL * ans * C(16 - m, k) % P;
}
int main() {
	scanf("%s%d", s + 1, &K); n = strlen(s + 1);
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= 16; i++) fac[i] = 1LL * fac[i - 1] * i % P;
	ifac[16] = qpow(fac[16], P - 2);
	for (int i = 15; i; i--) ifac[i] = 1LL * ifac[i + 1] * (i + 1) % P;
	int tot = 0, ans = 0;
	for (int i = 1; i <= n; i++) {
		int a = idx(s[i]);
		for (int j = 0; j <= a; j++) {
			if (i == 1 && j == 0 || i != n && j == a) continue;
			int _tot = tot + (c[j] == 0);
			ans = (ans + f(_tot, n - i)) % P;
		}
		if (c[a] == 0) tot++;
		c[a] = 1;
	}
	for (int i = 2; i <= n; i++) ans = (ans + 15LL * f(1, n - i)) % P;
	printf("%d", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)
#define INF 10e9
#define PI acos(-1)
bool cmp(const pair<int, int>& a, const pair<int, int>& b){
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
    return true;
}
int main() {
    ll n; cin >> n;
    vector<P> ball(n+1);
    EFOR(i,1,n) cin >> ball[i].first >> ball[i].second;
    sort(ball.begin(), ball.end(), cmp);
    // dp[i][j] : 色iのボールのうち,j=0なら一番左,
    //            j=1なら一番右のものと同じ位置にいて,
    //            色iのボールは全て回収し終わった状態になるまでの最小の時間
    vector<vector<ll>> dp(n+1, vector<ll>(2,INF));
    ll pr=0, pl=0;
    dp[0][0] = 0,dp[0][1] = 0;
    int index = 1;
    for(int i = 1; i <= n;){
        int j = i;
        ll l = ball[i].first, r = ball[i].first;
        for(;j <= n && ball[i].second == ball[j].second; j++) r = ball[j].first;

        ll tmp;
        if(pl > r) tmp = pl - l;
        else tmp = r - pl + r - l;
        dp[index][0] = dp[index-1][0] + tmp;
        if(pr > r) tmp = pr - l;
        else tmp = r - pr + r - l;
        dp[index][0] = min(dp[index][0], dp[index-1][1] + tmp);

        if(pr < l) tmp = r - pr;
        else tmp = pr - l + r - l;
        dp[index][1] = dp[index-1][1] + tmp;
        if(pl < l) tmp = r - pl;
        else tmp = pl - l + r - l;
        dp[index][1] = min(dp[index][1],dp[index-1][0] + tmp);

        pr = r;
        pl = l;
        index++;
        i = j;
    }
    cout << min(dp[index-1][0] +abs(pl), dp[index-1][1] +abs(pr)) << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define f(i,a,b) for(int i = a; i < b; i++)
#define fa(i,a,b) for(int i = a; i >= b; i--)
const int inf=1e9+10;
const ll N=1e5+5;
const ll mod=1e9+7;

int a[5];
int main(){
    cin >> a[1] >> a[2] >> a[3];
    sort(a+1,a+4);
    cout << a[2]+a[3] << endl;

    return 0;
}


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

// ap + bq = gcd(a, b) なる (p, q) を求め d = gcd(a, b) を返す
ll extgcd(const ll a, const ll b, ll &p, ll &q){
    if (b==0) { p=1; q=0; return a; }
    ll d = extgcd(b, a%b, q, p);
    q -= a/b * p;
    return d;
}

// x mod s = a, x mod t = b なる x >= 0 の最小値を求める。存在しなければ -1
ll solve(const ll a, const ll b, const ll s, const ll t){
    ll p, q;
    const ll d = extgcd(s, t, p, q);
    if ((a-b) % d != 0) return -1;
    const ll ret = a + s * (((b - a) / d * p) % (t / d));
    const ll s_lcm_t = s * t / d;
    return (ret % s_lcm_t + s_lcm_t) % s_lcm_t;
}

int main(){
    int t;
    cin >> t;
    for(int ti=0; ti<t; ++ti){
        ll x, y, p, q;
        cin >> x >> y >> p >> q;
        ll ret = -1;
        for(ll yi = 0; yi < y; ++yi){
            for(ll qi = 0; qi < q; ++qi){
                const ll v = solve(x + yi, p + qi, (x + y) * 2, p + q);
                if (v >= 0){
                    if(ret == -1){
                        ret = v;
                    }else{
                        ret = min(ret, v);
                    }
                }
            }
        }
        if(ret == -1){
            cout << "infinity" << endl;
        }else{
            cout << ret << endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define IFOR(i, a, b) for (long long i = (a); i <= (long long)(b); i++)
using namespace std;
using VL = vector<long long>;
using ll = int64_t;
ll mod(ll x,ll m){ll y=x%m;return (y>=0LL)?y:y+m;}
template<class T>bool chmin(T& a, T b){if(a>b){a=b;return true;}else return false;}
ll gcd(ll a,ll b,ll& x,ll& y)
{if(a){ll d=gcd(b%a,a,x,y);y-=(b/a)*x;swap(x,y);if(d<0LL){d=-d;x=-x;y=-y;}return d;}else{x=0;y=1;return b;}}

int main(){
    int T;
    cin>>T;
    string ans = "";
    REP(i,T){
        ll t = LLONG_MAX;
        ll X,Y,P,Q;
        scanf("%lld %lld %lld %lld",&X,&Y,&P,&Q);
        ll a=(X+Y)<<1, b=P+Q;
        ll x, y;
        ll d = gcd(a, -b, x, y);
        ll u = b/d, v = a/d;
        ll stop0=P-X, stop1=P-X+Q-1LL;
        ll wake0=P-X-Y+1LL, wake1=P-X;
        ll from=min(stop0, wake0), to=max(stop1, wake1);
        IFOR(z, from, to){
            if(mod(z,d)!=0LL)continue;
            if(stop0<=z && z<=stop1){
                chmin(t,a*mod(z/d*x,u)+X);
            }else{
                chmin(t, b*mod(z/d*y,v)+P);
            }
        }
        ans += (t==LLONG_MAX ? "infinity" : (to_string(t)))+"\n";
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define rrep(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename T>
void update_max(T& a, T b) {
    if (b > a) a = b;
}
template <typename T>
void update_min(T& a, T b) {
    if (b < a) a = b;
}
struct Tree {
    typedef int T;
    static constexpr T unit = 0;
    T f(T a, T b) { return a ^ b; }  // (any associative fn )
    vector<T> s;
    int n;
    Tree(int n = 0, T def = unit) : s(2 * n, def), n(n) {}
    void update(int pos, T val) {
        for (s[pos += n] = val; pos /= 2;)
            s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
    }
    T query(int b, int e) {  // query [ b , e)
        T ra = unit, rb = unit;
        for (b += n, e += n; b < e; b /= 2, e /= 2) {
            if (b % 2) ra = f(ra, s[b++]);
            if (e % 2) rb = f(s[--e], rb);
        }
        return f(ra, rb);
    }
};
int main() {
#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q, a;
    cin >> n >> q;
    Tree tree(n);
    rep(i, 0, n) {
        cin >> a;
        tree.update(i, a);
    }
    int t, x, y;
    rep(i, 0, q) {
        cin >> t >> x >> y;
        if (t == 1) {
            tree.update(x - 1, tree.s[x - 1 + tree.n] ^ y);
        } else {
            cout << tree.query(x - 1, y) << endl;
        }
    }
    return 0;
}

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

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

    int n;
    cin >> n;

    string c;
    cin >> c;

    char a[] = "BWR";
    for (int i = 0; i < n; i++) {
        c[i] = c[i] == a[0] ? 0 : c[i] == a[1] ? 1 : 2;
    }

    int t = 0, s = 0, r = 1;
    for (int i = 0; i < n; i++) {
        //comb(n - 1, i) * c[i];
        if (i > 0) {
            int a0 = n - i;
            int a1 = i;
            while (a0 % 3 == 0) a0 /= 3, s++;
            while (a1 % 3 == 0) a1 /= 3, s--;
            r *= a0;
            r %= 3;
            r *= a1;
            r %= 3;
        }
        int x = s > 0 ? 0 : r;
        if (n % 2 == 0 && x != 0) x ^= 3;
        t += x * c[i];
    }

    cout << a[t % 3] << endl;

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const double PI = 3.141592653589793238;
int main() {
  ll N, Q;
  cin >> N >> Q;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) cin >> A[i];
  for (ll q = 0; q < Q; ++q) {
    ll K;
    cin >> K;
    ll l = -1, r = (LLONG_MAX) / 2;
    while (r - l > 1) {
      ll m = (l + r) / 2;
      ll x = (upper_bound(A.begin(), A.end(), m) - A.begin());
      if (m - x >= K) r = m;
      else l = m;
    }
    cout << r << "\n";
  }
}

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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define pqi priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) vector<int> a(n+f);for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define printdecimal(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define mod (int)(1e9+7)
#define inf LLONG_MAX
#define OrderedSet tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int exp(int x,int y){int val=1;x=x%mod;while(y>0){if(y&1)val=(val*x)%mod;y=y>>1;x=(x*x)%mod;}return val;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}

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

	int n,q;
	cin>>n>>q;
	inp(a,n,0);
	vector<int> pre(n);
	pre[0]=a[0]-1;
	for(int i=1;i<n;i++)
		pre[i]=pre[i-1]+a[i]-a[i-1]-1;
	while(q--)
	{
		int k;
		cin>>k;
		auto it=lb(all(pre),k);
		if(it!=pre.end())
		{
			int pos=it-pre.begin();
			//cout<<a[pos]<<' '<<pre[pos]<<'\n';
			cout<<a[pos]-(pre[pos]-k+1)<<'\n';
		}
		else
			cout<<a[n-1]+k-pre[n-1]<<'\n';
	}
	return 0;
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<unsigned mod=998244353>struct fp {
   using uint=unsigned; uint v;
   static uint get_mod(){return mod;}
   int inv() const{
      int tmp,a=v,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0){x+=mod;} return x;
   }
   fp(ll x=0){init(x%mod+mod);}
   fp& init(uint x){v=(x<mod?x:x-mod); return *this;}
   fp operator-()const{return fp()-*this;}
   fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;}
   fp& operator+=(const fp& x){return init(v+x.v);}
   fp& operator-=(const fp& x){return init(v+mod-x.v);}
   fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;}
   fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;}
   fp operator+(const fp& x)const{return fp(*this)+=x;}
   fp operator-(const fp& x)const{return fp(*this)-=x;}
   fp operator*(const fp& x)const{return fp(*this)*=x;}
   fp operator/(const fp& x)const{return fp(*this)/=x;}
   bool operator==(const fp& x)const{return v==x.v;}
   bool operator!=(const fp& x)const{return v!=x.v;}
   friend istream& operator>>(istream& is,fp& x){is>>x.v; return is;}
   friend ostream& operator<<(ostream& os,const fp& x){os<<x.v; return os;}
}; using Fp=fp<>;
template<typename T>struct factorial {
   vector<T> Fact,Finv,Inv;
   factorial(int maxx){
      Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx);
      Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1;
      rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv();
      for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];}
   }
   T fact(int n,bool inv=0){if(n<0)return 0; return (inv?Finv[n]:Fact[n]);}
   T inv(int n){if(n<0)return 0; return Inv[n];}
   T nPr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(n-r,inv^1);}
   T nCr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(r,inv^1)*fact(n-r,inv^1);}
};

Fp memo[3010][3010];
bitset<3010> used[3010];
Fp rec(int n,int k){
   if(n<k)return 0;
   if(used[n][k])return memo[n][k];
   used[n][k]=1;
   if(k==0){
      return memo[n][k]=(n==0);
   }
   return memo[n][k]=rec(n-1,k-1)+rec(n,k*2);
}

int main(){
   int n,k;
   cin>>n>>k;
   cout<<rec(n,k)<<'\n';
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
typedef long long int ll;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n, m; cin >> n >> m;
	ll a[n][m];
	ll mi = 9999;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
			sum += a[i][j];
			mi = min(mi, a[i][j]);
		}
	}
	cout << sum - mi*(n * m);
}

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

int main(){
    int N; cin >> N;
    ll left[N+1],right[N+1]; bool col[N+1];
    rep(i,N+1){
        left[i] = 1000000001;
        right[i] = -1000000001;
        col[i] = false;
    }
    rep(i,N){
        ll x,c; cin >> x >> c;
        col[c] = true;
        left[c] = min(left[c],x);
        right[c] = max(right[c],x);
    }
    ll s1 = 0,s2 = 0;
    ll dp[N+1][2];
    rep(i,2){
        rep(j,N+1){
            dp[j][i] = 200000000000000000;
        }
    }
    dp[0][0] = 0; dp[0][1] = 0;
    rep(i,N){
        if(!col[i+1]){
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1]; continue;
        }
        ll len = right[i+1]-left[i+1];
        dp[i+1][0] = min(dp[i][0]+abs(s1-right[i+1]),dp[i][1]+abs(s2-right[i+1]));
        dp[i+1][1] = min(dp[i][0]+abs(s1-left[i+1]),dp[i][1]+abs(s2-left[i+1]));
        s1 = left[i+1]; s2 = right[i+1];
        dp[i+1][0] += len; dp[i+1][1] += len;
    }
    cout << min(dp[N][0]+abs(s1),dp[N][1]+abs(s2)) << endl;
}


#include <bits/stdc++.h>
// ifブロックはインデントがいる
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using PP = pair<ll, P>;

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

vector<vector<ll> > g, dist;
vector<vector<vector<ll>>> predicted_cost;
vector<vector<P>> pre;
const ll h = 30, w = 30;

void dijkstra(int sx, int sy) {
    dist = vector<vector<ll> >(h, vector<ll>(w, INF));
    pre = vector<vector<P> >(h, vector<P>(w, P(-1, -1)));
    dist[sx][sy] = 0;
    priority_queue<PP, vector<PP>, greater<PP> > pq;
    pq.push(PP(0, P(sx, sy)));

    while (!pq.empty()) {
        PP p = pq.top();
        pq.pop();
        ll c = p.first;
        ll vx = p.second.first, vy = p.second.second;

        rep(i, 4) {
            ll nx, ny;
            nx = vx + dx[i], ny = vy + dy[i];
            if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
            if (dist[nx][ny] <= g[nx][ny] + c) continue;
            dist[nx][ny] = g[nx][ny] + c;
            pre[nx][ny] = P(vx, vy);
            pq.push(PP(dist[nx][ny], P(nx, ny)));
        }
    }
}

vector<P> restore(ll tx, ll ty) {
    vector<P> path;
    ll x, y;
    for (; tx != -1 || ty != -1; tx = pre[x][y].first, ty = pre[x][y].second) {
        path.push_back(P(tx, ty));
        x = tx, y = ty;
    }
    reverse(path.begin(), path.end());

    return path;
}

char compare_pos(P s, P t) {
    if (s.first < t.first)
        return 'D';
    if (s.first > t.first)
        return 'U';
    if (s.second < t.second)
        return 'R';
    if (s.second > t.second)
        return 'L';
}

ll vector_average(vector<ll> &cost){
    ll sum = accumulate(all(cost),0LL);
    return sum / cost.size();
}

//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    g.resize(30);
    predicted_cost.resize(30);
    rep(i, 30) {
        g[i].resize(30);
        predicted_cost[i].resize(30);
        rep(j, 30) g[i][j] = 6000;
    }

    rep(q,1000){
        P s,t;
        cin >> s.first >> s.second >> t.first >> t.second;
        dijkstra(s.first, s.second);
        auto rstr = restore(t.first, t.second);
        rep(i, rstr.size() - 1) { cout << compare_pos(rstr[i], rstr[i + 1]); }
        cout << endl;
        ll len;
        cin >> len;
        if(rstr.size())len /= rstr.size();
        rep(i, rstr.size() - 1) {
            predicted_cost[rstr[i].first][rstr[i].second].push_back(len);
            if(q > 100)g[rstr[i].first][rstr[i].second] = vector_average(predicted_cost[rstr[i].first][rstr[i].second]);
        }
    }
    return 0;
}

/*グラフ情報とは別に、パス長からの平均を順次格納していった2+1次元の配列をやりながら、その平均値を取って暫定の頂点間距離にするといい感じに収束していくのでは
-> 84163614602

パス長から乱数パラメーターのV_ip,H_ipを求められれば道のコストの尤度が大きくなって幸せになる

クエリの点数計算式 round(2312311 * \sigma_{k=1}^1000 {0.998^{1000-k} * a_k / b_k})から、序盤より後半のak / bkが重視される
序盤でより正確な道のコストを求められれば点数の改善ができる
パスに関して、M=1のときはパスの評価値に平均を使えるけど、M=2のときはyj(ramdom)によって[0,yj),[yj,2]

*/

#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a,const T b){bool x=a>b;if(x)a=b;return x;}
constexpr int inf=1<<30;

double tate[29][30],yoko[30][29];
double dist[30][30];
int tateaccu[29][30],yokoaccu[29][30];
bool vis[30][30];
char rev[30][30];

using P=tuple<double,int,int>;
void solve(int sx,int sy,int ex,int ey){
  for(int i=0;i<30;++i)for(int j=0;j<30;++j){
    dist[i][j]=inf;
    vis[i][j]=false;
  }
  auto func=[](P& l,P& r){return get<0>(l)>get<0>(r);};
  priority_queue<P,vector<P>,decltype(func)> que(func);
  que.emplace(0,sx,sy);
  dist[sx][sy]=0;
  while(!que.empty()){
    double d;int i,j;
    tie(d,i,j)=que.top();que.pop();
    if(vis[i][j])continue;
    vis[i][j]=true;
    if(i>0&&chmin(dist[i-1][j],d+tate[i-1][j])){
      rev[i-1][j]='U';
      que.emplace(d+tate[i-1][j],i-1,j);
    }
    if(i<29&&chmin(dist[i+1][j],d+tate[i][j])){
      rev[i+1][j]='D';
      que.emplace(d+tate[i][j],i+1,j);
    }
    if(j>0&&chmin(dist[i][j-1],d+yoko[i][j-1])){
      rev[i][j-1]='L';
      que.emplace(d+yoko[i][j-1],i,j-1);
    }
    if(j<29&&chmin(dist[i][j+1],d+yoko[i][j])){
      rev[i][j+1]='R';
      que.emplace(d+yoko[i][j],i,j+1);
    }
  }
  string ans;
  while(sx!=ex||sy!=ey){
    ans+=rev[ex][ey];
    if(rev[ex][ey]=='U')++ex;
    else if(rev[ex][ey]=='D')--ex;
    else if(rev[ex][ey]=='L')++ey;
    else --ey;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<'\n';
  int dd;
  cin>>dd;
  double d=double(dd)/double(ans.size());
  for(auto x:ans){
    if(x=='U'){
      --sx;
      if(tateaccu[sx][sy]*2>ans.size()){
        tateaccu[sx][sy]=ans.size();
        tate[sx][sy]=d;
      }
    }
    if(x=='D'){
      if(tateaccu[sx][sy]*2>ans.size()){
        tateaccu[sx][sy]=ans.size();
        tate[sx][sy]=d;
      }
      ++sx;
    }
    if(x=='L'){
      --sy;
      if(yokoaccu[sx][sy]*2>ans.size()){
        yokoaccu[sx][sy]=ans.size();
        yoko[sx][sy]=d;
      }
    }
    if(x=='R'){
      if(yokoaccu[sx][sy]*2>ans.size()){
        yokoaccu[sx][sy]=ans.size();
        yoko[sx][sy]=d;
      }
      ++sy;
    }
  }
}
int main(){
  for(int i=0;i<29;++i)for(int j=0;j<30;++j){
    tate[i][j]=4500;
    tateaccu[i][j]=inf/2;
  }
  for(int i=0;i<30;++i)for(int j=0;j<29;++j){
    yoko[i][j]=4500;
    yokoaccu[i][j]=inf/2;
  }
  for(int k=0;k<1000;++k){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    solve(a,b,c,d);
  }
}


#include<cstdio>
#include<cstring>

#define int long long

const int N=105,MOD=998244353;

int n;
int w[N];
int f[N][N*N],fac[N],ans;

signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",w+i);
		w[0]+=w[i];
	}
	fac[0]=1;
	for(int i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%MOD;
	if(w[0]%2)
		printf("0\n");
	else
	{
		w[0]/=2;
	//	printf("%lld\n",w[0]);
		f[0][0]=1;
		for(int i=1;i<=n;++i)
			for(int j=w[0];j>=0;--j)
				for(int k=1;k<=i;++k)
					if(j>=w[i])
						f[k][j]=(f[k][j]+f[k-1][j-w[i]])%MOD;
		for(int k=1;k<n;++k)
		{
	//		printf("%lld\n",f[k][w[0]]);
			ans=(ans+f[k][w[0]]*fac[k]%MOD*fac[n-k]%MOD)%MOD;
		}
		printf("%lld\n",ans);
	}

	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <bitset>
#include <map>
// #include <bits/stdc++.h>
uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
constexpr int MAX=510000;

ll fact[MAX], fact_inv[MAX];

// 繰り返し二乗法
ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll comb(ll n, ll r){
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

/*
std::vector<std::vector<long long>> comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}
*/

int main(void) {
  int N;
  cin >> N;
  vector<long long> A(N, 0);
  fact[0]=1;

  // input
  for (int i = 0; i < N; i++) cin >> A[i];
  long long ans = 0;

  // 200で割ったあまりにする
  for (int i = 0; i < N; i++) {
    A[i] = A[i] % 200;
  }
  // 種類の数え上げ
  map<long long, long long> mp;
  for (int i = 0; i < N; i++) {
    // 存在する
    if ( auto iter = mp.find(A[i]); iter != end(mp) ) {
      // std::cout << iter->second << std::endl;
      mp[A[i]] += 1;
    } else {
      // std::cout << "not exists" << std::endl;
      mp[A[i]] = 1;
    }
  }

  // さらにまとめる
  map<long long, long long> mp2;
  for (const auto& [key, value] : mp){
    // 存在する
    if ( auto iter = mp2.find(value); iter != end(mp2) ) {
      // std::cout << iter->second << std::endl;
      mp2[value] += 1;
    } else {
      // std::cout << "not exists" << std::endl;
      mp2[value] = 1;
    }
  }

  for (const auto& [key, value] : mp2){
    // std::cout << key << " => " << value << "\n";
  }

  for (const auto& [key, value] : mp2){
    if (key > 1) {
      // std::cout << key << " => " << value << "\n";
      // cout << comb(value, 2)[value][2] << endl;
      ans += combination(key, 2) * value;
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < n; ++i)
using C = complex<double>;
const ll md = 1000000007;

int main(){
  int n;
  cin >> n;
  cout << n - 1 << endl;
  return 0;
}

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

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

    vector<ll> a;
    for(ll i=2;i<=n;i++){
        a.emplace_back(i);
    }
    rep(i,(int)a.size()-1) rep(j,(int)a.size()-1){
        a[j] = a[j]/__gcd(a[j],a[j+1])*a[j+1];
    }

    printf("%lld\n", a[0]+1);
}


//#include <atcoder/all>
#include <bits/stdc++.h>
#include <cassert>
#include <numeric>
using namespace std;
//using namespace atcoder;
typedef  long long LONG;
const int MOD = 1000000007;

int gcd(int x, int y) {
	if (x % y == 0) {
		return y;
	}
	else {
		return gcd(y, x % y);
		//x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。
	}
}
LONG pow2(long long x, long long n) {
	long long ret = 1;
	while (n > 0) {
		if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
		x = x * x % MOD;
		n >>= 1;  // n を1bit 左にずらす
	}
	return (int)ret;
}
void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}
LONG t(LONG N,LONG i) {
	return N - abs(i);
}
int count(vector<int>&a, int s) {
	int result = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == s) {
			result++;
		}
	}
	return result;
}

LONG kaizyo(int N) {
	LONG result = 1;
	LONG mod = 998244353;

	for (LONG i = 2; i <= N; i++) {
		result *= i;
		result = result % mod;
	}
	return result;
}
class Point {
public:
	int x;
	int y;
};
LONG stock[3500][3500];
LONG test(int N, int task) {
	LONG mod = 998244353;
	if (N < task)return 0;
	if (N < 0)return 0;
	if (task == 0) {
		if (N == 0) {
			return 1;
		}
		else {
			return 0;
		}

	}

	if (stock[N][task] > 0)return stock[N][task];
	stock[N][task] =( test(N - 1, task - 1) + test(N, task * 2)) % mod;

	return stock[N][task]%mod ;
}
class DP {
public:
	DP() {

	}
	DP(int a, int b) {
		other = a;
		path = b;

	}
	int other;
	int path;
};

void dp(vector<vector<DP>>& list, vector<int> &able, int pos,int limit) {
	for (int i = 0; i < list[pos].size(); i++) {
		if (list[pos][i].path <= limit) {
			if (able[list[pos][i].other] == 0) {
				able[list[pos][i].other] = 1;
				dp(list, able, list[pos][i].other, limit);
			}
		}
	}
}
int main() {

	LONG N;
	cin >> N;
	vector<Point>P(N);
	for (int i = 0; i < N; i++) {
		cin >>P[i].x>>P[i].y;
	}
	vector<vector<DP>>d(N+2, vector<DP>(0));

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

			int r = (P[i].x - P[j].x)*(P[i].x - P[j].x) + (P[i].y - P[j].y)*(P[i].y - P[j].y);
			if (r < 40000) {
				d[i+2].push_back(DP(j+2, r));
				d[j+2].push_back(DP(i+2, r));
			}
		}
	}
	for (int i = 0; i < N; i++) {
		d[i+2].push_back(DP(0, (100-P[i].y)* (100 - P[i].y)));
		d[0].push_back(DP(i+2, (100 - P[i].y)*(100-P[i].y)));
	}
	for (int i = 0; i < N; i++) {
		d[i + 2].push_back(DP(1, (-100 - P[i].y)* (-100 - P[i].y)));
		d[1].push_back(DP(i + 2, (-100 - P[i].y)* (-100 - P[i].y)));
	}
	d[0].push_back(DP(1, 40000));
	d[1].push_back(DP(0, 40000));
	int max = 40000;
	int min = 0;
	int mid = (max) / 2;
	while (max - min > 1) {
		bool frag = false;
		vector<int> able(N + 2, 0 );//未到達は0、到達は1
		able[0] = 1;
		dp(d, able, 0, mid);
		if (able[1] == 1) {
			max = mid;
			mid = (max + min) / 2;
		}else{
			min = mid;
			mid = (max + min) / 2;
		}
//		cout << max<<"\t" << min << "\t" << mid << "\n";
	}
	cout << std::fixed << std::setprecision(15) << sqrt(mid+1)/2.0;

	return 0;
}

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ch() getchar()
#define pc(x) putchar(x)
using namespace std;
template<typename T>void read(T&x){
	char c;int f;
	for(c=ch(),f=1;c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c>='0'&&c<='9';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>void write(T x){
	static char q[64];int cnt=0;
	if(x==0)return pc('0'),void();
	if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10,x/=10;
	while(cnt--)pc(q[cnt]+'0');
}
const int maxn=105;
struct Node{
	int v,w;
	Node(int v=0,int w=0):
		v(v),w(w){}
	bool operator < (const Node o)const{
		return w<o.w;
	}
}hp[maxn*maxn*2];
int sz;
void push(Node x){
	int no=++sz;
	while(no>1&&x<hp[no>>1])
		hp[no]=hp[no>>1],no>>=1;
	hp[no]=x;
}
void pop(void){
	swap(hp[1],hp[sz--]);
	int no=1,nt=2;Node x=hp[1];
	while(nt<=sz){
		if((nt|1)<=sz&&hp[nt|1]<hp[nt])nt|=1;
		if(hp[nt]<x)hp[no]=hp[nt];else break;
		no=nt;nt<<=1;
	}
	hp[no]=x;
}
int top(void){
	return hp[1].v;
}
struct Edge{
	int v,w,nt;
	Edge(int v=0,int w=0,int nt=0):
		v(v),w(w),nt(nt){}
}e[maxn*maxn*2];
int hd[maxn],num;
void qwq(int u,int v,int w){
	e[++num]=Edge(v,w,hd[u]),hd[u]=num;
}
void qvq(int u,int v,int w){
	qwq(u,v,w);qwq(v,u,w);
}
int sq(int x){
	return x*x;
}
int dis[maxn],vis[maxn],x[maxn],y[maxn];
int main(){
	int n;read(n);
	int S=n+1,T=S+1;
	qvq(S,T,sq(200));
	for(int i=1;i<=n;++i){
		read(x[i]),read(y[i]);
		qvq(S,i,sq(y[i]+100));
		qvq(i,T,sq(100-y[i]));
		for(int j=1;j<i;++j){
			qvq(i,j,sq(x[i]-x[j])+sq(y[i]-y[j]));
		}
	}
	memset(dis,0x3f,sizeof dis);
	push(Node(S,dis[S]=0));
	while(sz){
		int u=top();pop();
		if(vis[u])continue;vis[u]=true;
		for(int i=hd[u];i;i=e[i].nt){
			int v=e[i].v,w=max(dis[u],e[i].w);
			if(dis[v]>w)push(Node(v,dis[v]=w));
		}
	}
	printf("%.20f\n",sqrt(dis[T])/2.0);
	return 0;
}
/*
所以，永远不要问丧钟为谁而鸣，它为你而鸣。
*/


#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>
#include <iomanip>
#include <limits>
#include<tuple>
#include<algorithm>
#include<set>

using namespace std;
typedef long long int ll;
// ll
int main(){
    string s;
    cin >> s;
    // vector<pair<int,char>> block(26,{-1,'0'});
    int mae=(-1);
    ll point=0;
    char ima='0';
    for(int i=0;i<s.size()-1;i++){
        if(s.at(i)==s.at(i+1) && s.at(i)!=ima){
            if(mae!=(-1))point+=(s.size()-i);
            mae=i;
            ima=s.at(i);
        }else{
            if(ima!='0'){
                if(ima!=s.at(i)){
                    point++;
                }
            }
        }
    }
    if(s.at(s.size()-1)!=ima && ima!='0')point++;
    cout << point << endl;
    return 0;
}

#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("popcnt,abm,mmx,avx2")
#endif
#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define rep(i, l, r) for (int i = l; i < r; ++i)
using Long = long long;
using Double = double;
using vi = vector<int>;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#else
#define endl '\n'
#endif

  string s;
  cin >> s;
  Long res = 0;
  vector<int> cnt(26);
  for (int i = sz(s) - 1; i >= 0; --i) {
    ++cnt[s[i] - 'a'];
    if (i + 1 < sz(s) && s[i] == s[i + 1]) {
      res += sz(s) - i - cnt[s[i] - 'a'];
      cnt.assign(26, 0);
      cnt[s[i] - 'a'] = sz(s) - i;
    }
  }
  cout << res << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, w;
    cin >> a >> b >> w;
    int m = 1e9, M = 0;
    for (int n = 1; n <= 1000000; n++)
    {
        if (a * n <= 1000 * w && 1000 * w <= b * n)
        {
            m = min(m, n);
            M = max(M, n);
        }
    }
    if (M == 0)
        cout << "UNSATISFIABLE";
    else
        cout << m << ' ' << M;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	char a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c){
		cout<<"Won";
	}
	else cout<<"Lost";
}


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

using ll = int64_t;
using vi = vector<int>;
using vb = vector<bool>;

using si = set<int>;

#define pb push_back

#define ist insert

#define sz(x) int((x).size())

#define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i))

vector<si> adj(20);
vi comp, colors(20, -1); vb done(20);
ll ans = 1, temp = 0;

void check() {
    bool ok = true;
    ice(i, 0, sz(comp)) {
        ice(j, i + 1, sz(comp)) {
            if (adj[comp[i]].count(comp[j])) {
                ok &= (colors[i] != colors[j]);
            }
            if (!ok) {
                return;
            }
        }
    }
    temp++;
}

void color(int idx) {
    if (idx == sz(comp)) {
        check();
        return;
    }
    if (!idx) {
        colors[0] = 0;
        color(1);
        colors[0] = -1;
        colors[0] = 1;
        color(1);
        colors[0] = -1;
        colors[0] = 2;
        color(1);
        colors[0] = -1;
    }
    else {
        ice(i, 0, idx) {
            if (adj[comp[idx]].count(comp[i])) {
                if (colors[i] != 0) {
                    colors[idx] = 0;
                    color(idx + 1);
                    colors[idx] = -1;
                }
                if (colors[i] != 1) {
                    colors[idx] = 1;
                    color(idx + 1);
                    colors[idx] = -1;
                }
                if (colors[i] != 2) {
                    colors[idx] = 2;
                    color(idx + 1);
                    colors[idx] = -1;
                }
                return;
            }
        }
    }
}

void cnt() {
    if (ans) {
        color(0);
    }
    ans *= temp; temp = 0;
}

void dfs(int n) {
    if (done[n]) {
        return;
    }
    done[n] = true;
    comp.pb(n);
    for (int m : adj[n]) {
        dfs(m);
    }
}

void solve() {
    int n, m; cin >> n >> m;
    ice(i, 0, m) {
        int a, b; cin >> a >> b; a--; b--;
        adj[a].ist(b); adj[b].ist(a);
    }
    ice(i, 0, n) {
        if (!done[i]) {
            dfs(i);
            cnt();
            vi().swap(comp);
            vi(20, -1).swap(colors);
        }
    }
    cout << ans;
}

int main() {
    int tc = 1;
    ice(i, 0, tc) {
        solve();
    }
}

//                        YATIN KWATRA

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

#define ll                      long long
#define ar                      array
#define sz(v)                   (int)(v.size())
#define inf                     1e18
#define int                     ll
#define FIO                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld                      long double
#define ull                     unsigned long long
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define pq                      priority_queue
#define uomii                   unordered_map<int,int,best_hash>
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define mod                     1000000007
#define MIN                     -1e9
#define pi                      3.1415926535897932384626433832795
#define cz(x)                   63 - __builtin_clzll(x)

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct best_hash {
	static uint64_t splitmix64(uint64_t x) {

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

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

/*
----------------------------------------------------------------
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
----------------------------------------------------------------
*/

const int N = 20;
vii v[N];
int jude[N][N];
int col[N];
bool found;

void dfs(int node, int par, int c) {
	col[node] = c;
	for (auto &i : v[node]) {
		if (found) return;
		if (i == par or col[i] == 3) continue;
		if (!col[i]) dfs(i, node, 3 - c);
		else if (col[i] == c) {
			found = 1;
			return;
		}
	}
}
int n;

bool valid(int mask) {

	fo(i, 0, n - 1) {
		fo(j, i + 1, n - 1) {
			if (mask & (1 << i) and mask & (1 << j) and jude[i][j]) return 0;
		}
	}
	return 1;
}

void solve()
{
	int m;
	cin >> n >> m;
	while (m--) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		jude[x][y] = jude[y][x] = 1;
		v[x].pb(y);
		v[y].pb(x);
	}

	int ans = 0;

	fo(mask, 0, (1 << n) - 1) {
		if (!valid(mask)) continue;

		fo(i, 0, n - 1) {
			if (mask & (1 << i)) col[i] = 3;
			else col[i] = 0;
		}
		int cnt = 1;
		fo(i, 0, n - 1) {
			if (!col[i]) {
				found = 0;
				dfs(i, i, 1);
				if (found) {
					cnt = 0;
					break;
				}
				else cnt *= 2;
			}
		}
		ans += cnt;
	}

	cout << ans;
}

signed main() {

	FIO
	INPUT();

	int t;
	t = 1;
	//cin >> t;
	fo(i, 0, t - 1) {
		solve();
	}
	return 0;
}


//I'll always miss you like a darling.
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define ull unsigned long long
#define x first
#define y second
#define pb push_back
#define pf push_front
#define mp make_pair
#define Pair pair<int,int>
#define pLL pair<LL,LL>
#define pii pair<double,double>
#define LOWBIT(x) x & (-x)

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

const int INF=2e9;
const LL LINF=2e16;
const int magic=348;
const int MOD=1e9+7;
const double eps=1e-10;
const double pi=acos(-1);

struct fastio
{
    static const int S=1e7;
    char rbuf[S+48],wbuf[S+48];int rpos,wpos,len;
    fastio() {rpos=len=wpos=0;}
    inline char Getchar()
    {
        if (rpos==len) rpos=0,len=fread(rbuf,1,S,stdin);
        if (!len) return EOF;
        return rbuf[rpos++];
    }
    template <class T> inline void Get(T &x)
    {
        char ch;bool f;T res;
        while (!isdigit(ch=Getchar()) && ch!='-') {}
        if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
        while (isdigit(ch=Getchar())) res=res*10+ch-'0';
        x=(f?res:-res);
    }
    inline void getstring(char *s)
    {
        char ch;
        while ((ch=Getchar())<=32) {}
        for (;ch>32;ch=Getchar()) *s++=ch;
        *s='\0';
    }
    inline void flush() {fwrite(wbuf,1,wpos,stdout);fflush(stdout);wpos=0;}
    inline void Writechar(char ch)
    {
        if (wpos==S) flush();
        wbuf[wpos++]=ch;
    }
    template <class T> inline void Print(T x,char ch)
    {
        char s[20];int pt=0;
        if (x==0) s[++pt]='0';
        else
        {
            if (x<0) Writechar('-'),x=-x;
            while (x) s[++pt]='0'+x%10,x/=10;
        }
        while (pt) Writechar(s[pt--]);
        Writechar(ch);
    }
    inline void printstring(char *s)
    {
        int pt=1;
        while (s[pt]!='\0') Writechar(s[pt++]);
    }
}io;

template<typename T> inline void check_max(T &x,T cmp) {x=max(x,cmp);}
template<typename T> inline void check_min(T &x,T cmp) {x=min(x,cmp);}
template<typename T> inline T myabs(T x) {return x>=0?x:-x;}
template<typename T> inline T mygcd(T x,T y) {return y==0?x:mygcd(y,x%y);}
inline int add(int x) {if (x>=MOD) x-=MOD;return x;}
inline int add(int x,int MO) {if (x>=MO) x-=MO;return x;}
inline int sub(int x) {if (x<0) x+=MOD;return x;}
inline int sub(int x,int MO) {if (x<0) x+=MO;return x;}
inline void Add(int &x,int y) {x=add(x+y);}
inline void Add(int &x,int y,int MO) {x=add(x+y,MO);}
inline void Sub(int &x,int y) {x=sub(x-y);}
inline void Sub(int &x,int y,int MO) {x=sub(x-y,MO);}
template<typename T> inline int quick_pow(int x,T y) {int res=1;while (y) {if (y&1) res=1ll*res*x%MOD;x=1ll*x*x%MOD;y>>=1;}return res;}
template<typename T> inline int quick_pow(int x,T y,int MO) {int res=1;while (y) {if (y&1) res=1ll*res*x%MO;x=1ll*x*x%MO;y>>=1;}return res;}

const int MAXN=2000;

int n,a[MAXN+48];
unordered_map<int,int> Mp;

int main ()
{
#ifndef ONLINE_JUDGE
    double TIME=clock();
    freopen ("a.in","r",stdin);
    freopen ("a.out","w",stdout);
    cerr<<"Running..."<<endl;
#endif
    scanf("%d",&n);rep(i,1,n) scanf("%d",a+i);
    int minn=a[1];rep(i,2,n) check_min(minn,a[i]);
    rep(i,1,n) rep(j,1,int(sqrt(a[i]))) if (a[i]%j==0) Mp[j]=mygcd(Mp[j],a[i]),Mp[a[i]/j]=mygcd(Mp[a[i]/j],a[i]);
    int ans=0;for (auto item : Mp) if (item.x<=minn && item.x==item.y) ans++;
    printf("%d\n",ans);
#ifndef ONLINE_JUDGE
    cerr<<"Exec Time: "<<(clock()-TIME)/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0));
using Int = long long;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
int main() {
    int N; cin >> N;
    vector<int> V(2 * N); for (auto &v : V) cin >> v;
    MinHeap<int> heap;
    for (int i = N - 1; i >= 0; i--) {
        int a = i;
        int b = 2 * N - 1 - i;
        if (V[a] > V[b]) {
            heap.emplace(V[a]);
            if (!heap.empty() && V[b] > heap.top()) {
                heap.pop();
                heap.emplace(V[b]);
            }
        } else {
            heap.emplace(V[b]);
            if (!heap.empty() && V[a] > heap.top()) {
                heap.pop();
                heap.emplace(V[a]);
            }
        }
    }
    Int ans = 0;
    while (!heap.empty()) {
        ans += heap.top();
        heap.pop();
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {

ll N,M;
cin >> N >> M;

vector<ll> aa((1+N)/2);
vector<ll> bb((1+N)/2);

vector<ll> hh(N);
vector<ll> ww(M);

for(ll i=0;i<N;i++) cin >> hh[i];

for(ll i=0;i<M;i++) cin >> ww[i];

sort(ALL(hh));
ll ans=INF;

aa[0]=0;
for(ll i=1;i<(N+1)/2;i++){
aa[i]=aa[i-1]+hh[2*i-1]-hh[2*i-2];
}

for(ll i=(N-2)/2;i>=0;i--){
bb[i]=bb[i+1]+hh[2*i+2]-hh[2*i+1];
}

for(auto gg : ww){
ll x=lower_bound(ALL(hh),gg)-hh.begin();
 if(x & 1) x^=1;
 chmin(ans,aa[x/2]+bb[x/2]+abs(gg-hh[x]));

}

cout << ans << endl;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pdd;

#define lc u << 1
#define rc u << 1 | 1
#define mid (t[u].l + t[u].r) / 2
#define INF 0x3f3f3f3f
#define lowbit(x) x & (-x)
#define mem(a, b) memset(a , b , sizeof(a))
#define FOR(i, x, n) for(int i = x;i <= n; i++)

// const ll mod = 998244353;
// const ll mod = 1e9 + 7;
// const double eps = 1e-6;
// const double PI = acos(-1);
// const double R = 0.57721566490153286060651209;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<ll> v1(n + 1), v2(m + 1);
    for(int i = 1;i <= n; i++) cin >> v1[i];
    for(int i = 1;i <= m; i++) cin >> v2[i];
    sort(v1.begin() + 1, v1.end());
    vector<ll> pre(n + 2), suf(n + 2);
    for(int i = 2;i <= n; i += 2) pre[i] = pre[i - 2] + abs(v1[i] - v1[i - 1]);
    for(int i = n - 1;i >= 1; i -= 2) suf[i] = suf[i + 2] + abs(v1[i + 1] - v1[i]);
    ll ans = 1e18;
    for(int i = 1;i <= m; i++) {
        int pos = lower_bound(v1.begin(), v1.end(), v2[i]) - v1.begin();
        if(pos % 2 == 0) pos--;
        ans = min(ans, (pre[pos - 1] + suf[pos + 1] + abs(v2[i] - v1[pos])));
    }
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr);
#ifdef FZT_ACM_LOCAL
//    int size=40<<20;
//    __asm__ ("movq %0,%%rsp\n"::"r"((char*)malloc(size)+size));
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    signed test_index_for_debug = 1;
    char acm_local_for_debug = 0;
    do {
        if (acm_local_for_debug == '$') exit(0);
        if (test_index_for_debug > 20)
            throw runtime_error("Check the stdin!!!");
        auto start_clock_for_debug = clock();
        solve();
        auto end_clock_for_debug = clock();
        cout << "Test " << test_index_for_debug << " successful" << endl;
        cerr << "Test " << test_index_for_debug++ << " Run Time: "
             << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
        cout << "--------------------------------------------------" << endl;
    } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
    solve();
#endif
    return 0;
}


#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;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
   #define print(a,n) f(i,0,n){cout<<a[i]<<" ";}
    #define pf push_front
    #define fi first
    #define se second
    #define ps(x,y)         fixed<<setprecision(y)<<x
    #define INF 1e10
    const double pi=3.14159265358979323;
    const int mod=998244353;
    const int MAX=1000000+5;
    int p[MAX]={0};

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

    }
    void swap(int &a,int& b)
    {
      int temp=a;
      a=b;
      b=temp;
    }
    int  binpow(int  a,int  b)
    {
    int res = 1;
    while (b > 0) {
        if (b%2 == 1)
            res = (res * a)%mod;
        a = (a* a)% mod;
        b >>= 1;
    }
    return res;
}
    int modinv(int y)
    {
        return binpow(y,mod-2);
    }

    int fact[500000+5];
    void precal()
    {
    fact[0]=1;
    for(int i=1;i<500000+5;i++)
    {
        fact[i]=(i*fact[i-1])%mod;
    }
}
    bool isPrime(int n)
    {
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
    }
    int mm[200000+5]={0};
    int pos[200000+5]={0};
    bool flag=true;
    int pr[200000+5]={0};
    vector<pair<int ,int>> vv;
    int vis[200000+5]={0};
     vector<vector<int >> adj;
     queue<int > q;
     int dfs(int j)
     {
        vis[j]=1;
        pos[j]=1;
        for(auto i:adj[j])
        {
            if(vis[i]==0)
            {
               pos[j]+=dfs(i);
            }
        }
        return pos[j];
     }
     /*void bfs(int j)
     {
        q.push(j);
        while(!q.empty())
        {
            int r=q.front();
            q.pop();
        for(auto i:adj[r])
        {
            if(vis[i]==0)
            {
                pr[i]=r;
                vis[i]=1;
                q.push(i);
            }
        }
        }
     }*/
    signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*#ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout);
      }
    #endif*/
    int t=1;
   // cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n][2];
        f(i,0,n)
        {
            cin>>a[i][0]>>a[i][1];
        }
        bool flag=false;
        f(i,0,n-2)
        {
            f(j,i+1,n-1)
            {
                f(k,j+1,n)
                {
                    if((a[k][0]-a[i][0])*(a[j][1]-a[i][1])==(a[k][1]-a[i][1])*(a[j][0]-a[i][0]))
                    {
                        flag=true;
                    }
                }
            }
        }
        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int x[200000], y[200000];

signed main() {
	int i;

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

	int xl = x[0], xr = x[0], yl = y[0], yr = y[0];
	int xlc = 0, xrc = 0, ylc = 0, yrc = 0;
	rep(i, n) xl = min(xl, x[i]);
	rep(i, n) xr = max(xr, x[i]);
	rep(i, n) yl = min(yl, y[i]);
	rep(i, n) yr = max(yr, y[i]);

	rep(i, n) if (xl == x[i]) xlc++;
	rep(i, n) if (xr == x[i]) xrc++;
	rep(i, n) if (yl == y[i]) ylc++;
	rep(i, n) if (yr == y[i]) yrc++;

	int cnt = 0;
	rep(i, n) {
		if (xl == x[i] && yl == y[i]) continue;
		if (xr == x[i] && yr == y[i]) continue;
		if (xl == x[i] || yl == y[i] || xr == x[i] || yr == y[i]) cnt++;
	}

	int ans = 0;
	if (xlc * xrc >= 2) ans = max(ans, xr - xl);
	if (ylc * yrc >= 2) ans = max(ans, yr - yl);
	if (cnt > 0) ans = max(ans, min(xr - xl, yr - yl));

	rep(i, n) if (x[i] != xr) ans = max(ans, x[i] - xl);
	rep(i, n) if (x[i] != xl) ans = max(ans, xr - x[i]);
	rep(i, n) if (y[i] != yr) ans = max(ans, y[i] - yl);
	rep(i, n) if (y[i] != yl) ans = max(ans, yr - y[i]);

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


#include <bits/stdc++.h>

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

const string YES = "Yes";
const string NO = "No";

const double PI = 3.14159265359;

struct Gi {
    ll a, b;

    explicit Gi(ll x = 0, ll y = 0) : a(x), b(y) {}

    Gi operator*(const Gi &other) const {
        return Gi(a * other.a - b * other.b, a * other.b + b * other.a);
    }

    Gi operator-(const Gi &other) const {
        return Gi(a - other.a, b - other.b);
    }

    bool operator<(const Gi &other) const {
        if (a == other.a) return b < other.b;
        return a < other.a;
    }

    bool operator>(const Gi &other) const {
        if (a == other.a) return b > other.b;
        return a > other.a;
    }

    bool operator==(const Gi &other) const {
        return a == other.a && b == other.b;
    }

    [[nodiscard]] ll norm() const {
        return a * a + b * b;
    }
};

Gi inC() {
    ll a, b;
    cin >> a >> b;
    return Gi(a, b);
}

vector<Gi> cnv(vector<Gi> pos, Gi origin, Gi rad, int N) {
    rep(i, N) pos.at(i) = pos.at(i) - origin;
    rep(i, N) pos.at(i) = pos.at(i) * rad;
    sort(all(pos));
    return pos;
}

int main() {
    int N;
    cin >> N;
    vector<Gi> p(N), q(N);
    rep(i, N) p.at(i) = inC();
    rep(i, N) q.at(i) = inC();

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

    rep(i, N) {
        rep(j, N) {
            if (i == j) continue;
            if ((p.at(1) - p.at(0)).norm() != (q.at(j) - q.at(i)).norm()) continue;

            vector<Gi> xa = cnv(p, p.at(0), q.at(j) - q.at(i), N);
            vector<Gi> xb = cnv(q, q.at(i), p.at(1) - p.at(0), N);

            if (xa == xb) {
                cout << YES << endl;
                return 0;
            }
        }
    }

    cout << NO << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct Vec {
    ll x, y;
    Vec(ll _x = 0, ll _y = 0) : x(_x), y(_y) {}
    Vec operator-(const Vec &o) const {
        return {x - o.x, y - o.y};
    }
    Vec operator+(const Vec &o) const {
        return {x + o.x, y + o.y};
    }
    Vec operator*(const ll k) const {
        return {x * k, y * k};
    }
    ll operator^(const Vec &o) const {
        return x * o.y - o.x * y;
    }
    ll operator*(const Vec &o) const {
        return x * o.x + y * o.y;
    }
    bool operator==(const Vec &o) const {
        return x == o.x and y == o.y;
    }
    bool operator!=(const Vec &o) const {
        return !operator==(o);
    }
    bool upper() const {
        return x > 0 or (x == 0 and y >= 0);
    }
	int quad() const {
		if(x > 0 && y >=0) return 0;
		if(x <=0 && y > 0) return 1;
		if(x < 0 && y <=0) return 2;
		return 3;
	}
    bool operator<(const Vec &o) const {
        if(quad() != o.quad()) return quad() < o.quad();
        auto res = operator^(o);
        if(res) return res > 0;
        return (*this) * (*this) < o * o;
    }
};

vector<int> prefix_function(const auto &s) {
    int n = (int)s.size(); vector<int> b(n+1);
    b[0] = -1; int i = 0, j = -1;
    while(i < n) {
        while(j >= 0 && s[i] != s[j]) j = b[j];
        b[++i] = ++j;
    }
    return b;
}
bool kmp(const auto &text, const auto &p) {
    vector<int> b = prefix_function(p);
    int m = (int)p.size();
    int j = 0;
    for(auto c : text) {
        while(j >= 0 && c != p[j]) j = b[j];
        j++;
        if(j == m) {
            return true;
        }
    }
    return false;
}

auto read(int n) {
    vector<Vec> pt(n);
    Vec center;
    for(Vec &p : pt) {
        scanf("%lld %lld", &p.x, &p.y);
        center = center + p;
    }

    for(Vec &p : pt) p = p * n - center;
    for(int i = 0; i < (int)pt.size(); i++) {
        while(i < (int)pt.size() and pt[i] == Vec()) {
            swap(pt[i], pt.back());
            pt.pop_back();
        }
    }

    for(Vec p : pt) assert(p != Vec());

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

    n = (int)pt.size();

    vector<tuple<ll, ll, ll>> vec; vec.reserve(n);
    for(int i = 0; i < n; i++) {
        ll cross = pt[i] ^ pt[(i + 1) % n];
        ll dot = pt[i] * pt[(i + 1) % n];
        ll size = pt[i] * pt[i];
        vec.push_back({cross, dot, 0});
    }
    return vec;
}

int main() {

    int n;
    scanf("%d", &n);
    if(n == 1) return printf("Yes\n"), 0;

    auto s = read(n);
    auto t = read(n);

    if(s.size() != t.size()) return printf("No\n"), 0;

    for(int i = 0; i < (int)t.size(); i++) s.push_back(s[i]);

    printf("%s\n", kmp(s, t) ? "Yes" : "No");
}


#include<bits/stdc++.h>
#define I inline
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define re register
#define ll long long
#define db double
#define N 100
#define mod 1000000007
#define eps (1e-4)
#define U unsigned int
#define IT set<ques>::iterator
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
using namespace std;
int n,A[N+5],B[N+5],flag;db nowx,nowy;
struct point{db A,B;}S[N+5],C[N+5];I bool cmp(point x,point y){return x.A==y.A?(x.B<y.B):(x.A<y.A);}
int main(){
	//freopen("1.in","r",stdin);
	re int i,j;scanf("%d",&n);for(i=1;i<=n;i++) scanf("%d%d",&A[i],&B[i]);for(i=1;i<=n;i++) scanf("%lf%lf",&C[i].A,&C[i].B);sort(C+1,C+n+1,cmp);
	for(db i=0;i<=360;i+=(5e-4)){nowx=cos(i);nowy=sin(i);
		for(j=1;j<=n;j++) S[j].A=A[j]*nowx-B[j]*nowy,S[j].B=A[j]*nowy+B[j]*nowx;sort(S+1,S+n+1,cmp);
		flag=0;nowx=S[1].A-C[1].A;nowy=S[1].B-C[1].B;for(j=2;j<=n;j++) if(abs(S[j].A-C[j].A-nowx)>eps||abs(S[j].B-C[j].B-nowy)>eps){flag=1;break;}
		if(!flag){printf("Yes\n");return 0;}
	}printf("No\n");
}

#include <bits/stdc++.h>
using namespace std;
// clang-format off
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353

using ll = int64_t;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& a : v) cin >> a;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<pair<T, T>>& v) {
    for (auto& a : v) cin >> a.first >> a.second;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) {
    for (auto& a : v) {
        T a1, a2, a3;
        cin >> a1 >> a2 >> a3;
        a = {a1, a2, a3};
    }
    return is;
}
template<typename T>
istream& operator>>(istream &is, complex<T>& c) {
    double x, y;
    is >> x >> y;
    c.real(x);
    c.imag(y);
    return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
    for (auto& a : v) os << a << " ";
    os << endl;
    return os;
}
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;
}
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define TRC1(a) cout << #a ":" << a
#define TRC2(a, b) TRC1(a); cout << " "; TRC1(b)
#define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c)
#define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d)
#define GET_NAME(_1,_2,_3,_4,NAME,...) NAME
#define TRC(...) GET_NAME(__VA_ARGS__, TRC4, TRC3, TRC2, TRC1) (__VA_ARGS__) << endl
using veci = vector<int>;
using vecll = vector<ll>;
using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
const int IINF = INT32_MAX;
const ll LINF = INT64_MAX;

// cout << fixed << setprecision(15);
void solve();
int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cout << fixed << setprecision(15); solve(); return 0; }
// clang-format on

void solve() {
    int N;
    cin >> N;
    veci A(N);
    cin >> A;
    map<int, int> mp;
    rep(i, N) { mp[A[i]]++; }

    ll ans = 0;
    int k = N;
    for (int a : A) {
        ans += k - mp[a];
        mp[a]--;
        k--;
    }
    cout << ans << endl;
}


#line 1 "F.cpp"
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n, t; scanf("%d%d", &n, &t);
	std::vector<int> a(n); for(auto& v: a) scanf("%d", &v);

	int A = n / 2, B = n - n / 2;

	std::vector<i64> X, Y;
	for(int i = 0; i < (1 << A); i++) {
		i64 sum = 0;
		for(int j = 0; j < A; j++) if(i >> j & 1) sum += a[j];
		X.push_back(sum);
	}
	for(int i = 0; i < (1 << B); i++) {
		i64 sum = 0;
		for(int j = 0; j < B; j++) if(i >> j & 1) sum += a[j + A];
		Y.push_back(sum);
	}
	sort(begin(X), end(X));
	sort(begin(Y), end(Y));

	i64 ans = 0;
	int cur = Y.size() - 1;
	for(int i = 0; i < X.size(); i++) {
		while(cur >= 0 and X[i] + Y[cur] > t) cur--;
		if(cur != -1) ans = std::max(ans, X[i] + Y[cur]);
	}
	assert(ans <= t);

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//#include <atcoder/convolution>
//#include <atcoder/modint>
//using Modint = atcoder::modint998244353;

using namespace std;
typedef long long ll;

void ex_gcd(ll a, ll b, ll &d, ll &x, ll &y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    ex_gcd(b, a % b, d, y, x);
    y -= a / b * x;
  }
}
ll inv(ll a, ll n) {
  ll d, x, y;
  ex_gcd(a, n, d, x, y);
  return d == 1 ? (x % n + n) % (n / d) : -1;
}
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

const int maxn = 1000005;
const int mod = 998244353;

vector<int>prim;
bool b[maxn];
void init(){
  for(int i=2;i<maxn;i++){
    if(!b[i]){
      prim.push_back(i);
      for(int j=i+i;j<maxn;j+=i)b[j]=1;
    }
  }
}

vector<int>p,c;
void dfs(int pos, int cur, int cnt, int l, int r, int& sum){
  if(cur>r)return;
  if(pos==p.size()){
    if(cnt==0)return;
    int tt = r/cur-(l-1)/cur;
    if(cnt&1)sum += tt;
    else sum -= tt;
    return;
  }
  dfs(pos+1, cur * p[pos], cnt+1, l,r,sum);
  dfs(pos+1, cur, cnt, l, r, sum);
}
void dfs2(int pos, int cur, int l, int r, int&sum){
  if(cur>r)return;
  if(pos==p.size()){
    if(cur>=l&&cur<=r)sum++;
    return;
  }
  int tt = 1;
  for(int i=0;i<=c[pos];i++){
    dfs2(pos+1, cur*tt, l,r,sum);
    tt*=p[pos];
  }
}
int solve(int l, int x) {
  if(l>=x)return 0;
  p.clear();
  c.clear();
  int cur = x;
  for(int i=0;prim[i]*prim[i]<=cur;i++){
    int tt = prim[i];
    if(cur%tt==0){
      int cnt = 0;
      while(cur%tt==0){
        cur/=tt;
        cnt++;
      }
      p.push_back(tt);
      c.push_back(cnt);
    }
  }
  if(cur>1){
    p.push_back(cur);
    c.push_back(1);
  }
  int sum = 0;
  dfs(0,1,0,l,x-1,sum);
  int sum2=0;
  dfs2(0,1,l,x-1,sum2);
  return sum-sum2;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  init();
  int l,r;
  cin>>l>>r;
  ll ret = 0;
  for(int i=l+1;i<=r;i++){
    ret += solve(max(2, l), i);
  }
  cout<<ret*2<<endl;
  return 0;
}