#include <bits/stdc++.h>

using namespace std;

struct DSU {
    vector<int> ps;
    vector<vector<int>> children;
    DSU(int n): ps(n), children(n) {
        iota(ps.begin(), ps.end(), 0);
        for (int i = 0; i < n; ++i) {
            children[i].push_back(i);
        }
    }
    int find(int i) {
        if (ps[i] == i) {
            return i;
        }
        return ps[i] = find(ps[i]);
    }
    bool merge(int i, int j) {
        i = find(i);
        j = find(j);
        if (i == j) {
            return false;
        }
        if (children[i].size() > children[j].size()) {
            swap(i, j);
        }
        ps[i] = j;
        children[j].insert(children[j].end(), children[i].begin(), children[i].end());
        return true;
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> edges(m);
    map<pair<int, int>, int> edges_dir; // -1 = not set, 0 = org, 1 = reverse
    for (auto& edge : edges) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        edge = {u, v};
        edges_dir[edge] = -1;
    }
    vector<int> cs(n);
    for (int& c : cs) {
        cin >> c;
    }
    vector<vector<int>> adj_list(n);
    for (auto& edge : edges) {
        int u, v;
        tie(u, v) = edge;
        if (cs[u] != cs[v]) {
            edges_dir[edge] = cs[u] > cs[v] ? 0 : 1;
        } else {
            adj_list[u].push_back(v);
            adj_list[v].push_back(u);
        }
    }
    DSU dsu(n);
    for (int u = 0; u < n; ++u) {
        set<int> seen;
        stack<int> seen_order;
        stack<pair<int, int>> edge_order;
        set<pair<int, int>> used_edges;
        function<bool (int)> dfs = [&](int v) {
            v = dsu.find(v);
            seen_order.push(v);
            if (seen.count(v)) {
                return true;
            }
            seen.insert(v);
            for (int w : dsu.children[v]) {
                for (int z : adj_list[w]) {
                    if (dsu.find(z) != v && !used_edges.count({w, z})) {
                        used_edges.insert({w, z});
                        used_edges.insert({z, w});
                        edge_order.push({w, z});
                        if (dfs(z)) {
                            return true;
                        }
                        edge_order.pop();
                    }
                }
            }
            seen_order.pop();
            return false;
        };
        if (dfs(u)) {
            assert (seen_order.size() == edge_order.size() + 1);
            int v = seen_order.top();
            seen_order.pop();
            vector<int> cycle = {v};
            while (true) {
                int w = seen_order.top();
                seen_order.pop();
                if (w == v) {
                    break;
                }
                cycle.push_back(w);
            }
            int cycle_size = (int) cycle.size();
            for (int i = 0; i < cycle_size; ++i) {
                assert (!edge_order.empty());
                int u0, v0;
                tie(u0, v0) = edge_order.top();
                edge_order.pop();
                if (edges_dir.count({u0, v0})) {
                    assert ((edges_dir[{u0, v0}] == -1));
                    edges_dir[{u0, v0}] = 0;
                } else {
                    assert (edges_dir.count({v0, u0}));
                    assert ((edges_dir[{v0, u0}] == -1));
                    edges_dir[{v0, u0}] = 1;
                }
            }
            for (int w : cycle) {
                dsu.merge(w, v);
            }
            --u;
        }
    }
    for (auto& edge : edges) {
        if (edges_dir[edge] == 1) {
            cout << "<-\n";
        } else {
            cout << "->\n";
        }
    }
}

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

/*    Immediate Gratification Is A Dream Killer   */
#include<bits/stdc++.h>
using namespace std;
template <typename T>
void make_unique(vector<T>& vec) {
  //sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()), vec.end());
}
#define ll long long int
#define ld long double
#define ff first
#define ss second
void debb(ll x) {cerr << x;}
void debb(double x) {cerr << x;}
void debb(ld x) {cerr << x;}
void debb(char x) {cerr << '\'' << x << '\'';}
void debb(const char *x) {cerr << '\"' << x << '\"';}
void debb(const string &x) {cerr << '\"' << x << '\"';}
void debb(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void debb(const pair<T, V> &x) {cerr << '{'; debb(x.ff); cerr << ','; debb(x.ss); cerr << '}';}
template<typename T>
void debb(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), debb(i); cerr << "}";}
void _debb() {cerr << "]\n";}
template <typename T, typename... V>
void _debb(T t, V... v) {debb(t); if (sizeof...(v)) cerr << ", "; _debb(v...);}
#define endl '\n'
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,n) for(i=1;i<=n;i++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)
typedef pair<ll, ll>    pl;
typedef vector<ll>      vl;
typedef vector<pl>      vpl;
typedef vector<vl>      vvl;
const ll mod = 1000000007;
const ld PI = 3.141592653589793;
const ll inf = 1e15;
const ll cons=300005;
ll N,M;
ll solve(){

}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll n=0,m=0,i=0,j=0,k=0,cnt=0,ans=0,sum=0,flag=0,pos=-1,ind=-1,mn=inf,mx=-inf,res=0;
    cin>>n>>k;
    vl v(n),h(cons,0);
    fo(i,n){
        cin>>v[i];
        h[v[i]]++;
    }
    fo(i,cons){
        if(h[i]>=k){
            continue;
        }
        else{
            while(h[i]<k){
                ans+=i;
                k--;
            }
        }
        if(k==0){
            break;
        }
    }
    cout<<ans;

    return 0;
}


//12252024832524
#include <cstdio>
#include <cstring>
#include <algorithm>
#define TT template<typename T>
#define int LL
using namespace std;

typedef long long LL;
const int MAXN = 25;
const int MAXM = MAXN * MAXN;
int n,m,d[MAXN],cnt[MAXN][4];
bool vis[MAXN][MAXN];
LL bei = 1,ans = 0;

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
TT void Put1(T x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
TT void Put(T x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x); if(c >= 0) putchar(c);
}
TT T Max(T x,T y){return x > y ? x : y;}
TT T Min(T x,T y){return x < y ? x : y;}
TT T Abs(T x){return x < 0 ? -x : x;}

int head[MAXN],tot;
struct edge
{
    int v,nxt;
}e[MAXM << 1];
void Add_Edge(int x,int y)
{
    e[++tot].v = y;
    e[tot].nxt = head[x];
    head[x] = tot;
}
void Add_Double_Edge(int x,int y)
{
    d[x]++;d[y]++;
    vis[x][y] = vis[y][x] = 1;
    Add_Edge(x,y);
    Add_Edge(y,x);
}
int c,q[MAXN],f[MAXN];
void dfs(int x)
{
    f[x] = 1;
    q[++c] = x;
    for(int i = head[x]; i ;i = e[i].nxt)
        if(!f[e[i].v])
            dfs(e[i].v);
}
int clr[MAXN];
void solve(int x)
{
    if(x == c+1)
    {
        ans++;
        return;
    }
    for(int j = 1;j <= 3;++ j)
    {
        if(cnt[q[x]][j]) continue;
        clr[q[x]] = j;
        bool suc = 1;
        for(int i = head[q[x]]; i ;i = e[i].nxt)
        {
            if(j == clr[e[i].v])
            {
                suc = 0;
                break;
            }
        }
        if(!suc) continue;
        for(int i = head[q[x]]; i ;i = e[i].nxt)
            cnt[e[i].v][j]++;
        solve(x+1);
        for(int i = head[q[x]]; i ;i = e[i].nxt)
            cnt[e[i].v][j]--;
        clr[q[x]] = 0;
    }
}

signed main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
    n = Read(); m = Read();
    for(int i = 1;i <= m;++ i) Add_Double_Edge(Read(),Read());
    for(int i = 1;i <= n;++ i)
        if(!d[i]) bei *= 3;
    for(int i = 1;i <= n;++ i)
        for(int j = 1;j <= n;++ j)
            for(int k = 1;k <= n;++ k)
                for(int l = 1;l <= n;++ l)
                    if(i != j && j != k && k != l && i != k && i != l && j != l && vis[i][j] && vis[i][k] && vis[i][l] && vis[j][k] && vis[j][l] && vis[k][l])
                    {
                        Put(0);
                        return 0;
                    }
    for(int i = 1;i <= n;++ i)
    {
        if(!f[i] && d[i])
        {
            ans = c = 0;
            dfs(i);
            solve(1);
            bei *= ans;
        }
    }
    Put(bei);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

vector<ll> v[22],d(20),g;
ll u[22],n,cnt;

void dfs1(ll x,ll p) {
  if(u[x]) return;
  u[x]=1;
  g.pb(x);
  rep(i,v[x].size()) {
    ll y=v[x][i];
    if(y!=p) dfs1(y,x);
  }
}

void dfs(int k) {
  if(k>=g.size()) {
    cnt++;
    return;
  }
  ll x=g[k];
  rep(j,3) {
    d[x]=j;
    rep(i,v[x].size()) {
      ll y=v[x][i];
      if(d[y]==d[x]) goto next;
    }
    dfs(k+1);
  next:;
    d[x]=-1;
  }
}

