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

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

typedef long long ll;

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

#define fi first
#define se second

int n;
const int N = 2e5+10;
vector<pair<int,ll>> g[N];
ll ib;
ll n0;
void dfs(int no, int from, int cor){
	if(cor==0) n0++;
	for(auto &[it,c] : g[no]){
		if(it==from) continue;
		int cc = cor;
		if(c&(1ll<<ib)) cc = !cc;
		dfs(it,no,cc);
	}
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	fr(i,n-1){
		int a, b; ll w; cin >> a >> b >> w; a--,b--;
		g[a].emplace_back(b,w);
		g[b].emplace_back(a,w);
	}
	ll mod = round(1e9)+7;
	ll ans = 0;
	fr(ii,63){
		ib = ii;
		n0 = 0;
		dfs(0,-1,0);
		ans = (ans+n0*(n-n0)%mod*((1ll<<ib)%mod)%mod)%mod;
	}
	cout << ans << "\n";
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll z = 0, mod = 1000000007, MAX = 60;

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

  vector<vector<pair<ll, ll>>> G(N + 1, vector<pair<ll, ll>>(0));
  for (ll i = 0; i < N - 1; i++){
    ll u, v, w;
    cin >> u >> v >> w;

    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }

  ll root;
  for (ll i = 1; i <= N; i++){
    if (G[i].size() == 1){
      root = i;
      break;
    }
  }

  queue<ll> que;
  que.push(root);
  vector<vector<ll>> ev(MAX, vector<ll>(N + 1, -1));
  for (ll i = 0; i < MAX; i++){
    ev[i][root] = 0;
  }

  while (!que.empty()){
    ll tar = que.front();
    que.pop();

    for (pair<ll, ll> next : G[tar]){
      if (ev[0][next.first] != -1) continue;

      ll nw = next.second;
      for (ll i = 0; i < MAX; i++){
        if (nw % 2 == 1){
          ev[i][next.first] = ev[i][tar] ^ 1;
        }
        else{
          ev[i][next.first] = ev[i][tar];
        }
        nw /= 2;
      }

      que.push(next.first);
    }
  }

  ll ans = 0, base = 1;
  for (ll i = 0; i < MAX; i++){
    ll e = 0, o = 0;
    for (ll j = 1; j <= N; j++){
      if (ev[i][j] == 1){
        e++;
      }
      else{
        o++;
      }
    }

    ans += (((e * o) % mod) * base) % mod;
    ans %= mod;
    base *= 2;
    base %= mod;
    //cout << i << ' ' << e << ' ' << o << endl;
  }

  cout << ans << endl;
}


#include <bits/stdc++.h>

int main(){
    int n, l;
    std::cin >> n >> l;
    std::vector<std::pair<int, int>> vec(n + 2);
    vec[0] = std::make_pair(0, 0);
    vec[n + 1] = std::make_pair(l - n, l - n);
    for(int i = 1; i <= n; i++) std::cin >> vec[i].first, vec[i].first -= i;
    for(int i = 1; i <= n; i++) std::cin >> vec[i].second, vec[i].second -= i;
    long long res = 0;

    for(int i = 1; i <= n;){
        if(vec[i].first < vec[i].second){
            int iter = std::lower_bound(vec.begin() + i, vec.end(), std::make_pair(vec[i].second, -1)) - vec.begin();

            if(vec[i].second == vec[iter].first){
                res += (long long)(iter - i);
                while(i < iter && vec[i].second == vec[iter].first){
                    vec[i].first = vec[i].second;
                    i++;
                }
            }
            else{
                std::cout << "-1\n";
                return 0;
            }
        }
        else i++;
    }

    for(int i = n; i >= 1;){
        if(vec[i].first > vec[i].second){
            int iter = std::upper_bound(vec.begin() + 1, vec.begin() + i + 1, std::make_pair(vec[i].second, 0x7f7f7f7f)) - vec.begin();
            iter--;

            if(vec[i].second == vec[iter].first){
                res += (long long)(i - iter);
                while(i > iter && vec[i].second == vec[iter].first){
                    vec[i].first = vec[i].second;
                    i--;
                }
            }
            else{
                std::cout << "-1\n";
                return 0;
            }
        }
        else i--;
    }

    std::cout << res << "\n";
}

#include<bits/stdc++.h>
using namespace std;
    #define author          "Sihare0riginals"
    #define ss              string
    #define lli             long long int
    #define ld              long double
    #define f               first
    #define s               second
    #define all(v)          v.begin(),v.end()
    #define I(a,i)          memset(a,i,sizeof(a));
    #define pb              push_back
    #define mp              make_pair
    #define L(i,start,end)  for(lli i=start;i<=end;i++)
    #define R(i,start,end)  for(lli i=start;i>=end;i--)
    #define ip(n)           cin>>n;lli ip[n+1];L(i,1,n)cin>>ip[i];
const lli LINF = 1e18,mod=1e9+7;
void Bl0ck_M0mb0();

signed main()
{
    Bl0ck_M0mb0();
    lli t=1;
    //cin>>t;
    while(t--){
      lli n,x;
      cin>>n>>x;
      x*=100;
      lli ip[n+1],ans=0,res=-1;
      L(i,1,n)
      {
        lli a,b;
        cin>>a>>b;
        ans+=a*b;
        if(ans>x)
        {
            res=i;
            break;
        }
      }
      cout<<res<<endl;
    }
    return 0;
}

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


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

const ld eps = 1e-14;

