#ifdef LOCAL
#pragma warning(disable:4996)
#pragma warning(disable:4244)
#pragma warning(disable:4554)
#define gets gets_s

#endif
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<string>
#include<cctype>
#include<cstdio>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<assert.h>
#define ll long long
#define cl(a,x) memset((a),(x),sizeof(a))
#define lson 2*i
#define rson 2*i+1
#define sf scanf
#define ull unsigned long long
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define ti tree[i]
#define endl "\n"
#define debug(num) #num << "=" << num << " "
ll q_pow(ll x, ll n, ll mod) { ll ret = 1; while (n) { if (n & 1) ret = x * ret%mod; x = x * x%mod; n >>= 1; }return ret; }
ll __gcd(ll x, ll y) { if (!y) return x; return __gcd(y, x%y); }
ll getbit(ll now) { int cnt = 0; while (now) { cnt++; now -= lowbit(now); }return cnt; }
int dx[] = { -1,1,0,0 };//上下左右
int dy[] = { 0,0,-1,1 };//
using namespace std;
const ll maxn = 1e5 + 10;
const ll INF = 0x3f3f3f3f;
const ll IINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
int mod = 1e9 + 7;
void add(ll &a, ll num) { a += num; if (a >= mod) a -= mod; }

vector<int> edge[maxn];
int dp[maxn];
int sz[maxn];
int n;

void dfs(int pos, int fa) {
	sz[pos] = 1;
	dp[pos] = 1;
	int deltaa = 0, deltab = 0;
	vector<int> tmp;

	for (auto to : edge[pos]) {
		if (to == fa) continue;
		dfs(to, pos);
		sz[pos] += sz[to];
		if (sz[to] % 2 == 0) {//子树大小为偶数
			if (sz[to] - dp[to] > dp[to]) {//后手赢的多，必然先走
				dp[pos] += dp[to];
			}
			else {//先手赢的多，看最后谁先走这里
				deltaa += dp[to];
				deltab += sz[to] - dp[to];
			}
		}
		else {//子树大小为奇数，先后手顺序变化
			tmp.emplace_back(to);
		}
	}

	sort(tmp.begin(),tmp.end(),[&](const int x,const int y){
		return sz[x] - dp[x] - dp[x] > sz[y] - dp[y] - dp[y];//谁后手相对先手赢的多，就先走哪个
	});

	for (int i = 0; i < tmp.size(); i++) {
		if (i % 2 == 1) dp[pos] += sz[tmp[i]] - dp[tmp[i]];
		else dp[pos] += dp[tmp[i]];
	}

	if (tmp.size() % 2 == 0) {//说明此时先手边后手，先拿好东西
		dp[pos] += deltaa;
	}
	else dp[pos] += deltab;

	//cerr << debug(pos) << debug(dp[pos]) << endl;
}

void solve() {
	cin >> n;
	int num;
	for (int i = 2; i <= n; i++) {
		cin >> num;
		edge[num].emplace_back(i);
		edge[i].emplace_back(num);
	}

	dfs(1, 1);
	cout << dp[1] << endl;
}

signed main(int argc, char *argv[]) {
	if (argc == 2 && strcmp("-debug", argv[1]) == 0) {
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}

	cout << fixed << setprecision(20); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;

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

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll n;
gr g;

pll rec(ll u) { // ret (what takes Taker, odd/even)
    ll ret = 1, cnt = 1;
    vector<vll> o,e;
    for(auto v: g[u]) {
        auto [val, sz] = rec(v);
        if(sz&1) o.pb({2*val-sz, val,sz-val});
        else e.pb({2*val-sz, val,sz-val});
        cnt += sz;
    }
    sort(all(o));
    F(o.size()) ret += o[i][1+(i&1)];
    F(e.size()) if(e[i][0]<=0) {
        ret += e[i][1];
    } else {
        ret += e[i][1+(o.size()&1)];
    }
    return {ret, cnt};
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n;
    g = gr(n);
    F(n-1) {
        ll x; cin >> x; x--;
        g[x].pb(i+1);
    }
    cout << rec(0).x << endl;
    return 0;
}


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

    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())

    ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
    string str = "", s1 = "", s2 = "";
    ll mod = 1e9 + 7;
    //ll mod = 998244353;
    const int N = 100009;

    /**
        2021 challenge (16/365) : 16.01.2021
    */

    void solve(){
        cin >> n >> k;
        vector<ll> freq(n+100,0);
        for(int i=0; i < n; i++){
            cin >> a;
            freq[a]++;
        }
        int active = k;
        int curr = 0;
        ll sum = 0;
        for(int i=0; i <= n; i++){
            if(active == 0) break;
            if(freq[i] < active){
                int diff = active - freq[i];
                sum += (diff * i);
                active = freq[i];
            }
        }
        cout << sum << endl;
    }

    int main(){
        ios_base::sync_with_stdio(false);

        int cases = 1;
        //cin >> cases;

        while(cases--) solve();
        return 0;
    }

#include <bits/stdc++.h>
#define int long long
#define sc(x) scanf("%lld",&x);

#define P pair<int,int>
#define fi first
#define se second
#define pb push_back
#define endl '\n'

using namespace std;
int N;
int A[300006];
int B[300005];

signed main()
{
    int n,k;
    sc(n)sc(k)
    int x;
    for(int i = 0; i < n; i++){
        sc(x)
        A[x]++;
    }
    int ans = 0,r;
    for(int i = 0; i < n; i++){
        if(A[i] >= k){
            continue;
        }else{
           r = k - A[i];
           ans += r*i;
           k -= r;
        }
        if(k == 0)break;
    }
    cout << ans << '\n';
    return 0;
}