void Main() {
  ll m;
  cin >> n >> m;
  rep(i,m) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  ll ans=1;
  rep(i,n) {
    if(!u[i]) {
      g.clear();
      dfs1(i,-1);
      rep(i,n) d[i]=-1;
      d[i]=0;
      cnt=0;
      dfs(1);
      ans*=cnt*3;
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


#include<bits/stdc++.h>
using namespace std;
const int mod=10;
using ll=long long;
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define pr(s) cout<<s<<"\n"

void solve(){
    int n;
    cin>>n;
    std::vector<int>a(n),b(n);
    for (int i = 0; i < n; i++) {
        cin>>a[i];
    }
    for (int i = 0; i < n; i++) {
        cin>>b[i];
    }
    map<int,int>mp;
    for (int i = 0; i < n; i++) {
        for (int j = a[i]; j<=b[i]; j++) {
            mp[j]++;
        }
    }
    int ans=0;
    for(auto it:mp){
        if(it.second>=n){
            ans++;
        }
    }
    pr(ans);
}

int main(){
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("outputakash.txt", "w", stdout);
  #else*/
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 // #endif
    int T=1;
    //cin>>T;
    ///int TEST=1;
    while(T--){
     // cout<<"Case #"<<TEST<<": ";
      solve();
      //TEST++;
    }
    return 0;
}

#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<unordered_set>
#include<unordered_map>
#define ll long long
using namespace std;
template<typename t1>
void print(vector<t1>& arr){
	for(t1 x:arr)
	    cout<<x<<" ";
	cout<<"\n";
}
template<typename t1>
void print(vector<vector<t1>>& arr){
	for(vector<t1> vec:arr){
		for(t1 x:vec)
		    cout<<x<<" ";
		cout<<"\n";
	}
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	int mn = *min_element(b.begin(),b.end());
	int mx = *max_element(a.begin(),a.end());
	cout<<((mn-mx+1)<0?0:mn-mx+1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
namespace Ruri{
    #define ms(a,b) memset(a,b,sizeof(a))
    #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
    #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
    #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
    #define ce(i,r) i==r?'\n':' '
    #define pb push_back
    #define all(x) x.begin(),x.end()
    #define gmn(a,b) a=min(a,b)
    #define gmx(a,b) a=max(a,b)
    #define fi first
    #define se second
    typedef long long ll;
    typedef unsigned long long ull;
    typedef double db;
    const int infi=1e9;//infi较大，注意涉及inf相加时爆int
    const ll infl=4e18;
    inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
    inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
    //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Ruri;
namespace Read{
    #define ss(a) scanf("%s",a)
    inline int ri(){ int x; scanf("%d",&x); return x; }
    inline ll rl(){ ll x;  scanf("%lld",&x); return x; }
    inline db rd(){ db x; scanf("%lf",&x); return x; }
}
namespace DeBug{
    #define pr(x) cout<<#x<<": "<<(x)<<endl
    #define pra(x,a,b) cout<<#x<<": "<<endl; \
            repi(i,a,b) cout<<x[i]<<" ";     \
            puts("");
    #define FR(a) freopen(a,"r",stdin)
    #define FO(a) freopen(a,"w",stdout)
}
using namespace Read;
using namespace DeBug;
const int MAX_N=105;
int n;
char s[MAX_N];
int g[MAX_N][MAX_N];
bool vis[MAX_N];
void Dfs(int u)
{
	vis[u]=true;
	repi(i,1,n)if(g[u][i]&&!vis[i]) Dfs(i);
}
int main()
{
	n=ri();
	repi(i,1,n){
		ss(s+1);
		repi(j,1,n)if(s[j]=='1') g[j][i]=true;
	}
	db ans=0;
	repi(i,1,n){
		ms(vis,0);
		Dfs(i);
		int cnt=0;
		repi(j,1,n)if(vis[j]) ++cnt;
		ans+=1.0/cnt;
	}
	printf("%.10lf\n",ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define Maxn 500007
int n;
char s1[Maxn],s2[Maxn];
int main()
{
    scanf("%d",&n);
    scanf("%s",s1+1);
    scanf("%s",s2+1);
    long long ans=0LL;
    long long cnt=0;
    for (int i=1;i<=n;i++)
    {
        if (cnt==0)
        {
            if (s1[i]==s2[i]) cnt=0; else cnt=1;
            ans+=cnt;
        } else
        {
            long long tmp;
            if (s1[i]=='1') tmp=cnt-1; else tmp=cnt;
            s1[i]='0';
            if (s1[i]!=s2[i]) ++tmp;
            ans+=tmp;
            cnt=tmp;
        }
    }
    if (cnt>0) printf("%d\n",-1); else printf("%lld\n",ans);
    return 0;
}


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

typedef pair<int,int>  pint;
typedef pair<ll,ll>    pll;
typedef vector<int>    vint;
typedef vector<ll>     vll;
typedef vector<string> vstr;
typedef vector<pint>   vpint;
typedef vector<pll>    vpll;

#define vint2(v,n,m,init) vector<vector<int>> v(n, vector<int>(m, init))
#define vll2(v,n,m,init)  vector<vector<ll>>  v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vint var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vstr var(n); rep(i,n){cin >> var[i];}
#define ALL(var)         (var).begin(), (var).end()
#define sortall(var)     sort(ALL(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());

#define prt(var)         cout << (var) << "\n"
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
ll gcd(ll a, ll b){ return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}
//----------------------------------------------------------------
class PrimeTool{

public:
    vector<ll> myMinPrime;
    PrimeTool(){
        myMinPrime.resize(1000001, -1);
        eratosthenes();
    }
    ~PrimeTool(){}
    void eratosthenes(){
        for(ll i=2; i<1000001; i++){
            if(myMinPrime[i]>0) continue;
            ll j=1;
            while(i*j<1000001){
                myMinPrime[i*j]=i;
                j++;
            }
        }
    }
    vector<ll> divisors(ll x){
        vector<ll> v;
        for(ll i=1; i*i<=x; i++){
            if(x%i==0){
                v.push_back(i);
                if(i!=x/i) v.push_back(x/i);
            }
        }
        sort(v.begin(), v.end());
        return v;
    }
    bool isPrime(ll x){
        if (x<2) return false;
        else if (x<1000001){
            return myMinPrime[x]==x;
        } else {
            for (ll i = 3; i*i <= x; i += 2){
                if (x % i == 0) return false;
            }
            return true;
        }
    }
    map<ll, ll> factorize(ll x){
        map<ll, ll> mp;
        if(x<2) return mp;
        // fast prime Factorization
        if(x<1000001){
            while(x>1){
                mp[myMinPrime[x]]++;
                x/=myMinPrime[x];
            }
        }
        // slow prime Factorization
        else {
            while(x%2==0){
                mp[2]++;
                x/=2;
            }
            for(ll i=3; i*i<=x; i+=2){
                while(x%i==0){
                    mp[i]++;
                    x/=i;
                }
            }
            if(x!=1) mp[x] = 1;
        }
        return mp;
    }
};

int main(void){
    int n;
    cin >> n;
    arrll(x,n);

    PrimeTool pt;
    vll primeList;
    REP(i,2,50){
        if(pt.isPrime(i)) primeList.push_back(i);
    }

    int sz = primeList.size();
    ll ans = 3e18;
    rep(i,(1<<sz)){
        ll tmp = 1;
        rep(j,sz){
            if(i&(1<<j)) tmp*=primeList[j];
        }

        bool ok = true;
        rep(i,n){
            if(gcd(tmp, x[i])==1) ok = false;
        }

        if(ok) chmin(ans, tmp);
    }

    prt(ans);
}

#include<bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
//using namespace atcoder;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    int n;
    cin >> n;
    v1 x(n);
    v1 y(n);
    rep(i, n){
        cin >> x[i] >> y[i];
    }
    rep(i, n){
        for(int j = i+1; j < n; j++){
            rep(k, n){
                if(k == i || k ==j) continue;
                else{
                    if(x[i] == x[j]){
                        if(x[j] == x[k]){
                            cout << "Yes" << endl;
                            return 0;
                        }
                    }else if (y[i] == y[j]){
                        if(y[j] == y[k]){
                            cout << "Yes" << endl;
                            return 0;
                        }
                    }else{
                        if((x[j]-x[k])*(y[i]-y[j])==(y[j]-y[k])*(x[i]-x[j])){
                            cout << "Yes" << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout << "No" << endl;
}


#include"bits/stdc++.h"

using namespace std;

typedef long long ll;

const int A_MAX = 200;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    int N;
    cin >> N;
    ll ans = 0;
    vector<int>A(N);
    vector<int>K(A_MAX*2+1);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }

    for (int i = 0; i < N; i++){
        for (int j = -A_MAX; j <= A_MAX; j++){
            int b = K[A_MAX+j];
            int c = A[i] - j;
            ans += (ll)c*c*b;
        }
        K[A_MAX+A[i]]++;
    }

    cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define endl "\n"
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e6+10;
const int maxm=100+10;
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x&(-x))
using namespace std;
ll n,m,k;
ll a[maxn];
void run_case(){
    ios;
    int _;
    _ = 1;
    while(_--){
         cin>>n;
         ll ans = 0;
         ll sum = 0;
         for(int i = 1; i<=n; i++){
            cin>>a[i];
            sum+=a[i];
            ans += (a[i]*a[i]*(n-1));
         }
         for(int i = 1; i<=n; i++){
            sum-=a[i];
            ll res = (sum)*a[i]*2;
            ans -= res;
         }
         cout<<ans<<endl;

    }
}

int main(){
    ios;
    run_case();
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100010

using namespace std;

int n, a[N];

int main(){
//	freopen("funny.in", "r", stdin);
	scanf("%d", &n);
	a[1]=1;
	for (int i=1; i<=n; i++)
		for (int j=2; j<=n/i; j++)
			a[i*j]=max(a[i*j], a[i]+1);
	for (int i=1; i<=n; i++) printf("%d ", a[i]);

	return 0;
}

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

int main() {
    ll n;
    cin >> n;
    vector<vector<int>> seen(n + 1, vector<int>(500, 0));
    vector<ll> ans;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < 500; j++) {
            if (seen[i][j] == 0) {
                ans.push_back(j);
                break;
            }
        }
        for (int j = i; j <= n; j += i) {
            seen[j][*ans.rbegin()] = 1;
        }
    }

    rep(i, n) cout << ans[i] << " ";
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
struct Node;
vector<Node> V;
int cnt = 0;
struct Node {
  int idx;
  int d = 0;
  int ans = 0;
  int next = -1;
  vector<int> nbr;
  bool vst = false;
  void dfs(int _d) {
    vst = true;
    d = _d;
    for(int x : nbr) if(!V[x].vst) V[x].dfs(d+1);
  };
  int dfs2(int _t) {
    vst = true;
    for(int x : nbr) if(!V[x].vst) {
      int ret = V[x].dfs2(_t);
      if(ret != -1) next = ret;
    }
    if(idx == _t || next != -1) return idx;
    else return -1;
  }
  void dfs3() {
    vst = true;
    cnt++;
    ans = cnt;
    for(int x : nbr) if(x != next && !V[x].vst) {
      V[x].dfs3();
      cnt++;
    }
    if(next != -1) V[next].dfs3();
  }
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  V = vector<Node>(N);
  REP(i, N) V[i].idx = i;
  REP(i, N-1) {
    int A, B;
    cin >> A >> B;
    A--; B--;
    V[A].nbr.push_back(B);
    V[B].nbr.push_back(A);
  }
  V[0].dfs(0);
  int s = 0;
  int ma = -1;
  REP(i, N) if(V[i].d > ma) {
    ma = V[i].d;
    s = i;
  }
  REP(i, N) V[i].vst = false;
  V[s].dfs(0);
  int t = 0;
  ma = -1;
  REP(i, N) if(V[i].d > ma) {
    ma = V[i].d;
    t = i;
  }
  REP(i, N) V[i].vst = false;
  V[s].dfs2(t);
  REP(i, N) V[i].vst = false;
  V[s].dfs3();
  REP(i, N) cout << V[i].ans << (i!=N-1 ? " " : "");
  cout << "\n";
}

#include <bits/stdc++.h>
//#pragma GCC optimize ("03")
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)
#define ll long long
#define ld long double
#define pii pair < ld , ll >
#define pb push_back

using namespace std;

const ll N = 2e5 + 10;

int n , x , y;
int d[N] , num[N] , dep[N];
vector < int > G[N];

void dfs1(int w , int p)
{
    d[w] = d[p] + 1;

    for(auto i : G[w])
        if(i != p)
            dfs1(i , w);
}

void dfs2(int w , int p)
{
    for(auto i : G[w])
        if(i != p)
        {
            dfs2(i , w);
            dep[w] = max(dep[w] , dep[i] + 1);
        }
}

int cnt = 1;

void dfs3(int w ,  int p)
{
    num[w] = cnt;
    vector < pii > v;

    for(auto i : G[w])
        if(i != p)
            v.pb({dep[i] , i});

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

    for(auto i : v)
    {
        ++cnt;
        dfs3(i.second , w);
        ++cnt;
    }
}

signed main()
{
	#ifndef ONLINE_JUDGE
		FastIO , FILES;
	#endif

    int i;

    cin >> n;

    for(i = 1 ; i < n ; i++)
    {
        cin >> x >> y;
        G[x].pb(y);
        G[y].pb(x);
    }

    dfs1(1 , 0);

    int mx = 0 , root = 0;

    for(i = 1 ; i <= n ; i++)
        if(mx < d[i])
            mx = d[i] , root = i;

    dfs2(root , 0);
    dfs3(root , 0);

    for(i = 1 ; i <= n ; i++)
        cout << num[i] << ' ';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

	int x, y;

	cin >> x;

	y = x % 100;

	y = 100-y;

	cout << y;

	return 0;
}

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

#define N 200100
#define MOD 1000000007  //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 x;
	cin >> x;
	x %= 100;
	x = 100 - x;
	cout << x << endl;

	return 0;
}


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

int main() {

  ll si,sj;cin>>si>>sj;
  vector<vector<ll>> t(50, vector<ll>(50));
  vector<vector<ll>> p(50, vector<ll>(50));
  for(ll i=0;i<50;i++){
   for(ll j=0;j<50;j++){
    cin>>t[i][j];
   }
  }
  for(ll i=0;i<50;i++){
   for(ll j=0;j<50;j++){
    cin>>p[i][j];
   }
  }
  if(si>24&&sj>24){
    string S="";
    ll maxsum=-1;
   for (int tmp = 0; tmp < (1 << 24); tmp++) {
     ll SI=si,SJ=sj;
    bitset<24> BIT(tmp);
     string s="";
     ll sum=0;
//0は上、1は左
     bool a=true;
     ll b=t[SI][SJ];
     for(int i=0;i<24;i++){
       if(BIT.test(i)){
         SJ--;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break;
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='L';
         }
       }else{
         SI--;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break;
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='U';
         }
       }
       if(maxsum<sum){
         maxsum=sum;
         S=s;
       }
     }
  }
    cout<<S;
    return 0;
  }else if(si>24&&sj<=24){
      string S="";
    ll maxsum=-1;
   for (int tmp = 0; tmp < (1 << 24); tmp++) {
    bitset<24> BIT(tmp);
     ll SI=si,SJ=sj;
     string s="";
     ll sum=0;
//0は上、1は右
     bool a=true;
     ll b=t[SI][SJ];
     for(int i=0;i<24;i++){
       if(BIT.test(i)){
         SJ++;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break;
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='R';
         }
       }else{
         SI--;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break;
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='U';
         }
       }
       if(maxsum<sum){
         maxsum=sum;
         S=s;
       }
     }
  }
    cout<<S;
    return 0;
  }else if(si<=24&&sj>24){
    string S="";
    ll maxsum=-1;
   for (int tmp = 0; tmp < (1 << 24); tmp++) {
     string s="";
    bitset<24> BIT(tmp);
     ll SI=si,SJ=sj;
     ll sum=0;
//0は下、1は左
     bool a=true;
     ll b=t[SI][SJ];
     for(int i=0;i<24;i++){
       if(BIT.test(i)){
         SJ--;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break;
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='L';
         }
       }else{
         SI++;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break;
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='D';
         }
       }
       if(maxsum<sum){
         maxsum=sum;
         S=s;
       }
     }
  }
    cout<<S;
    return 0;
  }else{
    string S="";
    ll maxsum=-1;
   for (int tmp = 0; tmp < (1 << 24); tmp++) {
    bitset<24> BIT(tmp);
     ll SI=si,SJ=sj;
     string s="";
     ll sum=0;
//0は下、1は右
     bool a=true;
     ll b=t[SI][SJ];
     for(int i=0;i<24;i++){
       if(BIT.test(i)){
         SJ++;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break;
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='R';
         }
       }else{
         SI++;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break;
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='D';
         }
       }
       if(maxsum<sum){
         maxsum=sum;
         S=s;
       }
     }
  }
    cout<<S;
    return 0;
  }

}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y))
#define chmax(x,y) x = max((x),(y))
#define popcount(x) __builtin_popcount(x)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