int main() {
    long double x, y, r;
    cin >> x >> y >> r;
    r += eps;
    ll ans = 0;
    for (ll i = (ll)(y-r-1); i <= (ll)(y+r+1); ++i) {
        ld p = r * r - (y - i) * (y - i);
        if (p < 0.0) continue;
        ld dx = sqrt(p + eps);
        ans += (floor(x + dx) - ceil(x - dx) + 1);
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

struct Point
{
  ldouble x, y;
  ldouble dist(Point &other) { return sqrt((x - other.x)*(x - other.x) + (y - other.y)*(y - other.y)); }
  ldouble dist2(Point &other) { return (x - other.x)*(x - other.x) + (y - other.y)*(y - other.y); }
};

const ldouble inf = 1e9;
const ldouble eps = 1e-12;
ldouble cx, cy, r;
Point center;

bool valid(lli x, lli y)
{
  Point curr = {(ldouble)x, (ldouble)y};
  return curr.dist2(center) <= r * r || abs(r * r - curr.dist2(center)) <= eps;
}
lli binarySearch(lli y)
{
  lli base = ceill(cx);
  lli lo = base, hi = inf;
  while (lo < hi)
  {
    lli x = (lo + hi + 1) >> 1;
    if (valid(x, y)) lo = x;
    else hi = x - 1;
  }
  return valid(lo, y) ? lo - base + 1 : 0;
}
lli binarySearch2(lli y)
{
  lli base = floorl(cx) - (ceill(cx) == floorl(cx));
  lli lo = -inf, hi = base;
  while (lo < hi)
  {
    lli x = (lo + hi) >> 1;
    if (valid(x, y)) hi = x;
    else lo = x + 1;
  }
  return valid(lo, y) ? base - lo + 1 : 0;
}

int main()
{
  while (~scanf("%Lf %Lf %Lf", &cx, &cy, &r))
  {
    center = Point{cx, cy};
    lli ans = 0;
    for (lli y = cy - r; y <= cy + r; y++)
    {
      ans += binarySearch(y);
      ans += binarySearch2(y);
    }
    printf("%lld\n", ans);
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
#define F first
#define S second
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a/gcd(a, b)*b;}
template <typename T> bool chmax(T &a,const T& b){if(a<b){a=b;return true;}return false;}
template <typename T> bool chmin(T &a,const T& b){if(a>b){a=b;return true;}return false;}
//cout << fixed << setprecision(15);
int N, M, K, H, W, X, Y;
string S,T;
const int INF = 1e18;
// const int mod = 1e9+7;

signed main(){
    cin >> N >> K >> M;
    int sum = 0;
    rep(i,N-1){
        int a; cin >> a;
        sum += a;
    }
    int ans = N*M - sum;
    if(ans>K)COUT(-1);
    else if(ans<=0)COUT(0);
    else COUT(ans);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100];
int main(){
	ll n;
	scanf("%lld",&n);
	a[0]=1;a[1]=1;
	int i=1;
	while(a[i]+a[i-1]<=n)
	i++,a[i]=a[i-1]+a[i-2];        //a[i]<=n i的最小值
	//cout<<i<<endl;
	ll res=i,k=n;
	for(int j=i;j>=1;j--){
		if(k>=a[j])
		k-=a[j],res++;            //是否可以插入a[i]
	}
	printf("%d\n",res);
	for(int j=i;j>=1;j--){
		if(n>=a[j]){
			n-=a[j],printf("%d\n",(j&1)+1);                  //偶数步进行op1  结束进行op3 x+y->x    奇数步进行op2  结束进行op4 x+y->y
		}
		printf("%d\n",((j-1)&1)+3);
	}
	return 0;
}


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

//#define int long long

const int N = 2e5 + 7;

int p[N], r[N], t[N];

vector <int> ans;

int apply(int x) {
    if(r[x] == x) return 0;
    if(t[r[x] - 1]) return -1;
    int ax = p[r[x]], ay = p[r[x] - 1];
    t[r[x] - 1] = true;
    ans.push_back(r[x] - 1);
    swap(p[r[x]], p[r[x] - 1]);
    swap(r[ax], r[ay]);
    return 1;
}

int32_t main() {
    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> p[i];
        r[p[i]] = i;
    }

    for(int i = 1; i <= n; i++) {
        while(true) {
            int x = apply(i);
            if(x < 0) {
                cout << -1 << endl;
                return 0;
            }
            if(!x) break;
        }
    }
    if(ans.size() != n - 1) {
        cout << -1 << endl;
        return 0;
    }
    for(int x: ans) cout << x << endl;
}

#include "bits/stdc++.h"
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
//#define pi 3.141592653589793238462643383279502
#define M  998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1000000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
struct FenwickTree {
	std::vector<int> f, cnt;
	int n;
	FenwickTree(int _n) {
		n = _n; f.resize(n+10), cnt.resize(n+10);
	}
	void update(int i, int x) {
		while(i <= n) {
			cnt[i] += x, i += i&(-i);
		}
	}

	int sum(int i) {
		int ans = 0;
		while(i > 0) {
			ans += cnt[i], i -= i&(-i);
		}
		return ans;
	}
	int sum(int l, int r) {
		return sum(r)-sum(l-1);
	}

	void update_xor(int i, int x) {
		while(i <= n) {
			f[i] ^= x, i += i&(-i);
		}
	}
	int Xor(int i) {
		int ans = 0;
		while(i > 0) {
			ans ^= f[i], i -= i&(-i);
		}
		return ans;
	}
	int Xor(int l, int r) {
		return Xor(r)^Xor(l-1);
	}
}ft(N);
void solve()
{
    int n;
    cin>>n;
    vi a(n);
    rep(i,0,n)cin>>a[i];
    for(int i=0;i<n;i++)
    {
        if(a[i]==(i+1))
        {
            cout<<-1<<endl;
            return;
        }
    }
    int inv=0;
    vector<pii>res;
    for(int i=(n-1);i>=0;i--)
    {   int ad=ft.sum(a[i]-1);
        inv+=ad;
        res.pb({i,ad});
        ft.update(a[i],1);
    }
    if(inv!=(n-1))
    {
        cout<<-1<<endl;
        return;
    }
    else
    {
        for(auto x:res)
        {
            for(int j=x.F;j<(x.F+x.S);j++)
                cout<<(j+1)<<endl;
        }
    }

}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int t;
   t=1;
   for(int i=0;i<t;i++)
   {
       solve();
   }
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 998244353;

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

struct modint {
    long long x;
    modint(long long x=0):x((x%MOD+MOD)%MOD){}
    long long val(){
        return x;
    }
    modint operator-() const { return modint(-x);}
    modint& operator+=(const modint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    modint& operator-=(const modint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
    	return *this;
    }
    modint& operator*=(const modint a) {
    	(x *= a.x) %= MOD;
        return *this;
    }
    modint operator+(const modint a) const {
        modint res(*this);
        return res+=a;
    }
    modint operator-(const modint a) const {
        modint res(*this);
        return res-=a;
    }
    modint operator*(const modint a) const {
        modint res(*this);
        return res*=a;
    }
    modint pow(long long t) const {
        if (!t) return 1;
        modint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }

	// must be gcd(x,MOD)==1
    modint inv() const {
		// a^{-1} = 1/a MOD p (拡張Euclidの互除法)
		long long b = MOD, u = 1, v = 0, z = x;
		while(b){
			long long t = z / b;
			z -= t * b; swap(z, b);
			u -= t * v; swap(u, v);
		}
		u %= MOD;
		if (u < 0) u += MOD;
		return modint(u);
	}

    //modint inv() const {
    //    return pow(MOD-2);
    //}

    modint& operator/=(const modint a) {
    	return (*this) *= a.inv();
    }
    modint operator/(const modint a) const {
        modint res(*this);
        return res/=a;
    }
};
using mint = modint;

struct Factorial{

    vector<mint> fact, ifact;

    Factorial(int N): fact(N+1), ifact(N+1) {
        assert(N < MOD);

        fact[0] = 1;
        for(int i=0; i<N; i++) fact[i+1] = fact[i] * (i+1);

        ifact[N] = fact[N].inv();
        for(int i=N; i>0; i--) ifact[i-1] = ifact[i] * i;
    }

    mint C(int n, int k){
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }

    mint P(int n, int k){
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }

    mint inv(int n){
        assert(n>0);
        return fact[n-1]*ifact[n];
    }
};

Factorial F(10000);
vector<int> bi(15);

void Main(){
    int N,M; cin >> N >> M;
    bi[0] = 1; REP(i,15) bi[i+1] = bi[i]*2;
    mint dp[13][M+1];
    for(int i=0; i<=M; i+=2){
        dp[0][i] = F.C(N,i);
    }

    REP(i,12)REP(j,M+1){
        for(int k=0; k<=M-j; k+=2){
            if(j+k*bi[i+1] > M) break;
            dp[i+1][j+k*bi[i+1]] += dp[i][j] * F.C(N,k);
        }
    }

    int ans = dp[12][M].x;
    cout << ans << en;
    return;
}

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

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

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

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

int main2() {
  ll N = nextLong();
  map<ll, ll> count;
  REP(i, N) {
    count[nextLong()]++;
  }
  ll ans = N * (N-1)/2;
  for (auto p : count) {
    ll n = p.second;
    ans -= n * (n-1) / 2;
  }
  cout << ans << endl;
  return 0;
}

int main() {

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


/* In the name of Anton */

/*
* Motto :)
*
*
*
*
*
*/

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(x,a) for(auto &x: a)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
#define vt vector
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;

template<class A> void read(vt<A>& v);
template<class T> void read(T& x){
  cin>>x;
}

void read(double &d){
  string t;
  read(t);
  d=stod(t);
}
void read(long double &d){
  string t;
  read(t);
  d=stold(t);
}

template<class H, class... T> void read(H &h, T&...t){
  read(h);
  read(t...);
}

template <class A> void read(vt<A> &x){
  trav(a,x)
    read(a);
}

string to_string(char c){
  return string(1,c);
}

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

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

string to_string(string s){
  return string(s);
}

string to_string(vt<bool> v){
  string res;
  rep(i,sz(v)){
    res+=char('0'+v[i]);
  }
  return res;
}

template<class T> string to_string(T v){
  bool f=1;
  string res;
  trav(x,v){
    if(!f)
      res+=' ';
    f=0;
    res+=to_string(x);
  }
  return res;
}

template<class A> void write(A x){
  cout<<to_string(x);
}

template<class H, class...T> void write(const H& h, const T&...t){
  write(h);
  write(t...);
}

void print(){
  write("\n");
}

template<class H, class...T> void print(const H& h, const T&...t){
  write(h);
  if(sizeof...(t))
    write(' ');
  print(t...);
}

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

void pre(){

}

ll bring(string pat, string txt){
  string s=pat+'#'+txt;
  ll m=(ll)pat.size();
  ll n=(ll)s.size();
  vector <ll> pi(n);

  ll co=0;

  pi[0]=0;

  for(ll i=1;i<n;i++){
    ll j=pi[i-1];

    while(j>0 && s[i]!=s[j])
      j=pi[j-1];

    if(s[i]==s[j]) j++;

    pi[i]=j;

    if(pi[i]==m) co++;
  }

  return co;
}

vector <ll> lao(string pat, string txt){
  string s=pat+'#'+txt;
  ll n=(ll)s.size();
  vector <ll> pi(n);

  pi[0]=0;

  for(ll i=1;i<n;i++){
    ll j=pi[i-1];

    while(j>0 && s[i]!=s[j])
      j=pi[j-1];

    if(s[i]==s[j]) j++;

    pi[i]=j;
  }

  return pi;
}

void solve(){
  ll n; read(n);
  string pat; read(pat);

  string mine="110";

  string txt="";
  ll j=0;;

  for(ll i=0;i<n;i++){
    txt+=mine[j];
    j++;

    if(j==3) j=0;
  }

  for(ll i=0;i<n;i++){
    txt+=mine[j];
    j++;

    if(j==3) j=0;
  }

  for(ll i=0;i<n;i++){
    txt+=mine[j];
    j++;

    if(j==3) j=0;
  }

  ll val=bring(pat,txt);

  ll new_n=(ll)txt.size();

  txt+=txt;

  vector <ll> v1=lao(pat,txt);

  ll con=0;

  for(ll i=n+1+new_n;i<v1.size();i++){
    if(v1[i]==n) con++;
  }

  con-=val;

  ll num=30000000000;
  ll tot=num/new_n;
  ll lef=num%new_n;

  // print(lef);

  ll ans=(tot*val);
  ans+=(con*(tot-1));

  // print(val);

  j=0;
  ll lo=0;

  if(lef!=0){

  for(ll i=n+1+new_n;i<v1.size();i++){
    if(v1[i]==n) ans++;
    j++;

    if(j==lef) break;
  }

  }

  print(ans);
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t=1;
  // read(t);
  rep(i,t) solve();
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) { cerr << head; dump(); }
template <typename Head, typename... Tail> void dump(Head &&head, Tail &&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do { cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////

int N;
vector<int> X(210);
vector<int> Y(210);
vector<ll> R(210);

vector<int> a(210);
vector<int> b(210);
vector<int> c(210);
vector<int> d(210);

double calc(int x, int y, ll r, int a, int b, int c, int d)
{
    if (x < a || c <= x) return 0;
    if (y < b || d <= y) return 0;
    ll s = abs(a - c) * abs(b - d);
    return 1 - pow(1 - (double)min(r, s)/(double)max(r, s), 2);
}

ll calc_all(const vector<int>& a, const vector<int>& b, const vector<int>& c, const vector<int>& d)
{
  double res = 0;
  rep(i, N) {
    double ret = calc(X[i], Y[i], R[i], a[i], b[i], c[i], d[i]);
    res += ret;
  }
  return roundl(1000000000 * res / N);
}

void output()
{
  rep(i, N) {
    printf("%d %d %d %d\n", a[i], b[i], c[i], d[i]);
  }
}

int main()
{
  cin >> N;
  rep(i, N) {
    cin>>X[i]>>Y[i]>>R[i];
  }

  rep(i, N) {
    a[i] = X[i];
    b[i] = Y[i];
    c[i] = X[i]+1;
    d[i] = Y[i]+1;
  }

  ll res = calc_all(a, b, c, d);

  output();

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  REP(i, SZ(v)) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

void solve() {
  ll n, a, b; cin >> n >> a >> b;
  if(a < b) swap(a, b);

  ll tmp1 = 0;
  if(n - a - b + 1 >= 1) {
    tmp1 = (n - a - b + 1) * (n - a - b + 2) / 2 % MOD;
  }
  ll tmp2 = (n - b + 1) * (n - b + 2) / 2 % MOD;
  //ll tmp22 = (n - b + 1 - (a - b + 1) + 1) * (a - b + 1 + n - b + 1) / 2 % MOD;
  ll tmp22 = (n - a + 1) * (a - b + 1 + n - b + 1) / 2 % MOD;

  ll tmp3 = tmp1 * tmp22 % MOD;
  ll tmp4 = tmp1 * tmp1 % MOD;
  ll tmp5 = (n - a + 1) * (a - b + 1) % MOD * tmp1 % MOD;

  cout << ((8 * tmp3 % MOD - 4 * tmp4 % MOD + MOD) % MOD - 4 * tmp5 % MOD + MOD) % MOD << endl;
}

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

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

  return 0;
}

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>

using namespace std;

clock_t timeStart, timeFinish;

void timeBegin() {
    timeStart = clock();
}

void timeEnd() {
    timeFinish = clock();
}

void timeDuration() {
    double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " sec " << endl;
}

class InputReader {
public:
    InputReader() {
        input_file = stdin;
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
    inline InputReader &operator >>(long long &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

const int MOD = 1000000007;

int main() {
    timeBegin();
    //ifstream cin("input.txt");
    //ofstream cout("papagali.out");
    int tests;
    cin >> tests;
    for (int test = 1; test <= tests; test++) {
        int n, a, b;
        cin >> n >> a >> b;
        if (a + b > n) {
            cout << "0\n";
        } else {
            int answer = 2LL * (n - a + 1) * (n - b + 1) % MOD * (n - a - b + 1) % MOD * (n - a - b + 2) % MOD
                         - 1LL * (n - a - b + 1) * (n - a - b + 2) % MOD * (n - a - b + 1) % MOD * (n - a - b + 2) % MOD;
            if (answer < 0) {
                answer += MOD;
            }
            cout << answer << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;
int main(){
  int X;
  cin >> X;

  if( X%100 == 0) cout << 100 << endl;
  else cout << 100 - X%100 << endl;

}

//#define _GLIBCXX_DEB // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
#include <bits/stdc++.h>

using namespace std;

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

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

#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << "\n"
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define INF 1000000000
#define no_of_digits(n) floor(log10(n)) + 1
#define bits(n) __builtin_popcount(n)
#define lsb(n) __builtin_clz(n) // count leading zeroes before 1
#define rsb(n) __builtin_ctz(n) // count trailing zeroes before 1

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}
int sum_of_digits(int a)
{
    int s = 0;
    while (a > 0)
    {
        s += a % 10;
        a /= 10;
    }
    return s;
}
string toBinary(int n)
{
    string r;
    while (n != 0)
    {
        r = (n % 2 == 0 ? "0" : "1") + r;
        n /= 2;
    }
    return r;
}
int binaryToDecimal(string n)
{
    string num = n;
    int dec_value = 0;
    int base = 1;

    int len = num.length();
    for (int i = len - 1; i >= 0; i--)
    {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}
ll add(ll a, ll b, ll m = mod)
{
    if (a >= m)
        a %= m;
    if (b >= m)
        b %= m;
    if (a < 0)
        a += m;
    if (b < 0)
        b += m;
    ll res = a + b;
    if (res >= m or res <= -m)
        res %= m;
    if (res < 0)
        res += m;
    return res;
}

ll mul(ll a, ll b, ll m = mod)
{
    if (a >= m)
        a %= m;
    if (b >= m)
        b %= m;
    if (a < 0)
        a += m;
    if (b < 0)
        b += m;
    ll res = a * b;
    if (res >= m or res <= -m)
        res %= m;
    if (res < 0)
        res += m;
    return res;
}

ll pow_mod(ll a, ll b, ll m = mod)
{
    ll res = 1LL;
    a = a % m;
    while (b)
    {
        if (b & 1)
            res = mul(res, a, m);
        b >>= 1;
        a = mul(a, a, m);
    }
    return res;
}

ll fastexp(ll a, ll b)
{
    ll res = 1LL;
    while (b)
    {
        if (b & 1)
            res = res * a;
        b >>= 1;
        a *= a;
    }
    return res;
}
void solve()
{
    int x;
    cin>>x;
    if(x%100==0)
    cout<<100;
    else
    {
        double res=(ceil((double)x/100.0))*100.0;
        cout<<res-x;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define N 111
#define NN 131000
template <typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-')	flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
int n, K, P;
int ans[N], lmt[N];
int f[2][NN], g[2][NN], sum[NN];
inline void Try(int mid) {
	memset(f, 0, sizeof(f));
	memset(g, 0, sizeof(g));
	memset(sum, 0, sizeof(sum));
	int up = min(lmt[mid - 1], lmt[n - mid]);
	int nw = 0; f[nw][0] = 1;
	for (int i = 1; i < mid; ++i) {
		nw ^= 1;
		int d = mid - i;
		for (int j = 0; j <= up; ++j) {
			if (j - d >= 0)	sum[j] = (sum[j - d] + f[nw ^ 1][j]) % P;
			else	sum[j] = f[nw ^ 1][j];
		}
		for (int j = 0; j <= up; ++j) {
			if (j - (K+1) * d < 0)	f[nw][j] = sum[j];
			else	f[nw][j] = (sum[j] - sum[j - (K+1) * d] + P) % P;
		}
	}
	if (nw)	memcpy(f[0], f[1], sizeof(f[1]));
	nw = 0; g[nw][0] = 1;
	for (int i = mid + 1; i <= n; ++i) {
		nw ^= 1;
		int d = i - mid;
		for (int j = 0; j <= up; ++j) {
			if (j - d >= 0)	sum[j] = (sum[j - d] + g[nw ^ 1][j]) % P;
			else	sum[j] = g[nw ^ 1][j];
		}
		for (int j = 0; j <= up; ++j) {
			if (j - (K+1) * d < 0)	g[nw][j] = sum[j];
			else	g[nw][j] = (sum[j] - sum[j - (K+1) * d] + P) % P;
		}
	}
	if (nw)	memcpy(g[0], g[1], sizeof(g[1]));
	for (int j = 0; j <= up; ++j) if (f[0][j] && g[0][j]) {
		ans[mid] = (ans[mid] + 1ll * f[0][j] * g[0][j] % P * (K + 1)) % P;
	}
}
int main() {
	read(n), read(K), read(P);
	for (int i = 1; i <= n; ++i)	lmt[i] = lmt[i - 1] + K * i;
	for (int i = 1; i <= (n + 1) >> 1; ++i)	Try(i);
	for (int i = 1; i <= n; ++i) if (!ans[i])	ans[i] = ans[n - i + 1];
	for (int i= 1; i <= n; ++i) {
		printf("%d\n", ((ans[i] - 1 + P) % P + P) % P);
	}
	return 0;
}

/*
3 1 998244353
//1 3 1

10 8 861271909

100 100 7
*/


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

#define int             long long
#define ld              long double
#define F               first
#define S               second
#define PB              push_back
#define forn(i,a,b)     for(i=a;i<=b;i++)
#define nfor(i,a,b)     for(i=a;i>=b;i--)
#define all(x)          x.begin(),x.end()
#define rall(x)         x.rbegin(),x.rend()
#define pii             pair<int,int>
#define vi              vector<int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define si              set<int>
#define spii            set<pii>
#define usi             unordered_set<int>
#define uspii           unordered_set<pii>
#define mii             map<int,int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int>>
#define setbits(x)      __builtin_popcountll(x)
#define tzbits(x)       __builtin_ctzll(x)
#define lzbits(x)       __builtin_clzll(x)
#define pbits(x)        __builtin_parityll(x)
#define gcd             __gcd
#define lcm(x, y)       ((x)*(y))/gcd(x,y)
#define endl            '\n'
#define sz(s)           (int)s.size()
#define sp(x,y)         fixed<<setprecision(y)<<x
const int mod = 1000000007;
const int inf = 1000000000000000000;
const ld PI = 3.1415926535897932384626;
const ld eps = 1e-12;
void __print(int32_t x) {cout<<x;}
void __print(int x) {cout<<x;}
void __print(double x) {cout<<x;}
void __print(ld x) {cout<<x;}
void __print(float x) {cout<<x;}
void __print(bool x) {cout<<(x?"true":"false");}
void __print(char x) {cout <<'\''<<x<<'\'';}
void __print(const char *x) {cout <<'\"' <<x<<'\"';}
void __print(const string &x) {cout<<'\"'<<x<<'\"';}
template<typename T,typename V>     void __print(const pair<T,V> &x) {cout<<'{';__print(x.first);cout<<',';__print(x.second);cout<<'}';}
template<typename T>                void __print(const T &x) {int f=0;cout<<'{';for(auto &i:x)cout<<(f++?",":""),__print(i);cout<<"}";}void _print(){cout<<"]\n";}
template <typename T,typename... V> void _print(T t, V... v) {__print(t);if(sizeof...(v))cout<<", ";_print(v...);}
#define dbg(x...) cout<<"["<<#x<<"]=[";_print(x)
int powerm(int base,int exp) {int res=1;base%=mod;while(exp>0){if(exp&1)res=(res*base)%mod;base=(base*base)%mod;exp=exp>>1;}return res;}
int power(int base,int exp) {int res=1;while(exp>0){if(exp&1)res=res*base;base=base*base;exp=exp>>1;}return res;}
float powerNeg(float base,int exp) {float temp;if(exp==0)return 1;temp=powerNeg(base,exp/2);if(exp%2==0)return temp*temp;else{if(exp>0)return base*temp*temp;else return (temp*temp)/base;}}
int modinv(int exp) {return powerm(exp,mod-2);}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

const int N=2e6+5;

void solve()
{
    int i,j;
    int n; cin>>n;

    vi v;
    forn(i,1,sqrt(n)){
        if(n%i==0){
            if(i*i!=n) v.PB(i), v.PB(n/i);
            else v.PB(i);
        }
    }
    sort(all(v));

    for(int i: v) cout<<i<<endl;

    //cout<<<<endl;
}

int32_t main()
{

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t,T=1;
    // cin>>T;
    forn(t,1,T)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    // cout<<endl<<"Times Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"sec";
    return 0;
}

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

int main(){
  long long N;
  cin >> N;
  set<long long> S;
  for(long long i = 1; i*i<=N; i++){
    if(N%i==0){
      S.insert(i);
      S.insert(N/i);
    }
  }
  for(auto c:S){
    cout << c << endl;
  }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> pin;

const int N = 1e5 + 5;
const ll P = 1e9 + 7;

int n;
ll a[N], ans;
vector <ll> vec;

template <typename T>
inline void read(T &X) {
    char ch = 0; T op = 1;
    for (X = 0; ch > '9' || ch < '0'; ch = getchar())
        if (ch == '-') op = -1;
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        X = (X * 10) + ch - '0';
    X *= op;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("sample.in", "r", stdin);
    clock_t st_clock = clock();
#endif

    read(n);
    for (int i = 1; i <= n; i++) {
        read(a[i]);
        vec.push_back(a[i]);
    }
    sort(vec.begin(), vec.end());
    vector<ll>::iterator end = unique(vec.begin(), vec.end());
	vec.erase(end, vec.end());
    for (int i = 0; i < vec.size(); i++) a[i] = vec[i] - (i == 0 ? 0LL : vec[i - 1]);
    ans = 1;
    for (int i = 0; i < vec.size(); i++) {
        ans = ans * (a[i] + 1) % P;
    }
    printf("%lld\n", ans);

#ifndef ONLINE_JUDGE
    clock_t ed_clock = clock();
    printf("time = %f ms\n", (double)(ed_clock - st_clock) / CLOCKS_PER_SEC * 1000);
#endif
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 1e5 + 10;
const int MAXM = 1e5 + 10;
struct edge {
    int u,v;
    int next;
}e[MAXM * 2];
int first[MAXN];
int idx;
int n;
void add(int a, int b) {
    e[idx].u = a;
    e[idx].v = b;
    e[idx].next = first[a];
    first[a] = idx++;
}
void init() {
    fill(first, first + n + 1, -1);
    idx = 0;
}
int sz[MAXN];
int dp[MAXN];
struct node {
    int val1, val2;
};
bool cmp(node x, node y) {
    return x.val1 - x.val2 < y.val1 - y.val2;
}
void dfs(int u) {
    sz[u] = 1;
    dp[u] = 1;
    vector<node> v1, v2;
    for (int i = first[u]; i != -1; i = e[i].next) {
        int v = e[i].v;
        dfs(v);
        sz[u] += sz[v];
        if (sz[v] % 2) {
            v1.push_back({dp[v], sz[v] - dp[v]});
        } else {
            v2.push_back({dp[v], sz[v] - dp[v]});
        }
    }
    sort(v1.begin(), v1.end(), cmp);
    sort(v2.begin(), v2.end(), cmp);
    int sz1 = v1.size();
    int sz2 = v2.size();
    int now = 0;
    while (now < sz2 && v2[now].val2 - v2[now].val1 >= 0) {
        dp[u] += v2[now].val1;
        now++;
    }
    for (int i = 0; i < sz1; i++) {
        if (i % 2 == 0) {
            dp[u] += v1[i].val1;
        } else {
            dp[u] += v1[i].val2;
        }
    }
    for (int i = now; i < sz2; i++) {
        if (sz1 % 2 == 1) {
            dp[u] += v2[i].val2;
        } else {
            dp[u] += v2[i].val1;
        }
    }
}
int main() {
    scanf("%d", &n);
    init();
    for (int i = 2; i <= n; i++) {
        int fa;
        scanf("%d", &fa);
        add(fa, i);
    }
    dfs(1);
    printf("%d\n", dp[1]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i, n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define miele(v) min_element(v.begin(), v.end())
#define maele(v) max_element(v.begin(), v.end())
#define SUM(v) accumulate(v.begin(), v.end(), 0LL)
#define lb(a, key) lower_bound(a.begin(),a.end(),key)
#define ub(a, key) upper_bound(a.begin(),a.end(),key)
#define COUNT(a, key) count(a.begin(), a.end(), key)
#define BITCOUNT(x) __builtin_popcount(x)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using P = pair<int, int>;
using WeightedGraph = vector<vector<P>>;
using UnWeightedGraph = vector<vector<int>>;
using Real = long double;
using Point = complex<Real>; //Point and Vector2d is the same!
// p.real() or real(p) -> x軸, p.imag() or imag(p) -> y軸
using Vector2d = complex<Real>;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
const double EPS = 1e-15;
const double PI = 3.14159265358979323846;

template<typename T>
int getIndexOfLowerBound(vector<T> &v, T x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

template<typename T>
int getIndexOfUpperBound(vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin();
}

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 repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

istream &operator>>(istream &is, Point &p) {
    Real a, b;
    is >> a >> b;
    p = Point(a, b);
    return is;
}

template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p_var) {
    is >> p_var.first >> p_var.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}

template<typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << pair_var.first << ' ' << pair_var.second;
    return os;
}

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

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

template<typename T>
ostream &operator<<(ostream &os, vector<vector<T>> &df) {
    for (auto &vec : df) os << vec;
    return os;
}

template<typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    repi(itr, map_var) {
        os << *itr << ' ';
        itr++;
        itr--;
    }
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    repi(itr, set_var) {
        os << *itr << ' ';
        itr++;
        itr--;
    }
    return os;
}

void print() { cout << endl; }

template<class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int L, R; cin>>L>>R;

    vector<int> dp(R + 10); // dp iは、L以上R以下の数のペアでgcdがiになるものの数
    int ans = 0;
    for (int i = R; i >= 2; --i) {
        int tmp = (R/i - (L-1)/i)*(R/i - (L-1)/i);
        int now = i + i;
        while(now <= R) {
            tmp -= dp[now];
            now += i;
        }
        dp[i] = tmp;
    }

    ans = SUM(dp);

    for (int i = L; i <= R; ++i) {
        if(i == 1) continue;
        ans -= R/i*2;
    }

    for (int i = L; i <= R; ++i) {
        if(i == 1) continue;
        ans++;
    }

    print(ans);
}

// Problem: F - +1-1x2
// Contest: AtCoder - AtCoder Beginner Contest 188
// URL: https://atcoder.jp/contests/abc188/tasks/abc188_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(a) signed(a.size())
using namespace std;
map<ll,ll> dp,vis;
ll rec(ll x, ll y){
	if(y == 1){
		dp[y] = abs(y-x);
		return dp[y];
	}
	if(vis[y])
	return dp[y];
	vis[y] = 1;
	if(y%2){
		dp[y] = min({abs(y-x),2+rec(x,(y+1)/2),2+rec(x,(y-1)/2)});
	}
	else{
		dp[y] = min(abs(y-x),rec(x,y/2)+1);
	}
	return dp[y];
}
void solve(){
	ll x,y;
	cin >> x >> y;
	ll ans = rec(x,y);
	cout << ans ;
}

int main() {
    FAST;
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cmath>
#include <climits>
#include <queue>
#include <bitset>
#include <set>
#include <assert.h>
#include <map>
using namespace std;
typedef vector<vector<long> > dim2veclo;
typedef vector<vector<int> > dim2vecin;
typedef vector<vector<double> > dim2vecdo;
typedef vector<vector<long long> > dim2vecll;
typedef vector<int> vecin;
typedef vector<long> veclo;
typedef vector<double> vecdo;
typedef vector<long long> vecll;
typedef vector<bool> vecbo;
typedef vector<vector<bool> > dim2vecbo;
typedef long long ll;
typedef vector < pair<ll, ll> > vecpa;
typedef vector<string> vecst;
typedef pair<ll, ll> pail;
typedef pair<int, int> pain;
typedef vector<vecpa > dim2vecpa;

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

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

vecpa black;
ll res = 1;
vecbo isOK;
ll n, m;
ll now = n;
vector<pair<ll, bool>> nw;

bool solve(pail hoge) {
    ll Y = hoge.second;
    if (isOK[Y]) {
        if (Y == 0) {
            if (!isOK[Y + 1]) {
                nw.push_back(make_pair(Y, false));
                res--;
            }
        }
        else if (Y == 2 * n) {
            if (!isOK[Y - 1]) {
                nw.push_back(make_pair(Y, false));
                res--;
            }
        }
        else if (!isOK[Y - 1] && !isOK[Y + 1]) {
            nw.push_back(make_pair(Y, false));
            res--;
        }
        return true;
    }
    else {
        if (Y != 2 * n && isOK[Y + 1]) {
            nw.push_back(make_pair(Y, true));
            res++;
        }
        else if (Y != 0 && isOK[Y - 1]) {
            nw.push_back(make_pair(Y, true));
            res++;
        }
        return true;
    }
}

int main() {
    cin >> n >> m;
    black = vecpa(m);
    isOK = vecbo(2 * n + 1, false);
    rep(i, m) {
        ll x, y; cin >> x >> y;
        black[i] = make_pair(x, y);
    }
    sort(black.begin(), black.end(), [](pail a, pail b) {
        if (a.first != b.first) return a.first < b.first;
        return abs(n - a.second) < abs(n - b.second);
        });

    isOK[n] = true;
    rep(i, m) {
        solve(black[i]);
        if (i < m - 1 && black[i].first == black[i + 1].first) continue;
        rep(j, nw.size()) {
            isOK[nw[j].first] = nw[j].second;
        }
        nw = vector<pair<ll, bool>>();
    }
    cout << res;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main() {

long long int  n,i,j,x,y,z,k,z1,c1=0,sum=0,c=0,d,m,x1,y1,x2,y2;
string o,p;
cin>>o>>p;
for(i=0;i<o.size();i++)
{
sum=sum+(o[i]-'0');
}
for(i=0;i<p.size();i++)
{
c=c+(p[i]-'0');
}
cout<<max(c,sum);

return 0;
}


#include<bits/stdc++.h>

#define ll long long int

using namespace std;

const ll COPIES = 1e10;
int cnt;

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

    int n, i, flag = 0;
    string t;
    cin >> n >> t;
    string a = "", b = "", tmp = "";
    cnt = 0;
    for (i=0; i<n && flag < 2; i++) {
        tmp += t[i];
        if (t[i] == '0') {
            if (tmp == "110" && flag < 2) {
                flag = 1;
                cnt++;
                tmp = "";
            }
            else if (tmp.size() > 2) flag = 2;
            else {
                if (flag == 0) {
                    a = tmp;
                    flag = 1;
                    tmp = "";
                }
                else if (flag == 1) {
                    b = tmp;
                    flag = 2;
                }
            }
        }
    }
    if (i < n || tmp.size() > 2 || (tmp.size() && tmp[tmp.size()-1] == '0')) cout << "0\n";
    else {
        b = tmp;
        if (a.size() == 0 && b.size() == 0) cout << COPIES - cnt + 1 << endl;
        else if (a.size() == 0 && cnt == 0 && b == "1") cout << 2*COPIES << endl;
        else if (a.size() == 0 || b.size() == 0) cout << COPIES - cnt << endl;
        else cout << COPIES - cnt - 1 << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define endl "\n"
#define fill(A,x) memset(A,x,sizeof A);

void solve()
{
  int n;
    cin>>n;
	vi pos(n+5),ar(n+5);
	vi ans;
    for(int i=1;i<=n;i++)
    {
        cin>>ar[i];
        pos[ar[i]]=i;
    }
    if(n==2)
    {
        if(pos[1]==1)cout<<0<<endl;
        else {cout<<1<<endl;cout<<1;}
        cout<<endl;
        return;
    }

    for(int i=n;i>0;i--)
    {
        if(i>n||pos[i]==i)
        continue;
        int c=pos[i];
        if(c%2!=(ans.size())%2)
        {
            while(pos[i]!=i)
            {
                int x=ar[pos[i]+1];
                ar[pos[i]]=x;ar[pos[i]+1]=i;
                ans.pb(pos[i]);
                pos[i]++;pos[x]--;
            }
        }
        else
        {
            if(c%2==0)
            {
                ans.pb(1);
                ans.pb(2);
                ans.pb(1);
                pos[ar[1]]+=2;pos[ar[3]]-=2;
                swap(ar[1],ar[3]);
                i++;
            }
            else
            {
                ans.pb(2);
                ans.pb(1);
                ans.pb(2);
                pos[ar[1]]+=2;pos[ar[3]]-=2;
                swap(ar[1],ar[3]);
                i++;
                i++;
            }
        }
    }

    int x=ans.size();
    cout<<x<<endl;

    for(auto it:ans)cout<<it<<" ";
    cout<<endl;
}

signed main()
{
    boost
    int test=0,t;
    cin >> t ;
    //t=1;
   while(test++ <t){
	//   cout<<"Case #"<<test<<": ";
	   solve();}

}

#line 1 "/workspaces/compro/lib/template.hpp"

#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}

#line 2 "main.cpp"

double solve(ll N, const std::vector<long long> &A) {
  ll sum = accumulate(ALL(A), 0LL);
  auto E = [&](double x, double k, double sum) { return x * 2 * k + sum - x * N; };

  double ans = 1e20;
  REP(k, N + 1) {
    if (k == 0) {
      chmin(ans, E(0, 0, sum) / N);
      sum -= A[k];
    } else if (k == N) {
      chmin(ans, E((double)A[N - 1] / 2, N, sum) / N);
    } else {
      chmin(ans, E((double)A[k - 1] / 2, k, sum) / N);
      chmin(ans, E((double)A[k] / 2, k, sum) / N);
      sum -= A[k];
    }
  }

  return ans;
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
  int N;
  std::cin >> N;
  std::vector<long long> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }
  sort(ALL(A));
  auto ans = solve(N, A);
  std::coutd(10) << ans << std::endl;
  return 0;
}


#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto &i : (a))
#define SZ(x) ((int)(x).size())
#define X first
#define Y second
#define MP std::make_pair
#define PR std::pair
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

VI a, b;

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

        int n;
        std::cin >> n;
        std::string x, y;
        std::cin >> x >> y;
        a.resize(n);
        b.resize(n);
        FOR(i, n) a[i] = x[i]-'0', b[i] = y[i]-'0';

        ll ans = 0;
        int need = 0;
        if(a[0] != b[0]) ans = need = 1;

        REP(i, 1, n){
                if(need > 0){
                        if(a[i] == 1){
                                a[i] = 0;
                                need--;
                        }
                }
                if(a[i] != b[i]) need++;
                ans += need;
        }

        if(need == 0) std::cout << ans << "\n";
        else std::cout << -1 << "\n";

        return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数
// static_cast< long long ll >

int N = 30*30;
int L = 30;
// (i,j) i個下 , j個右
int ind(int a,int b){
	return a*L + b;
}

//vector< vector<string> > S(N,vector<string>(N));
vector<vector<long double>> H(L,vector<long double>(L,5000.0));
vector<vector<long double>> V(L,vector<long double>(L,5000.0));

// 上は下より(i,j)のiが小さい　右は左より(i,j)のjが大きい

// 順路正の向きで
const int From_U = 0;//上から来た
const int From_D = 1;//下から来た
const int From_L = 2;//左から来た
const int From_R = 3;//右から来た

// 復元
string make_char = "DURL";
const int dy[] = {-1,1,0,0};
const int dx[] = {0,0,-1,1};

int main(){
	int sy,sx,ty,tx;
	int s,t;
	FOR(k,0,1000){
		cin >> sy >> sx >> ty >> tx;

		int dir_y = 1;
		int dir_x = 1;
		if(sy > ty) dir_y = -1;
		if(sx > tx) dir_x = -1;

		// (i,j) には (i - dir_y , j) or (i , j - dir_x) から行く

		vector< vector<long double> > score(L,vector<long double>(L,INF));
		vector< vector<int> > from(L,vector<int>(L,-1));

		score[sy][sx] = 0;
		for(int y=sy;(y-dir_y)!=ty;y+=dir_y){
			for(int x=sx;(x-dir_x)!=tx;x+=dir_x){
				//cout << y << " " << x << endl;

				if(y==sy && x==sx) continue;
				long double a = INF,b = INF;
				if(y != sy) a = score[y-dir_y][x] + H[min(y-dir_y,y)][x];
				if(x != sx) b = score[y][x-dir_x] + V[y][min(x,x-dir_x)];

				if(a < b){
					from[y][x] = (dir_y == 1 ? From_U : From_D );
					score[y][x] = a;
				}else{
					from[y][x] = (dir_x == 1 ? From_L : From_R );
					score[y][x] = b;
				}

			}
		}
		//return 0;
		//cout << "95" << endl;

		string T;
		int y=ty,x=tx;
		while(y!=sy || x!=sx){
			int a = from[y][x];
			T += make_char[a];
			assert(0 <= a && a <= 3);
			y += dy[a];
			x += dx[a];
			//cout << "from[" << y <<  "][" << x << "] = "  << a << endl;
		}

		//cout << "106" << endl;

		//cout << T << endl;
		REV(T);
		/*{ // チェック
			assert(T.size() == (abs(sy-ty)+abs(sx-tx)));
			int ud=0,lr=0;
			for(auto c:T){
				if(c == 'U' || c == 'D') ud++;
				if(c == 'L' || c == 'R') lr++;
			}
			assert(abs(sy-ty) == ud);
			assert(abs(sx-tx) == lr);
		}*/
		cout << T << endl;
		cout << flush;

		long double score_now,r;
		cin >> score_now;

		r = pow( score_now / score[ty][tx] , 1.0 - 1.0*(abs(sy-ty) + abs(sx-tx)) / 110.0 );

		y=ty,x=tx;
		while(y!=sy || x!=sx){
			int a = from[y][x];
			int by = y + dy[a],bx = x + dx[a];
			if(by != y){
				H[min(by,y)][x] *= r;
			}else{
				V[y][min(bx,x)] *= r;
			}
			y += dy[a];
			x += dx[a];
		}
	}
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a,v) memset((a), v, sizeof(a))

using namespace std;

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

const int N = 3002;
const int MOD = 998244353;

int n, k;
int dp[N][N];

void fillDP() {
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = i; j > 0; j--) {
			dp[i][j] = (dp[i-1][j-1] + dp[i][min(N-1, 2*j)]) % MOD;
		}
	}
}

int main() {
	scanf("%d %d", &n, &k);
	fillDP();
	printf("%d\n", dp[n][k]);
	return 0;
}

#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll _v):v(normS(_v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ModInt& operator++(int){ return *this=*this+1;}
	ModInt& operator--(int){ return *this=*this-1;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll p[]={a,1,0},q[]={b,0,1};
		while(*q){
			ll t=*p/ *q;
			rep(i,3) swap(p[i]-=t*q[i],q[i]);
		}
		if(p[0]<0) rep(i,3) p[i]=-p[i];
		x=p[1],y=p[2];
		return p[0];
	}
	ModInt inv() const {
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	ModInt pow(ll p) const {
		if(p<0) return inv().pow(-p);
		ModInt a = 1;
		ModInt x = *this;
		while(p){
			if(p&1) a *= x;
			x *= x;
			p >>= 1;
		}
		return a;
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<998244353>;
mint dp[3001][3001];
bool alre[3001][3001];
mint calc(int n,int k){
	if(n<0||k<0) return 0;
	if(n<k) return 0;
	if(alre[n][k]) return dp[n][k];
	alre[n][k]=1;
	dp[n][k]=calc(n-1,k-1)+calc(n,2*k);
	return dp[n][k];
}
int main(){
	int N,K;
	scan(N>>K);
	dp[0][0]=1;
	alre[0][0]=1;
	prin(calc(N,K));
	return 0;
}


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout << fixed << setprecision(2); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on

using ld=long double;
struct edge {
    int v;
    ll cost;
};
struct edg2 {
    int v;
    ll c;
    ll d;
};
class greater_cost {
   public:
    bool operator()(const edge& lh, const edge& rh) const {
        return lh.cost > rh.cost;
    }
};
using pq_mincost = priority_queue<edge, vector<edge>, greater_cost>;

const ll LG = 1e17;
vector<vector<edge>> edgcost;
vector<vector<edg2>> edgs;
vector<ll> c;
vector<ll> d;
ll dijkstra() {
    ll n = edgs.size();
    vector<bool> done(n, false);
    pq_mincost pq;
    pq.push({0, 0});
    while (!pq.empty()) {
        edge e = pq.top();
        pq.pop();
        ll cost = e.cost;
        int u = e.v;
        if (done[u]) continue;
        done[u] = true;

        if (u == n - 1) {
            return cost;
        }
        for (auto v : edgs[u]) {
            ld eps = 1e-2;
            ld left = -eps + cost;
            ld right = LG;
            while (right-left >= 1.0) {
                ld  t1 = (left+right) / 2;
                ld  t2 = t1 + eps;
                ld  x1 = t1 + v.c + ld(v.d) / (t1 + 1);
                ld  x2 = t2 + v.c + ld(v.d) / (t2 + 1);
                if (x1 < x2) {
                    right = t2;
                } else {
                    left = t1;
                }
            }
            ll nc = INF;
            ll lf=roundl(left-1.1);
            ll rg=roundl(right+1.1);
            lf = max(cost,lf);
            for (ll t = lf; t <= rg; t++) {
                ll x = t + v.c + v.d / (t + 1);
                nc = min(nc, x);
            }
            pq.push({v.v, nc});
        }
    }
    return -1;
}
int main() {
    // ダイクストラで三分探索(!?)
    ioinit();
    ll n, m;
    cin >> n >> m;
    edgcost.resize(n);
    edgs.resize(n);
    c.resize(m);
    d.resize(m);
    for (ll i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b >> c[i] >> d[i];
        a--;
        b--;
        edgs[a].push_back({int(b), c[i], d[i]});
        edgs[b].push_back({int(a), c[i], d[i]});
    }
    ll ans = dijkstra();
    print(ans);
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static int IN(void)
{
  int x=0,f=1,c;while(c=getchar(),c<48||c>57){if(c==45)f=-f;}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
static void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);}
typedef struct List{int nx,v,c,d;}edge;
int hsz=0;long minHeap[200001][2],output[2];
static void PUSH(int id,long key)
{
  int i=++hsz,j=i>>1;long sw[2];
  minHeap[i][0]=id,minHeap[i][1]=key;
  while(j)
  {
    if(minHeap[i][1]<minHeap[j][1])
    {
      sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
      minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
      minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
      i=j;j>>=1;
    }else break;
  }
}
static void POP(void)
{
  int i=1,j=i+1;long sw[2];
  output[0]=minHeap[i][0],output[1]=minHeap[i][1];
  minHeap[i][0]=minHeap[hsz][0],minHeap[i][1]=minHeap[hsz--][1];
  while(j<=hsz)
  {
    if(j<hsz&&minHeap[j^1][1]<minHeap[j][1]){j^=1;}
    if(minHeap[j][1]<minHeap[i][1])
    {
      sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
      minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
      minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
      i=j;j=i<<1;
    }else break;
  }
  return;
}
int main(void)
{
  int N=IN(),M=IN(),vis[100000],esz=0,adj[100000];
  long dist[100000];edge e[200000];
  rep(i,N){dist[i]=9e18;}
  rep(i,M)
  {
    int A=IN(),B=IN(),C=IN(),D=IN();
    e[2*i].nx=adj[A-1];adj[A-1]=2*i+1;
    e[2*i].v=B;e[2*i].c=C;e[2*i].d=D;
    e[2*i+1].nx=adj[B-1];adj[B-1]=2*i+2;
    e[2*i+1].v=A;e[2*i+1].c=C;e[2*i+1].d=D;
  }
  dist[0]=0l;
  PUSH(1,0l);
  while(hsz)
  {
    POP();
    int u=output[0]-1;long v=output[1];
    if(vis[u]){continue;}
    for(int i=adj[u];i;i=e[i-1].nx)
    {
      int c=e[i-1].c,d=e[i-1].d,to=e[i-1].v;long len=0l;
      if(d)
      {
        int x=sqrt(d)-1;
        if(d/(x+1)>1+d/(x+2)){x++;}
        if(d/(x+1)>1+d/(x+2)){x++;}
        if(v>1l*x){len=1l*c+1l*d/(v+1l);}
        else{len=1l*c+1l*x-v+1l*d/(1l*x+1l);}
      }else{len=1l*c;}
      if(dist[to-1]>v+len){dist[to-1]=v+len;PUSH(to,v+len);}
    }
    vis[u]=1;
  }
  if(dist[N-1]==9e18){puts("-1");}else OUT(dist[N-1]);
}


#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define per(i, a, b) for(int i = b; i >= a; --i)

using ll = long long;
using namespace std;

const int N = 5005;
const int P = 998244353;

int n, m;
ll ans, dp[N];

ll pw(ll a, ll b) {
	ll c = 1;
	for (; b; b /= 2, a = a * a % P)
		if (b & 1) c = c * a % P;
	return c;
}

int main() {
	scanf("%d%d", &n, &m);
	ans = n * pw(m, n) % P;
	rep(len, 2, n)
		rep(x, 1, m)
			dp[len] = (dp[len] + pw(m - x, len - 2)) % P;
	rep(i, 1, n)
		rep(j, i + 1, n)
			ans = (ans - dp[j - i + 1] * pw(m, n - (j - i + 1)) % P + P) % P;
	printf("%lld\n", ans);
	return 0;
}

#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 5e3 + 1;
ll n, m;
ll p[N][N];
ll d[N][N];
ll s[N];
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;

    //cin >> T;
    while (T--) {
        ll mod = 998244353;
        cin >> n >> m;
        if(m == 1){
            cout << 1 << endl;
            return 0;
        }
        p[0][0] = 1;
        for(i = 1; i <= m; i++){
            p[i][0] = 1;
            for(j = 1; j <= n; j++){
                p[i][j] = (p[i][j - 1] * i) % mod;
            }
        }
        for(i = 2; i <= n; i++){
            for(j = 1; j <= m; j++){
                d[i][j] = p[m - 1][i - 2] - p[m - j][i - 2];
                d[i][j] %= mod;
                d[i][j] += mod;
                d[i][j] %= mod;
            }
        }
        for(i = 1; i <= m; i++){
            for(j = 2; j <= n; j++){
                s[j] += d[j][i];
                s[j] %= mod;
            }
        }
        vector<ll> dp(n + 1);
        dp[1] = m;
        for(i = 2; i <= n; i++){
            //cout << i << "##\n";
            dp[i] += m * dp[i - 1];
            //cout << dp[i] << endl;
            dp[i] %= mod;
            dp[i] += m * (p[m - 1][i - 1]);
            dp[i] %= mod;
            // for(j = 1; j <= m; j++){
            //     dp[i] += (p[m - 1][i - 1]);
            //     ll l = 0;
            //     for(ll k = i - 1; k >= 1; k--){
            //         dp[i] += (p[m][k - 1]) * (p[m - 1][l] - p[m - j][l]);
            //         dp[i] %= mod;
            //         l++;
            //     }
            //     //cout << dp[i] << endl;
            // }
            for(j = i - 1; j >= 1; j--){
                dp[i] += p[m][j - 1] * s[i - j + 1];
                dp[i] %= mod;
            }
        }
        cout << dp[n] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long int t;
	cin >> t;
	long long int sum = 0, a, b;
	for (long long int i = 0; i < t; i++)
	{
		cin >> a >> b;
		long long int ans;
		ans = ((b - a + 1) * (a + b)) / 2;
		sum = sum + ans;
	}
	cout << sum;

	return 0;
}

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

int main() { // 入力が相違を保証していることを見落とすときつい
  int N;
  cin >> N;
  set<P> s;
  for(int i = 0; i < N; i++){
    int x, y;
    cin >> x >> y;
    P p;
    p.first = x, p.second = y;
    s.insert(p);
  }

  for (set<P>::iterator i = s.begin(); i != s.end(); ++i) {
    for (set<P>::iterator j = i; j != s.end();) {
      j++;
      if(j == s.end()) continue;
      for (set<P>::iterator k = j; k != s.end();) {
        k++;
        if(k == s.end()) continue;
        int a = (*j).first - (*i).first, b = (*j).second - (*i).second;
        int c = (*k).first - (*i).first, d = (*k).second - (*i).second;
        if(a * d == b * c){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=20000311;
const int maxn=2e5+100;
const int N=2e5+100;
const int M=(1<<20)+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;//cout.tie(0);
    double x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    if(x1>x2) swap(x1,x2),swap(y1,y2);
    double ans=(y1*x2+x1*y2)/(y1+y2);
    printf("%.9f",ans);
    return 0;
}

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

//editorial

int main(){
    int n;
    string t, x;
    cin >> n >> t >> x;

    vi s(n);
    rep(i,n)s[i] = t[i] - '0';

    vv dp(n+1, vi (7, 0));//dp[i][j]: iターン目にjがあれば高橋君が勝つ
    dp[n][0] = 1;
    for(int i=n-1; i>=0; i--){
        if(x[i]=='T'){
            rep(r, 7){
                if( dp[i+1][ 10*r        %7] ) dp[i][r] = 1;
                if( dp[i+1][(10*r + s[i])%7] ) dp[i][r] = 1;
            }
        }
        if(x[i]=='A'){
            rep(r, 7){
                if(   dp[i+1][ 10*r        %7]
                   && dp[i+1][(10*r + s[i])%7] ) dp[i][r] = 1;
            }
        }
    }
    cout << (dp[0][0]?"Takahashi":"Aoki") << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <cmath>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<long long,long long>;
//ll INF = 1e18;
//int INF = 1e9;
//printf("%.10f\n",ans);

int main() {

  int n;
  cin >> n;
  int a = 0;
  rep(i,n){
    int x;
    cin >> x;
    a = max(a,x);
  }
  int b = 1000;
  rep(i,n){
    int y;
    cin >> y;
    b = min(y,b);
  }
  if(b < a) cout << 0 << endl;
  else cout << b-a+1 << endl;

  return 0;
}

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

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

  set<int> a;
  set<int> b;

  for(int i=0;i<n;i++){
    int x;
    cin >>x;
    a.insert(x);
  }
  for(int i=0;i<n;i++){
    int x;
    cin >>x;
    b.insert(x);
  }

  int ans=*begin(b)-*rbegin(a)+1;

  if(ans<=0){
    cout << 0 <<endl;
    return 0;
  }

  cout << ans << endl;

}


#include <cstdio>
#define int long long
const int N = 3005, P = 1000000007;
int n, a[N], ans, f[N], tub[N], b[N], t[N];
signed main() {
    scanf("%lld", &n);
    for(int i = 1; i <= n; i++) scanf("%lld", &a[i]), a[i] += a[i-1];
    for(int i = 1; i <= n; i++) f[i] = 1;
    ans = (ans + f[n]) % P;
    for(int i = 2; i <= n; i++) {
        for(int j = 1; j <= n; j++) b[j] = a[j] % i;
        for(int j = 0; j <= n; j++) tub[j] = 0;
        for(int j = 1; j <= n; j++) t[j] = f[j];
        for(int j = 1; j <= n; j++) {
            f[j] = tub[b[j]] % P;
            tub[b[j]] = (tub[b[j]] + t[j]) % P;
        }
        ans = (ans + f[n]) % P;
    }
    printf("%lld", ans);
    return 0;
}

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;
ll gcd(ll x, ll y) {
    if (x % y == 0) {
        return y;
    } else {
        return gcd(y, x % y);
        // x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。
    }
}

int main() {
    ll n, ans, max_cnt = 0;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    // rep(i, 1001) {
    //     int cnt = 0;
    //     for (int j = i + 1; j < n; j++) {
    //         if (gcd(a[i], a[j]) == a[i]) cnt++;
    //     }
    //     if (cnt > max_cnt) {
    //         max_cnt = cnt;
    //         ans = a[i];
    //         debug(max_cnt, ans);
    //     }
    // }
    for (int i = 2; i < 1001; i++) {
        int cnt = 0;
        for (int j = 0; j < n; j++) {
            // if (gcd(i, a[j]) == i) cnt++;
            if (a[j] % i == 0) cnt++;
        }
        if (cnt > max_cnt) {
            max_cnt = cnt;
            ans = i;
            debug(max_cnt, ans);
        }
    }
    cout << ans << endl;
    return 0;
}


using namespace std;
#include <iostream>

int main() {
    int n, a, b; cin >> n >> a >> b;
    cout << n - a + b << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vll vector<ll>
#define vi vector<int>
#define sz(v) (ll)v.size()
#define all(v) v.begin(),v.end()
#define pq_max priority_queue<ll>
#define pq_min priority_queue <ll, vector<ll>, greater<ll> >
#define debug(x) cout<<#x<<"->"<<x<<endl
#define debug2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<"->"<<y<<endl
#define debug3(x,y,z) cout<<#x<<"->"<<x<<", "<<#y<<"->"<<y<<","<<#z<<"->"<<z<<endl
#define endl '\n'
#define ff first
#define ss second
const ll INF = 4000000000000000000;
const ll mod = 1000000007;
const ll prime1 = 1999999973, prime2 = 1999999943;
void read(vll& arr,ll n){
    for(int i=0;i<n;i++) cin>>arr[i];
}
ll solve(){
    vll arr(3);
    read(arr,3);
    sort(all(arr));
    cout<<arr[2]+arr[1];
    return 0;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("minima.in","r",stdin);
    // freopen("minima.out","w",stdout);
    ll T=1;
    // cin>>T;
    for(int i=1;i<=T;i++){
        //cout<<"Case #"<< i <<":";
        solve();
        //cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define forn(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

void solve(){
	int N; cin >> N;
	int c = 0;
	for(int i = 0; i < N; i++) {
		int a; cin >> a;
		if(a > 10)
			c += (a - 10);
	}
	cout << c << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	fast_cin();
	int t = 1;
	//cin >> t;

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

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define double long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

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

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

    int n; cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    int x=0,ans=0;
    for(int i=0;i<n;i++){
        x=max(x,a[i]);
        ans=max(ans,b[i]*x);
        cout<<ans<<endl;
    }

}


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

const int N = 5e3+5 ,mod = 998244353;

long long fac[N]={1} ,inv[N]={1} ;
long long fast_power(long long b,long long p){
    long long res=1;
    while(p){
        if(p%2) res=(res*b)%mod;
        b=(b*b)%mod;
        p/=2;
    }
    return res;
}
void prep(){
    for(int i=1;i<N;++i){
        fac[i]=(fac[i-1]*i)%mod;
        inv[i]=fast_power(fac[i],mod-2);
    }
}
long long choose(int n,int r){
    return ((fac[n]*inv[r])%mod*inv[n-r])%mod;
}

int n ,m ;
int ways[N] ,mem[N][15] ;
int solve(int rem,int bt){
    if(rem==0) return 1;
    if(rem<0) return 0;
    if(bt<0) return 0;
    int&ret = mem[rem][bt] ;
    if(~ret) return ret ;
    ret = 0 ;
    int val = 1<<bt ;
    for(int cnt=0;cnt<=n;cnt+=2){
        long long cur = 1ll * val * cnt ;
        if(cur>rem) break ;
        ret = (ret + 1ll*solve(rem-cur,bt-1)*ways[cnt]%mod)%mod;
    }
    return ret ;
}
int main(){
    prep();
    cin >> n >> m ;
    for(int cnt=0;cnt<=n;++cnt) ways[cnt] = choose(n,cnt) ;
    memset(mem,-1,sizeof mem);
    cout << solve(m,13) ;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pp=pair<ll,ll>;
const ll INF=1e18;
const ll mod=1e9+7;
const double pi=3.14159265358979323846;

ll modpow(ll a, ll b) {     // aのb乗
  ll ans=1;
  for (ll i=0; i<63; i++) {
    if (b & ((ll)1<<i)) {
      ans*=a;
      ans%=mod;
    }
    a*=a;
    a%=mod;
  }
  return ans;
}

int main() {
  ll h, w, K=0, ans=0;
  cin >> h >> w;
  vector<vector<char>> S(h, vector<char>(w));
  vector<vector<ll>> V(h, vector<ll>(w,0));
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cin >> S[i][j];
      if (S[i][j]=='.') {K++;}
    }
  }

  int tmp=0;
  for (int i=0; i<h; i++) {
    tmp=0;
    int l=0, r=0;
    for (int j=0; j<w; j++) {
      if (S[i][j]=='.') {
        r++;
        tmp++;
      }
      else {
        for (int k=l; k<r; k++) {
          V[i][k]+=tmp;
        }
        l=r+1;
        r=l;
        tmp=0;
      }
    }
    if (S[i][w-1]=='.') {
      for (int k=l; k<r; k++) {
        V[i][k]+=tmp;
      }
    }
  }

  for (int j=0; j<w; j++) {
    tmp=0;
    int l=0, r=0;
    for (int i=0; i<h; i++) {
      if (S[i][j]=='.') {
        r++;
        tmp++;
      }
      else {
        for (int k=l; k<r; k++) {
          V[k][j]+=tmp;
        }
        l=r+1;
        r=l;
        tmp=0;
      }
    }
    if (S[h-1][j]=='.') {
      for (int k=l; k<r; k++) {
        V[k][j]+=tmp;
      }
    }
  }

  /*
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cout << V[i][j] << " ";
    }
    cout << endl;
  }
  */

  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (V[i][j]==0) {continue;}
      V[i][j]--;
      ans+=modpow(2, K);
      ans-=modpow(2, K-V[i][j]);
      ans+=mod;
      ans%=mod;
    }
  }
  cout << ans << endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef long long LL;
typedef long long ll;

inline LL quick_mul(LL a,LL b,LL m) //快速乘
{
    ll ans = 0;
    a %= m;
    b %= m;
    while (b) {
        if (b & 1) {
            ans = (ans + a) % m;
        }
        a = (a + a) % m;
        b >>= 1;
    }
    return ans;
}

LL quick_pow(LL a,LL b,LL m) //快速幂
{
    LL res=1;
    a%=m;
    while(b)
    {
        if(b&1) res=quick_mul(res,a,m);
        a=quick_mul(a,a,m);
        b>>=1;
    }
    return res;
}
bool Miller_rabin(LL n,int num)
{
//先将特殊情况判断一下
    if(n==2||n==3) return true;
    if(n%2==0||n==1) return false;
    srand((unsigned)time(NULL)); //为接下来a的随机取值用
    LL d=n-1;
    int s=0;
    while(!(d&1)) s++,d>>=1;//若d的二进制的最后一位不是1，则说明d还是偶数
    for(int i=0;i<num;i++)
    {
        LL a=rand()%(n-2)+2;//2~n-1;
        LL x=quick_pow(a,d,n), y=0;
        for(int j=0;j<s;j++)//一共平方s次
        {
            y=quick_mul(x,x,n);//先平方
            if(y==1&&x!=1&&x!=(n-1)) return false;//验证二次探测原理
            x=y;
        }
        if(y!=1) return false;//不满足费马小定理，那就肯定不是质数
    }
    return true;
}
ll n;

bool  isSqrt(ll t)
{
for (ll  i = 1 ;t > 0 ;i += 2 ) t -= i;
return   0   ==  t;
}

void solve()
{
	cin>>n;
	if(n % 4 == 0)
	{
		cout<<"Even"<<'\n';
	}

	if(n % 2 == 0 && n % 4 != 0)
	{
		cout<<"Same"<<'\n';
	}

	if(n % 2 != 0)
	{
		cout<<"Odd"<<'\n';
	}
}

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

#include <iostream>
using namespace std;
int main() {
  int t;
  cin>>t;
  for(int i=0;i<t;i++){
    long long  num ;
    cin >> num;
     if (num%4==0){
      cout<<"Even"<<endl;
      continue;
    }
    if(num % 2==1){
      cout<<"Odd"<<endl;
      continue;
    }
    else{
      cout<<"Same"<<endl;
      continue;
    }
  }
}


#include<bits/stdc++.h>
#define N 101
int a,b,c,vis[N][N][N];
double f[N][N][N];
inline double F(int x,int y,int z){
	if(x>99||y>99||z>99)return 0;
	if(vis[x][y][z])return f[x][y][z];vis[x][y][z]=1;
	return f[x][y][z]=(F(x+1,y,z)*x+F(x,y+1,z)*y+F(x,y,z+1)*z)/(x+y+z)+1;
}
signed main(void){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);printf("%.10lf\n",F(a,b,c));
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, x, y;
  cin >> a >> b >> x >> y;
   int y_ = min(2*x, y);
   cout << abs(2*a-1-2*b) / 2 * y_ + (abs(2*a-1-2*b)%2 == 0 ? 0 : x) << endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#define gg 9223372036854775807
#ifdef LOCAL
#define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl;
#define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl;
#else
#define debug(x) true
#define debugALL(x) true
#endif
using namespace std;

template<typename T>
struct segment_tree{
    function<T(T,T)> f = [](T a, T b){return a+b;};
    T inf=0;
    vector<T> value;
    int N;
    segment_tree(int n){
        N=1;
        while(N<n)N*=2;
        value.assign(2*N-1,inf);
    }
    segment_tree(int n, function<T(T,T)> func, T t1){
        N=1;
        while(N<n)N*=2;
        value.assign(2*N-1,t1);
        f=func;
        inf=t1;
    }
    void update(int i,T x){
        i+=N-1;
        value[i]=x;
        while(i>0){
            i=(i-1)/2;
            value[i]=f(value[i*2+1],value[i*2+2]);
        }
    }
    T query(T a,T b){
        return query(a,b,0,0,N);
    }
    T query(T a,T b, int k, int l, int r){
        if(r<=a || b<=l)return inf;
        if(a<=l && r<=b){
            return value[k];
        }else{
            ll c1=query(a,b,2*k+1,l,(l+r)/2);
            ll c2=query(a,b,2*k+2,(l+r)/2,r);
            return f(c1,c2);
        }
    }
    void print(){
        for(int i=0;i<ceil(log2(N))+1;i++){
            for(int j=0;j<(1<<i);j++){
                cout<<value[j+(1<<i)-1]<<((j==(1<<i)-1)?';':',');
            }
            cout<<endl;
        }
    }
};

V tmp;
int get(ll val){
    return lower_bound(tmp.begin(),tmp.end(),val)-tmp.begin();
}

int main(){
    ll n,m,q;
    cin>>n>>m>>q;
    V t(q),x(q),y(q);
    rep(i,q){
        cin>>t[i]>>x[i]>>y[i];
        x[i]--;
    }
    tmp=y;
    tmp.push_back(0);
    sort(tmp.begin(),tmp.end());

    segment_tree<ll> sa(3e5);
    segment_tree<ll> sb(3e5);
    sa.update(0,n);
    sb.update(0,m);
    segment_tree<ll> ssa(3e5);
    segment_tree<ll> ssb(3e5);
    ssa.update(0,0);
    ssb.update(0,0);
    V a(n,0),b(m,0);
    ll ans=0;
    rep(i,q){
        if(t[i]==1){
            ll nowvalid=get(a[x[i]]);
            ll pval=a[x[i]];
            ll prev=sb.query(0,nowvalid);
            ll pprev=ssb.query(0,nowvalid);
            sa.update(nowvalid,sa.query(nowvalid,nowvalid+1)-1);
            ssa.update(nowvalid,ssa.query(nowvalid,nowvalid+1)-a[x[i]]);
            a[x[i]]=y[i];
            ll nextvalid=get(y[i]);
            ll next=sb.query(0,nextvalid);
            ll nnext=ssb.query(0,nextvalid);
            sa.update(nextvalid,sa.query(nextvalid,nextvalid+1)+1);
            ssa.update(nextvalid,ssa.query(nextvalid,nextvalid+1)+a[x[i]]);
            ans+=a[x[i]]*next-prev*pval-(nnext-pprev);
        }else{
            ll nowvalid=get(b[x[i]]);
            ll pval=b[x[i]];
            ll prev=sa.query(0,nowvalid);
            ll pprev=ssa.query(0,nowvalid);
            sb.update(nowvalid,sb.query(nowvalid,nowvalid+1)-1);
            ssb.update(nowvalid,ssb.query(nowvalid,nowvalid+1)-b[x[i]]);
            b[x[i]]=y[i];
            ll nextvalid=get(y[i]);
            ll next=sa.query(0,nextvalid);
            ll nnext=ssa.query(0,nextvalid);
            sb.update(nextvalid,sb.query(nextvalid,nextvalid+1)+1);
            ssb.update(nextvalid,ssb.query(nextvalid,nextvalid+1)+b[x[i]]);
            //ans+=(next-prev)*y[i]+pprev-nnext;
            ans+=b[x[i]]*next-prev*pval-(nnext-pprev);
        }
        cout<<ans<<endl;
    }
}

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

const int N = 100 + 1;
const int K = 1'000'000;

int mod;

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

int sub(int &a, int b) {
  a -= b;
  if (a < 0) {
    a += mod;
  }
  return a;
}

int mul(int a, int b) {
  return (long long) a * b % mod;
}

int ways[N][K];

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

  int n, m;
  cin >> n >> m >> mod;

  ways[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < K; ++j) {
      int prv = j - i;
      int prv_prv = j - i * (m + 1);

      ways[i][j] = ways[i - 1][j];
      if (prv >= 0) {
        add(ways[i][j], ways[i][prv]);
      }
      if (prv_prv >= 0) {
        sub(ways[i][j], ways[i - 1][prv_prv]);
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    int ans = 0;
    for (int j = 0; j < K; ++j) {
      add(ans, mul(ways[i][j], ways[n - i - 1][j]));
    }
    ans = mul(ans, m + 1);
    sub(ans, 1);
    cout << ans << "\n";
  }
}


// {{{ by unolight
#pragma region
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
#pragma endregion
// }}}

// {{{ 1-indexed BIT
template<class T>
struct BIT {
    int n;
    vector<T> bit;
    BIT(int n_):n(n_+1), bit(n_+1, 0) {}
    void init() { fill(bit.begin(), bit.end(), 0); }
    void add(int k, T v) {
        for(;k<n; k+=k&-k) bit[k] += v;
    }
    T get(int k) {
        T r=0;
        for(;k>0;k-=k&-k) r+=bit[k];
        return r;
    }
    // (l, r]
    T get(int l, int r) {
        return get(r) - get(l);
    }
    T operator[](int i) { return get(i-1,i); }
};

const int N=200010;
vector<array<int,4>> events;
LL intersection_points() {
  BIT<LL> bit(N);
//   for ( int i=0; i<n; i++ ) {
//     int a,b,c,d;
//     cin >> a >> b >> c >> d; // (x1,y1) (x2,y2)
//     if ( a==c ) { // query
//       events.push_back({a, 2, b, d});
//     } else { // at x1 add, x2 remove
//       events.push_back({a, 1, b, 1});
//       events.push_back({c, 3, b, -1});
//     }
//   }
  sort(events.begin(), events.end());
  long long ans = 0;
  for ( int i=0; i<events.size(); i++ ) {
    if ( events[i][1]==1 ) {
      int y = events[i][2];
      bit.add(y, 1);
    } else if ( events[i][1]==3 ) {
      int y = events[i][2];
      bit.add(y, -1);
    } else {
      int l = events[i][2], r = events[i][3];
      ans += bit.get(l-1, r);
    }
  }
  return ans;
}

void main() {
    int h,w,m;
    R(h,w,m);
    vector<int> x(h+1,w+1),y(w+1,h+1);
    REP(i,m) {
        int a,b;
        R(a,b);
        chmin(x[a],b);
        chmin(y[b],a);
    }
    LL ans=0;
    REP1(i,1,y[1]-1) ans+=x[i]-1;
    REP1(i,1,x[1]-1) ans+=y[i]-1;
    REP1(i,1,y[1]-1) events.push_back({i,2,1,x[i]-1});
    REP1(i,1,x[1]-1) {
        events.push_back({1,1,i,-1});
        events.push_back({y[i]-1,3,i,-1});
    }
    // dump(intersection_points());
    W(ans-intersection_points());
}

 // {{{ main
}}
int main() { unolight::main(); return 0; }
// }}}

/**
 *  author: souravrax
 *  created: 19.06.2021 17:50:09
**/
#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#define len(x) int((x).size())
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename TC, typename T = typename enable_if<!is_same<TC, string>::value, typename TC::value_type>::type>
ostream& operator<<(ostream &os, const TC &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
struct dbg {
#ifdef LOCAL
    ~dbg() { cerr << endl; }
    template<typename T> dbg& operator<<(const T& args) { cerr << args; return *this; }
#else
    template<typename T> dbg& operator<<(__attribute__((unused))const T& args) { return *this; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int, int>;

const int MAXN = (int)2e5 + 5;
bitset<MAXN> visited;
vector<int> graph[MAXN];

int dfs(int u) {
    visited[u] = true;
    int ans = 1;
    for (int& v : graph[u]) {
        if (!visited[v]) {
            ans += dfs(v);
        }
    }
    return ans;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int& i : a) cin >> i;
    for (int i = 0, j = n - 1; i < j; i++, j--) {
        if (a[i] != a[j]) {
            graph[a[i]].push_back(a[j]);
            graph[a[j]].push_back(a[i]);
        }
    }
    ll ans = 0;
    for (auto& i : a) {
        if (!visited[i]) {
            ans += dfs(i) - 1;
        }
    }
    cout << ans << '\n';
}