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

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

#define _USE_MATH_DEFINES
#include <math.h>

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

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

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

typedef int i64;

using namespace std;
using namespace std::chrono;

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

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

const long double eps = 1e-8;

struct TCalcSegTree {
    using Type = i64;
    const Type Zero = 0;

    inline Type Combine(Type a, Type b) {
        return a ^ b;
    }

    i64 N = 0;
    vector<Type> St;

    TCalcSegTree() {}

    TCalcSegTree(i64 size) {
        Init(size);
    }

    void Init(i64 size) {
        N = 1;
        while (N < size) {
            N *= 2;
        }
        St.assign(N * 2, Zero);
    }

    void Set(i64 i, Type v, i64 x, i64 lx, i64 rx) {
        if (rx - lx == 1) {
            St[x] = Combine(St[x], v);
            return;
        }

        i64 m = (lx + rx) / 2;
        if (i < m) {
            Set(i, v, x * 2 + 1, lx, m);
        }
        else {
            Set(i, v, x * 2 + 2, m, rx);
        }

        St[x] = Combine(St[x * 2 + 1], St[x * 2 + 2]);
    }

    void Set(i64 i, Type v) {
        Set(i, v, 0, 0, N);
    }

    Type Calc(i64 l, i64 r, i64 x, i64 lx, i64 rx) {
        if (lx >= r || l >= rx) {
            return Zero;
        }

        if (l <= lx && rx <= r) {
            return St[x];
        }

        i64 m = (lx + rx) / 2;
        Type v1 = Calc(l, r, x * 2 + 1, lx, m);
        Type v2 = Calc(l, r, x * 2 + 2, m, rx);
        return Combine(v1, v2);
    }

    Type Calc(i64 l, i64 r) {
        return Calc(l, r, 0, 0, N);
    }
};

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

    if (sizeof(i64) != sizeof(long long int)) {
        cerr << "i64 != long long int" << endl;
    }

    i64 n, m;
    cin >> n >> m;

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

    TCalcSegTree st(n);
    for (i64 i = 0; i < n; i++) {
        st.Set(i, a[i]);
    }

    stringstream ss;

    for (i64 i = 0; i < m; i++) {
        i64 t, x, y;
        cin >> t >> x >> y;
        if (t == 1) {
            st.Set(x - 1, y);
        }
        else {
            i64 R = st.Calc(x - 1, y);
            ss << R << endl;
        }
    }
    cout << ss.str();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>
#include <iomanip>
#include <limits>
#include <random>
#include <unordered_map>

typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;

#define rip(_i, _n, _s) for (int _i = (_s); _i < (int)(_n); _i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename _T>
using MaxHeap = std::priority_queue<_T>;
template<typename _T>
using MinHeap = std::priority_queue<_T, std::vector<_T>, std::greater<_T>>;

template<typename _T>
inline bool chmax(_T &_l, const _T _b) {
    if (_l < _b) {
        _l = _b;
        return true;
    }
    return false;
}
template<typename _T>
inline bool chmin(_T &_l, const _T _b) {
    if (_l > _b) {
        _l = _b;
        return true;
    }
    return false;
}