//data
const int h = 50;
int tile[50][50];
int point[50][50];
int use[3000]; // not used 0,used 1

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
char direction[] = {'D','U','R','L'};

vector<char> ans;

//function
bool onboad(int i,int j) {return 0<=i && i<h && 0<=j && j<h;}

bool can_reach(int i,int j,int c){
    if(c==0) return true;
    bool ok = false;
    use[ tile[i][j] ] = 1;
    rep(k,4){
        int new_i = i + dx[k];
        int new_j = j + dy[k];
        if(!onboad(new_i,new_j)) continue;
        if(use[ tile[new_i][new_j] ] == 1) continue;
        ok = ok || can_reach(new_i,new_j,c-1);
        if(ok) break;
    }
    use[ tile[i][j] ] = 0;
    return ok;
}

void dfs(int i,int j){
    int res = -1;
    char c;
    int next_i,next_j;
    use[ tile[i][j] ] = 1;
    rep(k,4){
        int new_i = i + dx[k];
        int new_j = j + dy[k];
        if(!onboad(new_i,new_j)) continue;
        if(use[ tile[new_i][new_j] ] == 1) continue;
        if(res == -1 || can_reach(new_i,new_j,30) ){
            res = point[new_i][new_j];
            c = direction[k];
            next_i = new_i;
            next_j = new_j;
        }
    }
    if(res == -1) return;
    ans.push_back(c);
    dfs(next_i,next_j);
    return;
}