#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
set<pair<int,int>> s;
set<int> st;
int a[100010],b[100010],d[100010] = {};
vector<int> v;
int main(){
    int i,j,n,l; cin >> n >> l;
    for(i=1;i<=n;i++) cin >> a[i];
    for(i=1;i<=n;i++) cin >> b[i];
    for(i=1;i<=n;i++) d[i] = b[i] - a[i];
    a[0] = 0; a[i] = l + 1;
    for(i=0;i<=n + 1;i++){
        s.insert({a[i] - i,i}); st.insert(a[i] - i);
    }
    for(i=0;i<=n + 1;i++){
        if(d[i]==0) v.push_back(i);
    }
    ll ans = 0;
    for(i=1;i<v.size();i++){
        vector<pair<ll,ll>> v2,v3;
        for(j=v[i - 1] + 1;j<v[i];j++){
            if(!st.count(a[j] - j + d[j])){
                cout << -1 << endl;
                return 0;
            }
            if(d[j]<0) v2.push_back({(*(--s.upper_bound({a[j] - j + d[j],1000000000}))).second,j});
            else v3.push_back({(*s.lower_bound({a[j] - j + d[j],-1})).second,j});
        }
        for(j=0;j<(int)v2.size() - 1;j++){
            if(v2[j + 1].second - v2[j].second>1){
                cout << -1 << endl;
                return 0;
            }
        }
        for(j=0;j<(int)v3.size() - 1;j++){
            if(v3[j + 1].second - v3[j].second>1){
                cout << -1 << endl;
                return 0;
            }
        }
        if(v2.size()){
            ll cnt = 0,x = v2.back().first;
            for(j=v2.size() - 1;j>=0;j--){
                if(x!=v2[j].first){
                    ans += cnt; cnt = 0;
                }
                cnt = max(cnt,v2[j].second - v2[j].first);
                x = v2[j].first;
            }
            ans += cnt;
        }
        if(v3.size()){
            ll cnt = 0,x = v3[0].first;
            for(j=0;j<v3.size();j++){
                if(x!=v3[j].first){
                    ans += cnt; cnt = 0;
                }
                cnt = max(cnt,v3[j].first - v3[j].second);
                x = v3[j].first;
            }
            ans += cnt;
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N;
	double D,H;
	cin >> N >> D >> H;
	double ans = 0;
	while(N--){
		double d,h; cin >> d >> h;
		chmax(ans,h-(H-h)/(D-d)*d);
	}
	cout << ans << endl;
}


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

long long int a[50] = {0} , b[50] = {0};
int main() {
	// your code goes here
    int n;
    long long int t;
    cin >> n >> t;
    int x = n/2;
    for(int i = 0 ; i < x ; i++){
           cin >> a[i];
    }

    for(int i = 0 ; i < n-x ; i++){
        cin >> b[i];
    }
    vector<long long int > v , u;
    for(int i = 0 ; i < (1 << x) ; i++){
        long long int val = 0;
        for(int j = 0 ; j < x ; j++){
            if((i&(1<<j)))
                val += a[j];
        }
        v.push_back(val);
    }

    for(int i = 0 ; i < (1 << (n-x)) ; i++){
        long long int val = 0;
        for(int j = 0 ; j < (n-x) ; j++){
            if((i&(1<<j)))
                val += b[j];
        }
        u.push_back(val);
    }

    sort(u.begin() , u.end());
    long long int ans = 0 , k;
    for(int i = 0 ; i < v.size() ; i++){
         k = t - v[i];
         if(k <= 0) continue;
         int f = upper_bound(u.begin() , u.end() , k) - u.begin();
         f--;
         if(f < 0) continue;
         else ans = max(ans , v[i] + u[f]);
    }
    cout << ans << endl;

	return 0;
}

/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

ll n,t,w[N],ans;
void rec(int i,int n,vector<ll>&s,ll sum){
    if(i>n){
        if(sum<=t){
            ans=max(ans,sum);
            s.pb(sum);
        }
        return;
    }
    rec(i+1,n,s,sum);
    rec(i+1,n,s,sum+w[i]);
}
signed main(){
    FastIO;
    cin>>n>>t;
    rep(i,1,n) cin>>w[i];
    vector<ll>a,b;
    rec(1,n/2,a,0);
    rec(n/2+1,n,b,0);
    sort(all(a));
    sort(all(b));
    for(ll i:a){
        auto it=ub(all(b),t-i);
        if(it==b.begin()) continue;
        --it;
        if(*it+i<=t) ans=max(ans,*it+i);
    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=401000;
int n;
int a[maxn],rk[maxn];
bool type[maxn];
int scnt,stype;
inline int read(){
    int res=0;
    char ch=getchar(),ch1=ch;
    while(!isdigit(ch))ch1=ch,ch=getchar();
    while(isdigit(ch))res=res*10+ch-'0',ch=getchar();
    return ch1=='-'?-res:res;
}
int main(){
    n=read();
    for(int i=1;i<=(n<<1);++i)rk[i]=a[i]=read();
    sort(rk+1,rk+1+(n<<1));
    int cnt=0;
    for(int i=1;i<=(n<<1);++i){
        if(a[i]>rk[n+1]){
            ++cnt;type[i]=true;
        }
    }
    for(int i=1;i<=(n<<1);++i){
        if(a[i]==rk[n+1]){
            ++cnt;type[i]=true;
            if(cnt==n)break;
        }
    }
    for(int i=1;i<=(n<<1);++i){
        if(!scnt){
            ++scnt;stype=type[i];
            putchar('(');
        }
        else{
            if(stype!=type[i])--scnt,putchar(')');
            else ++scnt,putchar('(');
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
inline int read() {
	int x=0,f=1;char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
using namespace std;
typedef long long ll;
const int M=1e6+5,mod=1e9+7;
vector <int> E[M];
int A[M],B[M];
int n;
int Q(int a,int b=mod-2){
	int ans=1;
	for(;b;a=1ll*a*a%mod,b>>=1)if(b&1)ans=1ll*ans*a%mod;
	return ans;
}
void init(int m) {
	rep(i,1,m){
		int u=read(),v=read();
		E[u].push_back(v),E[v].push_back(u);
	}
}
void graph(){n=read();init(read());}
void tree(){n=read();init(n-1);}

int Mod[M],rest[M];
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){
        x=1,y=0;
        return ;
    }
    exgcd(b,a%b,y,x);
    y-=a/b*x;
}
ll inv(ll a,ll b){
    ll x,y;
    exgcd(a,b,x,y);
    return (x%b+b)%b;
}
void CRT() {
    ll mul=1;
    rep(i,1,n)mul*=Mod[i];
    ll ans=0;
    rep(i,1,n){
		ll m=mul/Mod[i],tmp=inv(m,rest[i]);
		(ans+=Mod[i]*m*tmp)%=mul;
    }
}
struct node {
	int id;ll num;
	bool operator <(const node &a)const {
		if(num!=a.num)return num>a.num;
		return id<a.id;
	}
};
int T[M];
int query(int x,int ans=0){
	while(x<=n)ans+=T[x],x+=x&-x;
	return ans;
}
void add(int x){
	while(x)T[x]++,x-=x&-x;
}
int mk[M],st[M],mat[M];
void solve() {
	n=read()<<1;
	rep(i,1,n)A[i]=B[i]=read();
	sort(B+1,B+1+n);
	int mid=n/2,tot=0;
	rep(i,1,n)if(tot<mid&&A[i]<B[mid])tot++,mk[i]=1;
	rep(i,1,n)if(tot<mid&&A[i]==B[mid])tot++,mk[i]=1;

	bool op;int tp=0;
	rep(i,1,n){
		if(mk[i]){
			if(!tp)st[++tp]=i,op=1;
			else if(op==1)st[++tp]=i;
			else {
				int tmp=st[tp];
				mat[tmp]=i;
				mat[i]=tmp;
				tp--;
			}
		}else {
			if(!tp)st[++tp]=i,op=0;
			else if(op==0)st[++tp]=i;
			else {
				int tmp=st[tp];
				mat[tmp]=i;
				mat[i]=tmp;
				tp--;
			}
		}
	}
	rep(i,1,n){
		if(mat[i]>i)putchar('(');
		else putchar(')');
	}
}
int main() {
	int T=1;
	while(T--)solve();
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int mn = 1e9, mx = -1e9;
  for(int i=0;i<n;++i){
    int x; cin >> x;
    mx = max(mx, x);
  }
  for(int i=0;i<n;++i){
    int x; cin >> x;
    mn = min(mn, x);
  }

  cout << (mn < mx ? 0 : mn-mx+1);
  cout << endl;

  return 0;
}

#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define sqr(x) ((x) * (x))
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;
    cin>>n;
    int a[n], b[n];
    loop(i,0,n) cin>>a[i];
    loop(i,0,n) cin>>b[i];

    int mn = a[0], mx = b[0];
    loop(i,1,n)
    {
        mn = max(mn,a[i]);
        mx = min(mx,b[i]);
    }

    int ans = max(0,mx-mn+1);
    cout<<ans<<'\n';

    return 0;
}


#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")

#include"bits/stdc++.h"
using namespace std;
const int p = 31;
const int M = 998244353;
typedef long long ll;
typedef double d;
typedef long double ld;
typedef unsigned long long ull;
#define ar array
#define ff first
#define ss second
#define vt vector
mt19937_64 rnd(time(NULL));
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
ll euclid(ll a, ll b, ll &x, ll &y) {if (!b) return x = 1, y = 0, a; ll d = euclid(b, a % b, y, x); return y -= (a / b) * x, d;}

int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int l, r;
    cin >> l >> r;
    ll ans = 0ll;
    if (l == r) {
        cout << 0;
        return 0;
    }
    vector<ll>pf(r + 3);
    for (int i = r + 1; i >= 2; --i) {
        ll dif = (r / i - (l + i - 1) / i + 1);
        pf[i] = dif*dif;
        ll now = 2 * i;
        for (; now <= r; now += i) {
            pf[i] -= pf[now];
        }
    }
    for(int i=2;i<=r;++i){
        ans+=pf[i];
        if(i>=l){
            ans-=2*((r / i - (l + i - 1) / i + 1));
            ans+=1;
        }
    }
    cout<<ans<<'\n';
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; //check time
    return 0;
}

#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define dbg(msg, var) cout << msg << " " << var << endl;
//

const int MAX = 200010;
const ll MOD = (int) 998244353;
const int INF = 1e9;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-8;

int32_t main() {
    // sws;
    int n, m;
    cin >> n >> m;

    vector<vector<char>> mat(n, vector<char>(m, 0));
    vi qtr(n+m+10), qtb(n+m+10), qtp(n+m+10);

    ll res = 1;

    forn(i, n) {
        forn(j, m) {
            cin >> mat[i][j];
            int d = i+j;
            if(mat[i][j] == 'R')
                qtr[d]++;
            if(mat[i][j] == 'B')
                qtb[d]++;
            if(mat[i][j] == '.')
                qtp[d]++;
        }
    }

    forn(d, n+m-1) {
        if(qtr[d] and qtb[d]) {
            res = 0;
            break;
        }
        if(!qtr[d] and !qtb[d]) {
            res = (res + res) % MOD;
        }
    }

    cout << res << endl;

    // int overflow, array bounds special cases (n=1?)
    // do smth instead of nothing and stay organized - divide in subproblems?
    // WRITE STUFF DOWN DON'T GET STUCK ON ONE APPROACH
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll maxN = 110000;

ll N, M, K;
vector<ll> G[maxN];
vector<ll> C;
vector<vector<ll>> dist;

void init() {
    cin >> N >> M;
    rep(i,M) {
        ll x, y; cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    cin >> K;
    C.resize(K);
    rep(i,K) cin >> C[i];
    rep(i,K) C[i]--;
    dist.resize(K,vector<ll>(K));
}

vector<ll> bfs(ll st) {
    vector<ll> tmp(N,inf);
    tmp[st] = 0;
    queue<ll> que;
    que.push(st);
    while (que.size()) {
        ll x = que.front();
        que.pop();
        for (ll y : G[x]) {
            if (tmp[y]!=inf) continue;
            tmp[y] = tmp[x] + 1;
            que.push(y);
        }
    }
    vector<ll> res(K);
    rep(i,K) res[i] = tmp[C[i]];
    return res;
}

int main() {
    init();
    rep(i,K) dist[i] = bfs(C[i]);
    vector<vector<ll>> dp(1<<K,vector<ll>(K,inf));
    rep(i,K) dp[1<<i][i] = 1;
    rep(bit,1<<K) {
        if (bit==0) continue;
        rep(i,K) {
            if (!((bit>>i)&1)) continue;
            rep(j,K) {
                if ((bit>>j)&1) continue;
                ll nbit = bit | (1<<j);
                chmin(dp[nbit][j], dp[bit][i] + dist[i][j]);
            }
        }
    }
    ll X = (1<<K) - 1;
    ll ans = inf;
    rep(i,K) chmin(ans,dp[X][i]);
    if (ans==inf) ans = -1;
    Cout(ans);
}

#include<bits/stdc++.h>
using namespace std;
const long long maxn=2e5+5;
const long long maxm=20;
const long long inf=0x3f3f3f3f;
vector<long long> g[maxn];
queue<pair<long long,long long> >q;
bool vis[maxn];
long long n,m,k,c[maxm],idx[maxn];
long long dist[maxm][maxm],dp[maxm][1<<maxm];
int main(){
	cin>>n>>m;
	for(long long i=0;i<m;i++)
	{
		long long x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	cin>>k;
	memset(idx,-1,sizeof(idx));
	for(long long i=0;i<k;i++)
	{
		cin>>c[i];
		idx[c[i]]=i;
	}
	for(long long i=0;i<k;i++)
	{
		q.push({c[i],0});
		memset(vis,0,sizeof(vis));
		for(long long j=0;j<k;j++)
			dist[i][j]=maxn;
		while(!q.empty())
		{
			auto cur=q.front();
			q.pop();
			long long node=cur.first,cost=cur.second;
			if(vis[node])
				continue;
			vis[node]=1;
			if(idx[node]!=-1)
				dist[i][idx[node]]=cost;
			for(long long nbr:g[node])
			{
				if(!vis[nbr])
					q.push({nbr,cost+1});
			}
		}
	}
//	cout<<"11111111111"<<endl;
//	for(int i=0;i<k;i++)
//	{
//		for(int j=0;j<k;j++)
//			cout<<dist[i][j]<<" ";
//		cout<<endl;
//	}
	memset(dp,maxn,sizeof(dp));
	for(long long i=0;i<k;i++)
		dp[i][1<<i]=0;
	for(long long j=0;j<(1<<k);j++)
	{
		for(long long i=0;i<k;i++)
		{
			if(j&(1<<i))
			{
				long long cur=j&~(1<<i);
				for(long long l=0;l<k;l++)
					if(cur&(1<<l))
						dp[i][j]=min(dp[i][j],dp[l][cur]+dist[l][i]);
			}
		}
	}
//	cout<<"11111111111"<<endl;
//	for(int i=0;i<k;i++)
//	{
//		for(int j=0;j<k;j++)
//			cout<<dp[i][j]<<" ";
//		cout<<endl;
//	}
	long long ans=maxn;
	for(long long i=0;i<k;i++)
		ans=min(ans,dp[i][(1<<k)-1]);
	if(ans==maxn)
		cout<<"-1"<<endl;
	else
		cout<<ans+1<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
vector<bool> seen;
const ll MOD = 998244353;

void dfs(Graph &G, int v){
    seen[v] = true;
    for(auto next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v);
    }
}

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

    Graph G(n);
    rep(i,n){
        G[i].push_back(f[i]);
        G[f[i]].push_back(i);
    }

    seen.assign(n, false);
    int cnt = 0;
    for(int v = 0; v < n; v++){
        if(seen[v]) continue;
        dfs(G, v);
        cnt++;
    }
    ll ans = 1;
    rep(i, cnt){
        ans *= 2;
        ans %= MOD;
    }
    cout << ans-1 << endl;
    return 0;
}

# pragma GCC optimize ("O3")
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define rep2(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define x first
#define y second
using namespace std;
using ll = long long;
using tl = tuple<ll, ll, ll, ll>;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
using ld = long double;

const ll MOD = 998244353;
const int MAX = 2e5 + 1;
int N, f[MAX], fin[MAX], vis[MAX], cnt;

bool dfs(int u){
    bool ret = 0;
    vis[u] = 1;
    int v = f[u];
    if(!vis[v]) ret |= dfs(v);
    else if(!fin[v]) {ret = 1; cnt++;}
    fin[u] = 1;
    return ret;
}
ll calc(ll a, ll b){
    ll ret = 1;
    while(b){
        if(b & 1) ret = ret * a % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    ret = (ret + MOD - 1) % MOD;
    return ret;
}
int main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    cin >> N;
    rep(i, 1, N + 1) cin >> f[i];
    rep(i, 1, N + 1) if(!vis[i]) dfs(i);
    cout << calc(2, cnt);
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

// dijkstra(O((E+V)log(V)))
template<class T>
struct dijkstra {
    struct edge{
        int to;
        T cost;
        int K;
    };
    vector<T> d;
    vector<vector<edge>> G;
    T init_v;
    int N;

    dijkstra(int n, T init_v) : N(n), init_v(init_v) {init(n);}

    void init(int n) {
        G.resize(n);
        d.resize(n);
    }

    void add_edge(int s, int t, T cost, int k) {
        edge e;
        e.to = t; e.cost = cost; e.K = k;
        G[s].push_back(e);
    }

    void run(int s) {
        rep(i,N) d[i] = init_v;
        priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
        d[s] = 0;
        q.push(pair<T,int>(0,s));
        while (!q.empty()) {
            pair<T,int> e = q.top(); q.pop();
            int v = e.second;
            if (d[v] < e.first) continue;
            for (auto e: G[v]) {
                if (chmin(d[e.to], (d[v] + e.K - 1) / e.K * e.K + e.cost)) {
                    q.push(pair<T,int>(d[e.to],e.to));
                }
            }
        }
    }
};

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    x--; y--;
    dijkstra<ll> dj(n, inf_l);
    rep(i,m) {
        int a, b, t, k;
        cin >> a >> b >> t >> k;
        a--; b--;
        dj.add_edge(a, b, t, k);
        dj.add_edge(b, a, t, k);
    }
    dj.run(x);
    if (dj.d[y] == inf_l) cout << -1 << endl;
    else cout << dj.d[y] << endl;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
int head[maxn],tot;
struct Edge{
	int next,to,tim,val;
}e[maxn];
void add_edge(int x,int y,int z,int w){
	e[++tot] = (Edge){head[x],y,z,w},head[x] = tot;

}
int n,m,x,y;
struct Sta{
	long long tim;
	int u;
	bool operator <(Sta b)const{return tim>b.tim;}
};
int vis[maxn];
long long dis[maxn];
std :: priority_queue <Sta> q;
void Dijkstra(){
	memset(dis,0x3f,sizeof(dis));
	q.push((Sta){0,x}),dis[x] = 0;
	while(!q.empty()){
		Sta u = q.top();
		q.pop();
		if(vis[u.u])continue;
		vis[u.u] = 1;
//		cout << u.u << ' ' << head[1] << endl;
		for(int i=head[u.u],v;v=e[i].to,i;i=e[i].next){
			long long to = dis[u.u]?((dis[u.u]-1)/e[i].tim+1)*e[i].tim+e[i].val:e[i].val;
//			cout << u.u << ' ' << v<< ' ' << to  << endl;
			if(to < dis[v] && !vis[v])dis[v] = to,q.push((Sta){to,v});
		}
	}
	if(vis[y])printf("%lld",dis[y]);
	else puts("-1");
}
int main(){
	scanf("%d %d %d %d",&n,&m,&x,&y);
	for(int i=1,a,b,c,d;i<=m;++i){
		scanf("%d %d %d %d",&a,&b,&c,&d);
		add_edge(a,b,d,c),add_edge(b,a,d,c);
	}
//	for(int i=1;i<=n;++i)cout << head[i] << ' ';
//	cout<< '\n';
	Dijkstra();
	return 0;
}


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

struct level{
  int type; //-1 = left, 1 = right
  int id;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N;
  cin >> N;
  vector<level> e(2 * N + 1);
  vector<bool> dp(2 * N + 1);
  dp[0] = true;
  for(int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    if(a != -1){
      if(e[a].type != 0){
        cout << "No" <<endl;
        return 0;
      }
      e[a].type = -1;
      e[a].id = i+1;
    }
    if(b != -1){
      if(e[b].type != 0){
        cout << "No" <<endl;
        return 0;
      }
      e[b].type = 1;
      e[b].id = i+1;
    }
  }
  //*
  for(int i = 0; i <= 2 * N; i++){
    //cout << i << " " <<  e[i].id << " " << e[i].type << endl;
  }
  //*/
  for(int i = 0; i <= 2 * N; i+=2){
    if(dp[i]){
      for(int j = i + 2; j <= 2 * N; j+=2){
        //cout << "j " << j <<endl;
        bool bad = false;
        int length = (j - i) / 2;
        for(int t = i+1; t <= i + length; t++){
          //cout << "t " << t <<endl;
          if(e[t].type == 1 || e[t+length].type == -1){
            //cout << "bad due to type" <<endl;
            bad = true;
            break;
          }
          if(e[t].id != 0 && e[t+length].id != 0){
            if(e[t+length].id != e[t].id){
              //cout << "bad due to id" <<endl;
              bad = true;
              break;
            }
          }
        }
        if(!bad) dp[j] = true;
      }
    }
  }
  /*
  for(int i = 0; i <= 2 * N + 1; i++){
    cout << dp[i] << " ";
  }
  cout <<endl;
  //*/
  if(dp[2*N]) cout << "Yes" <<endl;
  else cout << "No" <<endl;
}

#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=205;
int n,a[MAX_N],b[MAX_N];
int belong[MAX_N],w[MAX_N];
bool dp[MAX_N][MAX_N];
bool Check()
{
	ms(belong,-1);
	repi(i,1,n){
		if(a[i]!=-1){
			if(belong[a[i]]!=-1) return false;
			belong[a[i]]=0;
		}
		if(b[i]!=-1){
			if(belong[b[i]]!=-1) return false;
			belong[b[i]]=1;
		}
		if(a[i]!=-1&&b[i]!=-1){
			if(a[i]>b[i]) return false;
			w[a[i]]=w[b[i]]=b[i]-a[i];
		}
	}
	repi(len,1,n)for(int st=1;st+2*len-1<=2*n;st+=2){
		int ed=st+2*len-1;
		dp[st][ed]=true;
		repi(i,st,st+len-1){
			if(belong[i]==1) dp[st][ed]=false;
			if(w[i]&&w[i]!=len) dp[st][ed]=false;
			if(!w[i]&&belong[i]==0&&belong[i+len]==1) dp[st][ed]=false;
		}
		repi(i,st+len,ed){
			if(belong[i]==0) dp[st][ed]=false;
			if(w[i]&&w[i]!=len) dp[st][ed]=false;
		}
		for(int i=st+1;i<ed;i+=2)if(dp[st][i]&&dp[i+1][ed]) dp[st][ed]=true;
	}
	return dp[1][2*n];
}
int main()
{
	n=ri();
	repi(i,1,n) a[i]=ri(),b[i]=ri();
	puts(Check()?"Yes":"No");
    return 0;
}


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

int main() {
	long long t,n,i;
	cin >> t;
	while(t--){
		cin >> n;
		if(n%4==0){
			cout << "Even" << endl;
		}else if(n%2==0){
			cout << "Same" << endl;
		}else{
			cout << "Odd" << endl;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (intt i = 0; i < (intt)(n); i++)
using intt = int64_t;
intt sum(const long &a, const long &b) { return (a + b) * (b - a + 1) / 2; }
vector<char> alphabet={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
bool is_squere(intt N) {
    intt r = (intt)floor(sqrt((long double)N));  // 切り捨てした平方根
    return (r * r) == N;
}
int main() {
  intt n;
  cin>>n;
  rep(i,n){
    intt x;
    cin>>x;
    if(x%2!=0){
      cout<<"Odd"<<endl;
    }
    else if(is_squere(x)||x%4==0){
      cout<<"Even"<<endl;;
    }
    else{
      cout<<"Same"<<endl;
    }
  }
}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define vi vector<int>
#define vll vector<long long>
#define vb vector<bool>
#define vs vector<string>
#define all(x) x.begin() , x.end()
#define pb push_back
#define eb emplace_back
#define chmax(x,y) (x) = max((x) , (y))
#define chmin(x,y) (x) = min((x) , (y))
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

//const int MOD = int(1e9) + 7;
//const int MOD = 998244353;
//const ll MOD = ll(1e9) + 7;
const ll MOD = 998244353;
const ld PI = 3.1415926535897932384626;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
const int MX = 220000;

ll modpow (ll x , ll p) {
    ll ret = 1;
    while (p) {
        if (p % 2 == 1) {
            ret *= x;
            ret %= MOD;
        }
        x *= x;
        x %= MOD;
        p /= 2;
    }
    return ret;
}

vll fact(MX);
vll factinv(MX);
void init_fact () {
    fact[0] = 1;
    for (int i = 1; i < MX; i++) {
        fact[i] = 1LL * i * fact[i - 1] % MOD;
    }
    for (int i = 0; i < MX; i++) {
        factinv[i] = modpow(fact[i] , MOD - 2);
    }
}

bool is_prime (int x) {
    if (x == 2 || x == 3 || x == 5 || x == 7) {
        return true;
    }
    for (ll i = 2; i*i <= x; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

vb prime_table(MX , true);
void init_prime() {
    for (int i = 2; i < MX; i++) {
        for (int j = i + i; j < MX; j += i) {
            prime_table[j] = false;
        }
    }
    return;
}

map<ll, int> factrization(ll x) {
    map<ll, int> ret;
    for (int i = 2; i*i <= x; i++) {
        while (x % i == 0) {
            ret[i]++;
            x /= i;
        }
    }
    if (x > 1) ret[x]++;
    return ret;
}

ll moddiv (ll a , ll b) { return a * modpow(b , MOD - 2) % MOD; }
ll modsub (ll a , ll b) { if (a >= b) return (a - b) % MOD; else return (MOD - a + b); }
ll nCk (ll n , ll k) { return ((fact[n] * factinv[k] % MOD) * factinv[n - k] % MOD); }
ll nHk (ll n , ll k) { return nCk(n - 1 + k , k); } // 仕切り- 1 + boll を並べる組み合わせ
ll gcd (ll a , ll b) { if (a < b) swap(a , b); if (a % b == 0) return b; else return gcd(b , a % b); }
ll lcm (ll a , ll b) { return a / gcd(a , b) * b; }
ll lin() { ll x; scanf("%lld" , &x); return x; }
int in() { int x; scanf("%d" , &x); return x; }
bool is_palindrome (string s) { string t = s; reverse(all(t)); return (s == t); }
void io_setup() { cout << fixed << setprecision(20); }

void solve () {
    int n , m;
    cin >> n >> m;
    map<int , int> mp1 , mp2;
    rep(i,n) {
        int a = in();
        mp1[a]++;
    }
    rep(i,m) {
        int a = in();
        mp2[a]++;
    }
    vi ans;
    for (auto i : mp1) {
        if (mp2[i.fi] == 0) ans.pb(i.fi);
    }
    for (auto i : mp2) {
        if (mp1[i.fi] == 0) ans.pb(i.fi);
    }
    sort(all(ans));
    int SZ = ans.size();
    rep(i,SZ) {
        cout << ans[i];
        if (i != SZ - 1) cout << " ";
        else cout << endl;
    }
    return;
}

int main() {
    io_setup();
    //init_fact();
    //init_prime();
    solve();
    return 0;
}

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

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

	int n, w; cin >> n >> w;
	cout << n / w << "\n";

	return 0;
}


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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;
struct edge {
    int to, cost, id;
};
const double EPS = 1E-09;
const ll MOD = 1E+09 + 7; // =998244353;
const ll INF = 1E18;
const int MAX_N = 1E+05;

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

int N;

string s;

bool fox(string& t, char c);

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

    cin >> N >> s;

    string t;
    int ans = N;
    for (int i = 0; i < N; i++) {
        if (fox(t, s[i]))
            ans -= 3;
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    //cout << "s = " << s << "\n";

    cout << ans << "\n";

    return 0;
}

bool fox(string& t, char c)
{
    t += c;
    if (t.size() < 3)
        return false;
    int n = t.size();
    if (t[n - 3] == 'f' && t[n - 2] == 'o' && t[n - 1] == 'x') {
        t.erase(t.begin() + n - 3, t.end());
        return true;
    }
    return false;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPE(i,l,n) for(ll i=l;i<=ll(n);i++)
#define FORA(i,I) for(const auto& i:I)
#define ALL(v) v.begin(),v.end()
#define P(str) cout << str << endl
#define VLL vector<ll>
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
constexpr int64_t INF = 1e18;

void c(VLL& v){
    REP(i, v.size()){
        v[i] -= v[i] * 2;
    }
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll mi = min(a, b);
    ll ma = max(a, b);
    bool f = true;
    if(a < b) f = false;
    VLL vmi(mi), vma(ma);
    ll summa = 0;
    REP(i, ma){
        vma[i] = i + 1;
        summa += vma[i];
    }
    ll summi = 0;

    REP(i, mi){
        vmi[i] = i + 1;
        summi += vmi[i];
    }
    // cout << summa << " " << summi << endl;
    vmi[mi - 1] += (summa - summi);
    if(f) c(vmi);
    else c(vma);
    FORA(i, vmi) cout << i << " ";
    REP(i, vma.size()){
        cout << vma[i];
        if(i == vma.size() - 1) cout << endl;
        else cout << " ";
    }
}


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

int main(){
    int N,K;cin >> N >> K;
    vector<vector<int> >A(N,vector<int>(N));
    for (int i=0;i<N;i++){
        for (int j=0;j<N;j++){
            cin >> A[i][j];
        }
    }
    int r=1000000008;
    int l=-1;
    while (abs(r-l)>1){
        int m=(r+l)/2;
        vector<vector<int> >high_low(N,vector<int>(N,0));
        for (int i=0;i<N;i++){
            for (int j=0;j<N;j++){
                if (A[i][j]<=m) high_low[i][j]=1;
            }
        }
        vector<vector<int> > dp(N,vector<int>(N));
        for (int i=0;i<N;i++){
            for (int j=0;j<N;j++){
                dp[i][j]+=high_low[i][j];
                if (i-1>=0) dp[i][j]+=dp[i-1][j];
                if (j-1>=0) dp[i][j]+=dp[i][j-1];
                if (i-1>=0 && j-1>=0) dp[i][j]-=dp[i-1][j-1];
            }
        }
        int count=0;
        int centers=0;
        for (int i=K-1;i<N;i++){
            for (int j=K-1;j<N;j++){
                count=0;
                count+=dp[i][j];
                if (i-K>=0) count-=dp[i-K][j];
                if (j-K>=0) count-=dp[i][j-K];
                if (i-K>=0 && j-K>=0) count+=dp[i-K][j-K];
                if (K%2==0){
                    if (K*K/2<=count) centers++;
                }else{
                    if (K*K/2+1<=count) centers++;
                }
            }
        }
        if (centers>=1) r=m;
        else l=m;
    }
    cout << r << endl;
    return 0;
}

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

#define fst ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define tc int tt; cin >> tt; while(tt--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N = 2e5 + 5, mod = 1e9 + 7, INF = 1e16 + 6;

int power(int a, int n) {
	int res = 1;
	while(n) {
		if(n&1) res = (res*a)%mod;
		n >>= 1;
		a = (a*a)%mod;
	}
	return res;
}

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

	int n, m;
	cin >> n >> m;
	int mat[n][m];
	int mn = 1e18;
	for(int i=0;i<n;++i) {
		for(int j=0;j<m;++j) cin >> mat[i][j], mn = min(mn, mat[i][j]);
	}

	int ans = 0;
	for(int i=0;i<n;++i) {
		for(int j=0;j<m;++j) ans += (mat[i][j] - mn);
	}
cout << ans;
}


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

#define int unsigned long long
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; }

int memo[200][20];
int l;

int dp(int i, int j){
	if(i == l-1){
		return j == 11 ? 1 : 0;
	}

	if(memo[i][j] != -1) return memo[i][j];

	int ans = dp(i+1, j);
	if(j < 11){
		ans += dp(i+1, j+1);
	}
	return memo[i][j] = ans;
}

signed main(){
	cin >> l;
	memset(memo, -1, sizeof(memo));
	cout << dp(0, 0) << endl;

	return 0;
}

#include <bits/stdc++.h>
//abcdefghijklmnopqrstuvwxyz
/*
Народ все кто играет в CodeForces вступайте в нашу
Организацию "Megumin's Fan Club" там был Я, Я все еще там
Хорошая организация классная правда сейчас загнивает))))
*/

#define F first
#define S second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define in(x) insert(x)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define did_you_calis_enough ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define int long long

using namespace std;

const int INF =  2147483647;
const int  N = 2e5 + 667;
const int mod = 1e9 + 7;
const int BL = 450;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double PI = acos(-1.0);

int pw(int a, int n) {
	int res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
	}
	return res;
}

int lg(int b, int n, int r = 0){
	return ((n <= 1)? r : lg(b, n/b,++r));
}// log N with base of B

int32_t main() {
	did_you_calis_enough
	int n;
	cin >> n;
	int a = 1, b = 1, cur = n-12;
	for(int i = n-1;i >= 12;i--){
		a *= i;
		b *= cur--;
		int g = __gcd(a, b);
		a /= g;
		b /= g;
	}
	cout << a;
	return 0;
}

//Coded by LoliThief


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

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

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

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

#define en "\n"

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

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

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

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

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

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

void Main(){
    int N,M,K; cin >> N >> M >> K;
    if(N==1 || M==1){
        cout << mint(K).pow(N*M).x << en;
        return;
    }

    vector<mint> f(K+1,0), g(K+1,0);
    FOR(i,1,K+1){
        f[i] = mint(i).pow(N) * mint(K-i+1).pow(M);
        g[i] = mint(i-1).pow(N) * mint(K-i+1).pow(M);
    }

    mint ans(0);
    REP(i,K) ans += f[i+1] - g[i+1];
    cout << ans.x << en;
    return;
}

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

/* bimillahir rahmanir rahim...
 * AUTHOR
 * mubin_akib */
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

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

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

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

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

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

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

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

const int mod = 1e9 + 7;
const char nl = '\n';

void solve() {
    int n;
    cin >> n;
    vi v(2000);
    F0R(i, n){
        int x;
        cin >> x;
        v[x]++;
    }
    int a = 0, ans = 0;
    FOR(i, 2, 2000){
        int k = 0;
        for(int j = i; j < 2000; j += i){
            k += v[j];
        }
        if(ans < k){
            ans = k;
            a = i;
        }
    }
    cout << a << nl;
}
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


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

int main()
{
  ll n; cin >> n;
  map<ll, ll> map;
  rep(i, n) {
    ll x; cin >> x;
    map[x]++;
  }
  ll ans = n*(n-1)/2;
  for (auto p : map) {
    auto num = p.second;
    ans -= num * (num-1) / 2;
  }
  cout << ans << endl;
}

/*
	You Can Do This!
	From Madeline
	To You
	https://www.youtube.com/watch?v=vBUhgkMD5kc
*/
#include <bits/stdc++.h>

#define inf ll (1e18)
#define ninf ll (-1e18)
#define mod ll (1e9 + 7)
#define first F
#define second S
#define fast ios::sync_with_stdio (0); cin.tie (0);

using namespace std;
using ll = long long;
using pi = pair < ll , ll >;

void solution (ll tc = 0) {
	ll n;
	cin >> n;

	map < ll , ll > m;
	vector < ll > v (n);

	for (ll i = 0; i < n; i++) {
		cin >> v[i];
		m[v[i]]++;
	}

	ll current = n - 1;
	ll res = 0;

	for (ll i = 0; i < n; i++) {
		ll x = m[v[i]]--;
		x--;

		res += current - x;
		current--;
	}

	cout << res << '\n';
}

int main () {
	fast

	solution ();
}


#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using ll = long long;
using lint = long long;
typedef vector<long long> vint;
typedef pair<long long, long long> pint;
#define INF INT32_MAX / 2
#define INF64 INT64_MAX / 2
#define EPS 0.001
#define EPS14  1.0E-14
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define c(n) cout<<n<<endl;
#define cf(n) cout<<fixed<<setprecision(15)<<n<<endl;
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<class T>inline T sum(T n){return n*(n+1)/2;}
map<ll,ll> prime_fac(ll A) {map<ll,ll>mp;for(ll i=2;i*i<=A;i++){while(A%i== 0){mp[i]++;A/=i;}}if(A!=1){mp[A]=1;}return mp;}
bool is_prime(ll N){if(N<=1)return false;for(ll i=2;i*i<=N;i++){if(N%i==0) return false;}return true;}
template<class T>inline T myceil(T a,T b){return (a+(b-1))/b;}
bool is_product_overflow(long long a,long long b) {long prod=a*b;return (prod/b!=a);}

void solve(long long N, std::string S){
    ll ans = 0;
    REP (i, N) {
        vector<ll> mp(10000, 0);
        for (int j = i; j < N; j++) {
            mp[S[j]]++;
            if (mp['A'] == mp['T'] && mp['G'] == mp['C']) ans++;
        }
    }
    c(ans)
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=55;
int n,vis;
int a[maxn],prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
bool s[maxn][15];
inline int read(){
	int ret=0,f=1;	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while(isdigit(ch)){ret=ret*10+ch-'0';ch=getchar();}
	return ret*f;
}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
signed main(){
	n=read();
	for(int k=1;k<=n;k++)   a[k]=read();
	int ans=0;
	for(int k=0;k<(1<<15);k++){
		int sum=1;
		vis=0;
		for(int j=0;j<15;j++){
			int p=1ll<<j,x=prime[j];
			if(!(k&p))  continue;
			sum*=x;
			for(int i=1;i<=n;i++)
			if(gcd(x,a[i])>1) vis|=1ll<<i-1;
		}
		if(vis==(1ll<<n)-1){
			if(!ans)    ans=sum;			else    	ans=min(ans,sum);
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
10
2 5 7 12 27 8 18 33 13 32
*/


#include <bits/stdc++.h>
using namespace std;
using ll = int64_t; using Vll =vector<ll>; using VVll =vector<vector<ll>>;
template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>;
#define INF 9223372036854775807LL/2
void Z(ll i=-1){ if(i==-1)cout<<"Test"<<endl; else cout<<"Test"<<i<<endl; }
template <class T> void VVcout(VVec<T> A){ for(auto Vi:A) { for(auto i:Vi)cout<<i<<' '; cout<<endl;}}
template <class T> void Vcout(Vec<T> A){ for(auto i:A) cout<<i<<' '; cout<<endl;}
template <class T> void chmax(T &x,T y){if(x<y) x=y;} template <class T> void chmin(T &x,T y){if(x==-1 || x>y) x=y;}
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(si, i,n) for(ll i=si;i<n;i++)

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<a+b+c-min(a,min(b,c))<<endl;
}

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>
#include <ctype.h>

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = (1LL<<60)-1;

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

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

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

#define MAX (ll)3e6+1    //nCrのnの最大値+1

ll fac[MAX], inv[MAX], finv[MAX];

void COMinit(ll mod) {
    fac[0] = 1, finv[0] = 1;
    fac[1] = 1, inv[1] = 1, finv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - (inv[mod % i] * (mod/i) % mod) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(ll n, ll k, ll mod) {
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * finv[k] % mod * finv[n-k] % mod;
}

ll P(ll n, ll r, ll mod) {
    if (n < r)
        return 0;
    if (n < 0 || r < 0)
        return 0;
    return fac[n] * finv[n-r] % mod;
}

//コーナーケースに気をつけろ！
int main() {
    ll n, m, k; cin >> n >> m >> k;
    ll mod = 1e9+7;
    COMinit(mod);
    if (n <= m+k)
        cout << (COM(n+m, m, mod) + mod - COM(n+m, m+k+1, mod)) % mod << endl;
    else
        cout << 0 << endl;
    return 0;
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;


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

ll gcd(ll m,ll n){
    if(n==0) return m;
    return gcd(n,m%n);
}

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

    int ans;

    rep(i,1,b){
        int tmp = 0;
        if(b / i > 1) tmp = b / i;
        else break;

        if(i * (tmp - 1) >= a) ans = i;
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,x,y;
    cin>>a>>b;
    int d=b-a;
    while(true){
        x=a/d;
        if(a%d!=0) x++;
        y=b/d;
        if(x<y){
            cout<<d;
            break;
        }
        d--;
    }
}


#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;
typedef pair<int,int> pi;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

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

  if(b==0){
    cout<<c/2+max(ll(0),ll((c-1)/2))+1<<endl;
  }
  else if(b>0){
     if(-b+((c-1)/2)<b-(c/2)){
      cout<<2*((c-1)/2)+(c/2)+max(ll(((c-2)/2)),ll(0))+2;
    }

    else {
      cout<<2*b+((c-1)/2)+max(ll(0),ll(((c-2)/2)))+1;
    }
  }
  else if(b<0){
    if(b+(c-2)/2<-b-(c-1)/2)cout<<2*((c-1)/2)+(c/2)+max(ll(((c-2)/2)),ll(0))+2<<endl;
    else cout<< -2*b+(c-1)/2+c/2+1 <<endl;
  }
}

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

pair<long, long> extract(const long&B, const long&C) {
  const auto n = C/2;
  if (C%2) {
    return {-B-n, -B+n};
  } else {
    if (!C) return {B,B};
    return {B-n, B+n-1};
  }
}

int main() {
  long B, C;
  cin >> B >> C;
  const auto [a,b] = extract(B,C);
  const auto [c,d] = extract(B,C-1);
  cout << (b-a+1) + (d-c+1) - max(0l, min(b,d)-max(a,c)+1) << endl;
  return 0;
}


#define _USE_MATH_DEFINES
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cassert>
#include <numeric>
#include <unordered_map>
#include <queue>
#include <math.h>
#include <climits>
#include <set>
#include <map>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
//template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;

#define FOR(i, a, b) for(ll i=(a); i<(b);i++)
#define REP(i, n) for(ll i=0; i<(n);i++)
#define ROF(i, a, b) for(ll i=(b-1); i>=(a);i--)
#define PER(i, n) for(ll i=n-1; i>=0;i--)
#define REPREP(i,j,a,b) for(ll i=0;i<a;i++)for(ll j=0;j<b;j++)
#define VV(type) vector< vector<type> >
#define VV2(type,n,m,val) vector< vector<type> > val;val.resize(n);for(ll i;i<n;i++)val[i].resize(m)
#define vec(type) vector<type>
#define VEC(type,n,val) vector<type> val;val.resize(n)
#define VL vector<ll>
#define VVL vector< vector<ll> >
#define SZ size()
#define all(i) begin(i),end(i)
#define SORT(i) sort(all(i))
#define BITI(i) (1<<i)
#define BITSET(x,i) x | (1<<i)
#define BITCUT(x,i) x & ~(1<<i)
#define EXISTBIT(x,i) ((x>>i) & 1 != 0)
#define ALLBIT(n) (1<<n-1)

class UndirectedGraph {
public:
  struct edge { ll to,cost; };  // 行先,容量,逆容量,コスト

  UndirectedGraph(ll n) {
    edges.resize(n);
  }
  void addEdge(ll from, ll to, ll cost) {
    edge eF = { to,cost };
    edges[from].push_back(eF);
    edge eT = { from,cost };
    edges[to].push_back(eT);
  }

  void FindConnect(ll v, vector<bool>& out) {
    out.assign(edges.size(), false);
    vector<ll> stack;
    stack.push_back(v);
    out[v] = true;
    while (!stack.empty()) {
      v = stack.back(); stack.pop_back();
      for (int i = 0; i < edges[v].size(); i++) {
        ll t = edges[v][i].to;
        if (!out[t]) {
          out[t] = true;
          stack.push_back(t);
        }
      }
    }
  }
  vector<vector<edge>> edges;
};

int main() {
  ll n, m;
  cin >> n >> m;
  VL a(m), b(m), c(m);
  UndirectedGraph g(n);

  REP(i, m) {
    char cc;
    cin >> a[i] >> b[i] >> cc;
    a[i]--; b[i]--;
    c[i] = cc - 'a';
    g.addEdge(a[i], b[i], c[i]);
  }

  queue<tuple<ll, ll, ll>> que;
  vector<vector<bool>> used(n);
  REP(i, n) {
    used[i].assign(n, false);
  }
  que.push({ 0,0,n - 1 });
  used[0][n - 1] = true;
  used[n - 1][0] = true;

  ll find = -1;
  while (!que.empty()) {
    auto [dist, l, r] = que.front();
    que.pop();
    if (find != -1 && find < dist) {
      cout << find * 2 + 1;
      return 0;
    }
    if (l == r) {
      cout << dist * 2;
      return 0;
    }
    REP(i, g.edges[l].size()) {
      REP(j, g.edges[r].size()) {
        if (g.edges[l][i].cost == g.edges[r][j].cost) {
          if (g.edges[l][i].to == r && g.edges[r][j].to == l) {
            find = dist;
            continue;
          }
          if (used[g.edges[l][i].to][g.edges[r][j].to])
            continue;
          que.push({ dist + 1,g.edges[l][i].to ,g.edges[r][j].to });
          used[g.edges[l][i].to][g.edges[r][j].to] = true;
          used[g.edges[r][j].to][g.edges[l][i].to] = true;
        }
      }
    }
  }
  if (find != -1) {
    cout << find * 2 + 1;
    return 0;
  }
  cout << -1;
}

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

//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define pb push_back
#define fi first
#define se second
#define ll long long
#define tp top()
#define fr front()
#define vi vector<int>
#define sz size()
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define mem(a,  b) memset(a,  (b),  sizeof(a))
#define clr(a) memset(a,  0,  sizeof(a))
#define sqr(x) ( (x) * (x) )
#define all(v) v.begin(),  v.end()

typedef pair<int, int> pii;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;

void base(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

void solve(){
//	rep(i,1,40){
//		cout<<i<<" -> "<<8*i<<"\n";
//	}
	string s; cin>>s;
	char ch[20]={0};
	rep(i,0,s.sz) ch[s[i]-'0']++;
	bool found = 0;
	rep(i,0,10) {
		if (ch[i]==0) continue;
		ch[i]--;
		if (s.sz == 1) {
			if (i % 8 == 0) found = 1;
			continue;
		}
		rep(j,0,10){
			if (ch[j]==0) continue;
			ch[j]--;
			int res = i*10 + j;
			bool hasodd=0, haseven=0;

			rep(k,0,10){
				if (k&1) {
					if (ch[k]>0) hasodd=1;
				} else {
					if (ch[k]>0) haseven=1;
				}
			}
			if (s.sz == 2) haseven = 1;
			if (haseven && (res % 8 == 0)) found = 1;
			if (hasodd && ((res+4) % 8 == 0)) found = 1;
			ch[j]++;
		}
		ch[i]++;
	}

	if (found) cout<<"Yes\n";
	else cout<<"No\n";
}

int main()
{
	base();
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define REPR(i,n) for (ll i = (n)-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = (m); i < (n); ++i)
#define FORR(i,m,n) for (ll i = (n)-1; i >= (m); --i)
#define FORE(x,xs) for (const auto& x : (xs))
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, (y))
#define CHMAX(x,y) x = max(x, (y))
#define BIT(x,i) (((x) >> (i)) & 1)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

const int MAX = 2020;

int H, W;
string A[MAX];
int steps[MAX][MAX];

vii teles[30];
bool used[30];

int solve() {
    int gx = -1, gy = -1, sx = -1, sy = -1;
    REP (h, H) REP (w, W) {
        steps[h][w] = -1;
        if (A[h][w] == 'S') {
            sx = w, sy = h;
            steps[h][w] = 0;
        }
        if (A[h][w] == 'G') gx = w, gy = h;
        if ('a' <= A[h][w] && A[h][w] <= 'z') teles[A[h][w]-'a'].push_back(make_pair(w, h));
    }

    queue<ii> q;
    q.push(ii(sx, sy));
    while (!q.empty()) {
        int x, y; tie(x, y) = q.front();
        q.pop();
        int next = steps[y][x] + 1;

        if (x > 0 && steps[y][x-1] < 0 && A[y][x-1] != '#') {
            steps[y][x-1] = next;
            q.push(ii(x-1, y));
        }
        if (x < W-1 && steps[y][x+1] < 0 && A[y][x+1] != '#') {
            steps[y][x+1] = next;
            q.push(ii(x+1, y));
        }
        if (y > 0 && steps[y-1][x] < 0 && A[y-1][x] != '#') {
            steps[y-1][x] = next;
            q.push(ii(x, y-1));
        }
        if (y < H-1 && steps[y+1][x] < 0 && A[y+1][x] != '#') {
            steps[y+1][x] = next;
            q.push(ii(x, y+1));
        }

        if ('a' <= A[y][x] && A[y][x] <= 'z') {
            int k = A[y][x]-'a';
            if (!used[k]) {
                used[k] = 1;
                FORE (xy, teles[k]) {
                    int x_, y_; tie(x_, y_) = xy;
                    if ((x_ != x || y_ != y) && steps[y_][x_] < 0) {
                        steps[y_][x_] = next;
                        q.push(ii(x_, y_));
                    }
                }
            }
        }
    }

    return steps[gy][gx];
}

int main() {
    cout << fixed << setprecision(15);
    cin >> H >> W;
    REP (h, H) cin >> A[h];
    cout << solve() << endl;
}

#include <vector>
#include <queue>
#include <functional>
#include <utility>

using namespace std;

//  E[i]: vertexes which can be reased from i
//  W[i]: their weight
template<class T>
vector<T> dijkstra(vector<vector<int>> E, vector<vector<T>> W, int s, T inf)
{
    int n = (int)E.size();

    vector<T> D(n, inf);
    typedef pair<T,int> P;
    priority_queue<P,vector<P>,greater<P>> Q;

    D[s] = T();
    Q.push(make_pair(D[s], s));

    while (!Q.empty())
    {
        T d = Q.top().first;
        int p = Q.top().second;
        Q.pop();
        if (d > D[p])
            continue;
        for (int i=0; i<(int)E[p].size(); i++)
        {
            int t = E[p][i];
            if (d+W[p][i] < D[t])
                D[t] = d+W[p][i],
                Q.push(make_pair(D[t], t));
        }
    }
    return D;
}

#include <iostream>

int main()
{
    int H, W;
    cin>>H>>W;
    vector<string> a(H);
    for (string &t: a)
        cin>>t;

    vector<vector<int>> E(W*H+26), We(W*H+26);
    int S, G;
    int dx[] = {1, -1, 0, 0};
    int dy[] = {0, 0, 1, -1};
    for (int y=0; y<H; y++)
    for (int x=0; x<W; x++)
        if (a[y][x]!='#')
        {
            if (a[y][x]=='S')
                S = y*W+x;
            if (a[y][x]=='G')
                G = y*W+x;

            for (int d=0; d<4; d++)
            {
                int tx = x+dx[d];
                int ty = y+dy[d];
                if (0<=tx && tx<W && 0<=ty && ty<H)
                {
                    E[y*W+x].push_back(ty*W+tx);
                    We[y*W+x].push_back(1);
                }
            }

            if ('a'<=a[y][x] && a[y][x]<='z')
            {
                E[y*W+x].push_back(W*H+a[y][x]-'a');
                We[y*W+x].push_back(1);
                E[W*H+a[y][x]-'a'].push_back(y*W+x);
                We[W*H+a[y][x]-'a'].push_back(0);
            }
        }

    int ans = dijkstra(E, We, S, W*H)[G];
    cout<<(ans<W*H ? ans : -1)<<endl;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vvi field(n, vi(n));
    rep(i,n)rep(j,n) cin >> field[i][j];
    vi num(n-1);
    rep(i,n-1){
        num[i] = i+1;
    }

    // for (auto ele : num){
    //     printf("%d ",ele);
    // }
    // cout << endl;

    int ans = 0;
    do {
        ll sum = field[0][num[0]];
        int pre = num[0];
        rep(i,n-1){
            sum += field[pre][num[i]];
            pre = num[i];
        }
        sum += field[num[n-2]][0];
        if (sum == k) ans++;
    } while(next_permutation(num.begin(), num.end()));

    cout << ans << endl;
}

#include <iostream>
#include <string>
#define ll long long
using namespace std;
const int N = 2e5+10;
int cnt[N][26];
int main() {
	string s; cin >> s;
	int n = s.size();
	ll ans = 0;
	for(int i = n - 1; i >= 0; --i) {
		for(int x = 0; x < 26; ++x) {
			cnt[i][x] = cnt[i+1][x];
		}
		++cnt[i][s[i] - 'a'];
	}
	int prev = n;
	for(int i = n - 1; i >= 0; --i) {
		int j = i;
		while(j >= 0 && s[i] == s[j]) --j; ++j;
		if(i - j + 1 >= 2) {
			for(int x = i; x < prev; ++x) {
				if(s[i] != s[x]) ++ans;
			}
			if(prev < n && s[prev] != s[i]) {
				ans += n - prev;
			}
			prev = j;
		}
		i = j;
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define ll long long
#define lll long long
#define mp make_pair
#define pb push_back
#define inf 1000000001
#define vll vector <ll>

lll p = 1000000007;

using namespace std;

lll sq(lll i){
return i*i;
}

lll fact(ll n){
ll ans=1;
for(ll i=1; i<=n;i++)ans=(ans*i)%p;
return ans;

   }

unsigned long long power(unsigned long long x, ll y)
{
    unsigned long long res = 1; // Initialize result

    x = x % p; // Update x if it is more than p

    while (y > 0)
    {

        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}

lll modInverse(unsigned lll n, unsigned lll p)
{ return power(n, p - 2);
}

lll nCrModPFermat(unsigned lll n, unsigned lll r, lll fac[])
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

vector <ll>  sieve(ll n){
    vector <bool> prime (n+1, true);
    prime[1]=false;

    vll primes;

    for(ll i=2; i<=sqrt(n); i++){
        if(prime[i]){
            for(ll j=i*i; j<=n; j+=i)prime[j]=false;
        }
    }

    for(ll i=2; i<=n;i++)if(prime[i])primes.pb(i);
        return primes;
}

vector <ll> factors(ll n){
    //vector <ll> primes = sieve(sqrt(n));
    vector <ll> v;
    for(ll i=2; i<=sqrt(n); i++){
        if(n%i==0){v.pb(i);v.pb(n/i);}
    }
    v.pb(n);
    //if(v.size()==0)v.pb(n);

    return v;
}

//***********************GRAPH ALGORITHMS*************************************************************

void dfs(vector <ll> v[], vector<ll> &df, ll cov[], ll i){ //Also outputed resultant dfs

    df.pb(i);
    for(ll j=0; j<v[i].size(); j++){if(cov[v[i][j]]==0){cov[v[i][j]]=cov[i]; dfs(v, df, cov, v[i][j]);}}
}

void djikstra (vector <pair<ll, ll>> v[], ll d[], ll par[], ll s, ll n){ //n^2 || d returns shortest dist // s for start

    for(ll i=0; i<n;i++){d[i]=inf; par[i]=-1;}
    par[s]=s; d[s]=0;
    bool cov[n]; for(ll i=0; i<n;i++)cov[i]=0;

    ll u=-1;

    for(int j=0; j<n;j++)
    {
        u=-1;
        for(ll i=0; i<n;i++){
        if(!cov[i] && (d[i]<d[u] || u==-1))u=i;
    }

    cov[u]=1;

    for(ll i=0; i<v[u].size(); i++){
        if(d[v[u][i].first] > d[u]+v[u][i].second){d[v[u][i].first]=d[u]+v[u][i].second; /*cout << d[u] << " " <<v[u][i].second <<"\n"; */par[v[u][i].first]=u;}
    }

}

}

ll bfs(vector<ll> v[], ll par[], ll root, ll finish, ll n) //par returns parent array
{
    ll cov[n];
    for(ll i=0; i<n;i++)cov[i]=0;
    queue<ll> q;
    cov[root]=0;
    q.push(root);
    while(!q.empty())
    {
       for(ll i=0;i<v[q.front()].size();i++)
       {
           if(cov[v[q.front()][i]]==0)
           {
               q.push(v[q.front()][i]);
               cov[v[q.front()][i]]=cov[q.front()]+1;
               par[v[q.front()][i]] = q.front();
           }
           if(v[q.front()][i]==finish)return cov[v[q.front()][i]];
       }
       q.pop();
    }
    return -1;
}

ll findConnComp(vector <ll> v[], ll cov[], ll n){
    ll j=0;
    vector <ll> df;
    for(ll i=0; i<n;i++)cov[i]=0;
    for(ll i=0; i<n; i++){
        if(!cov[i]){cov[i]=++j; dfs(v, df, cov, i);}
    }
    return j;
}

//*****************CODE STARTS **************************************

ll summ(ll a[], ll n){

    bool sp[n];
    for(ll i=0; i<n;i++)sp[i]=0;
    for(ll i=1; i<n-1; i++){
            if(a[i]>a[i-1] && a[i]>a[i+1])sp[i]=1;
            if(a[i]<a[i-1] && a[i]<a[i+1])sp[i]=1;
        }
    ll cnt=0;
     for(ll i=1; i<n-1; i++){
            if(sp[i])cnt++;
     }

     return cnt;
}

int main(){

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

    ll x,y; cin >> x >> y;
    if(abs(x-y)>=3)cout << "No\n";
    else cout << "Yes\n";

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef vector<int> vi;
typedef vector<vi> vvi;
int h,w;
vvi a(2010, vi(2010));
vvi opt(2010, vi(2010));

int main(){
  cin>>h>>w;
  rep(i,h)rep(j,w) {
    char A; cin>>A;
    if(A=='+') a[i][j]=1; else a[i][j]=-1;
  }
  opt[h-1][w-1]=0;
  for(int i=h-1; i>=0; i--) {
    for(int j=w-1; j>=0; j--) {
      if((i+j)%2==0) {
        int ma = -2000;
        if(i==h-1 && j==w-1) continue;
        if(i+1<=h-1) ma = max(ma,opt[i+1][j]+a[i+1][j]);
        if(j+1<=w-1) ma = max(ma,opt[i][j+1]+a[i][j+1]);
        opt[i][j] = ma;
      } else {
        int mi = 2000;
        if(i==h-1 && j==w-1) continue;
        if(i+1<=h-1) mi = min(mi,opt[i+1][j]-a[i+1][j]);
        if(j+1<=w-1) mi = min(mi,opt[i][j+1]-a[i][j+1]);
        opt[i][j] = mi;
      }
    }
  }
  if(opt[0][0]>0) puts("Takahashi");
  else if (opt[0][0]<0) puts("Aoki");
  else puts("Draw");
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define intmax 0x7fffffff
#define halfintmax 0x3fffffff

typedef pair<int, int> pii;
typedef pair<int, char> pic;

const int N = 200009;
const int mod = 998244353;

ll n;

int main() {
    cin >> n;
    ll l = 0, r = 1.5e9;
    while(l < r) {
        ll mid = l + r + 1 >> 1;
        if(mid * (mid + 1) / 2 <= n + 1) l = mid;
        else r = mid - 1;
    }
    cout << n - l + 1;
    return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long int
#define s(x)	cin>>x
#define p(x)	cout<<x<<"\n"
#define goog(x, y)  cout<<"Case #"<<x<<": "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpi;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
typedef long double ld;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
int gcd(int a, int b) ;

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve() {
  ll n;cin>>n;
  //ll tp=1e9+1e8;
  ll tp=2*floor(sqrt(n));
  ll res;
  ll st=0;
  while(st<=tp)
  { ll m=(st+tp)/2;
    if(m*(m+1)<=2*(n+1))
    {res=m;st=m+1;}
    else
    tp=m-1;
  }
  p(n+1-res);

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    //u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

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


#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<time.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
bool flag[2510];
int t[51][51];
int p[51][51];
int dx[4];
int dy[4];
string direction = "UDLR";
string route;
string bestroute;
time_t start_time, end_time;
int nx,ny;
int mx;
int sm,maxsum;
bool is_legal_action(int nx,int ny,bool *flag){
	if(0<=nx&&nx<50&&0<=ny&&ny<50&&flag[t[nx][ny]]==0){
		return true;
	}else{
		return false;
	}
}
int legallistlength(int x,int y,bool *flag){
  	int k=0;
  	rep(i,4){
      	nx = x + dx[i];
		ny = y + dy[i];
      	if(is_legal_action(nx,ny,flag)){
          	k++;
        }
    }
    return k;
}
void dfs(int x,int y,bool *flag){
  	end_time = time(NULL);
  	if(end_time - start_time>1.95)return;
  	flag[t[x][y]]=1;
  	sm+=p[x][y];
  	//sm++;
  	rep(i,4){
		nx = x + dx[i];
		ny = y + dy[i];
		if(is_legal_action(nx,ny,flag)){
          	//cout << x <<" " <<  y <<" " << i << endl;
          	route.push_back(direction[i]);
			dfs(nx,ny,flag);
			route.pop_back();
        }
    }
    if(maxsum<sm){
          	maxsum=sm;
      		bestroute=route;
    }
  	sm-=p[x][y];
  	//sm--;
  	flag[t[x][y]]=0;
  	return;
}
/*void func(int x,int y,bool *flag,vector<char>& route){
	flag[t[x][y]]=1;
	int s=-1;
	int nxt=-1;
	rep(i,4){
		nx = x + dx[i];
		ny = y + dy[i];
		if(is_legal_action(nx,ny,flag)){
			if(s<=p[nx][ny]){
				s=p[nx][ny];
				nxt=i;
			}
          	sm=0;
          	maxsum=-1;
          	dfs(nx,ny,flag,22);
          	if(maxsum>=s){
              	s=maxsum;
              	nxt=i;
            }
          	//cout << i << " " << maxsum <<endl;

		}
      	//cout <<x<<" " << y <<direction[i]<< nxt << endl;
	}
  	flag[t[x][y]]=1;
	if(nxt==-1){
		for (auto i: route){
			cout << i;
		}
		cout << "\n";
	}else{
		route.push_back(direction[nxt]);
		func(x + dx[nxt],y + dy[nxt],flag,route);
		route.pop_back();
	}
	flag[t[x][y]]=0;
	return;
}*/
int main(){
  	start_time = time(NULL);
	int si,sj;
	scanf("%d %d",&si,&sj);
	int M=0;
	rep(i,50)rep(j,50){
		cin >> t[i][j];
		if(M<t[i][j])M=t[i][j];
	}
	M++;
	rep(i,50)rep(j,50) scanf("%d", &p[i][j]);
	rep(i,2500)flag[i]=0;
	dx[0]=-1;
  	dx[1]=1;
  	dy[2]=-1;
  	dy[3]=1;
	dfs(si,sj,flag);
  	for(auto i: bestroute){
      	cout << i;
    }
  	cout << "\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=2e18;
ll MOD=1000000007;
ll mod=998244353;

int main() {
    int n,l;
    cin >> n >> l;
    vector<int> a(n+2),b(n+2);
    rep(i,n) cin >> a[i+1];
    rep(i,n) cin >> b[i+1];
    a[0]=0;
    a[n+1]=l+1;
    b[0]=0;
    b[n+1]=l+1;
    ll ans=0;
    for (int i=1;i<=n;i++){
        int l=-1,r=n+1;
        while(r-l>1){
            int mid=(r+l)/2;
            if (mid<=i) {
                l=mid;
                continue;
            }
            if (a[mid]-(mid-i)>=b[i]) r=mid;
            else l=mid;
        }
        if (a[r]-(r-i)==b[i] && a[i]!=b[i]){
            rep(j,r-i){
                a[r-j-1]=a[r]-j-1;
                ans++;
            }
        }
    }
    for (int i=n;i>=1;i--){
        int l=0,r=n+2;
        while(r-l>1){
            int mid=(r+l)/2;
            if (mid>=i) {
                r=mid;
                continue;
            }
            if (a[mid]+(i-mid)<=b[i]) l=mid;
            else r=mid;
        }
        if (a[l]+(i-l)==b[i] && a[i]!=b[i]){
            rep(j,i-l){
                a[l+j+1]=a[l]+j+1;
                ans++;
            }
        }
    }
    bool w=true;
    rep(i,n){
        if (a[i+1]!=b[i+1]) w=false;
    }
    if (w) cout << ans << endl;
    else cout << -1 << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repit(i,C) for (auto i = (C).begin(); i != (C).end(); i++)
#define pr(a) cout << a
#define prl(a) cout << (a) << endl
#define prld(a) cout << setprecision(15)<< (a) << endl
#define allrange(a) a.begin(),a.end()

bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){
    int N = S.size();
    int dx = S[0].first-T[0].first;
    int dy = S[0].second-T[0].second;
    bool flg = true;
    reps(i,1,N){
        if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;}
    }
    return flg;
}
/*ピタゴラ三角形
    5	12	13
    8	15	17
    3	4	5
*/
vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){
    int N = S.size();
    vector<pair<int,int>> PS(N);
    auto pt0 = S[0];
    PS[0] = pt0;
    bool flg = true;
    reps(i,1,N){
        int dx = S[i].first - pt0.first;
        int dy = S[i].second - pt0.second;
        int x=dx*a-dy*b;
        int y=dx*b+dy*a;
        if(((x%c)!=0) || ((y%c)!=0)) {flg = false; break;}
        PS[i] = make_pair(x/c+pt0.first, y/c+pt0.second);
    }
    if(flg) return PS;
    else return vector<pair<int,int>>();
}

int main(){
    std::cin.tie(0); // cinとcoutの同期を解除
    std::ios::sync_with_stdio(false);
    int N;cin >> N;

    vector<pair<int,int>> S(N),T(N);
    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        S[i].first = x;S[i].second = y;
    }

    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        T[i].first = x;
        T[i].second = y;
    }
    sort(allrange(T));

/*ピタゴラ三角形
    5	12	13
    8	15	17
    3	4	5
*/
/*    vector<vector<int>> tri(12);
    tri[0]={0,1,1};
    tri[1]={-1,0,1};
    tri[2]={0,-1,1};
    tri[3]={1,0,1};
    tri[4]={3,4,5};
    tri[5]={4,3,5};
    tri[6]={-3,4,5};
    tri[7]={-4,3,5};
    tri[8]={-3,-4,5};
    tri[9]={-4,-3,5};
    tri[10]={3,-4,5};
    tri[11]={4,-3,5};*/

    vector<vector<int>> tri(0);
    tri.push_back(vector<int>({3,4,5}));
    tri.push_back(vector<int>({4,3,5}));
    tri.push_back(vector<int>({-1,0,1}));
    tri.push_back(vector<int>({0,-1,1}));
    tri.push_back(vector<int>({-3,4,5}));
    tri.push_back(vector<int>({-4,3,5}));
    tri.push_back(vector<int>({0,1,1}));
    tri.push_back(vector<int>({1,0,1}));
    tri.push_back(vector<int>({-3,-4,5}));
    tri.push_back(vector<int>({-4,-3,5}));
    tri.push_back(vector<int>({3,-4,5}));
    tri.push_back(vector<int>({4,-3,5}));

 //   tri.push_back(vector<int>({-5, -12, 13}));
 //   tri.push_back(vector<int>({-12, -5, 13}));
 //   tri.push_back(vector<int>({-8,-15,17}));
 //   tri.push_back(vector<int>({-15,-8,17}));
 //   tri.push_back(vector<int>({5, 12, 13}));
 //   tri.push_back(vector<int>({12, 5, 13}));
 //   tri.push_back(vector<int>({8,15,17}));
 //   tri.push_back(vector<int>({15,8,17}));
 //   tri.push_back(vector<int>({-5, 12, 13}));
 //  tri.push_back(vector<int>({-12, 5, 13}));
  //  tri.push_back(vector<int>({-8,15,17}));
  //  tri.push_back(vector<int>({-15,8,17}));
 //   tri.push_back(vector<int>({5, -12, 13}));
 //   tri.push_back(vector<int>({12, -5, 13}));
 //   tri.push_back(vector<int>({8,-15,17}));
 //   tri.push_back(vector<int>({15,-8,17}));

    bool flg;

    if(S.size()==2 && T.size()==2){
        auto sx = S[0].first-S[1].first;
        auto sy = S[0].second-S[1].second;
        auto tx = T[0].first-T[1].first;
        auto ty = T[0].second-T[1].second;
        flg= (sx*sx+sy*sy==tx*tx+ty*ty);
    } else {
        rep(j,tri.size()){
            auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]);
            if(S2.empty()) continue;
            sort(allrange(S2));
            flg = solve_translated(S2,T);
            if(flg) break;
        }
    }
    if(flg) prl("Yes"); else prl("No");
}

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

int main(){

  int n; cin>>n;
  vector<complex<double>>a(n),c(n);
  for(int i=0; i<n; i++){
    int a1,a2;
    cin>>a1>>a2;
    a.at(i).real(a1);
    a.at(i).imag(a2);
  }
  for(int i=0; i<n; i++){
    int a1,a2;
    cin>>a1>>a2;
    c.at(i).real(a1);
    c.at(i).imag(a2);
  }
  if(n==1){
    cout<<"Yes"<<endl;
    return 0;
  }
  auto a1 = a.at(0);
  auto a2 = a.at(1);
  for(int t1=0; t1<n; t1++){
    for(int t2=0; t2<n; t2++){
      if(t1==t2)continue;
      auto c1=c.at(t1),c2=c.at(t2);
      if(abs( abs(a1-a2)-abs(c1-c2) )>0.0001)continue;
      auto b = a;
      auto d = c;
      for(int i=0; i<n; i++){
        b.at(i) -= a1;
        d.at(i) -= c1;
      }

      double ara = arg(b.at(1));
      double arc = arg(d.at(t2));
      complex<double> e1=polar(1.,-ara),e2=polar(1.,-arc);

      for(int i=0; i<n; i++){
        b.at(i) *= e1;
        d.at(i) *= e2;
      }
      vector<int> to(n,-1);
      for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
          if(abs(b.at(i)-d.at(j))<0.0001)to.at(i)=1;
        }
      }
      int sum{};
      for(int i=0; i<n; i++){
        if(to.at(i)==1) sum++;
      }
      if(sum==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;

}


#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <memory>
#include <list>
#include <deque>
#include <queue>
#include <iomanip>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <string.h>
#include <functional>
#include <sstream>

using namespace std;

#define REP(i,n) for (decltype(n) i = 0; i < n; i++)
#define THE_MOD 1'000'000'007

using ll = long long;
using ivec = vector<int>;
using lvec = vector<long>;
using ipair = pair<int, int>;
using llvec = vector<ll>;
using llpair = pair<ll, ll>;

#define umap unordered_map
#define uset unordered_set

template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { auto n = v.size(); REP(i,n) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &e : v) is >> e; return is; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }

void in() {} template <typename T, typename... Args> void in(T& t, Args& ...args) { cin >> t; in(args...); }
void out() { cout << endl; } template <typename T, typename... Args> void out(const T& t, const Args& ...args) { cout << t; if (sizeof...(args)) cout << " "; out(args...); }

constexpr ll LLINF = numeric_limits<ll>::max();

template<class T> void sort(T& v) {	sort(v.begin(), v.end()); }
template<class T> void rsort(T& v) { sort(v.begin(), v.end(), greater<typename T::value_type>()); }

void YN(bool b) {	cout << (b ? "Yes" : "No") << endl; }

template <typename T = ll, typename U = ll>
vector<T> Dijkstra(const vector<vector<pair<U,T>>>& edges, U start, U numNodes)
{
	using Node = pair<U,T>;
	auto compare = [](Node a, Node b){ return a.second > b.second;};
	priority_queue<Node, vector<Node>, decltype(compare)> q{compare};

	vector<T> costs(numNodes, numeric_limits<T>::max());

	q.emplace(start, 0);
	while (!q.empty()) {
		auto [from, cost] = q.top();
		q.pop();
		if (cost > costs[from]) continue;

		for (const auto& edge : edges[from]) {
			auto to = edge.first;
			auto newCost = cost + edge.second;
			if (newCost < costs[to]) {
				costs[to] = newCost;
				q.emplace(to, newCost);
			}
		}
	}
	return costs;
}

struct Range {
	ll x;
	ll y;
	Range(ll x, ll y) : x(x), y(y)
	{
		if (y > x) swap(x,y);
	}

	struct Iterator {
		using difference_type   = ptrdiff_t;
		using value_type        = ll;
		using pointer           = ll*;
		using reference         = ll&;
		using iterator_category = std::random_access_iterator_tag;
		Iterator() = default;
		Iterator(ll n) : n(n) {}
		ll n;
		bool operator!=(const Iterator&rhs) const { return n != rhs.n; }
		bool operator==(const Iterator&rhs) const { return n == rhs.n; }
		Iterator& operator++() { n++; return *this; }
		Iterator& operator--() { n--; return *this; }
		Iterator& operator+=(ll x) { n+=x; return *this; }
		ll operator*() const { return n; }
		ptrdiff_t operator-(const Iterator&rhs) const { return n - rhs.n; }
	};

	Iterator begin() { return Iterator(x); }
	Iterator end() { return Iterator(y); }
};

ll extgcd(ll a, ll b, ll &x, ll &y)
{
/*
a = pb*q; // p = a / b, q = a % b
ax + by
 = pbx + qx + by
 = b(px + y) + qx
 = bY + qX // Y = px + y, X = x ->  y = Y - px
*/

	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll d = extgcd(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

ll run()
{
	ll n;in(n);
	ll s = 0;
	ll s2 = 0;
	REP(i,n) {
		ll a;in(a);
		s += a;
		s2 += a * a;
	}

	return n * s2 - s * s;
}

int main()
{
	cout << fixed << setprecision(15);
	auto r = run();
	//YN(r);
	out(r);
	//cout << r << endl;
	return 0;
}


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

#include <iostream>
#include <cassert>

template<long long mod>
class modint{
private:
  using T = long long;
  T a;
public:
  constexpr modint(const long long x = 0) noexcept : a((x%mod+mod)%mod) {}
  constexpr T& value() noexcept { return a; }
  constexpr const T& value() const noexcept { return a; }
  constexpr modint operator-() const noexcept {
    return modint(0) -= *this;
  }
  constexpr modint operator+(const modint& rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint& rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint& rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint& rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint& rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint& rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint& rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(const modint& rhs) noexcept {
    return *this *= rhs.inv();
  }
  constexpr bool operator==(const modint& rhs) const noexcept {
    return a == rhs.a;
  }
  constexpr bool operator!=(const modint& rhs) const noexcept {
    return not (*this == rhs);
  }
  constexpr modint pow(long long k) const noexcept {
    modint ret(1);
    modint x = k > 0 ? *this : this->inv();
    k = abs(k);
    while(k > 0){
      if(k&1) ret *= x;
      x *= x;
      k >>= 1;
    }
    return ret;
  }
  constexpr modint inv() const noexcept {
    return pow(mod-2);
  }
  friend std::ostream& operator<<(std::ostream &os, const modint &X) noexcept {
    return os << X.a;
  }
  friend std::istream& operator>>(std::istream &is, modint &X) noexcept {
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

template<typename T>
T power(T x, long long k){
  T ret{1};
  while(k > 0){
    if(k&1) ret *= x;
    x *= x;
    k /= 2;
  }
  return ret;
}

int main(){
  using mint = modint<998244353>;
  int n, m;
  cin >> n >> m;
  mint ans = 0;
  vector<mint> pow_m(n+1);
  pow_m[0] = 1;
  for(int i = 0; i < n; ++i)
    pow_m[i+1] = pow_m[i]*m;
  for(int i = 1; i <= m; ++i){
    ans += power<mint>(m-i+1,n) - power<mint>(m-i,n);
    mint a = 1, b = 1;
    for(int j = 1; j+1 <= n; ++j){
      a *= m-i+1, b *= m-i;
      if(j+2 <= n){
        mint p = a - b;// i が 1 回以上使われる
        p *= n-j-1;// 長さ j+2 の区間の取り方
        p *= (i-1)*(i-1);//両端
        p *= pow_m[n-j-2];//残り
        ans += p;
      }
      mint q = a - b;
      q *= 2;
      q *= i-1;//両端
      q *= pow_m[n-j-1];//残り
      ans += q;
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)

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

const int N = 1e5 + 505;

int n, L, a[N], b[N], d[N];
ll ans;

void solve(int l, int r) {
	if (d[l] > 0) {
		rep(i, l, r) {
			a[i] = L - a[i] + 1;
			b[i] = L - b[i] + 1;
		}
		reverse(a + l, a + r + 1);
		reverse(b + l, b + r + 1);
	}
	//~ printf ("%d -- %d\n", l, r);
	//~ rep(i, l, r)
		//~ cout << a[i] << " " << b[i] << endl;
	int j = l, i = l + 1;
	while (i <= r) {
		while (i <= r && a[j] + i - j == b[i]) {
			ans++;
			i++;
		}
		if (i == r + 1) break;
		//~ cat(i);
		//~ cat(j);
		//~ cat(a[j + 2]);
		//~ cat(b[i]);
		j++;
		while (j < i && a[j] + i - j != b[i]) j++;
		if (i == j) {
			printf ("-1\n");
			exit(0);
		}
		while (a[j + 1] + i - (j + 1) == b[i]) j++;
		ans += i - j - 1;
	}
	if (d[l] > 0) {
		rep(i, l, r) {
			a[i] = L - a[i] + 1;
			b[i] = L - b[i] + 1;
		}
		reverse(a + l, a + r + 1);
		reverse(b + l, b + r + 1);
	}
}

int sign(int x) {
	return (x > 0) - (x < 0);
}

int main() {
	scanf ("%d%d", &n, &L);
	a[0] = b[0] = 0;
	a[n + 1] = b[n + 1] = L + 1;
	rep(i, 1, n) scanf ("%d", a + i);
	rep(i, 1, n) scanf ("%d", b + i);
	rep(i, 1, n) d[i] = b[i] - a[i];
	for (int i = 1; i <= n;) {
		int j = i;
		while (j <= n && sign(d[i]) == sign(d[j])) j++;
		if (d[i] < 0)
			solve(i - 1, j - 1);
		if (d[i] > 0) {
			if (d[j] < 0) return !printf ("-1\n");
			solve(i, j);
		}
		i = j;
	}
	printf ("%lld\n", ans);
	return 0;
}


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

int main() {

  int N;

  cin >> N;

  vector<int> B(N), mem_A(N,0), mem_B(N,0);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    mem_A.at(A - 1)++;  //mem_A.at(n - 1) = 数列Aのうちnの値の数字の個数
  }
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);  //B.at(n - 1) = 数列Bの第n項の値
  }
  for (int i = 0; i < N; i++) {
    int C;
    cin >> C;
    mem_B.at(i) = B.at(C - 1);  //mem_B.at(n - 1) = 数列Bの第「数列Cの第n項の値」項の値
  }
  long long count = 0;
  for (int j = 0; j < N; j++) {
    count += mem_A.at(mem_B.at(j) - 1);
  }
  cout << count << endl;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef vector<int> vi;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())

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

    vi arr(n), b(n);
    forn(i, n)
    {
        cin >> arr[i];
    }
    forn(i, n)
    {
        cin >> b[i];
    }

    map<int, int> m;

    forn(i, n)
    {
        int x;
        cin >> x;
        --x;
        int val = b[x];
        m[val]++;
    }

    ll cnt = 0;

    forn(i, n)
    {
        if (m.find(arr[i]) != m.end())
        {
            cnt += m[arr[i]];
        }
    }

    cout << cnt << ln;
}
int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    for (int it = 0; it < t; it++)
    {
        // cout << "Case #" << it + 1 << ": ";
        solve();
    }
    return 0;
}