template<typename _T>
void vdeb(const std::vector<_T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename _T>
void vdeb(const std::vector<std::vector<_T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    int a, b; cin >> a >> b;
    a += b;
    if(a >= 15 && b >= 8) cout << 1 << endl;
    else if(a >= 10 && b >= 3) cout << 2 << endl;
    else if(a >= 3) cout << 3 << endl;
    else cout << 4 << endl;
}

#include <iostream>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <utility>
#include <set>
const long long INF = 1LL<<60;
using ll = long long;
using namespace std;

int main() {
    ll t,N;cin>>t>>N;
    vector<ll> T(100);
    map<ll,ll> m;
    ll msize = 0;
    for (int i = 0; i < 100; i++)
    {
        T[i] = (i*t)%100;
        // cout << T[i];
        if(i>0&&T[i]<T[i-1]){
            m[msize] = i-1;
            // cout << " "  <<msize << " " <<i-1;
            msize++;
        }
        // cout << endl;
    }
    m[msize] = 99;
    msize++;
    m[-1] = -1;
    // cout << msize << endl;
    ll id = N%msize;
    ll id1 = (N-id)/msize;
    // cout << id << id1 << endl;
    ll A = id1*100 + m[id-1];
    // cout << A << endl;
    double b = A*(100+t)/100;
    cout << (ll)(floor(b)+0.5)+1<<endl;
}


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

ll sum(ll mn, ll mx) {
	return (mx - mn + 1)*(mn + mx) / 2;
}

int main() {
	int t, l, r;
	cin >> t;
	rep(i, t) {
		cin >> l >> r;
		int mx;
		mx = r - l - l + 1;
		mx = max(mx, 0);

		cout << sum(1, mx) << endl;
	}
}

/*
    author : Aryan Agarwal, IIT KGP
    created : 10-January-2021 18:43:37 IST
*/

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

const int mxn = 2e5;
const long long INF = 2e18;
const int32_t M = 1000000007; /*more than 1e9 */ /*7 + 1e9*/
// const int32_t M = 998244353; /*less than 1e9 */   /*1 + 7*17*(1<<23) */
const long double pie = acos(-1);

#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

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

vector <int> mx(mxn,-INF);
vector <int> a(mxn);
vector< vector<int> > adj(mxn);
vector <bool> vis(mxn);
// vector <bool> ans(mxn,-INF);
int ans=-INF;
int n,m;

void dfs(int u){
    vis[u]=true;

    for(int to : adj[u])
    {
        if(!vis[to])dfs(to);
    }

    for(int to : adj[u])
    {
        mx[u]=max(mx[to],mx[u]);
        mx[u]=max(a[to],mx[u]);
    }

    ans=max(ans,-a[u]+mx[u]);
    // dbg(u,a[u],mx[u]);

}

void solve_LOG()
{
    cin>>n>>m;

    F(i,0,n-1)cin>>a[i];

    F(i,0,m-1)
    {
        int u,v;
        cin>>u>>v;
        --u;--v;
        adj[u].pb(v);
    }

    F(i,0,n-1)
    {
        if(!vis[i])
            dfs(i);
    }

    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    // defualt mxn_sieve = 1e5
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    // default [L,R] = [1,1e5]
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    // default mxn_fact = 1e5
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    // cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOG();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define READ freopen("out.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
typedef unsigned long long int ull;
ll INF=1<<28;
//typedef long long lld;
//const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
//int X[8]={0,0,1,-1,-1,1,1,-1};
int Y[8]={1,-1,0,0,-1,-1,1,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-16;
//#define INF 10000

ll lcm(ll a,ll b)
{
    return ((a*b)/__gcd(a,b));
}
struct compare
{
  bool operator()(const pii& l, const pii& r)
  {
      if(l.ff==r.ff)
      {
          return l.sn>r.sn;
      }
      return l.ff<r.ff;
  }
};

const int mx=301050;
//const int mod=998244353;
const int mod=1e9+7;
// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
//////cout<<*X.find_by_order(1)<<endl;
////cout<<X.order_of_key(-5)<<endl;

//4352348930241
//const int mod=11092019;

int arr[mx];
int tree[4*mx];
void update(int b,int e,int ind,int st,int en)
{
    if(st>e || en<b)
        return;
    if(st<=b && e<=en)
    {
        cnd=1;
        return;
    }
    update(lndp,st,en);
    update(rndp,st,en);
    cnd=lnd+rnd;
}
int query(int b,int e,int ind,int st,int en)
{
    if(st>e || en<b)
    {
        return 0;
    }
    if(st<=b && e<=en)
        return cnd;
    return query(lndp,st,en)+query(rndp,st,en);
}
int main()
{

    int t=1,tc=1;
//    sf(t);
    while(t--)
    {
        int n;
        sf(n);
        for(int i=0;i<n;i++)
        {
            sf(arr[i]);
        }
        ll ans=0;
        for(int i=n-1;i>=0;i--)
        {
            ans+=query(0,n-1,1,0,arr[i]-1);
            update(0,n-1,1,arr[i],arr[i]);
        }
        printf("%lld\n",ans);
        vector<ll>v;
        for(int i=n-1;i>=1;i--)
        {
            ans-=(n-1-arr[i]);
            ans+=(arr[i]);
            v.pb(ans);
        }
        reverse(v.begin(),v.end());
        for(int i=0;i<v.size();i++)
        {
            printf("%lld\n",v[i]);
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define FOR(i, j, k, in) for (ll i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (ll i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

void add(vector<ll> &fw, ll index) {
    index++;
    while (index <= fw.size()) {
        fw[index - 1]++;
        index += index & -index;
    }
}

ll prefix(const vector<ll> &fw, ll index) {
    ll ret = 0;
    while (index > 0) {
        ret += fw[index - 1];
        index -= index & -index;
    }

    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<ll> perm(n);
    REP(i, n)
    cin >> perm[i];
    vector<ll> forward(n), backward(n);
    // set<int> elems;
    vector<ll> fw(n + 2, 0);
    REP(i, n) {
        // int dist = distance(elems.begin(), elems.upper_bound(perm[i]));
        ll dist = prefix(fw, perm[i] + 1);
        // forward[i] = elems.size() - dist;
        forward[i] = i - dist;
        if (i != 0) forward[i] += forward[i - 1];
        // elems.insert(perm[i]);
        add(fw, perm[i] + 1);
    }
    // cout << "forward:";
    // for (const auto el : forward) cout << ' ' << el;
    // cout << endl;
    fw.clear();
    fw.resize(n + 2, 0);
    // cout << "fw:";
    // for (const auto el : fw) cout << ' ' << el;
    // cout << endl;
    RFOR(i, n - 1, 0, 1) {
        // int dist = distance(elems.begin(), elems.upper_bound(perm[i]));
        ll dist = prefix(fw, perm[i] + 1);
        backward[i] = dist;
        if (i != n - 1) backward[i] += backward[i + 1];
        // elems.insert(perm[i]);
        add(fw, perm[i] + 1);
    }
    // cout << "backward:";
    // for (const auto el : backward) cout << ' ' << el;
    // cout << endl;
    ll total = forward[n - 1];
    cout << total << endl;
    // cout << endl;
    FOR(i, 0, n - 1, 1) {
        ll possible = (i + 1) * (n - 1 - i);
        // cout << "i: " << i << endl;
        // cout << "possible: " << possible << endl;
        ll current = total - forward[i] - backward[i + 1];
        // cout << "current: " << current << endl;
        cout << possible - current + forward[i] + backward[i + 1] << endl;
        // cout << endl;
    }
    return 0;
}


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

#if defined(DONLINE_JUDGE)
	#define NDEBUG
#elif defined(ONLINE_JUDGE)
	#define NDEBUG
#endif

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

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

	i64 ans = 1LL << 60;
	for(int k = 1; k <= n; k++) {
		auto dp = make_v<int>(k + 1, k + 1); // dp[i][j] := sum (i 個使って sum % k = j)
		for(int i = 0; i < dp.size(); i++) for(int j = 0; j < dp[i].size(); j++) dp[i][j] = -1;
		dp[0][0] = 0;

		for(auto v: a) {
			for(int i = k - 1; i >= 0; i--) {
				for(int j = 0; j < k; j++) {
					if(dp[i][j] == -1) continue;
					int sum = dp[i][j] + v;
					int to = sum % k;
					if(dp[i + 1][to] == -1) dp[i + 1][to] = sum;
					dp[i + 1][to] = std::max(dp[i + 1][to], sum);
				}
			}
		}

		int r = x % k;
		if(dp[k][r] == -1) continue;
		ans = std::min(ans, (x - dp[k][r]) / k);

		#ifndef NDEBUG
		cout << k << ": " << dp[k][r] << endl;
		#endif
	}

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

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(),(v).end()
#define rmax(a,b) a = max<ll>(a,b)
#define rmin(a,b) a = min<ll>(a,b)

typedef long long ll;

const int N = 110;
ll dp[N][N][N];

ll v[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n, targ; cin >> n >> targ;
	ll soma = 0;
	fr(i,n) cin >> v[i], soma+=v[i];
	if(soma==targ){
		cout << 0 << "\n";
		return 0;
	}

	ll ans = LLONG_MAX;

	for(ll t = 1; t<=n; t++){
		fr(i,n+1) fr(j,n+1) fr(k,n+1) dp[k][i][j] = INT_MIN;
		dp[0][0][0] = 0;

		fr(i,n){
			fr(t_sofar,n+1) fr(p,n){
				ll r = (p+v[i])%t;
				rmax(dp[i+1][t_sofar][p],
					dp[i][t_sofar][p]);
				if(t_sofar==n) continue;
				rmax(dp[i+1][t_sofar+1][r],
					dp[i][t_sofar][p]+v[i]);

			}
		}

		ll need_r = targ%t;
		if(dp[n][t][need_r]>0){

			assert(dp[n][t][need_r]<=targ);
			//prin(t);
			//prin(dp[n][t][need_r]);
			assert((targ-dp[n][t][need_r])%t==0);
			rmin(ans, (targ-dp[n][t][need_r])/t);
		}
	}

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


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
ll gcd(ll x,ll y){
  if(x<y)swap(x,y);
  if(y==0)return x;
  return gcd(y,x%y);
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

int main() {

  ll t,N;
  cin>>t>>N;
  int Q[200]={0};
  for(int i=1;i<101;i++){
    for(int j=1;j<=100+t;j++){
      if(i+(t*i)/100==j){
        Q[j]=1;
      }
    }

  }

  ll count=0;
  ll R[200];
  for(int i=1;i<=100+t;i++){

    if(Q[i]==0){
    count++;

    R[count]=i;

    }

  }

  ll L=0;
  if(N%count==0)L=N/count-1;
  else L=N/count;
  ll M=N%count;
  ll ans=0;
  if(M==0){
  ans=L*(100+t)+R[count];
  }
  else{
  ans=L*(100+t)+R[M];
  }
  cout<<ans<<endl;

}

#include<cstdio>
#define ll long long
ll t, n, ans;
int main(){
	scanf("%lld%lld", &t, &n);
	ans = 100*n/t;
	if(100*n % t != 0) ans++;
	ans = ans + ans*t/100;
	printf("%lld", ans-1);
	return 0;
}


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

#define endl        "\n"
#define LL          long long
#define READ(x)     freopen(x,"r",stdin)
#define WRITE(x)    freopen(x,"w",stdout)
#define BOOST       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb          push_back
#define mem(x,y)    memset(x,y,sizeof x )
#define ch          printf("Came Here!!!!!!!!!!!!!!!\n")
#define deb(x)      cerr<<#x<<" :: "<<x<<" "
#define dnl         cerr<<endl;
#define FOR(i,n)    for(int i=0;i<n;i++)
#define cnd         tree[idx]
#define lc          tree[idx*2]
#define rc          tree[idx*2+1]
#define lnd         (2*idx),(b),( (b+e) /2 )
#define rnd         ((2*idx)+1),(((b+e)/2)+1),(e)
#define popcount    __builtin_popcount

//const LL        INF = 1LL<<59;
const double    PI = 2.0 * acos(0.0);

typedef pair<int,int>   pii;
typedef pair<LL,LL>     pll;
typedef vector<int>     vi;
typedef vector<LL>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/////cout<<*X.find_by_order(1)<<endl;
/////cout<<X.order_of_key(-5)<<endl;
//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

// Grid direction array [4]
int X[4]={0,0,-1,1};
int Y[4]={1,-1,0,0};
// Grid direction array [8]
int X8[8]={0,0,1,-1,-1,1,1,-1};
int Y8[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
int BX[8]={0,0,1,-1,-1,1,1,-1};
int BY[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
int KX[8] = {1,1,2,2,-1,-1,-2,-2};
int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline LL modMul(LL a, LL b,LL mod){
    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
inline LL power(LL a,LL b,LL mod){
    if(b==0)return 1LL%mod;
    LL x=power( a,b/2,mod );
    x = (x*x) % mod;
    if( b%2==1 )x = (x*a)%mod;
    return x%mod;
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 234567;

void solve(int cs){
    int n,m;
    LL a,b,c;
    cin>>a>>b>>c;

    if( c%2==0 ){
        if( abs(a)==abs(b) )cout<<"=";
        else if( abs(a)<abs(b) )cout<<"<";
        else cout<<">";
    }
    else{

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

int main(){
    BOOST;
    #ifdef MujahidPC
        double start = clock();
//        READ("in.txt");
//        WRITE("out.txt");
    #endif

    int t;
    t = 1;
//    cin>>t;
    FOR(cs,t)solve(cs+1);

    #ifdef MujahidPC
        double tim = (clock() - start)/CLOCKS_PER_SEC;
        cerr<<"Running Time : "<<tim<<" \n";
    #endif
    return 0;
}

#include<iostream>
using namespace std;
//       {{{{{{{{{{{{{{{ SOLVER    :    SANGAM KUMAR }}}}}}}}}}}}}}}

#include<math.h>
#include<stdio.h>
#include <cstdlib>
#include <ctime>
#include<cmath>
#include<string.h>
#include<stdlib.h>
#include<bits/stdc++.h>
#define ll long long int
#define start ll _; cin>>_;  while(_--){ runtest();}
#define loop(j,n) for(ll h=j;h<n;h++)
#define var ll n,m,x,y,z,c,j,h,k;
#define array ll a[200004],b[200004];
#define ci cin
#define co cout
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define nan cout<<"-1\n";
#define line cout<<"\n";
#define getarray cin>>n; ll a[200005]; loop(0,n){ ci>>a[h];}
#define putarray loop(0,n){ co<<a[h]<<" "; }

// predefined functions

ll lcm(ll a, ll b)
{
    ll k=(a*b)/(__gcd(a,b));
    return k;
}

bool isprime(ll n)
{

	if (n <= 1)
		return false;
	if (n <= 3)
		return true;

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

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

	return true;
}

ll fact(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * fact(n - 1);
}

void runtest()
{
    var;
}

int main()
{
  //  start
  ll a,b,c;

  ci>>a>>b>>c;
  ll x=(ll)pow(a,c);
  ll y=(ll)pow(b,c);
  if(c%2==0)
  {
      if(abs(a)==abs(b))
      {
          co<<"=";
      }
      else if(abs(a)>abs(b))
      {
          co<<">";
      }
      else co<<"<";
  }
  else
  {
      if(a>b)
      {
          co<<">";
      }
      else if(a<b)
      {
          co<<"<";
      }
      else co<<"=";
  }

    return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define bg begin()
#define en end()
#define endl "\n"
#define vvl(n,m) vector<vector<ll> > a( n , vector<ll> (m))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)
        return b;
    else return gcd(b%a,a);
}
ll power(ll x, ll y, ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y / 2, m) % m;
    p = (p * p) % m;

    return (y % 2 == 0) ? p : (x * p) % m;
}
ll modInverse(ll a, ll m)
{
    return power(a, m - 2, m);
}
ll ncr(ll n, ll k)
{
    ll res = 1;

    if (k > n - k)
        k = n - k;
    for (ll i = 0; i < k; ++i) {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}
void permute(string str)
{
    set<string> s;
    sort(str.begin(), str.end());
    do {
        if(s.count(str)==0)
        cout << str << endl;
        s.insert(str);
    } while (next_permutation(str.begin(), str.end()));
}
void solve()
{
    ll n,i,j;
    cin>>n;
    ll x[n],y[n];
    for(i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    ll ans=0;
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if(abs(x[j]-x[i])>=abs(y[j]-y[i]))
                ans++;
        }
    }
    cout<<ans;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    solve();
    #ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock()  / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <functional>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vec>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

/*
string x="atcoder";

int func(string s){
    if(s.length()>x.length()){
        bool flag=true;
        rep(i,x.length())if(s[i]!=x[i])flag=false;
        if(flag)return 0;
    }
    rep(i,s.length())if(s[i]!='a')return i;
    return -1;
}

int main(){
    int n=in();
    rep(i,n)cout<<func(stin())<<endl;
}
*/
int main(){
    int n=in();
    ll ans=0;
    vecll a(n),b(n);
    rep(i,n)a[i]=in();
    rep(i,n)b[i]=in();
    vecll odd,even;
    rep(i,n){
        ans += a[i];
        if(i%2==0){
            even.pb(b[i]-a[i]);
        }else{
            odd.pb(b[i]-a[i]);
        }
    }
    sort(ALL(odd),greater<ll>());
    sort(ALL(even),greater<ll>());
    vecll sumO(n/2+1),sumE(n/2+1);
    rep(i,n/2){
        sumO[i+1]=sumO[i]+odd[i];
        sumE[i+1]=sumE[i]+even[i];
    }
    ll tmp=LONG_MIN;
    rep(i,n/2+1)tmp=max(tmp,sumO[i]+sumE[i]);
    cout<<ans+tmp<<endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

// 負の数にも対応した mod
// 例えば -17 を 5 で割った余りは本当は 3 (-17 ≡ 3 (mod. 5))
// しかし単に -17 % 5 では -2 になってしまう
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
//
// ## ax + by = Aを満たす一般解(x, y)を求める
// auto d = extGcd(a, b, p, q);
// if(A % d != 0) continue;
// p *= A/d, q *= A/d;
// (x, y) = (p + k * (b/d), q + k * (a/d));
long long extGcd(long long a, long long b, long long &p, long long &q) {
    if (b == 0) { p = 1; q = 0; return a; }
    long long d = extGcd(b, a%b, q, p);
    q -= a/b * p;
    return d;
}

// 中国剰余定理
// x % m1 == b1 && x % m2 == b2であるxを計算.
// リターン値を (r, m) とすると解は x ≡  r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
  long long p, q;
  long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
  if ((b2 - b1) % d != 0) return make_pair(0, -1);
  long long m = m1 * (m2/d); // lcm of (m1, m2)
  long long tmp = (b2 - b1) / d * p % (m2/d);
  long long r = mod(b1 + m1 * tmp, m);
  return make_pair(r, m);
}

int main(){
    ll T;
    cin >> T;
    while(T--){
        ll X, Y, P, Q;
        cin >> X >> Y >> P >> Q;

        ll T_train = 2*X + 2*Y;
        ll T_player = P + Q;

        const ll INF = LLONG_MAX;
        ll ans = INF;

        for(ll t1 = X; t1 < X+Y; t1++){
            for(ll t2 = P; t2 < P+Q; t2++){
                auto [r, m] = ChineseRem(t1, T_train, t2, T_player);
                if(m == -1) continue;
                chmin(ans, r);
            }
        }

        if(ans == INF){
            cout << "infinity" << endl;
        }
        else{
            cout << ans << endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
    template<class Fun>
    class y_combinator_result{
        Fun fun_;
        public:
            template<class T>
            explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
            template<class ...Args>
            decltype(auto) operator()(Args&&...args){
                return fun_(std::ref(*this), std::forward<Args>(args)...);
            }
    };
    template<class Fun>
    decltype(auto) y_combinator(Fun && fun){
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
    }
};
template<typename T>
bool umax(T& a, T b){
    bool ret = a < b;
    if(ret) a = b;
    return ret;
}
template<typename T>
bool umin(T& a, T b){
    bool ret = a > b;
    if(ret) a = b;
    return ret;
}
struct edge{
    int to; ll cost;
    int from;
    edge(){ edge(0,0);}
    edge(int to_, ll cost_) : to(to_), cost(cost_){}
    edge(int to_, int from_, ll cost_) : to(to_), cost(cost_), from(from_){}
};

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}

template<typename... T>
void write(T... a){
    ((cout << a),...);
}

template<typename T>
vector<T> read_array(int sz){
    vector<T> ret(sz);
    for(auto & x : ret) cin >> x;
    return ret;
}

long long gcd(long long  a, long long b){
    if( a < b) std::swap(a, b);
    if( b == 0) return a;
    return gcd(b, a%b);
}

void ext_gcd(long long a, long long b, long long& x, long long& y){
    if(b == 0){
        x = 1;
        y = 0;
        return;
    }
    if( a < b){
        ext_gcd(b, a, y, x);
    }else{
        long long tmpx, tmpy;
        ext_gcd(b, a % b, tmpx, tmpy);
        // g = b * x + y *( a - a / b * b)
        // g = y +( x - a / b * y);
        x = tmpy;
        y = tmpx - a / b * tmpy;
    }
}

//to be verified
long long mod_inverse(long long a, long long m){
    //return such that b * a = 1(mod m)
    long long x, y;
    ext_gcd(a, m, x, y);
    assert( a * x + m * y == 1);
    return ( m + x % m) % m;
}

void solve(){
    ll x, y, p, q;
    read(x,y, p, q);
    ll T1 = 2 * (x + y) ;
    ll T2 = (p + q);
    ll mxT = T1 * T2;
    ll ans = mxT;
    ll g = gcd(T1, T2);
    ll t1 = T1 / g;
    ll t2 = T2 / g;
    REP(i, y){
        //find smallest n such that T1 * n + x + i = p (mod T2)
        // T1 * n = (p - x -i) (mod T2)
        if( ( p - x -i) % g != 0){
            continue;
        }
        ll rhs = ( p - x - i) / g;
        // deb(rhs)
        rhs = (rhs % t2 + t2) % t2;
        // deb(rhs)
        ll n = mod_inverse(t1, t2);
        // deb(n)
        n = (n * rhs) % t2;
        // deb(n)
        ll res = T1 * n + x + i;
        // debl(i) deb(res)
        umin(ans, res);
    }

    REP(i, q){
        //find smallest n such that T2 * n + p + i = x (mod T1)
        // T2 * n = (x - p - i) (mod T1)
        if( (x - p - i) % g != 0){
            continue;
        }
        ll rhs = (x - p - i) / g;
        // deb(rhs)
        rhs = (rhs % t1 + t1) % t1;
        // deb(rhs)
        ll n = mod_inverse(t2, t1);
        n = (n * rhs) % t1;
        // deb(n)
        ll res = T2 * n + p + i;
        // debl(i) deb(res)
        umin(ans, res);
    }
    if(ans < mxT){
        write(ans, "\n");
    }else{
        write("infinity\n");
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    int T = 1;
    cin >> T;
    while(T--)
        solve();
    return 0;
}


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

void solve(){

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

	vector<pair<int, int>> cond(m);

	for(auto& [a, b] : cond)cin>>a>>b;

	int k;
	cin>>k;

	vector<pair<int, int>> choice(k);
	for(auto& [c , d] : choice) cin>>c>>d;

	int ans = 0;
	for(int bit=0;bit< 1 << k;bit++){
		vector<bool> ball(n);
		for(int i=0;i<k;i++){
			const auto [c, d] = choice[i];
			ball[bit & 1 << i ? c : d] = 1;
		}
		int cnt = 0;
		for(auto [a, b] : cond) if(ball[b] && ball[a]) cnt++;
		if(ans < cnt) ans = cnt;
	}
	cout<<ans;
}

int main(){
	solve();
}

#include <bits/stdc++.h>

using namespace std;

// clang-format off
/* accelration */
// 高速バイナリ生成
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// cin cout の結びつけ解除, stdioと同期しない(入出力非同期化)
// cとstdの入出力を混在させるとバグるので注意
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;

/* alias */
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;

/* define short */
#define pb push_back
#define mp make_pair
#define all(obj) (obj).begin(), (obj).end()
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

/* REP macro */
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

/* debug */
// 標準エラー出力を含む提出はrejectされる場合もあるので注意
#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" << endl;

/* func */
inline int in_int() {int x; cin >> x; return x;}
inline ll in_ll() {ll x; cin >> x; return x;}
inline string in_str() {string x; cin >> x; return x;}
// search_length: 走査するベクトル長の上限(先頭から何要素目までを検索対象とするか、1始まりで)
template <typename T> inline bool vector_finder(std::vector<T> vec, T element, unsigned int search_length) {
    auto itr = std::find(vec.begin(), vec.end(), element);
    size_t index = std::distance( vec.begin(), itr );
    if (index == vec.size() || index >= search_length) {return false;} else {return true;}
}
template <typename T> inline void print(const vector<T>& v, string s = " ")
    {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template <typename T, typename S> inline void print(const pair<T, S>& p)
    {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << "\n";}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v)
    {for (auto&& p : v) print(p);}
// 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}

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

    if(a == b) {cout << c << endl;return 0;}
    if(b == c) {cout << a << endl;return 0;}
    if(a == c) {cout << b << endl;return 0;}
    if(a != b && b != c){cout << 0 << endl; return 0;}
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 1100001; //check the limits, dummy

template<int SZ> struct DSU {
    int parent[SZ], size[SZ];

    DSU() {
        F0R(i, SZ) parent[i] = i, size[i] = 0;
    }

    int get(int x) {
        if (parent[x] != x) parent[x] = get(parent[x]);
        return parent[x];
    }

    void unify(int x, int y) {
        x = get(x); y = get(y);
        if (x == y) return;
        if (size[x] < size[y]) swap(x, y);
        if (size[x] == size[y]) size[x]++;
        parent[y] = x;

    }
};

void solve() {

    int N, M; cin >> N >> M;
    DSU<MX> dsu;
    bool A[N][M];
    F0R(i, N) {
        F0R(j, M) {
            char C; cin >> C; A[i][j] = C == '#';
        }
    }
    bool fr[N], fc[M];
    F0R(i, N) fr[i] = false;
    F0R(i, M) fc[i] = false;
    F0R(i, N) {
        F0R(j, M) {
            if (A[i][j]) {
                fr[i] = true; fc[j] = true;
                dsu.unify(i*M+j, N*M+i);
                dsu.unify(i*M+j, N*M+N+j);
                if (i == 0 || i == N-1 || j == 0 || j == M-1) {
                    dsu.unify(i*M+j, N*M+N+M);
                }
            }
        }
    }
    set<int> comps;
    FOR(i, 1, N-1) {
        FOR(j, 1, M-1) {
            if (A[i][j]) comps.ins(dsu.get(i*M+j));
        }
    }
    int ed = 0;
    if (sz(comps)) {
        ed = 1;
        F0R(i, N) {
            if (comps.count(dsu.get(i*M)) || comps.count(dsu.get(i*M+M-1))) ed = 0;
        }
        F0R(i, M) {
            if (comps.count(dsu.get(i)) || comps.count(dsu.get((N-1)*M+i))) ed = 0;
        }
    }
    int a1 = 0, a2 = 0;
    FOR(i, 1, N-1) if (!fr[i]) a1++;
    FOR(i, 1, M-1) if (!fc[i]) a2++;
    cout << max(0, sz(comps)-1) + min(a1, a2) + ed << nl;

}

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

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

	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e3 + 5;
const int MAXM = 1e3 + 5;

int fa[MAXN + MAXM];
inline void init(int n){ for(int i=1; i<=n; ++i) fa[i] = i;}
int find(int u){ return fa[u] == u? u: fa[u] = find(fa[u]);}
inline void connect(int u,int v){ fa[find(u)] = find(v);}

char s[MAXN][MAXM];

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i) scanf("%s",s[i]+1);
	s[1][1] = s[1][m] = s[n][1] = s[n][m] = '#';

	init(n+m);
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=m; ++j) if(s[i][j] == '#')
			connect(i, j+n);

	static int vis[MAXN + MAXM];
	int ans1 = 0, ans2 = 0;
	for(int i=1; i<=n; ++i)
		if(vis[find(i)] != 1)
			vis[find(i)] = 1, ++ans1;
	for(int i=1; i<=m; ++i)
		if(vis[find(i+n)] != 2)
			vis[find(i+n)] = 2, ++ans2;

	printf("%d",min(ans1, ans2) - 1);
	return 0;
}


#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;

#define REP(i,b,e) for(int i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second

const int MOD = 1e9+7;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	int a[n];
	REP(i, 0, n) scanf("%d", &a[i]);
	ll cnt[n] = {};
	REP(i, 0, n) cnt[a[i]]++;

	ll ans = 0, ct = k;
	REP(i, 0, n){
		ans += std::max(0l, ct-cnt[i]) * i;
		ct = std::min(ct, cnt[i]);
	}
	printf("%ld\n", ans);
	return 0;
}

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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define sdi(x) scanf("%d",&x)
#define sdc(c) scanf("%c",&c)
#define inf 1000000000000000000ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second
#define all(x) x.begin(),x.end()

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

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}

const int MOD = 1e9+7;

inline ll add(ll x, ll y, ll MOD) {
    x %= MOD;
    y %= MOD;
    ll ans = (x+y)%MOD;
    return ans;
}

inline ll mul(ll x,ll y, ll MOD) {
    x %= MOD;
    y %= MOD;
    ll ans = ((x*y)%MOD+MOD)%MOD;
    return ans;
}

int main() {
    fastio;

    ll N,K;
    cin>>N>>K;

    vector<ll> cnt(N+1,0);

    ll x;
    for(int i=0;i<N;i++) {
        cin>>x;
        cnt[x]++;
    }

    ll ans = 0;
    ll kitne = K;
    for(int i=0;i<N;i++) {
        kitne = min(kitne,cnt[i]);
        ans += kitne;
    }

    cout<<ans<<endl;

    time_taken();
}


#include <iostream>
#include <climits>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int A[100];
	int A_max = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A_max = max(A[i], A_max);
	}

	int max = 0;
	int ans;

	for (int k = 2; k <= A_max; ++k) {
		int count = 0;
		for (int i = 0; i < N; ++i) {
			if (A[i] % k == 0)++count;
		}
		if (count > max) {
			ans = k;
			max = count;
		}
	}

	cout << ans << endl;

}

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

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

    ll p[N];
    for(ll i = 0; i < N; i++){
        cin >> p[i];
    }

    ll ans = 0;
    ll t[210000];

    for(ll i = 0; i < N; i++){
        t[p[i]]++;
        while (t[ans])
        {
            ans++;
        }

        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
const ll INF = 1001001001;
void chmin(ll& a,ll b){if(a>b)a = b;}

int main(){
    int n;
    cin >> n;
    vector<string> S(n);
    set<string> sset;
    rep(i,n){
        cin >> S[i];
        sset.insert(S[i]);
    }
    rep(i,n){
        if(sset.count('!'+S[i])){
            cout << S[i] << endl;
            return 0;
        }
    }
    cout << "satisfiable" << endl;
    return 0;

}

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

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

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

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

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

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

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

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

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

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

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

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

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

pair<int, int> diam_dfs(int v, int p, int dep, const vector<vector<int>> &G, vector<pair<int, int>> &ds) {
  pair<int, int> res(dep, v);
  for (auto &u : G[v]) {
    if (u == p) continue;
    chmax(res, diam_dfs(u, v, dep + 1, G, ds));
  }

  ds[v] = res;
  return res;
}

void dfs(int v, int p, int &e, const vector<vector<int>> &G, const vector<pair<int, int>> &ds, vector< int > &ans) {
  ans[v] = e;

  vector< pair<int, int> > us;
  for (auto &u : G[v]) {
    if (u == p) continue;
    us.emplace_back(ds[u].first, u);
  }

  whole(sort, us);
  for (auto &[d, u] : us) {
    e++;
    dfs(u, v, e, G, ds, ans);
    e++;
  }
}

void solve() {
  int n = input();

  vector< vector< int > > G(n);
  range(i, 1, n) {
    int a = input() - 1, b = input() - 1;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  vector< pair<int, int> > ds(n);
  auto [d0, v0] = diam_dfs(0, -1, 0, G, ds);
  diam_dfs(v0, -1, 0, G, ds);

  int e = 1;
  vector< int > ans(n);
  dfs(v0, -1, e, G, ds, ans);

  cout << ans << endl;
}

signed main() {
  solve();
}


#include <bits/stdc++.h>
using namespace std;
struct s{
    int value;
    int idx;
}a[65538];
int main()
{
    int n;
    cin>>n;
    n=pow(2,n);
    for (int i=1;i<=n;i++)
	{
        cin>>a[i].value;
        a[i].idx=i;
    }
    while(n>2)
	{
        for (int i=1;i<=n;i+=2)
		{
            if (a[i].value<a[i+1].value){
                a[i/2+1].value=a[i+1].value;
                a[i/2+1].idx=a[i+1].idx;
            }
			else
			{
                a[i/2+1].value=a[i].value;
                a[i/2+1].idx=a[i].idx;
            }
        }
        n/=2;
    }
    if (a[1].value>a[2].value) cout<<a[2].idx<<endl;
	else cout<<a[1].idx<<endl;
    return 0;
}

//nik
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#define reg register
#define FOR(a, b, c) for (a = b; a <=c; a++)
#define rFOR(a, b, c) for (a = b;a >= c; a--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define SORT(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define newl "\n"
#define alls(x) x.begin(), x.end(), x.begin()
#define umap(v, t1, t2) unordered_map<t1, t2> v
#define uset(v,t1) unordered_set<t1> v
#define IOF ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using UL  =  unsigned long int;
using UI  =  unsigned int;
using ULL =  unsigned long long int;
using LI  =  long int;
using LL  =  long long;
using LF  =  double;
using LLF =  long double;
const int MOD1 = 1000000007;
/*const int MOD2 = */
/* Combinatorics Start */
int binoMax = 10000;
vector<LL> numInv(binoMax + 1), factNumInv(binoMax + 1), fact(binoMax + 1);
inline void generate_ncrp(LL p)
{   int i;numInv[0] = numInv[1] = 1;
	FOR(i, 2, binoMax)
	{	numInv[i] = numInv[p % i] * (p - p / i) % p;
	}	factNumInv[0] = factNumInv[1] = 1;
	FOR(i, 2, binoMax)
	{	factNumInv[i] = (numInv[i] * factNumInv[i - 1]) % p;
	}
	fact[0] = 1;
	FOR(i, 1, binoMax)
	{	fact[i] = (fact[i - 1] * i) % p;
	}
}
LL ncrmodp(LL n, LL r, LL p)
{	LL ans = ((fact[n] * factNumInv[r]) % p * factNumInv[n - r]) % p;
	return ans;
}
/* Combinatorics End */

LL expmodp(LL x, LL y, LL p)
{	LL res = 1;
	while (y > 0)
	{	if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}return res;
}
/* Matrix Operations Start */
struct Matrix{
	int row,col;
	vector<vector<LL> > a;
	Matrix(int r,int c){
		row=r;col=c;
		a.resize(row,vector<LL>(col,0));
;	}
    static Matrix IDM(LL n){
    	Matrix res(n,n);
    	for(int i=0;i<n;i++)res.a[i][i]=1;
    	return res;
	}
};
Matrix Matmult(Matrix A,Matrix B){
	Matrix res(A.row,B.col);
	LL i,j,k;
	FOR(i,0,A.row-1){
		FOR(j,0,B.col-1){
			FOR(k,0,A.col-1){
				res.a[i][j]=(res.a[i][j]+A.a[i][k]*B.a[k][j])%MOD1;
			}
		}
	}
	return res;

}
Matrix BinExp(Matrix X,LL n){
	Matrix res=Matrix::IDM(X.row);
	while(n>0){
		if(n&1){
			res=Matmult(X,res);
		}
		X=Matmult(X,X);
		n>>=1;
	}
	return res;
}
/* Matrix Operations End */

bool check(int x){
	int noct = x,z;
	int ndec = x;
	while(ndec>0){
		z = ndec%10;
		ndec/=10;
		if(z==7)return false;
	}
	while(noct>0){
		z = noct%8;
		noct/=8;
		if(z==7)return false;
	}
	return true;

}

int main()
{
	IOF
    int N,i,j,k,tp1,tp2;
	cin>>N;
	LL A[(1<<N)];
	FOR(i,0,(1<<N)-1){
		cin>>A[i];
	}
	vector<int> temp,temp1;
	FOR(i,0,(1<<N)-1){
		temp.push_back(i);
	}
	FOR(i,1,N-1){
		FOR(j,0,(1<<(N-i))-1){
			if(A[temp[2*j]]<A[temp[2*j+1]])temp1.push_back(temp[2*j+1]);
			else temp1.push_back(temp[2*j]);
		}
		temp.clear();
		temp.assign(all(temp1));
		temp1.clear();
	}
	if(A[temp[0]]<A[temp[1]])cout<<temp[0]+1;
	else cout<<temp[1]+1;
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int n, m, q;
    cin >> n >> m >> q;
    vs64 w(n), v(n);
    rep (i, n)
    {
        cin >> w[i] >> v[i];
    }

    vs64 x(m);
    rep (i, m) cin >> x[i];

    rep (i, q)
    {
        int l, r;
        cin >> l >> r;
        --l;
        vs64 y;
        rep (j, m)
        {
            if (IN(l, r, j)) continue;
            y.emplace_back(x[j]);
        }
        sort(y.begin(), y.end());

        s64 ans = 0;
        vector< bool > used(n, false);
        for (const auto& X : y)
        {
            int idx = -1;
            rep (j, n)
            {
                if (used[j]) continue;
                if (w[j] <= X && !used[j])
                {
                    if (idx < 0)
                    {
                        idx = j;
                    }
                    else if (v[idx] < v[j] || (v[idx] == v[j] && w[idx] < w[j]))
                    {
                        idx = j;
                    }
                }
            }
            if (idx >= 0)
            {
                ans += v[idx];
                used[idx] = true;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}

#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<ll,ll>;
const ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll modpow(ll x, ll n, ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (modpow((x * x) % mod, n / 2, mod) % mod);
	else
		return (x * modpow(x, n - 1, mod)) % mod;
}
bool is_prime(int n) {//素数判定
	bool ans = true;
	for (int i = 2; i <= sqrt(n); i++)if (n % i == 0)ans = false;
	return ans;
}
void solveA() {
	int n; cin >> n;
	vector<ll>a(n);
	vector<ll>b(n);
	rip(i, n)cin >> a[i];
	rip(i, n)cin >> b[i];
	vector<Pa>bmax(n);
	vector<ll>amax(n);
	ll bmaxx = 0;
	rip(i, n) {
		bmaxx = max(bmaxx, b[i]);
		bmax[i].first = bmaxx;
		if (bmaxx == b[i]) {
			bmax[i].second = i;
		}
	}
	ll amaxx = 0;
	rip(i, n) {
		amaxx = max(amaxx, a[i]);
		amax[i] = amaxx;
	}
	vector<ll>ans(n);
	ans[0] = a[0] * b[0];
	for (int i = 1; i < n; i++) {
		ll maxx = 0;
		maxx = b[i] * amax[i];
		ans[i] = max(ans[i - 1], maxx);
	}
	rip(i, n)cout << ans[i] << endl;
}
void solveB() {
	int N, K;
	cin >> N >> K;
	vector<ll>a(N);
	rip(i, N)cin >> a[i];
	sort(all(a));
}
void solveC() {

}
int main() {
	solveA();
}


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

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

#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, mn;
  cin >> a >> b >> c;
  mn = min({a,b,c});
  cout << a+b+c-mn << endl;
}


#include<bits/stdc++.h>
// #include<iostream>
// #include<algorithm>
// #include<vector>
// #include<set>
// #include<queue>
// #include<map>
using namespace std;

#define ll long long
#define ld long double

#define For(n) for(ll i=0;i<n;i++)
#define Forr(a,b) for(ll i=a;i<b;i++)

#define sortt(x) sort(x.begin(),x.end())
#define rsortt(x) sort(x.rbegin(),x.rend())
#define condsortt(x) sort(x.begin(),x.end(),sortBy)

#define MOD 1000000007
#define en "\n"

#define F first
#define S second

#define input(x,n) for(ll i=0;i<n;i++) cin>>x[i]
#define v(A,n) vector<ll> A(n)
#define vi(x) vector<ll> x
#define pb(x) push_back(x)
#define MP make_pair
#define PI 3.14159265

void print(vector<ll> vec)
{
    for(auto itr:vec)
        cout<<itr<<" ";
    cout<<en;
}

void solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b)
        cout<<c;
    else if(b==c)
        cout<<a;
    else if(a==c)
        cout<<b;
    else
    cout<<0;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    // cin>>t;
    for(ll i=1;i<=t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vector<int>>
#define mi  map<int,int>
#define mii map<pii,int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"YES",0;
#define retn return cout<<"NO",0;
#define fl fflush(stdout)
#define hell 1000000007
#define hell2 998244353
#define pi 3.14159265358979323846

int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=ans*a%m; b/=2;a=a*a%m;}return ans;}
int inverse(int a, int p){return fexp(a, p-2,p);}

int fac[300005]; //fac[0]=0;fac[1]=1;rep(i,2,300005)fac[i]=(fac[i-1]+fac[i-2])%hell;

int ncr(int n, int r,int p) {
    if (r==0) return 1;
    return (fac[n]*inverse(fac[r],p)%p*inverse(fac[n-r],p)%p)%p;
}
void code_hunter(){
    int n,m;cin>>n>>m;
    if((min(n,m)+3)>max(n,m))
         cout<<"Yes";
    else
        cout<<"No";
}
 signed main(){
    IOS;
    int t=1;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // cin>>t;
    while(t--){
        code_hunter();
       // cout<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10;

int ans[N];
vector <int> g[N];
struct node{
    int step;
    int num;
}p;
int a[N];
int b[N];

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    if(x==y)cout<<z;
    else if(x==z) cout<<y;
    else if(y==z) cout<<x;
    else cout<<0;
}

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

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
char s[maxn];
int n,sum[maxn][30];
long long ans;
int book;
char ch;

int main() {
	scanf("%s",s+1);
	n=strlen(s+1);
	book=n+1; ch='a'-1;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=26;j++) sum[i][j]=sum[i-1][j];
		sum[i][(s[i]-'a'+1)]++;
	}

	for(int i=n-2;i>=1;i--) {
		if(s[i]==s[i+1] && s[i+1]!=s[i+2]) {
			if(ch==s[i]) ans+=(book-1)-(i+1);
			else ans+=n-(i+1);
			ans-=sum[(book-1)][(s[i]-'a'+1)]-sum[i+1][(s[i]-'a'+1)];
			book=i,ch=s[i];
		}
	}
	printf("%lld",ans);
	return 0;
}

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

#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)
#ifdef ENV_LOCAL
#define dump if (1) cerr
#else
#define dump if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

pair<i32,bool> solve(const vector<vi32>& g, i32 i) {
  bool flip = true;
  vector<pair<i32,bool>> children;
  for (auto&& to : g[i]) {
    auto [sc, fl] = solve(g, to);
    if (fl) flip = !flip;
    children.emplace_back(-sc, fl);
  }
  dump<<i<<endl;
  sort(all(children), [](auto&& lhs, auto&& rhs) {
      auto [ls, lf] = lhs;
      auto [rs, rf] = rhs;
      if (ls >= 0 && rs < 0) return true;
      else if (ls < 0 && rs >= 0) return false;
      if (ls >= 0) {
        if (lf == rf) {
          return ls > rs;
        } else {
          return rf;
        }
      } else {
        if (lf == rf) {
          return ls > rs;
        } else {
          return lf;
        }
      }
  });
  i32 score = 1;
  bool current = false;
  for (auto&& [sc, fl] : children) {
    dump<<sc<<" "<<fl<<endl;
    if (current) {
      score += sc;
    } else {
      score -= sc;
    }
    if (fl) current = !current;
  }
  return make_pair(score, flip);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i32 n;
  cin>>n;
  vector<vi32> g(n);
  rep2(i,1,n) {
    i32 p;
    cin>>p;
    --p;
    g[p].push_back(i);
  }
  auto [score, flip] = solve(g, 0);
  auto ans = (n + score) / 2;
  cout<<ans<<endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;//1000000007;
constexpr long long INF = 1000000000 + 100;
constexpr long long LINF = 1000000000000000000 + 100;
constexpr double EPS = 1e-9;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
#define rrep(i, n) for(int i=(n); i>=0; i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//dp[i][j]:=i番目まで見て、j=1ならtrue, 0ならfalseの数
ll dp[66][2];
int main(){
    int N; cin >> N;
    vector<string> S(N); rep(i, N)cin >> S[i];

    dp[0][0] = dp[0][1] = 1;
    rep(i, N){
        rep(j, 2){
            if(S[i]=="AND"){
                rep(k, 2){
                    dp[i+1][j and k] += dp[i][j];
                }
            }
            else{
                rep(k, 2){
                    dp[i+1][j or k] += dp[i][j];
                }
            }
        }
    }
    cout << dp[N][1] << ln;
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define FastIO cin.sync_with_stdio(false), cin.tie(nullptr)
#define pb push_back
#define fs first
#define sc second
#define mkp make_pair
#define endl '\n'

// IO
#define multitest signed __T; cin >> __T; while(__T--)
template<typename T>
void _read(T& t);
template<typename T>
void _read(vector<T>& v);
template<typename T1, typename T2>
void _read(pair<T1, T2>& p);
template<typename T>
void _read(T& t) { cin >> t; }
template<typename T>
void _read(vector<T>& v) { for (unsigned _i = 0; _i < v.size(); _i++)_read(v[_i]); }
template<typename T1, typename T2>
void _read(pair<T1, T2>& p) { _read(p.first); _read(p.second); }
void _masterread() {}
template<typename T, typename... V>
void _masterread(T& t, V& ... v) { _read(t); _masterread(v...); }
#define re(...)_masterread(__VA_ARGS__)

template<typename T>
void _print(T t);
template<typename T>
void _print(vector<T>& v);
template<typename T1, typename T2>
void _print(pair<T1, T2>& p);
template<typename T>
void _print(T t) { cout << t; }
template<typename T>
void _print(vector<T>& v) { for (unsigned _i = 0; _i < v.size(); _i++)_print(v[_i]), cout << (_i == v.size() - 1 ? "" : " "); }
template<typename T1, typename T2>
void _print(pair<T1, T2>& p) { _print(p.first); cout << " "; _print(p.second); }
void _masterprint() { cout << endl; }
template<typename T, typename... V>
void _masterprint(T t, V... v) { _print(t); if (sizeof...(v))cout << " "; _masterprint(v...); }
#define pr(...)_masterprint(__VA_ARGS__)

// DEBUG
// colored output???
template <typename T> // start forward declaration
void _debug(T t);
template<typename T1, typename T2>
void _debug(pair<T1, T2> p);
template<typename T>
void _debug(vector<T>v);
template <typename T> // end forward declaration
void _debug(T t) { cerr << t; }
template<typename T1, typename T2>
void _debug(pair<T1, T2> p) { cerr << "{"; _debug(p.first); cerr << ", "; _debug(p.second); cerr << "}"; }
template<typename T>
void _debug(vector<T>v) { cerr << "("; for (unsigned _i = 0; _i < v.size(); _i++)_debug(v[_i]), cerr << (_i == v.size() - 1 ? "" : ", "); cerr << ")"; }
void _masterdebug() { cerr << "]\n"; }
template<typename T, typename... V>
void _masterdebug(T t, V... v) { _debug(t); if (sizeof...(v))cerr << ", "; _masterdebug(v...); }
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#define int long long

void solve() {
	string s;
	cin >> s;
	char c1 = s[0], c2 = s[1], c3 = s[2];
	if (c1 == c2 && c2 == c3) {
		pr("Won");
	}
	else
		pr("Lost");
}

signed main() {
	FastIO;
	/*int t;
	cin >> t;
	while (t--)*/
		solve();
}


#include<bits/stdc++.h>
typedef long long LL;
typedef long double dl;
#define opt operator
#define pb push_back
#define pii std::pair<LL,LL>
const LL maxn=1e6+9,mod=998244353,inf=1e18;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
void Chkmin(LL &x,LL y){
	if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
	if(y>x) x=y;
}
LL add(LL x,LL y){
	return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
	return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
	return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
	LL ret(1); while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
LL n;
dl a[maxn],suf[maxn];
int main(){
	n=Read();
	for(LL i=1;i<=n;++i){
		a[i]=Read();
	}
	std::sort(a+1,a+1+n);
	dl ret(1000000000000000000.0);
//	printf("%.10Lf\n",ret);
	for(LL i=n;i>=1;--i) suf[i]=suf[i+1]+a[i];
	for(LL i=1;i<=n;++i){
		dl x(1.0*a[i]/2.0);
		dl sum(1.0*i*x+suf[i+1]-1.0*(n-i)*x);
		ret=std::min(ret,sum);
	}
	ret/=1.0*n;
	printf("%.10Lf\n",ret);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  long n,k,a;
  cin>>n;
  vector<long> vec(n);
  for(long i=0; i<n; i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  k=n/2;
  a=vec.at(k);
  double ans=0;
  double b=a;
  for(long i=0; i<n; i++){
    ans+=vec.at(i)-min(vec.at(i),a);
  }
  ans=ans/n;
  ans=ans+b/2;
  cout << fixed << setprecision(10);
  cout<<ans;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define N 10100
#define MOD 998244353
#define ll long long
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define rep3(i, a, b) for(int i = a; i >= b; --i)
#define eb emplace_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
struct Setup_io {
	Setup_io() {
		ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
		cout << fixed << setprecision(15);
	}
} setup_io;

int main() {
	int n;
	int x, s;
	int a[100];
	ll dp[101][N];
	ll k[110];
	ll y, z;
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n + 1) {
		rep(j, N)dp[i][j] = 0;
	}
	s = 0;
	dp[0][0] = 1;
	rep(i, n) {
		s += a[i];
		rep3(ii, i, 0) {
			rep3(j, 100*(i+1), a[i])dp[ii + 1][j] = (dp[ii + 1][j] + dp[ii][j - a[i]]) % MOD;
		}
	}
	if (s % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	s /= 2;
	k[0] = 1;
	rep2(i, 1, 100) {
		y = (ll)i;
		k[i] = (k[i - 1] * y) % MOD;
	}
	ll ans = 0;
	rep(i, n + 1) {
		y = dp[i][s];
		y = (y*k[i]) % MOD;
		y = (y*k[n - i]) % MOD;
		ans = (ans + y) % MOD;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N, M, A;
    cin >> N >> M;
    vector<vector<int>> pos(N + 1);
    for(int i = 0; i <= N; ++i) pos[i].emplace_back(-1);
    for(int i = 0; i < N; ++i){
        cin >> A;
        pos[A].emplace_back(i);
    }
    for(int i = 0; i <= N; ++i) pos[i].emplace_back(N);
    for(int i = 0; i <= N; ++i){
        for(int j = 0; j + 1 < (int)pos[i].size(); ++j){
            if(pos[i][j + 1] - pos[i][j] > M){
                cout << i << '\n';
                return 0;
            }
        }
    }

    return 0;
}

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

using namespace std;
using ll = long long;

map<ll, ll> freq;
set<ll> mex;
int n, m;

int main(){

    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(ll i = 0; i <= n; ++i)
        mex.insert(i);

    vector<ll> vec(n);
    for(auto & el: vec)
        cin >> el;

    for(int i = 0; i < m; ++i){
        freq[vec[i]]++;
        mex.erase(vec[i]);
    }

    ll res = *mex.begin();
    for(int i = m; i < n; ++i){
        freq[vec[i - m]]--;
        if(freq[vec[i - m]] == 0 ){
            mex.insert(vec[i - m]);
            freq.erase(vec[i - m]);
        }

        freq[vec[i]]++;
        if(freq[vec[i]] == 1)
            mex.erase(vec[i]);

        res = min(res, * mex.begin());
    }

    cout << res;
}


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

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

using namespace std;
template<int64_t M = 1000000007>
class ModInt {
public:
	ModInt() : val_(0) {};

	ModInt(int64_t val) {
		this->val_ = val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0)  this->val_ += M;
	}

	operator int64_t() const {
		return this->val_;
	}

	ModInt& operator += (int64_t val) {
		this->val_ += val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator -= (int64_t val) {
		this->val_ -= val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator *= (int64_t val) {
		this->val_ *= val;
		this->val_ %= M;

		return *this;
	}

	ModInt& operator /= (int64_t val) {
		ModInt v = ModInt::pow(val, M - 2);
		*this *= v;

		return *this;
	}

	ModInt operator + (int64_t v) const {
		ModInt ret = *this;
		return (ret += v);
	}

	ModInt operator - (int64_t v) const {
		ModInt ret = *this;
		return (ret -= v);
	}

	ModInt operator * (int64_t v) const {
		ModInt ret = *this;
		return (ret *= v);
	}

	ModInt operator / (int64_t v) const {
		ModInt ret = *this;
		return (ret /= v);
	}

	static ModInt pow(ModInt n, int64_t m) {
		if (m == 0) {
			ModInt ret(1);
			return ret;
		}
		if (m == 1) {
			return n;
		}

		ModInt v = pow(n, m / 2);
		ModInt ret = v * v;
		if (m & 1) {
			ret *= n;
		}
		return ret;
	}

	ostream& operator << (ostream& out) {
		out << this->val_;
		return out;
	}

private:
	int64_t val_;
};
bool gmap[2001][2001];
int  nmap[2001][2001];

ModInt <> val(int n, int m)
{
	ModInt<> s = 2;
	auto a = ModInt<>::pow(2, n);
	auto d = ModInt<>::pow(2, n - m);
	//cout << n << " " << m << endl;
	return a - d;
}

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

	int h, w; cin >> h >> w;
	int g = 0;
	FOR_LT(i, 0, h) {
		string s; cin >> s;
		FOR_LT(j, 0, w) {
			if (s[j] == '#') {
				gmap[i][j] = true;
				g++;
			}
			else {
				nmap[i][j] = 1;
			}
		}
	}

	FOR_LT(i, 0, h) {
		int j = 0;
		int s = -1;
		while (j < w) {
			while (j < w && gmap[i][j]) j++;
			s = j;
			while (j < w && !gmap[i][j]) j++;
			if (s != -1) {
				int c = (j - s);
				//cout << c << endl;
				FOR_LT(k, s, j) {
					nmap[i][k] += c - 1;
					//cout << i << " " << k << " " << nmap[i][k] << endl;
				}
			}
			s = -1;
		}
	}

	FOR_LT(j, 0, w) {
		int i = 0;
		int s = -1;
		while (i < h) {
			while (i < h && gmap[i][j]) i++;
			s = i;
			while (i < h && !gmap[i][j]) i++;
			if (s != -1) {
				int c = (i - s);
				FOR_LT(k, s, i) {
					nmap[k][j] += c - 1;
				}
			}
			s = -1;
		}
	}

	ModInt<> ans = 0;
	FOR_LT(i, 0, h) {
		FOR_LT(j, 0, w) {
			ans += val(h * w - g, nmap[i][j]);
		}
	}
	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod ll(1e9+7)
#define inv ll(500000004)
ll exp(ll a,ll b)
{
	if(b==0)
	 return 1;
	if(b%2==0){
		return exp(a*a%mod,b/2);
	}
	return a*exp(a*a%mod,(b-1)/2)%mod;
}
int main()
{
	int h,w;
	cin>>h>>w;
	int cnt=0;
	vector<string>arr(h);
	for(int i=0; i<h; i++)
	 cin>>arr[i];
	vector<vector<int> >mtr1(h,vector<int>(w)),mtr2(h,vector<int>(w));
	for(int i=0; i<h; i++){
		int len=0;
		for(int j=0; j<w; j++){
			if(arr[i][j]=='#'){
				len=0;
			}
			else{
				len++;
				cnt++;
				mtr1[i][j]=len;
			}
		}
	}
	for(int i=0; i<h; i++){
		int num=0;
		for(int j=w-1; j>=0; j--){
			if(mtr1[i][j]>0){
			   num=max(num,mtr1[i][j]);
			   mtr1[i][j]=num;
			}
			else
			 num=0;
		}
	}
	for(int i=0; i<w; i++){
		int len=0;
		for(int j=0; j<h; j++){
			if(arr[j][i]=='#')
			 len=0;
			else{
				len++;
				mtr2[j][i]=len;
			}
		}
	}
	for(int i=0; i<w; i++){
		int num=0;
		for(int j=h-1; j>=0; j--){
			if(mtr2[j][i]>0){
				num=max(num,mtr2[j][i]);
				mtr2[j][i]=num;
			}
			else
			 num=0;
		}
	}
	ll ans=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(arr[i][j]=='.'){
		      ll num1=mtr1[i][j]+mtr2[i][j]-1;
		      ll num2=cnt-num1;
			  ans=(ans+(exp(2,num1)-1+mod)*exp(2,num2)%mod)%mod;
			}
		}
	}
	cout<<ans;
	return 0;

}


/*
_/_/_/_/    _/_/_/_/_/  _/_/_/
_/      _/      _/    _/      _/
_/      _/      _/    _/      _/
_/      _/      _/    _/      _/
_/      _/      _/    _/  _/  _/
_/      _/  _/  _/    _/    _/_/
_/_/_/_/      _/_/     _/_/_/_/_/

_/_/_/_/    _/    _/  _/      _/
_/      _/   _/  _/   _/_/  _/_/
_/      _/    _/_/    _/ _/_/ _/
_/      _/     _/     _/  _/  _/
_/      _/    _/_/    _/      _/
_/      _/   _/  _/   _/      _/
_/_/_/_/    _/    _/  _/      _/

_/_/_/_/_/ _/_/_/_/_/ _/_/_/_/_/
    _/         _/     _/
    _/         _/     _/
    _/         _/     _/_/_/_/
    _/         _/     _/
    _/         _/     _/
    _/     _/_/_/_/_/ _/_/_/_/_/

_/_/_/_/_/ _/_/_/_/_/ _/_/_/_/_/
    _/         _/     _/
    _/         _/     _/
    _/         _/     _/_/_/_/
    _/         _/     _/
    _/         _/     _/
    _/     _/_/_/_/_/ _/_/_/_/_/
*/
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int P = 998244353;

int norm(int x) { return x >= P ? (x - P) : x; }

void add(int &x, int y) { if ((x += y) >= P) x -= P; }

void sub(int &x, int y) { if ((x -= y) < 0) x += P; }

void exGcd(int a, int b, int &x, int &y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  exGcd(b, a % b, y, x);
  y -= a / b * x;
}

int inv(int a) {
  int x, y;
  exGcd(a, P, x, y);
  return norm(x + P);
}

const int N = 3010, L = 15;

int A[L], B[L];
int f[L][N];
int q[N];

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  n -= k;

  for (int i = 1; i != L; ++i) {
    B[i] = (1 << i) - 1;
    A[i] = A[i - 1] + B[i];
  }

  {
    q[0] = 1;
    int C = 0;
    for (int i = 0; C <= n; ++i, C = A[i] + k * ((1 << i) - 1)) {
      if (i)
        for (int j = B[i]; j <= n - C; ++j) add(q[j], q[j - B[i]]);
      if (i & 1)
        for (int j = C; j <= n; ++j) sub(f[0][j], q[j - C]);
      else for (int j = C; j <= n; ++j) add(f[0][j], q[j - C]);
    }
  }

  for (int i = 0; i <= n; ++i) {
    for (int j = 1; A[j] <= i; ++j)
      sub(f[0][i], f[j][i - A[j]]);
    int j;
    for (j = 1; B[j] <= i; ++j)
      f[j][i] = norm(P - f[j - 1][i] + f[j][i - B[j]]);
    for (; B[j] <= n; ++j)
      f[j][i] = norm(P - f[j - 1][i]);
  }

  cout << f[0][n] << '\n';

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}

//#include<cstdio>
//#include<cassert>
//#include<iostream>
//#include<cstring>
//#include<algorithm>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)2e9 + 5)
#define MAXP ((int)2e5)
#define MAXL ((ll)1e18 + 5)
#define MAX_X ((ll)1e5 + 2)
#define pi acos(-1)
#define M ((int)1e6 + 7)
#define MOD ((int)998244353 + 0)
//#define MOD1 ((int)998244353 + 0)
#define BAS ((int)1e6 + 3)
#define BAS1 ((int)2e5 + 3)
#define NN ((int)1e5 + 5)
#define N ((int)3e3 + 5)
#define eps (1e-8)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 10
#define endl "\n"
#define mp make_pair
#define BUCK 105
#define LEF (idx<<1)
#define RIG ((idx<<1)|1)
//#define int ll

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/

typedef tree < int,  null_type,  less < int >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
typedef tree < pair < int, int >,  null_type,  less < pair < int, int > >,  rb_tree_tag,  tree_order_statistics_node_update > o_setp;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).

int dpp[N][N] , sum[N][N];

int call(int last , int rem);

int fun(int last , int rem)
{
    last = min(last , rem);
    if(rem < 0) return 0;
    if(sum[last][rem] != -1) return sum[last][rem];
    int ans = call(last,rem) + fun(last + 2 , rem-1);
    if(ans >= MOD) ans -= MOD;
    return sum[last][rem] = ans;
}

int call(int last , int rem)
{
    last = min(last , rem);
    if(rem < 0) return 0;
    if(rem == 0) return 1;
    if(dpp[last][rem] != -1) return dpp[last][rem];
    int ans = fun(2,rem-1) - fun(last+last+2,rem-last-1);
    if(ans < 0) ans += MOD;
    return dpp[last][rem] = ans;
}

int main()
{
    fastio;
    int n , k;
    cin>>n>>k;
    memset(dpp,-1,sizeof dpp);
    memset(sum,-1,sizeof sum);
    cout<<call(k,n-k)<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
	int res = 1;
	x = x % p;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res % p;
}
int lcm(int a, int b)
{
	return a / __gcd(a, b) * b;
}
void solve()
{
	int n, k;
	cin >> n >> k;
	int a[n];
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mp[a[i]]++;
	}
	int ans = 0;
	int f = 0;
	for (int i = 0; i < n; i++) {
		if (k <= 0)
			break;
		if (mp[i] / k == 0) {
			ans += (k - mp[i]) * i;
			k -= (k - mp[i]);
		}
	}
	cout << ans << endl;

}
int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int tc;
	tc = 1;
#ifndef ONLINE_JUDGE
	freopen("inputf.txt", "r", stdin);
	freopen("outputf.txt", "w", stdout);
#endif
	// cin >> tc;
	while (tc--)
	{

		solve();

	}

	return 0;
}

#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

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

int main() {
  int n, k;
  cin >> n >> k;
  ll ans = n;
  REP(i, k) {
    if (ans % 200) {
      string tmp = to_string(ans) + "200";
      ans = stoll(tmp);
    } else {
      ans /= 200;
    }
  }
  print(ans);
  return 0;
}


/*
   Bismillahir rahmanir rahim
   Name : Mir Rifat
   Bsmrstu.
*/

#include <bits/stdc++.h>
using namespace std ;
typedef    long long    ll;
#define    fastio      ios_base::sync_with_stdio(false),cin.tie(NULL)
#define    T           int t,q; cin >> t; for(q=1;q<=t;q++)
#define    Forn(i,n)   for(int i=0;i<n;i++)
#define    ForN(i,n)   int i;for(i=n-1;n>=0;i--)
#define    Sort(s)     sort(s.begin(),s.end())
#define    ff          first
#define    ss          second
#define    pb          push_back
#define    mem(a)      memset(a,0,sizeof a)
#define    memn(a)     memset(a,-1,sizeof a)
#define    pi          acos(-1
#define    PI          3.1415926535

#define  Int(f)         cin>>f;
#define  Pnt(k)         cout<<k<<endl;
#define yy()             cout<< "YES"<<endl;
#define nn()             cout<< "NO"<<endl;
void solve(){
string s;cin>>s;
cin>>s;
ll ans=0;
for(int i=0;i<9;i++){
    if(s[i]=='Z' && s[i+1]=='O' && s[i+2]=='N' && s[i+3]=='e'){
        ans++;
    }
}
cout<<ans<<endl;
}

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

#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define full(a) memset(a, 0x3f, sizeof(a))
#define mset(a, b) memset(a, b, sizeof(a))
#define cpy(a,b) memcpy(a, b, sizeof(a))
#define fornext(x, i) for(signed i = hd[x], y = ver[i]; i; i = nxt[i], y = ver[i])
#define Rep(i, a, b) for(signed i = (signed)(a); i <= (signed)(b); ++i)
#define dRep(i, a, b) for(signed i = (signed)(a); i >= (signed)(b); --i)
#define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define pb push_back
#define It iterator
#define endl '\n'
#define un unsigned
#define int ll
#define ll long long
#define db double
#define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
#define dbg cout<<"c "
#define dbug(x) cerr << #x " = " << (x) << endl
template<typename _T> inline void _prt(_T _d) { cerr << _d << ' '; }
template <typename _T, typename ...Args> inline void _prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...); }
template <typename _T, typename ...Args> inline void prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...), cerr<<endl; }
template <typename _T, typename ...Args> inline void prt(_T _d) { cerr << _d <<endl; }
template<typename _T> inline void rd(_T &_d) {
	signed _f; char _c; _f = 1,_d = 0; while (_c = getchar(), !isdigit(_c)) if(_c=='-') _f=-1;
	while (isdigit(_c)) _d = _d * 10 + _c - '0', _c = getchar();
	_d=_f*_d;
}
template <typename _T, typename ...Args> inline void rd(_T &_d, Args &..._a) { rd(_d); rd(_a...); }

// const int N=

signed main() {
	int n;
	rd(n);
	--n;
	printf("1155 ");
	Rep(i,1,5000) {
		if(!n) break;
		if(i%3==0||i%5==0||i%7==0||i%11==0) --n,printf("%d ",i*2);
	}
	return 0;
}


//*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/

#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
int popcount(ll t) { return __builtin_popcountll(t); }
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(25);
    }
} setup_io;
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    int n;
    cin >> n;
    vector<double> dp(n + 1);
    dp[n] = 0;
    for (int i = n - 1; i >= 0; i--) {
        dp[i] = 1 + (n - i) * dp[i + 1] / (double)n;
        dp[i] *= n / (double)(n - i);
    }
    cout << dp[1] << endl;
}

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, j, n) for (ll i = j; i < (n); ++i)
#define ALL(s) ((s).begin(), (s).end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
using namespace std;
typedef long long ll;
constexpr ll INF = 3e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, ans = INF;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  rep(bit, 1 << n) {
    vector<ll> res;
    ll t = 0;
    rep(i, n) {
      if (bit >> i & 1)
        res.push_back(t), t = a[i];
      else
        t |= a[i];
    }
    res.push_back(t);
    t = 0;
    for (ll tt : res) t ^= tt;
    ans = min(ans, t);
  }

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


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

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

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

#include<bits/stdc++.h>

using namespace std;

int M, mod;
long long N;

int mul (int x, int y) {return 1LL * x * y % mod;}

int power (int a, long long b)
{
    int p = 1;
    for (int i=0; (1LL<<i) <= b; i++)
    {
        if (b & (1LL << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%lld %d", &N, &M);
mod = M * M;
printf ("%d\n", power (10, N) / M);
return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<str> vs;
typedef vector<ld> vd;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 1e6 + 10;
const int nx[8] = {0, 0, 1, -1, -1, 1, 1, -1}, ny[8] = {1, -1, 0, 0, 1, -1, 1, -1}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

ll random(ll a, ll b){
    return a + rng() % (b - a + 1);
}

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

//Geometry
typedef long long C;
typedef complex<C> P;
#define X real()
#define Y imag()
#define pi 3.14159265359

int main()
{
    boost;
    IO();

    str n;
    cin >> n;

    if(n=="0")
    {
        cout << "Yes" << endl;
        return 0;
    }

    int len = (int)n.length();

    int j = len-1;
    while(n[j]=='0'&&j>=0)
    {
        n = '0' + n;
    }

    len = (int)n.length();
    bool flag = true;
    FOR(i, 0, len/2)
    {
        if(n[i]!=n[len-i-1])
        {
            flag = false;
            break;
        }
    }

    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

bool palind(string nb){
    int i = 0;
    int j = nb.size() - 1;

    bool palind = true;
    while (i <= j & palind == true){
        if (nb[i] == nb[j]){
            i += 1;
            j -= 1;
        }
        else{
            palind = false;
        }
    }
    return palind;
}

int numberOfZeros(string nb){
    int i = nb.size() - 1;
    int nbOfZero = 0;
    while (i >= 0 & nb[i] == '0'){
        nbOfZero += 1;
        i--;
    }
    return nbOfZero;
}

int main(){

    int number;
    cin >> number;
    string numberInString = to_string(number);
    string nbAfterAdd;

    if (palind(numberInString)){
        cout << "Yes";
    }
    else if (numberOfZeros(numberInString) != 0){
        for (int i = 0; i < numberOfZeros(numberInString); i++){
            nbAfterAdd += '0';
        }
        nbAfterAdd += numberInString;
        if (palind(nbAfterAdd)){
            cout << "Yes";
        }
        else{
            cout << "No";
        }
    }
    else{
        cout << "No";
    }
}