//score
int score(int si,int sj){
    int tmpi = si,tmpj = sj;
    int res = point[si][sj];
    for(auto c:ans){
        if(c=='D') tmpi += dx[0],tmpj += dy[0];
        if(c=='U') tmpi += dx[1],tmpj += dy[1];
        if(c=='R') tmpi += dx[2],tmpj += dy[2];
        if(c=='L') tmpi += dx[3],tmpj += dy[3];
        res += point[tmpi][tmpj];
    }
    return res;
}

FILE *fp;

int main(){
    int si,sj;
    cin >> si >> sj;
    rep(i,h)rep(j,h) cin >> tile[i][j];
    rep(i,h)rep(j,h) cin >> point[i][j];
    dfs(si,sj);

    for(auto c:ans) cout << c;
    cout << endl;

    #ifdef LOCAL_
    fp = fopen("score.txt","w");
    fprintf(fp,"%d\n",score(si,sj));
    fclose(fp);
    #endif

    return 0;
}


// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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

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

	int n, k, m;
	cin >> n >> k >> m;
	int a[n];
	int sum = 0;
	forn(i, n - 1)cin >> a[i], sum += a[i];
	int req = n * m - sum;
	if(req >= 0 && req <= k)cout << req << '\n';
	else if(req < 0)cout << 0;
	else cout << -1 << '\n';
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

bool eq(int a[], int b[], int c[], int n){
    pair<int,int> x[n],y[n];
    for(int i=0; i<n; i++) x[i]={a[i],i}, y[i]={b[i],i};
    sort(x,x+n);
    sort(y,y+n);
    for(int i=0; i<n; i++)
        if(x[i].first!=y[i].first)
            return false;
    for(int i=0; i<n; i++) c[x[i].second]=y[i].second;
    return true;
}

long long inversions=0;

void merge(int arr[], int l, int m, int r)
{
    int n1 = m - l + 1;
    int n2 = r - m;

    // Create temp arrays
    int L[n1], R[n2];

    // Copy data to temp arrays L[] and R[]
    for (int i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (int j = 0; j < n2; j++)
        R[j] = arr[m + 1 + j];

    // Merge the temp arrays back into arr[l..r]

    // Initial index of first subarray
    int i = 0;

    // Initial index of second subarray
    int j = 0;

    // Initial index of merged subarray
    int k = l;

    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            arr[k] = L[i];
            i++;
        }
        else {
            arr[k] = R[j];
            j++;
            inversions+=(long long)n1-i;
        }
        k++;
    }

    // Copy the remaining elements of
    // L[], if there are any
    while (i < n1) {
        arr[k] = L[i];
        i++;
        k++;
    }

    // Copy the remaining elements of
    // R[], if there are any
    while (j < n2) {
        arr[k] = R[j];
        j++;
        k++;
    }
}

// l is for left index and r is
// right index of the sub-array
// of arr to be sorted */
void mergeSort(int arr[],int l,int r){
    if(l>=r){
        return;//returns recursively
    }
    int m =l+ (r-l)/2;
    mergeSort(arr,l,m);
    mergeSort(arr,m+1,r);
    merge(arr,l,m,r);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        a[i]+=i;
    }
    for(int i=0; i<n; i++){
        cin>>b[i];
        b[i]+=i;
    }

    if(eq(a,b,c,n)){
        //for(int i=0; i<n; i++) cout<<c[i]<<"\n";
        mergeSort(c,0,n-1);
        cout<<inversions;
    }
    else{
        cout<<-1;
    }

}


//Quizzes

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rrep(i,x,y) for(ll i=x-1;i>=y;i--)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18
//cout<<fixed<<setprecision(15)<<x<<nnn;

signed main (){
    int n,x;string s;cin>>n>>x>>s;
    for(auto i:s){
        if(i=='o'){
            x++;
        }else{
            if(x>0)x--;
        }
    }
    cout<<x<<nnn;
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

template <typename F>
class
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
  [[nodiscard]]
#endif  // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
FixPoint final : private F
{
public:
  template <typename G>
  explicit constexpr FixPoint(G&& g) noexcept
    : F{std::forward<G>(g)}
  {}

  template <typename... Args>
  constexpr decltype(auto)
  operator()(Args&&... args) const
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
  noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...)))
#endif  // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
  {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};  // class FixPoint

#if defined(__cpp_deduction_guides)
template <typename F>
FixPoint(F&&)
  -> FixPoint<std::decay_t<F>>;
#endif  // defined(__cpp_deduction_guides)

namespace
{
  template <typename F>
#if !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
  #  if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
__attribute__((warn_unused_result))
#  elif defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_Check_return_)
_Check_return_
#  endif  // defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#endif  // !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
  inline constexpr decltype(auto)
  makeFixPoint(F&& f) noexcept
  {
    return FixPoint<std::decay_t<F>>{std::forward<std::decay_t<F>>(f)};
  }
}  // namespace

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, M;
	cin >> N >> M;
	vector<int64> A(N), B(M);
	set<int64> as, bs;
	REP(i, N) {
	  cin >> A[i];
	  as.insert(A[i]);
	}
	REP(i, M) {
	  cin >> B[i];
	  bs.insert(B[i]);
	}

	vector<int64> res;
	REP(i, N) {
	  if (bs.find(A[i]) == bs.end()) res.push_back(A[i]);
	}
	REP(i, M) {
	  if (as.find(B[i]) == as.end()) res.push_back(B[i]);
	}
	sort(all(res));

	for (auto &x : res) {
	  cout << x << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
constexpr char ln = '\n';
istream& operator>>(istream& is, __int128_t& x) {
    x = 0;
    string s;
    is >> s;
    int n = int(s.size()), it = 0;
    if (s[0] == '-') it++;
    for (; it < n; it++) x = (x * 10 + s[it] - '0');
    if (s[0] == '-') x = -x;
    return is;
}
ostream& operator<<(ostream& os, __int128_t x) {
    if (x == 0) return os << 0;
    if (x < 0) os << '-', x = -x;
    deque<int> deq;
    while (x) deq.emplace_front(x % 10), x /= 10;
    for (int e : deq) os << e;
    return os;
}
template<class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    for (int i = 0; i < int(v.size()); i++) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "}";
}
template<class Container> inline int SZ(const Container& v) { return int(v.size()); }
template<class T> inline void UNIQUE(vector<T>& v) { v.erase(unique(v.begin(), v.end()), v.end()); }
template<class T1, class T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return true; } return false; }
template<class T1, class T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return true; } return false; }
inline int topbit(ull x) { return x == 0 ? -1 : 63 - __builtin_clzll(x); }
inline int botbit(ull x) { return x == 0 ? 64 : __builtin_ctzll(x); }
inline int popcount(ull x) { return __builtin_popcountll(x); }
inline int kthbit(ull x, int k) { return (x >> k) & 1; }
inline constexpr long long TEN(int x) { return x == 0 ? 1 : TEN(x-1) * 10; }
template<class T> inline T ABS(T x) { return max(x, -x); }
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
inline void YES(bool t = 1) { cout << YESNO[t] << "\n"; }
inline void Yes(bool t = 1) { cout << YesNo[t] << "\n"; }
inline void yes(bool t = 1) { cout << yesno[t] << "\n"; }
inline void print() { cout << "\n"; }
template<class T>
inline void print(const vector<T>& v) {
    for (auto it = begin(v); it != end(v); ++it) {
        if (it != begin(v)) cout << " ";
        cout << *it;
    }
    print();
}
template<class T, class... Args>
inline void print(const T& x, const Args& ... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
inline void debug_out() { cerr << endl; }
template <class T, class... Args>
inline void debug_out(const T& x, const Args& ... args) {
    cerr << " " << x;
    debug_out(args...);
}
#define debug(...) cerr << __LINE__ << " : [" << #__VA_ARGS__ << "] =", debug_out(__VA_ARGS__)
#else
#define debug(...) (void(0))
#endif
struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(7); }; } fast_ios_;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    string S; cin >> S;
    cout << ((S[0]==S[1] and S[1]==S[2]) ? "Won" : "Lost") << ln;
}

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

#ifdef DEBUG
#include <dbprinter.hpp>
#define ios_base freopen("input.txt", "r", stdin);ios_base
#define o cerr << "Line " << __LINE__ << ": "; debug
#endif

#define endl '\n'
constexpr int N = 5001;
constexpr int INF = numeric_limits<int>::max() >> 1;

void solve() {
  string s;
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2]) cout << "Won";
  else cout << "Lost";
}

signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int tc = 1;
  // cin >> tc;
  while (tc --) { solve(); cout << "\n"; }
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n, m; cin >> n >> m;
    if(n == 1 &&  m == 0){
        out("1 2"); return 0;
    }
    if(m > n-2 || m < 0){
        out(-1); return 0;
    }

    vector<int> l(n), r(n);
    rep(i, n-1){
        l[i] = 2+3*i; r[i] = 4+3*i;
    }
    if(m==0){
        l[n-1] = 2+3*(n-1); r[n-1] = 4+3*(n-1);
    }
    else{
        l[n-1] = 1; r[n-1] = 3+3*m;
    }

    rep(i, n){
        outs(l[i]); out(r[i]);
    }
}

/* Author: rrrr_wys
 **/

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
typedef double db;
typedef long long ll;
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int N = 200110;
const int P = 998244353;

int fa[N];
int fd(int u) {
  if (u == fa[u])
    return u;
  return fa[u] = fd(fa[u]);
}
void mer(int x, int y) {
  int tx = fd(x), ty = fd(y);
  if (tx != ty) {
    fa[tx] = ty;
  }
}
signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n - 1) cin >> a[i];
  rep(i, 0, N - 1) fa[i] = i;
  int ans = 0;
  rep(i, 0, n - 1) {
    if (fd(a[i]) != fd(a[n - i - 1])) {
      mer(a[i], a[n - i - 1]);
      ++ans;
    }
  }
  cout << ans << "\n";
}


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

int main() {
  int N;
  cin >> N;
  int A, B;
  vector<int> vec_a;
  vector<int> vec_b;
  for(int i = 0; i < N; i++) {
    cin >> A >> B;
    vec_a.push_back(A);
    vec_b.push_back(B);
  }

  vector<int>::iterator a_iter = min_element(vec_a.begin(), vec_a.end());
  size_t a_index = distance(vec_a.begin(), a_iter);

  vector<int>::iterator b_iter = min_element(vec_b.begin(), vec_b.end());
  size_t b_index = distance(vec_b.begin(), b_iter);

  if(a_index != b_index) {
    if(*a_iter > *b_iter) {
      cout << *a_iter << endl;
      return 0;
    } else {
      cout << *b_iter << endl;
      return 0;
    }
  } else {
    int ans = *a_iter + *b_iter;
    int _a = *a_iter;
    int _b = *b_iter;
    sort(vec_a.begin(), vec_a.end());
    if (ans > max(vec_a[1], _b)) {
      ans = max(vec_a[1], _b);
    }
    sort(vec_b.begin(), vec_b.end());
    if (ans > max(vec_b[1], _a)) {
      ans = max(vec_b[1], _a);
    }
    cout << ans << endl;
    return 0;
  }
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long int;
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> T(N);
  rep(i, N) cin >> T[i].first >> T[i].second;

  int ans = INT_MAX;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) {
        chmin(ans, T[i].first + T[i].second);
      } else {
        chmin(ans, max(T[i].first, T[j].second));
      }
    }
  }
  cout << ans << endl;
}


//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

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

const int MOD=998244353;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	ll a,b,c;
	cin>>a>>b>>c;

	a=((a)*(a+1)/2)%MOD;
	b=((b)*(b+1)/2)%MOD;
	c=((c)*(c+1)/2)%MOD;

	cout<<a*b%MOD*c%MOD<<endl;
}

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
const int mod=998244353;
inline LL ksm(LL x,LL a){
	LL ret=1,k=x;
	for (;a;a>>=1,k=k*k%mod)
		if (a&1) ret=ret*k%mod;
	return ret%mod;
}
int main(void)
{
    LL a,b,c;cin>>a>>b>>c;
    LL aa=(a+1)%mod*a%mod*ksm(2,mod-2)%mod;
    LL bb=(b+1)%mod*b%mod*ksm(2,mod-2)%mod;
    LL cc=(c+1)%mod*c%mod*ksm(2,mod-2)%mod;
    printf("%lld",aa%mod*bb%mod*cc%mod);
}


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

int main()
{
    long long A, B;
    cin >> A >> B;
    cout << A * 1.0 * B / 100 << endl;
}

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

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

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

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

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

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

int a,b,c,d;

signed main(){
    read(a,b,c,d);
    writeln(b-c);
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
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; }

struct d{ll f, s, t;};//first, second, turn

bool comp(d a, d b) {
  if (a.t == 0 || b.t == 0) {
    return a.t >= b.t;
  }
  return (a.s - a.f) >= (b.s - b.f);
}

ll N;
vector<ll> p;
vector<vector<ll>> child;
d dfs(ll now, ll turn) {
  vector<ll> FS(2, 0);
  FS.at(0) += 1;
  turn = (turn + 1) % 2;
  vector<d> ds;
  vector<vector<ll>> datas;
  for (ll i = 0; i < child.at(now).size(); ++i) {
    d temp = {1, 0, 1};
    if (child.at(child.at(now).at(i)).size() != 0) {
      temp = dfs(child.at(now).at(i), 0);
    }
    if (temp.f <= temp.s && temp.t == 0) {
      FS.at(turn) += temp.s;
      FS.at((turn + 1) % 2) += temp.f;
    }
    else {
      ds.push_back(temp);
      datas.push_back({temp.t, temp.s - temp.f, temp.f, temp.s, temp.t});
    }
  }
  // for (ll i = 0; i < datas.size(); ++i) {
  //   cout << datas.at(i).at(0) << ' ' << datas.at(i).at(1) << "\n";
  // }
  sort(rrng(datas));
  // for (ll i = 0; i < datas.size(); ++i) {
  //   cout << datas.at(i).at(0) << ' ' << datas.at(i).at(1) << "\n";
  // }
  // cout << "\n";
  for (ll i = 0; i < datas.size(); ++i) {
    d temp = {datas.at(i).at(2), datas.at(i).at(3), datas.at(i).at(4)};
    FS.at(turn) += temp.s;
    FS.at((turn + 1) % 2) += temp.f;
    turn = (turn + temp.t) % 2;
  }
  // cout << "now" << now + 1 << "\n";
  // cout << FS.at(0) << ' ' << FS.at(1) << ' ' << turn << "\n";
  return {FS.at(0), FS.at(1), turn};
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  p = vector<ll>(N, -1);
  child = vector<vector<ll>>(N);
  for (ll i = 1; i < N; ++i) {
    cin >> p.at(i);
    p.at(i) -= 1;
    child.at(p.at(i)).push_back(i);
  }
  cout << dfs(0, 0).f << "\n";
}

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

double eval(double x,const vector<int> &a){
    double ret=0;
    for(int amt:a){
        double d=amt;
        ret+=x+d-min(d,x*2);
    }
    return ret;
}

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int &x:a)
        cin>>x;
    double l=0,r=1000000000;
    while(r-l>1e-7){
        double m1=(l*2+r)/3,m2=(l+r*2)/3;
        if(eval(m1,a)<eval(m2,a))
            r=m2;
        else
            l=m1;
    }
    cout<<setprecision(15)<<eval((l+r)/2,a)/n<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const double eps=1e-5;
int n,fa[110];
struct POINT
{int x,y;}p[110];
inline int read()
{
	int x=0,w=0;char ch=0;
	while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return w?-x:x;
}
int getfa(int x)
{return fa[x]==x?x:fa[x]=getfa(fa[x]);}
double dis(int x,int y)
{return sqrt(pow(p[x].x-p[y].x,2)+pow(p[x].y-p[y].y,2));}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		p[i].x=read(),p[i].y=read();
	double L=0,R=100,M,T=0;
	while(R-L>eps){
		M=(L+R)/2;
		for(int i=1;i<=n+2;i++)fa[i]=i;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)
			if(dis(i,j)<=M*2)
				fa[getfa(j)]=getfa(i);
			if(100-p[i].y<=M*2)fa[getfa(n+1)]=getfa(i);
			if(p[i].y+100<=M*2)fa[getfa(n+2)]=getfa(i);
		}
		if(getfa(n+1)!=getfa(n+2))T=L=M;
		else R=M;
	}
	printf("%.6f\n",T);
}

// Skyqwq
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

typedef long long LL;

const int N = 2e5 + 5;

int n, k, mid, cnt, h[N];

vector<int> g[N];

int dfs(int u, int fa) {
	int s = 0, w = 0; h[u] = -2e9;
	for (int i = 0; i < g[u].size(); i++) {
		int v = g[u][i];
		if (v == fa) continue;
		int t = dfs(v, u);
		s = max(s, t + 1);
		h[u] = max(h[u], h[v] - 1);
	}
	if (s > h[u] && s >= mid) s = -1e9, h[u] = mid, cnt++;// cout << u << " ..." << endl;
	else if (s <= h[u]) {
		s = -1e9;
	}
	if (u == 1 && s >= 0) cnt++;
	return s;
}

bool inline check() {
	cnt = 0, dfs(1, 0);
	return cnt <= k;
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d%d", &u, &v);
		g[u].push_back(v), g[v].push_back(u);
	}
	if (k >= n) {
		puts("0"); return 0;
	}
	int l = 1, r = n;

	while (l < r) {
		mid = (l + r) >> 1;
		if (check()) r = mid;
		else l = mid + 1;
	}
	printf("%d\n", r);
	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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

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

void solve(long long A, long long B, long long C, long long D){
  vector<ll> v{A,B,C,D};
  ll sum = A+B+C+D;
  REP(16){
    ll tmp=0;
    For(j,4){
      if((1<<j)&i){
        tmp+=v[j];
      }
    }
    if(sum==tmp*2){
      cout<<YES<<endl;
      return;
    }
  }
  cout<<NO<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <functional>
#include <cstdlib>
#include <list>
#include <iomanip>
#define ll long long
using namespace std;

int main() {

	ll N, W;
	cin >> N >> W;

	vector<ll> v(200005, 0);

	for (int i = 0; i < N; i++) {
		int a, b, p;
		cin >> a >> b >> p;

		v[a] += p;
		v[b] -= p;
	}

	if (v[0] > W) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 1; i < 200001; i++) {
		v[i] += v[i - 1];
		if (v[i] > W) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

bool cmp(pair<string, int>& a,
         pair<string, int>& b)
{
    return a.second < b.second;
}

// Function to sort the map according
// to value in a (key-value) pairs
void sort(map<string, int>& M, int n)
{

    // Declare vector of pairs
    vector<pair<string, int> > A;

    // Copy key-value pair from Map
    // to vector of pairs
    for (auto& it : M) {
        A.push_back(it);
    }

    // Sort using comparator function
    sort(A.begin(), A.end(), cmp);
  	int i =0;
     for (auto& it : A) {
  		if(i==n-2){
        cout << it.first<<  endl;
             return;
        }
        i++;
    }
}
int main(){
	int n; cin >> n;
	map<string,int>  mountain;

	for(int i = 0; i < n; i++){
		string mount; cin >> mount;
		int height; cin >> height;
		mountain.insert(pair<string,int>(mount,height));
	}
	sort(mountain, n);

	 return 0;
}

#include <bits/stdc++.h>
#define PB push_back
#define MP(x,y) make_pair(x,y)
#define F first
#define S second
#define LOOP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define lp(i,n) LOOP(i,0,n)
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
int main(){
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int n;
    scanf("%d", &n);
    char s[20];
    int h;
    int h1 = -1, h2 =-2;
    char s1[20], s2[20];
    lp(i,n){
        scanf(" %s %d", s, &h);
        if (h > h1){
            strcpy(s2, s1);
            strcpy(s1, s);
            h2 = h1;
            h1 = h;
        } else if (h > h2) {
            strcpy(s2, s);
            h2 = h;
        }
    }
    printf("%s", s2);
    return 0;
}


#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n)
    {
        cin >> v[i];
        if ((i % 2) == 0)
            v[i] *= -1;
    }
    map<ll, int> mp;
    ll ans = 0;
    ll cur = 0;
    rep(i, n)
    {
        cur += v[i];
        //cerr << cur << endl;
        ans += mp[cur];
        if (cur == 0)
            ans++;
        mp[cur]++;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SZ(x) ((int)(x).size())
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];
  SORT(a);
  SORT(b);
  int ans = b[0] - a[n - 1] + 1;
  if (ans < 0) ans = 0;
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


#include <bits/stdc++.h>
using namespace std;
#define rep(a,b,c) for(int a=(b);a<=(c);a++)
#define per(a,b,c) for(int a=(b);a>=(c);a--)
#define pb push_back
const int N=5e5+5e4+5;
template<class T>inline void read(T &x) {
	T f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	x*=f;
}
int n,k,p,f[101][N],ans,g[N],sum;
inline void solve() {
	read(n); read(k); read(p);
	f[0][0]=1;
	rep(i,1,n) {
		sum+=i*k;
		rep(j,0,sum) g[j]=(f[i-1][j]+((j>=i)?(g[j-i]):(0)))%p;
		rep(j,0,sum) f[i][j]=(p+g[j]-(((j-(k+1)*i)>=0)?(g[j-(k+1)*i]):(0)))%p;
	}
	rep(i,1,n) {
		ans=0;
		rep(sm,0,sum) (ans+=1ll*f[n-i][sm]*f[i-1][sm]%p)%=p;
		printf("%d\n",(1ll*ans*(k+1)-1)%p);
	}
}
int main() {
	//int TEST; read(TEST); while(TEST--)
	solve();
}

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

const int MAXN = 101;
const int MAXSUM = 50 * 99 * 50 + 1;
int dp[MAXN][MAXSUM];

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

  int N, K, M;
  cin >> N >> K >> M;

  dp[0][0] = 1;

  for (int n(1); n < MAXN; ++n)
    for (int curSum = 0; curSum < MAXSUM; ++curSum) {
      for (int take(0); take <= K and curSum >= take * n; ++take) {
        dp[n][curSum] += dp[n - 1][curSum - take * n];
      }
      dp[n][curSum] %= M;
    }

  for (int x(1); x <= N; ++x) {
    int sol = 0;
    int maxSum = min((N - x) * (N - x + 1) * K / 2, (x - 1) * x * K / 2);
    for (int sum(0); sum <= maxSum; ++sum)
      sol += dp[N - x][sum] * dp[x - 1][sum] % M * (K + !!sum);
    cout << sol % M << '\n';
  }
}


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

int main(){

ll aa,bb,cc;
cin>>aa>>bb>>cc;

if(cc==0){

if(aa>bb){
cout<<"Takahashi"<<endl;
return 0;
}else{
cout<<"Aoki"<<endl;
return 0;
}

}else{
if(aa>=bb){
cout<<"Takahashi"<<endl;
return 0;
}else{
cout<<"Aoki"<<endl;
return 0;
}

}

}

#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

class ModCalc
{
	LLONG m_mod = 1000000007;
	vector<LLONG> m_fac;
	vector<LLONG> m_ifac;

public:
	ModCalc(const LLONG mod)
	{
		m_mod = mod;
	}

	// Combinationを計算したいときの前処理：O(max)
	ModCalc(const int max, const LLONG mod)
	{
		m_mod = mod;
		m_fac = vector<LLONG>(max + 1);
		m_ifac = vector<LLONG>(max + 1);
		m_fac[0] = m_ifac[0] = 1;
		for (int i = 0; i < max; ++i)
		{
			m_fac[i + 1] = m_fac[i] * (i + 1) % mod;    // n! (mod M)
			m_ifac[i + 1] = m_ifac[i] * ModPow(i + 1, mod - 2) % mod;   // k!^(M-2) (mod M)
		}
	}

	const LLONG ModAdd(LLONG a, LLONG b) const
	{
		return (a + b) % m_mod;
	}

	const LLONG ModSubtract(LLONG a, LLONG b) const
	{
		LLONG diff = a - b;
		return diff >= 0 ? diff : diff + m_mod;
	}

	const LLONG ModMulti(LLONG a, LLONG b) const
	{
		LLONG prod = a * b % m_mod;
		return prod >= 0 ? prod : prod + m_mod;
	}

	const LLONG ModDiv(LLONG a, LLONG b) const
	{
		LLONG c = m_mod, u = 1, v = 0;
		while (c)
		{
			LLONG t = b / c;
			b -= t * c; swap(b, c);
			u -= t * v; swap(u, v);
		}
		u %= m_mod;
		if (u < 0) u += m_mod;
		return (a % m_mod) * u % m_mod;
	}

	const LLONG ModPow(LLONG x, LLONG n) const
	{
		LLONG ret = 1;
		while (n != 0)
		{
			if (n & 1) ret = ret * x % m_mod;
			x = x * x % m_mod;
			n = n >> 1;
		}
		return ret;
	}

	const LLONG ModComb(LLONG n, LLONG r) const
	{
		if (n == 0 && r == 0) return 1;
		if (n < r || n < 0) return 0;
		LLONG tmp = m_ifac[n - r] * m_ifac[r] % m_mod;
		return tmp * m_fac[n] % m_mod;
	}
};

int main()
{
	LLONG N, M, K; cin >> N >> M >> K;
	ModCalc m(MOD);

	if (N == 1)
	{
		cout << m.ModPow(K, M) << endl;
	}
	else if (M == 1)
	{
		cout << m.ModPow(K, N) << endl;
	}
	else
	{
		LLONG ans = 0;
		for (LLONG Amax = 1; Amax <= K; ++Amax)
		{
			LLONG Anum = m.ModSubtract(
				m.ModPow(Amax, N), m.ModPow(Amax - 1, N));
			LLONG Bnum = m.ModPow(K - Amax + 1, M);
			ans = m.ModAdd(ans, m.ModMulti(Anum, Bnum));
		}
		cout << ans << endl;
	}
}


#include <iostream>
using namespace std;

typedef long long ll;

int main() {
    ll b, c;
    cin >> b >> c;
    if (b == 0) {
        cout << c << endl;
    }
    else if (b > 0) {
        if (c < 3) cout << min(2 * b, c) + 1 << endl;
        else cout << min(2 * b, c) + c - 1 << endl;
    }
    else {
        if (c < 3) cout << c + 1 << endl;
        else cout << c + min(2 * (-b), c - 1) << endl;
    }
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

// clang-format off
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#define int long long
using namespace std;
#define stoi stoll
#define fi first
#define se second
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++)
#define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--)
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define _max(x) *max_element(ALL(x))
#define _min(x) *min_element(ALL(x))
#define _sum(x) accumulate(ALL(x), 0LL)

const int MOD   = 1000000007;
// const int MOD    = 998244353;
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-8;
const double PI  = 3.14159265358979;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T> using VVV = vector<vector<vector<T>>>;
template <class T, class S>  using P = pair<T, S>;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return true;}return false;}
int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
int _mod(int a) {return a >= 0 ? a % MOD : a - (MOD * _ceil(a, MOD));}
int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;}
struct mint {long long x;mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}mint operator-() const { return mint(-x); }mint &operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint &operator-=(const mint a) {if ((x += MOD - a.x) >= MOD) x -= MOD;return *this;}mint &operator*=(const mint a) { (x *= a.x) %= MOD;return *this; }mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// clang-format on

class BB {
public:
  static void solve(istream &cin, ostream &cout) {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int B, C;
    cin >> B >> C;
    int ans = 0;
    if (B > 0) {
      ans++;
      if (C / 2 >= B) {
        ans += B;
      } else {
        ans += C / 2;
      }
      if ((C - 1) / 2 >= B - 1) {
        ans += B;
      } else {
        ans += (C - 1) / 2 + 1;
      }
      C--;
      ans += C / 2;
      ans += (C - 1) / 2;
    } else if (B == 0) {
      ans++;
      ans += C / 2 + (C - 1) / 2;
    } else {
      ans++;
      ans += C / 2;
      ans += (C - 1) / 2;
      ans++;
      C--;
      B *= -1;
      if (C / 2 >= B) {
        ans += B;
      } else {
        ans += C / 2;
      }
      if ((C - 1) / 2 >= B - 1) {
        ans += B - 1;
      } else {
        ans += (C - 1) / 2;
      }
    }
    cout << ans << endl;
  }
};

signed main() {
  BB solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<array>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    long long int N,K; cin>>N>>K;
    rep(i,K){
        if(N%200==0){
            N /= 200;
        }else{
            N = N*1000+200;
        }
    }
    cout<<N;
}

                               // CPP
#include<bits/stdc++.h>
using namespace std;
//include <ext/pb_ds/assoc_container.hpp>
//include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define fon(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll ,ll>
#define vii vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vpii vector<pii>
#define vpll vector<pll>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define M (1000*1000*1000+7)
#define test ll T; cin>>T; while(T--)
#define all(z) z.begin() , z.end()
#define allr(z) z.rbegin() , z.rend()
#define memo(oo , zz) memset(oo , zz , sizeof(oo))
// =============================================
//1.integer overflow (1e5 * 1e5) (2e9 + 2e9)

void solve()
{
    ll n , k;
    cin >> n >> k;

    while(k--)
    {
      if(n%200 == 0)
      {
          n /= 200;
      }
      else{
          n *= 1000;
          n += 200;
      }
    }
    cout << n<< endl;

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


#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

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

//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1024>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り

	if (p != -1)
	{
		x %= p;
	}
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
//using namespace atcoder;

void solve()
{
	ll n;
	cin>>n;
	ll ans=0;
	string s="1";
	ll x=stoll(s+s);
	while(x<=n){
		++ans;
		ll num=stoll(s);
		++num;
		s=to_string(num);
		x=stoll(s+s);
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n, m; cin >> n >> m;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h));
    vector<ll> sum_l(n/2+1), sum_r(n/2+1);
    for(int i=0; i<n-1; i+=2) sum_l[i/2+1] = sum_l[i/2] + h[i+1] - h[i];
    for(int i=0; i<n-1; i+=2) sum_r[i/2+1] = sum_r[i/2] + h[n-i-1] - h[n-i-2];
    ll ans = INF;
    rep(i, m) {
        ll w; cin >> w;
        ll l = -1, r = n-1;
        while(r - l > 1) {
            ll mid = (l + r) / 2;
            if(h[mid] < w) l = mid;
            else r = mid;
        }
        if(r % 2 == 0) chmin(ans, abs(h[r] - w) + sum_l[r/2] + sum_r[(n-r-1)/2]);
        else chmin(ans, abs(h[l] - w) + sum_l[l/2] + sum_r[(n-l-1)/2]);
    }
    cout << ans << endl;
}


//                        YATIN KWATRA

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

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

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

struct best_hash {
	static uint64_t splitmix64(uint64_t x) {

		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

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

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

const int N = 2e5 + 5;
vii v[N];
int in[N];
int out[N];
int t;
vii a;

void dfs(int node, int par, int dunga) {
	in[node] = t++;
	a.pb(dunga);
	for (auto &i : v[node]) {
		if (i == par) continue;
		dfs(i, node, dunga + 1);
	}
	out[node] = t++;
	a.pb(dunga);
}

void solve()
{
	int n;
	cin >> n;
	fo(i, 1, n - 1) {
		int x;
		cin >> x;
		x--;
		v[x].pb(i);
		v[i].pb(x);
	}

	// make a euler tree first

	dfs(0, 0, 0);

	// now make occurance array of vectors

	vii pos[n];
	fo(i, 0, 2 * n - 1) pos[a[i]].pb(i);

	int q;
	cin >> q;
	while (q--) {
		int u, d;
		cin >> u >> d;
		--u;

		// find no of values in subtree of u with value d
		// or find no of values in range in[u] to out[u] with value d

		int l = in[u];
		int r = out[u];

		auto up = upper_bound(all(pos[d]), r) - pos[d].begin();
		auto down = lower_bound(all(pos[d]), l) - pos[d].begin();
		int cnt = (up - down) / 2;
		cout << cnt << endl;
	}

}

signed main() {

	FIO
	INPUT();

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

//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << 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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll k;
    vector<int> bai;
    if(s.size()==1){
        int base = 1;
        while (base * 8 < 10)
        {
            bai.push_back(base * 8);
            base++;
        }
    }
    else if(s.size()==2){
        int base = 2;
        while (base * 8 < 100)
        {
            bai.push_back(base * 8);
            base++;
        }
    }
    else{
        int base = 13;
        while (base * 8 < 1000)
        {
            bai.push_back(base * 8);
            base++;
        }
    }
    //debug(bai);
    vector<map<int, int>> bai_m(bai.size());
    rep(i, bai.size())
    {
        while (bai[i])
        {
            bai_m[i][bai[i] % 10]++;
            bai[i] /= 10;
        }
    }
    map<int, int> sm;
    rep(i, s.size())
    {
        sm[s[i] - '0']++;
    }
    rep(i, bai_m.size())
    {
        bool check = false;
        rep(j, 10)
        {
            if (bai_m[i][j] > sm[j])
                check = true;
        }
        if (check == false)
        {
            yes;
            return 0;
        }
    }
    no;
}


#include <iostream>
using namespace std;

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

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll A,B; cin >> A >> B;
    ll arr[A+B+9];
    ll i,j,sum=0;
    bool s = A < B;
    if(s) swap(A,B);
    FOR(i,1,A+1,1){
        sum += i;
        arr[i] = i;
    }
    j=-2;
    FOR(i,A+1,A+B,1){
        arr[i] = j;
        sum += j;
        j--;
    }
    arr[A+B] = -1*sum;
    if(s){
        FOR(i,1,A+B+1,1){
            printf("%lld ",-1*arr[i]);
        }
    }else{
        FOR(i,1,A+B+1,1){
            printf("%lld ",arr[i]);
        }
    }
}

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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

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

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,a,b;
    cin >> n >> a >> b;
    cout << (n-a)+b ENDL;

    return 0;
}


    #include <bits/stdc++.h>
    using namespace std;
    #define rep(i,n) for(int i=0;i < n;i++)
    typedef long long ll;
    int main(){
        int n;
        cin >> n;
        vector<long long> a(n);
        rep(i,n){
            cin >> a[i];
        }
        vector<vector<bool>> dp(n,vector<bool>(100001,false));
        dp[0][0] = true;
        dp[0][a[0]] = true;
        for(int i=1;i < n;i++){
            for(int j=0;j < 100001;j++){
                if(j-a[i] >= 0 && dp[i-1][j-a[i]]){
                    dp[i][j] = true;
                }
                if(dp[i-1][j]){
                    dp[i][j] = true;
                }
            }
        }
        long long totaltime = accumulate(a.begin(),a.end(),0L);
        long long besttime = 999999999;
        rep(j,100001){
            if(dp[n-1][j] && abs(totaltime - 2*j) < abs(totaltime - 2*besttime)){
                besttime = j;
            }
        }
        cout << max(besttime,totaltime-besttime) << endl;

        return 0;
    }

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

const int N = 2e5 + 10;
const int INF = 2e9;

int l[N], r[N];
long long f[N], g[N];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		l[i] = INF, r[i] = -INF;
	}
	for (int i = 1; i <= n; ++i)
	{
		int x, c;
		cin >> x >> c;
		l[c] = min(l[c], x);
		r[c] = max(r[c], x);
	}
	for (int i = 1, lst = 0; i <= n + 1; ++i)
	{
		//如果不存在的话 直接跳过
		if (l[i] == INF)
			continue;
		//走到当前的左边
		//		上一个的左边+左边走到当前的右边 上一个的右边走到当前的右边
		f[i] = min(f[lst] + abs(l[lst] - r[i]), g[lst] + abs(r[lst] - r[i])) + r[i] - l[i];
		//走到当前的右边
		g[i] = min(f[lst] + abs(l[lst] - l[i]), g[lst] + abs(r[lst] - l[i])) + r[i] - l[i];
		lst = i;
	}
	cout << f[n + 1] << endl;
	return 0;
}


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

#define ff first
#define ss second
#define pb push_back

using ll = long long;
using ld = long double;

const long double pi = acos((ld) - 1.0);
const double eps = (double)1e-9;
const int inf = 1e9 + 7;

int main(){

   int n;
   cin >> n;
   string s;
   cin >> s;
   int q;
   cin >> q;
   int t[q], a[q], b[q];
   for(int i = 0; i < q; i++){
      cin >> t[i] >> a[i] >> b[i];
      a[i]--, b[i]--;
   }
   int ch_at[2*n];
   int cnt = 0;
   for(int i = 0; i < 2*n; i++)ch_at[i] = i;
   for(int i = 0; i < q; i++){
      if(t[i] == 2){
         cnt++;
         cnt %= 2;
      } else{
         if(cnt){
            if(a[i] < n)a[i] += n;
            else a[i] -= n;
            if(b[i] < n)b[i] += n;
            else b[i] -= n;
         }
         swap(ch_at[a[i]], ch_at[b[i]]);
      }

   }
   if(cnt){
      for(int i = 0; i < 2 * n; i++){
         if(i < n)cout << s[ch_at[i+n]];
         else cout << s[ch_at[i-n]];
      }
   } else{
      for(int i = 0; i < 2*n; i++){
         cout << s[ch_at[i]];
      }
   }
   return 0;
}

const int fastio=[](){
   ios::sync_with_stdio(false);
   cin.tie(nullptr); cout.tie(nullptr);
   return 0;
}();

///////////////////////////////
////ACくれなきゃ悪戯しちゃうぞ!////
///////////////////////////////
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
#include <map>
#include <utility>
#include <set>
#include <deque>
//using
using namespace std;
using vi = vector <int>;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
using vd = vector <double>;
using vpl = vector <pair<ll,ll> >;
//define
#define rep(i,r) for(ll i=0;i<(r);i++)
#define Rep(i,l,r) for(ll i=(l);i<(r);i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
#define all(n) n.begin(),n.end()
//素数判定　O(√A)
bool is_prime(ll x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
 //各位の和
int wa(ll x)
{
ll sum = 0;
while(x!=0){
  sum += x% 10;
  x /= 10;
}
return sum;
}
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/
//最大公約数　ユークリッドの互除法
ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//最小公倍数　a*b/gcd
ll lcm(ll a, ll b) {
    return a/gcd(a, b)*b;
}
//10進→２進
ll binary(ll bina){
    ll ans = 0;
    for (ll i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
//'A'65,'a'97
//reverse 回文
/*for(const auto& [x,y]:m)    mapの範囲for
  {
    q+=y*(y-1)/2;
  }*/
/*小数点精度指定
cout<<fixed<<setprecision(9)<<;
*/
//文字列の削除 erase(n)

//グローバル変数宣言等
ll p=0,q=0,r=0;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#define inf 1000000000000 //10^12:∞
#define mod 1000000007 //10^9+7:合同式の法
char ja(char a,char b)
{
  if ((a=='R'&&b=='S')||(b=='R'&&a=='S')||(a=='R'&&b=='R'))
  {
    return 'R';
  }
  if ((a=='P'&&b=='S')||(b=='P'&&a=='S')||(a=='S'&&b=='S'))
  {
    return 'S';
  }
  if ((a=='R'&&b=='P')||(b=='R'&&a=='P')||(a=='P'&&b=='P'))
  {
    return 'P';
  }
}
int main()
{
  ll n,k;cin>>n>>k;
  string t;cin>>t;
  vs s(k+1);
  s[0]=t;
  r=inf;
  rep(j,k)
  {
    p=j+1;
    if((k-j)<=6)r=pow(2,(k-j));
    if(n%2==1)q=n*2;else q=n;
    for (int i = 0; i < q; i+=2)
    {
      char a=s[j][i%n],b=s[j][(i+1)%n];
      s[p]+=ja(a,b);
    }
    n=s[p].size();
  }
  print(s[k][0]);
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main()
{
  int N, Q;
  cin >> N >> Q;
  vector<long long> A(N), B(N);
  for (auto& vi: A) cin >> vi;

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

  long long K;
  for (int k = 0; k < Q; k++) {
    cin >> K;
    int i = lower_bound(B.begin(), B.end(), K) - B.begin();

    if (i == B.size()) {
      cout << A[i-1] + (K-B[i-1]) << endl;
    } else {
      cout << A[i]- (B[i]-K + 1) << endl;
    }
  }

  return 0;
}

#include <bits/stdc++.h>

#pragma region my_template

struct Rep {
  struct I {
    int i;
    void operator++() { ++i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i < *o; }
  };
  const int l_, r_;
  Rep(int l, int r) : l_(l), r_(r) {}
  Rep(int n) : Rep(0, n) {}
  I begin() const { return {l_}; }
  I end() const { return {r_}; }
};
struct Per {
  struct I {
    int i;
    void operator++() { --i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i > *o; }
  };
  const int l_, r_;
  Per(int l, int r) : l_(l), r_(r) {}
  Per(int n) : Per(0, n) {}
  I begin() const { return {r_ - 1}; }
  I end() const { return {l_ - 1}; }
};

template <class F>
struct Fix : private F {
  Fix(F f) : F(f) {}
  template <class... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T = int>
T scan() {
  T res;
  std::cin >> res;
  return res;
}

template <class T, class U = T>
bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif

using namespace std;

#define ALL(c) begin(c), end(c)

#pragma endregion

constexpr auto Inf = numeric_limits<int>::max() / 2;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int ans = +Inf;
  for (int n = scan(); n--;) {
    int a = scan();
    int p = scan();
    int x = scan();
    if (x > a) chmin(ans, p);
  }
  if (ans == +Inf) ans = -1;
  cout << ans << '\n';
}


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

using namespace std;

    const static long long MOD = 1000000007;

    long long norm(long long a) {
        a %= MOD;
        if (a < 0) {
            a += MOD;
        }
        return a;
    }

    long long inverse(long long a) {
        long long b = MOD;
        long long u = 0, v = 1;
        a = norm(a);
        while (a != 0) {
            long long d = b / a;
            b -= d * a;
            u -= d * v;
            swap(a, b);
            swap(u, v);
        }
        return norm(u);
    }

    long long powM(long long x, long long e) {
        long long res = 1;
        while (e > 0) {
            if (e & 1) {
                res = res * x % MOD;
            }
            x = x * x % MOD;
            e >>= 1;
        }
        return res;
    }

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n, m;
    cin >> n >> m;
    --m;
    long long res = m * 1LL * powM(m - 1, n - 1) % MOD;
    cout << res << '\n';

    return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define sz size()

using namespace std;

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

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

ll inv[maxn+3];
ll fac[maxn+3];
ll qpow(ll x,ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n & 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}
inline ll A(ll n, ll m){
    return fac[n] * inv[n - m] % MOD;
}
inline ll C(ll n, ll m){
    return A(n, m) * inv[m] % MOD;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    fac[0] = fac[1] = 1;
    for(ll i = 1; i < maxn; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
    inv[0] = 1;
    inv[1] = 1;
    for(ll i = 2; i < maxn; i++){
        inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
    }
    for(ll i = 2; i < maxn; i++){
        inv[i] = inv[i] * inv[i - 1] % MOD;
    }
    ll n, p;
    cin >> n >> p;;
    cin >> n >> p;
    ll ans = (p - 1) * qpow(p - 2, n - 1) % MOD;
    ans %= MOD;
    cout << ans;
    return 0;
}


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

const int maxN = 1e6 + 10;

int n;
char s[maxN + 1];

vector<int> v0, v1;

int main()
{
	scanf("%d", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++)
		if(s[i] == '0') v0.push_back(i);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++)
		if(s[i] == '0') v1.push_back(i);

	if(v0.size() != v1.size()) return puts("-1"), 0;

	int ans = 0;
	for(int i = 0; i < v0.size(); i++) ans += (v0[i] != v1[i]);

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

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

int n;
string a, b;
vector<char> p, q;
vi x, y;

void input()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	cin >> a >> b;
}

void solve()
{
	int s = 0;
	F (i, n)
		if (a[i] == '1') ++s;
	F (i, n)
		if (b[i] == '1') --s;
	if (s) { cout << "-1\n"; return; }
	int ans = 0;
	a = ' ' + a;
	b = ' ' + b;
	int x = 0, y = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (x > 0 && a[i] == '0') { a[i] = '1'; --x; }
		if (y > 0 && b[i] == '0') { b[i] = '1'; --y; }
		if (a[i] != b[i])
		{
			if (a[i] == '1') { a[i] = '0'; ++x; }
			if (b[i] == '1') { b[i] = '0'; ++y; }
			++ans;
		}
	}
	cout << ans << '\n';
}

main()
{
	input();
	solve();
}