#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const int inf = (int)1e9;
const ll inf_ll = (ll)1e19;
const int mod = 1000000007;
const int mod2 = 998244353;

int main(){
    char s, t; cin >> s >> t;
    if(s == 'Y') cout << char(t - 32) << endl;
    else cout << t << endl;
}

/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';
#define int long long
using namespace std;
template <class T, class K>ostream& operator<<(ostream &cout, pair<T, K> a) {cout << a.first << ' ' << a.second; return cout;}
template<class T>void show(vector<T> &a) {cerr << "[ "; for (int ij = 0; ij < (int)a.size(); ij++) {cerr << a[ij] << " ";} cerr << "]\n";}
template<class T>void show(T a) {cerr << a << endl;}
template<typename... T>void show(T... args) {((cerr << args << ' '), ...); cerr << endl;}
template<class T>void read(vector<T> &a) {for (auto &x : a) {cin >> x;}}
template<class T> void read(T &a) {cin >> a;}

void solve() {
	int a, b, c;

	cin >> a >> b >> c;

	char ans = '=';
	if (c % 2 == 0) {
		a = abs(a);
		b = abs(b);
	}

	if (a < b) {
		ans = '<';
	}
	else if (a > b) {
		ans = '>';
	}

	cout << ans << endl;

}

int32_t main(int32_t argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int T = 1;
	// cin >> T;
	while (T--) {
		solve();
	}
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  int n,m,k; cin >> n >> m >> k;
  vi a(n+1, 0);
  rep(i,k) {
    int tmp; cin >> tmp;
    a[tmp] = 1;
  }

  vector<ld> x(n+1), y(n+1);
  vector<ld> sumx(n+1, 0), sumy(n+1, 0);
  int id = 0;
  for(int i = n-1; i >= 0; --i) {
    if(a[i]) {
      x[i] = 1;
      y[i] = 0;
    }
    else {
      x[i] = ld(1)/ld(m) * (sumx[id] - sumx[max(0, id-m)]);
      y[i] = ld(1)/ld(m) * (sumy[id] - sumy[max(0, id-m)]) + 1;
    }
    sumx[id+1] = sumx[id] + x[i];
    sumy[id+1] = sumy[id] + y[i];
    id++;
  }
  if(x[0] == 1) cout << -1 << "\n";
  else {
    ld res = y[0] / (1. - x[0]);
    printf("%.4Lf\n", res);
  }

  return 0;
}

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

typedef long long ll;

int main() {
    ll N, M, K, A;
    cin >> N >> M >> K;
    vector<bool> start(N + 1, false);
    rep(i, K) {
        cin >> A;
        start[A] = true;
    }
    double L = 0, R = 1e20;
    vector<double> dp(N + 1 + M, 0);
    rep(i, 100) {
        double m = (L + R) / 2, s = 0;
        rep(j, N) {
            if (start[N - 1 - j]) {
                dp[N - 1 - j] = m;
            } else {
                dp[N - 1 - j] = 1 + s / M;
            }
            s += dp[N - 1 - j];
            if (j >= M - 1) s -= dp[N - 1 - j + M];
            //cout << "s=" << s << " ";
        }
        if (dp[0] > m) L = m;
        else R = m;
        //rep(i, N + 1) cout << dp[i] << " "; cout << "\n";
        //cout << L << " " << R << "\n";
    }
    if (dp[0] > 1e15) cout << "-1\n";
    else cout << fixed << setprecision(20) << dp[0] << "\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXX 3000002
ll pre[3][MAXX];
ll dp[3][MAXX];

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

    ll N,K; cin>>N>>K;
    ll MAX_SUM = 3LL*N;

    for(ll j=1;j<=MAX_SUM;++j)
    {
        if(j <= N)
            dp[0][j] = 1;

        pre[0][j] = pre[0][j - 1] + dp[0][j];
    }

    for(ll i=1;i<3;++i)
    {
        for(ll j=1;j<=MAX_SUM;++j)
        {
            ll L = max(0LL, j - N);
            ll R = max(0LL, j - 1);

            dp[i][j] = pre[i - 1][R] - ((L > 0) ? pre[i - 1][L - 1] : 0);
            pre[i][j] = pre[i][j - 1] + dp[i][j];
        }
    }

    ll sum = 0;

    for(ll i=1;i<=MAX_SUM;++i)
    {
        if(K <= dp[2][i])
        {
            sum = i;
            break;
        }

        K -= dp[2][i];
    }

    ll arr[3];

    for(ll i=1;i<=N;++i)
    {
        //Checking beauty = i
        ll rem_sum = sum - i;
        if(!dp[1][rem_sum])
            continue;

        if(K <= dp[1][rem_sum])
        {
            sum -= i;
            arr[0] = i;
            break;
        }

        K -= dp[1][rem_sum];
    }

    for(ll i=1;i<=N;++i)
    {
        //Checking taste = i
        ll rem_sum = sum - i;
        if(!dp[0][rem_sum])
            continue;

        if(K <= dp[0][rem_sum])
        {
            sum -= i;
            arr[1] = i;
            break;
        }

        K -= dp[0][rem_sum];
    }

    assert(K <= N);

    arr[2] = sum;

    cout<<arr[0]<<" "<<arr[1]<<" "<<arr[2]<<endl;
}

#include<bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void sc(int &x){scanf("%d",&x);}
void sc(int &x,int &y){scanf("%d%d",&x,&y);}
void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void sc(ll &x){scanf("%lld",&x);}
void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);}
void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}
void sc(char *x){scanf("%s",x);}
void sc(char *x,char *y){scanf("%s%s",x,y);}
void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);}
void out(int x){printf("%d\n",x);}
void out(ll x){printf("%lld\n",x);}
void out(int x,int y){printf("%d %d\n",x,y);}
void out(ll x,ll y){printf("%lld %lld\n",x,y);}
void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);}
void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);}
using namespace std;
const int N=3e6+5;
ll n,k,s2[N];
ll cal1(ll sum)
{
    if(sum<=2) return 0;
    ll l=max(1ll,sum-2*n),r=min(n,sum-2);
    l=sum-l;r=sum-r;
    swap(l,r);
    return s2[r]-s2[l-1];
}
ll cal2(ll sum)
{
    return min(n,sum-1)-max(1ll,sum-n)+1;
}
int main()
{
    //freopen("1.in","r",stdin);freopen("1.out","w",stdout);
    sc(n,k);
    ll ans=0;
    for(int i=2;i<=n*2;i++) s2[i]=cal2(i)+s2[i-1];
    for(ll i=3;i<=n*3;i++)
    {
        ll t=cal1(i);
        if(k>t) k-=t;
        else
        {
            for(ll j=max(1ll,i-2*n);j<=min(n,i-2);j++)
            {
                ll t=cal2(i-j);
                if(k>t) k-=t;
                else
                {
                    for(ll h=max(1ll,i-j-n);h<=min(n,i-j-1);h++)
                    {
                        k--;
                        if(k==0)
                        {
                            printf("%lld %lld %lld\n",j,h,i-j-h);
                            break;
                        }
                    }
                    break;
                }
            }
            break;
        }
    }
}


#include <bits/stdc++.h>

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

using namespace std;
using lint = long long;

int main(void)
{
    string S;
    cin >> S;

    string T1 = "";
    string T2 = "";
    int t = 1;
    for(int i = 0; i < S.size(); i++){
        if(S[i] != 'R'){
            if(t == 1){
                T1.push_back(S[i]);
            }
            else{
                T2.push_back(S[i]);
            }
            int n_t1 = T1.size() - 1;
            int n_t2 = T2.size() - 1;
            if(T1.size() >= 2 && T1[n_t1] == S[i] && T1[n_t1-1] == S[i]){
                T1.pop_back();
                T1.pop_back();
            }
            else if(T2.size() >= 2 && T2[n_t2] == S[i] && T2[n_t2-1] == S[i]){
                T2.pop_back();
                T2.pop_back();
            }
            else if(T1.size() >= 1 && T2.size() >= 1 && T1[0] == S[i] && T2[0] == S[i]){
                T1.erase(T1.begin());
                T2.erase(T2.begin());
            }
            //cout <<S[i] << " "<< T1 << " " << T2 << endl;
        }
        else{
            t *= -1;
        }
    }

    if(t == 1){
        reverse(T2.begin(), T2.end());
        cout << T2 << T1 << endl;
    }
    else{
        reverse(T1.begin(), T1.end());
        cout << T1 << T2 << endl;
    }
    return 0;
}

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

int main() {
    string s, t = "";
    cin >> s;
    int n = s.length();
    bool flip = true;
    deque<char> deq;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            flip = !flip;
        } else {
            if (flip) {
                deq.emplace_front(s[i]);
            } else {
                deq.emplace_back(s[i]);
            }
        }
    }

    if (flip) reverse(deq.begin(), deq.end());

    stack<char> st;
    for (auto c: deq) {
        if (st.size() and st.top() == c) {
            st.pop();
            continue;
        }
        st.push(c);
    }

    stack<char> tmp;

    while (st.size()) {
        char c = st.top();
        st.pop();
        tmp.push(c);
    }

    while (tmp.size()) {
        char c = tmp.top();
        tmp.pop();
        cout << c;
    }
    cout << endl;
}


#include <bits/stdc++.h>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using pii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//#define pi 3.14159265358979
#define ss string
#define db double
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define ci(x) cin >> (x)
#define cii(x) int (x);cin >> (x)
#define cci(x,y) int (x),(y);cin >> (x) >>(y)
#define co(x) cout << (x) << endl

int t[200010];
int main(){
  cii(n);
  vi v(n);
  rep(i,0,n)ci(v[i]);
  int at=0;
  rep(i,0,n){
  t[v[i]]++;
  while(t[at])at++;
  co(at);
  }
}

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

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

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

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 300009

ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n;cin>>n;
	stack<char> st;
	ll ans = n;
	string s;cin>>s;
	rep(i,0,n) {
		st.push(s[i]);

		while(1) {
			ll cnt = 0;
			if(!st.empty() and st.top() == 'x' ) {
				cnt ++;
				st.pop();
				if(!st.empty() and st.top() == 'o' ) {
					cnt ++;
					st.pop();
					if(!st.empty() and st.top() == 'f' ) {
						cnt ++;
						st.pop();
					}
				}
			}
			//test2(i,cnt);
			if(cnt == 3) {
				ans -=3;
			}
			else {
				if(cnt == 1) {
					st.push('x');
				}
				if(cnt == 2) {
					st.push('o');
					st.push('x');
				}
				break;
			}
		}
	}
	cout << ans  << endl;
}


#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
void eras(map<int,int> &m,int x)
{
    m[x]--;
    if (!m[x])
        m.erase(x);
}
const int N=(int)3e5+100;
const int M=(int)2e6+100;
const int inf=(int)1e9+2;
#define filename ""
    vector<int> v[N];
    int h[N];
    pair<int,int> o[N];
bool sss(pair<int,int> &x,pair<int,int> &y)
{
    if (x.fi-x.se==y.fi-y.se) re x<y;
    re x.fi-x.se>y.fi-y.se;
}
void dfs(int x)
{
    h[x]=1;
    vector<pair<int,int> > vv[2];
    for(auto y:v[x])
    {
        dfs(y);
        h[x]+=h[y];
        vv[h[y]%2].pb(o[y]);
    }
    o[x]={0,0};
    if (vv[1].size()%2)
    {
        for(auto &j:vv[0])
        {
            o[x].fi+=max(j.fi,j.se);
            o[x].se+=min(j.fi,j.se);
        }
    }
    else
    {
        for(auto &j:vv[0])
        {
            o[x].fi+=j.fi;
            o[x].se+=j.se;
        }
    }
    sort(all(vv[1]),sss);
    int i;
    fo(i,vv[1].size())
    {
        if (i%2)
        {
            o[x].fi+=vv[1][i].se;
            o[x].se+=vv[1][i].fi;
        }
        else
        {
            o[x].fi+=vv[1][i].fi;
            o[x].se+=vv[1][i].se;
        }
    }
    o[x].se++;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,i;
    cin>>n;
    fo(i,n-1)
    {
        int a;
        cin>>a;
        a--;
        v[a].pb(i+1);
    }
    dfs(0);
    cout<<o[0].se;
}

///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define     FAST            ios::sync_with_stdio(0); cin.tie(0)
#define     int 	        long long
#define 	pb 	            push_back
#define     pp              pop_back
#define 	mp 	            make_pair
#define 	pi 	            2*acos(0.0)
#define     scan(i)         scanf("%lld",&i)
#define     scann(i,j)      scanf("%lld%lld",&i,&j)
#define     print(i)        printf("%lld\n",i)
#define     printt(i,j)     printf("%lld %lld\n",i,j)
#define     loop(i,n) 	    for(int i = 0 ; i <n ; i++)
#define     loopp(i,n) 	    for(int i = 1 ; i <n ; i++)
#define     rep(i,n)        for(int i=n-1;i>=0;i--)
#define     rev(v)          reverse(v.begin(),v.end())
#define     reset(a,b)      memset(a,b,sizeof(a))
#define 	vect 	        vector<int>
#define 	vec_it 	        vector<int>::reverse_iterator vi
#define     sorta(v)        sort(v.begin(),v.end())
#define     sortd(v)        sort(v.begin(),v.end(),greater<>())
#define     sorted(v)       is_sorted(v.begin(),v.end())
#define     mnv(v)          *min_element(v.begin(),v.end())
#define     mxv(v)          *max_element(v.begin(),v.end())
#define     countv(v,a)     count(v.begin(),v.end(),a)
#define     vplusa(v,a)     v.insert(v.end(),a.begin(),a.end())
#define 	mapp 	        map<int,int>
#define     rmap            map<int,int,greater<>>m
#define 	pairr 	        pair<int,int>
#define 	sett	        set<int>
#define     rset            set<int,greater<>>s
#define 	set_it 	        set<int>::reverse_iterator si
#define     map_it          map<int,int> :: reverse_iterator mi
#define     digit(n)        floor(log10(n)+1)
#define 	yes 	        cout<<"YES"<<endl
#define 	no 	            cout<<"NO"<<endl
#define 	ff 	            first
#define 	ss 	            second
#define     mx              INT_MAX
#define     lmx             LLONG_MAX
#define     mn              INT_MIN
#define     lmn             LLONG_MIN
#define     inf             0x3f3f3f3f
#define     inff            10e18
#define     GCD             __gcd(a,b)
#define     LCM             (a/GCD)*b
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
int modulo (int a, int b) { return a >= 0 ? a % b : ( b - abs ( a%b ) ) % b; }

void solve()
{
   // freopen ("(input).txt" , "r",  stdin) ;
    string st,stt;
    int low=0,high=0;
    int l,r; char ch;
    int n,k,t,x,y,z,d=0,cnt=0,temp=mx,sum=0,f=0,flag=0;
    cin>>n>>k ; vect v(n) ,a ,b ; sett s ; mapp m,mm ; pairr p ;
    for(int i=0;i<=n;i++) m[i]++;
    loop(i,n) cin>>v[i];
    for(int i=0;i<n;i++)
    {
        mm[v[i]]++;
        m.erase(v[i]);
        cnt++;
        if(cnt==k)
        {
            cnt--;
            for(auto i:m)
            {
                temp=min(temp,i.ff);
                if(d==0)
                    break;
            }
            mm[v[low]]--;
            if(mm[v[low]]==0)
                m[v[low]]++;
            low++;
        }
    }
    cout<<temp<<endl;

}

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


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

string s = "atcoder";

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

    string a;
    int t,n,i,j;
    cin >> t;
    while(t--)
    {
        cin >> a;
        n = a.length();
        if(a > s) cout << 0 << endl;
        else
        {
            for(i=0;i<n;i++)
            {
                if(a[i]!='a') break;
            }
            if(i==n) cout << -1 << endl;
            else if(a[i]>'t') cout << i-1 << endl;
            else cout << i << endl;
        }

    }
}

#include <iostream>
#include <vector>

using namespace std;

vector <long long> x;

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

int main() {
	long long primes[15] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 };
	int n;
	cin >> n;
	long long temp;
	long long currmin = 9223372036854775806;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		x.push_back(temp);
	}

	long long y;
	bool can;
	for (long long i = 1; i < (1 << 16); i++) {
		y = 1;
		can = true;
		long long t;
		long long s;
		for (int j = 0; j < 15; j++) {
			t = (long long)1 << j;
			s = i & t;
			if (s != 0) y *= primes[j];
		}

		for (int j = 0; j < n; j++) {
			if (gcd(y, x[j]) == 1) {
				can = false;
				break;
			}
		}

		if (can) currmin = min(currmin, y);
	}

	cout << currmin << endl;

	return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using s = string;
using P = pair<int, int>;
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;

class BQuizzes {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll n, x;
        s s;
        in >> n >> x >> s;
        for (int i = 0; i < n; ++i) {
            if(s[i] == 'x'){
                if(x > 0) x--;
            }else{
                x++;
            }
        }
        out << x;
	}
};

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

#include <iostream>

using namespace std;

int main()
{
    int a,sum=0,dex=3;
    while(dex--)
    {
    cin >> a;
    if(a==1)
    {
        a=6;
    }
    else if(a==2)
    {
        a=5;
    }
    else if(a==3)
    {
        a=4;
    }
    else if(a==4)
    {
        a=3;
    }
    else if(a==5)
    {
        a=2;
    }
    else if(a==6)
    {
        a=1;
    }
    sum+=a;
    }
    cout << sum << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>
#include <cassert>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
//const int mod = 998244353;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

int N;
VVI g;
VI d;
VVI Qv; //頂点iのqidxが格納
vector<PII> qlist; //クエスチョンが連番
VI ans;

void dfs1(int v, int p, int dep){
    d[v] = dep;
    for(int u : g[v]){
        if(u == p) continue;

        dfs1(u,v,dep+1);
    }
}

map<int,int> dfs2(int v, int p){
    map<int,int> res;
    res[d[v]]++;
    for(int u : g[v]){
        if(u == p) continue;

        auto qmap = dfs2(u,v);

        if(res.size() < qmap.size()){
            swap(res, qmap);
        }

        for(auto p : qmap){
            res[p.first] += p.second;
        }

    }
    int sz = SZ(Qv[v]);
    REP(i,sz){ //この時点でクエリに答える
        int qidx = Qv[v][i];
        int x = qlist[qidx].second;
        if(res.find(x) == res.end()){
            ans[qidx] = 0;
        }else{
            ans[qidx] = res[x];
        }
    }

    return res;

}

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

    cin >> N;
    g.resize(N);
    d.resize(N);
    Qv.resize(N);
    FOR(i,1,N){
        int p;
        cin >> p;
        p--;
        g[i].eb(p);
        g[p].eb(i);

    }

    int Q; cin >> Q;
    qlist.resize(Q);
    ans.resize(Q);
    REP(i,Q){
        int u,d;
        cin >> u >> d;
        u--;
        qlist[i] = make_pair(u,d);
        Qv[u].eb(i);
    }

    dfs1(0,-1,0);
    dfs2(0,-1);

    REP(i,Q){
        cout << ans[i] << "\n";
    }

}

// E - Count Descendants
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;

vec<vi> adj, T;
vi L, R;

int dfs(int d, int p, int t){
	T[d].push_back(t);
	L[p] = t;
	for(int&c:adj[p]) t = dfs(d+1, c, t+1);
	R[p] = t+1;
	return t+1;
}

int f(int d, int t){
	return lower_bound(T[d].begin(), T[d].end(), t) - T[d].begin();
}

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

	adj.resize(n);
	for(int i=0; i<n-1; ++i){
		int p; cin>>p;
		adj[p-1].push_back(i+1);
	}

	T.resize(n), L.resize(n), R.resize(n);
	dfs(0, 0, 0);

	int q; cin>>q;
	while(q--){
		int u, d; cin>>u>>d;
		cout<< f(d, R[u-1]) - f(d, L[u-1]) <<endl;
	}
}


/* #region header */

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
// types
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<ll, ll> Pl;
typedef pair<int, int> Pi;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
template <typename T>
using mat = vector<vector<T>>;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef vector<vector<char>> vvc;
// abreviations
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep_(i, a_, b_, a, b, ...) for (ll i = (a), max_i = (b); i < max_i; i++)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define rrep_(i, a_, b_, a, b, ...) \
    for (ll i = (b - 1), min_i = (a); i >= min_i; i--)
#define rrep(i, ...) rrep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define srep(i, a, b, c) for (ll i = (a), max_i = (b); i < max_i; i += c)
#define SZ(x) ((int)(x).size())
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp make_pair
//入出力
#define print(x) cout << x << endl
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto& e : v) cout << e << " ";
    cout << endl;
    return os;
}
void scan(int& a) { cin >> a; }
void scan(long long& a) { cin >> a; }
void scan(char& a) { cin >> a; }
void scan(double& a) { cin >> a; }
void scan(string& a) { cin >> a; }
template <class T>
void scan(vector<T>& a) {
    for (auto& i : a) scan(i);
}
#define vsum(x) accumulate(all(x), 0LL)
#define vmax(a) *max_element(all(a))
#define vmin(a) *min_element(all(a))
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
// functions
// gcd(0, x) fails.
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
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;
}
template <typename T>
T mypow(T x, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) (ret *= x);
        (x *= x);
        n >>= 1;
    }
    return ret;
}
ll modpow(ll x, ll n, const ll mod) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) (ret *= x);
        (x *= x);
        n >>= 1;
        x %= mod;
        ret %= mod;
    }
    return ret;
}

uint64_t my_rand(void) {
    static uint64_t x = 88172645463325252ULL;
    x = x ^ (x << 13);
    x = x ^ (x >> 7);
    return x = x ^ (x << 17);
}
int popcnt(ull x) { return __builtin_popcountll(x); }
template <typename T>
vector<int> IOTA(vector<T> a) {
    int n = a.size();
    vector<int> id(n);
    iota(all(id), 0);
    sort(all(id), [&](int i, int j) { return a[i] < a[j]; });
    return id;
}
struct Timer {
    clock_t start_time;
    void start() { start_time = clock(); }
    int lap() {
        // return x ms.
        return (clock() - start_time) * 1000 / CLOCKS_PER_SEC;
    }
};
/* #endregion*/
// constant
#define inf 1000000000ll
#define INF 4000000004000000000LL
#define mod 998244353ll
#define endl '\n'
const long double eps = 0.000000000000001;
const long double PI = 3.141592653589793;
// give the solution which minimize |x|+|y|
template <typename T>
T extgcd(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;  // gcd(a, b)
}
void solve() {
    ll n, s, k;
    cin >> n >> s >> k;
    ll x, y;
    ll d = extgcd(k, n, x, y);
    if (s % d != 0) {
        print(-1);
        return;
    }
    x *= s / d;
    x *= -1;
    x = (x % (n / d) + n / d) % (n / d);
    print(x);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(30) << fixed;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

#include <iostream>
#include <cstdint>

using namespace std;

int main() {
  int N, K, M;
  cin >> N >> K >> M;
  int64_t sum = 0;
  for (size_t i = 1; i < N; ++i) {
    int n;
    cin >> n;
    sum += n;
  }
  int64_t diff = (M * N) - sum;
  if (diff > K) {
    cout << -1 << endl;
  } else {
    cout << max(diff, static_cast<int64_t>(0)) << endl;
  }

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define ll long long
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll  b)
{
    return a/gcd(a,b)*b;
}
int main()
{
    ll n;
    cin>>n;
    ll ans=1;
    for(int i=2;i<=n;i++)
        ans=lcm(ans,i);
    cout<<ans+1<<endl;

}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }

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

    int n; cin >> n;
    ll l = 1;
    for (int x = 2; x <= n; x++) l = lcm(l, x);
    auto ans = l+1;
    for (int x = 2; x <= n; x++) assert(ans%x == 1);
    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll,ll>pll;

const int mod = 1e9 + 7;

pair<int,int> find(vector<vector<int>>& grid){
    for(int i = 0; i < grid.size(); i++){
        for(int j = 0; j < grid[0].size(); j++){
            if(grid[i][j] == 0){
                return mp(i, j);
            }
        }
    }
    return mp(-1,-1);
}

void dfs(int& ans, vector<vector<int>>& grid, int a, int b){
    int n = grid.size();
    int m = grid[0].size();
    pair<int,int>start = find(grid);
    if(start.first == -1 && start.second == -1){
        ans++;
        return;
    }
    int i = start.first;
    int j = start.second;
    if(a > 0){
        // use 2x1
        // I
        // I
        if(i+1 < n && grid[i+1][j] == 0){
            grid[i][j] = 1;
            grid[i+1][j] = 1;
            dfs(ans, grid, a-1, b);
            grid[i][j] = 0;
            grid[i+1][j] = 0;
        }
        if(j+1 < m && grid[i][j+1] == 0){
            grid[i][j] = 1;
            grid[i][j+1] = 1;
            dfs(ans, grid, a-1, b);
            grid[i][j] = 0;
            grid[i][j+1] = 0;
        }
    }
    if(b > 0){
        grid[i][j] = 1;
        dfs(ans, grid, a, b-1);
        grid[i][j] = 0;
    }
}

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vector<vector<int>>grid(h, vector<int>(w, 0));
    int ans = 0;
    dfs(ans, grid, a, b);
    cout << ans << endl;
}

#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <cassert>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
#include <cassert>
using namespace std;
using ll = int64_t;
#define rep(i, a) for (int i = 0; i < (int)(a); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repr(i, a) for (int i = (int)((a) - 1); i >= 0; --i)
template <class T> class V1 : public vector<T> { public: V1(size_t n1, T init = T()) : vector<T>(n1, init) {} };
template <class T> class V2 : public vector<V1<T>> { public: V2(size_t n1, size_t n2, T init = T()) : vector<V1<T>>(n1, V1<T>(n2, init)) {} };
template <class T> class V3 : public vector<V2<T>> { public: V3(size_t n1, size_t n2, size_t n3, T init = T()) : vector<V2<T>>(n1, V2<T>(n2, n3, init)) {} };
template <class T> class V4 : public vector<V3<T>> { public: V4(size_t n1, size_t n2, size_t n3, size_t n4, T init = T()) : vector<V3<T>>(n1, V3<T>(n2, n3, n4, init)) {} };
template <class T> class V5 : public vector<V4<T>> { public: V5(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, T init = T()) : vector<V4<T>>(n1, V4<T>(n2, n3, n4, n5, init)) {} };
template <class T> vector<T> GetV1(istream& in, size_t N) { vector<T> ret; ret.reserve(N); rep(i, N) { T a; in >> a; ret.emplace_back(a); } return ret; }

ll Calc(vector<pair<int, int>> items, vector<int> xs)
{
	sort(xs.begin(), xs.end());
	sort(items.begin(), items.end());
	ll sum = 0;
	for (int x : xs) {
		int vmax = 0;
		int imax = -1;
		rep(i, items.size()) {
			if (items[i].first > x)
				break;
			if (vmax < items[i].second) {
				vmax = items[i].second;
				imax = i;
			}
		}
		if (imax >= 0) {
			sum += vmax;
			items[imax].second = 0;
		}
	}
	return sum;
}

int main()
{
#if 0
	stringstream sstr;
	sstr << R"()";
	auto& in = sstr;
#else
	auto& in = cin;
#endif

	int N, M, Q;
	in >> N >> M >> Q;
	vector<pair<int, int>> items(N); // w, v
	rep(i, N) {
		in >> items[i].first >> items[i].second;
	}
	vector<int> xs(M);
	rep(i, M) {
		in >> xs[i];
	}

	rep(q, Q) {
		int l, r;
		in >> l >> r;
		ll vsum = 0;
		auto cxs = xs;
		for (int i = l - 1; i <= r - 1; ++i) {
			cxs[i] = 0;
		}
		cout << Calc(items, cxs) << "\n";
	}

	return 0;
}


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

int main()
{
  string S;
  cin >> S;
  bool reversed = false;
  deque<char> T;
  for (auto c : S)
  {
    if (c == 'R')
    {
      reversed = !reversed;
      continue;
    }
    if (reversed)
    {
      if (!T.empty() && T.front() == c)
      {
        T.pop_front();
      }
      else
      {
        T.push_front(c);
      }
    }
    else
    {
      if (!T.empty() && T.back() == c)
      {
        T.pop_back();
      }
      else
      {
        T.push_back(c);
      }
    }
  }
  if (reversed)
  {
    reverse(T.begin(), T.end());
  }
  while (!T.empty())
  {
    cout << T.front();
    T.pop_front();
  }
  cout << endl;
}

// Problem: D - Message from Aliens
// Contest: AtCoder - ZONe Energy Programming Contest
// URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms

#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define test  ll t; cin>>t; while(t--)
#define loop(i,a,b)  for(ll i=a;i<b;i++)
#define loopr(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 1000 * 1000 + 10;
const ld pi      = 3.141592653589793;
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll ncr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}

void solve(){
    string s;
    cin>>s;
    vector<char> ans;
    for(ll i=0;i<s.length();i++){
    	if(s[i]!='R'){
    		if(ans.size() > 0 && ans[ans.size() - 1]==s[i]){
    			ans.pop_back();
    		}
    		else{
    			ans.pb(s[i]);
    		}
    	}
    	else{
    		reverse(all(ans));
    	}
    }
    for(auto i:ans) cout<<i;
    cout<<endl;
}
signed main(){
    fastio();
    // test
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
	char c;
	int w=1;
	while((c=getchar())>'9'||c<'0')if(c=='-')w=-1;
	int ans=c-'0';
	while((c=getchar())>='0'&&c<='9')ans=(ans<<1)+(ans<<3)+c-'0';
	return ans*w;
}
int n,m;
struct nod
{
	int next,to;
}e[1000005];
int cnt;
int h[1000005];
void add(int x,int y)
{
	cnt++;
	e[cnt].next=h[x];
	h[x]=cnt;
	e[cnt].to=y;
}
ll dis[18][100005];
int vis[18][100005];
struct node
{
	ll x,dis;
	bool operator<(const node&w)const
	{
		return dis>w.dis;
	}
	node(){}
	node(int a,int b){x=a,dis=b;}
};
priority_queue<node>q;
int k;
int id[25];
void dij(int x)
{
	while(!q.empty())q.pop();
	dis[x][id[x]]=0;
	q.push(node(id[x],0));
	while(!q.empty())
	{
//	cout<<q.size()<<endl;
		int f=q.top().x;
		q.pop();
		if(vis[x][f])continue;
		vis[x][f]=1;
//		cout<<f<<endl;
		for(int i=h[f];i;i=e[i].next)
		{
			if(dis[x][e[i].to]>dis[x][f]+1)
			{
				dis[x][e[i].to]=dis[x][f]+1;
				if(!vis[x][e[i].to])q.push(node(e[i].to,dis[x][f]+1));
			}
		}
	}
}
ll s[25][25];
ll f[131078][18];//131072
signed main(){
	memset(dis,0x3f,sizeof(dis));
	n=read();
	m=read();
	for(int i=1;i<=m;i++)
	{
		int a,b;
		a=read();
		b=read();
		add(a,b);
		add(b,a);
	}
	k=read();
	for(int i=1;i<=k;i++)id[i]=read();
	for(int i=1;i<=k;i++)dij(i);
	for(int i=1;i<=k;i++)
		for(int j=1;j<=k;j++)
			s[i][j]=dis[i][id[j]];
	memset(f,0x3f,sizeof(f));
	for(int i=1;i<=k;i++)f[(1<<i-1)][i]=0;
	for(int i=0;i<(1<<k);i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(f[i][j]>1e9)continue;
			for(int t=1;t<=k;t++)
			{
				if(i&(1<<t-1))continue;
				f[i+(1<<t-1)][t]=min(f[i+(1<<t-1)][t],f[i][j]+s[j][t]);
			}
		}
	}
	ll ans=1e18;
	for(int j=1;j<=k;j++)
	{
		ans=min(ans,f[(1<<k)-1][j]);
	}
	if(ans>1e9)
	{
		puts("-1");
	}
	else cout<<ans+1<<endl;
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (int)(a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using VD = vector<double>;
using VII = vector<VI>;
using VLL = vector<VL>;
using VDD = vector<VD>;
using P = pair<int, int>;
using PL = pair<ll, ll>;

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

void solve(std::vector<std::string> S) {
  set<char> moji_set;
  vector<char> moji;
  REP(i, 3) {
    REP(j, S[i].size()) {
      if(moji_set.count(S[i][j]) > 0) continue;
      moji.push_back(S[i][j]);
      moji_set.insert(S[i][j]);
    }
  }
  sort(moji.begin(), moji.end());
  if(moji.size() > 10) {
    cout << "UNSOLVABLE" << endl;
    return;
  }
  if(moji.size() < 10) {
    char last = moji[moji.size() - 1];
    while(moji.size() != 10) {
      moji.push_back(last + 1);
      last++;
    }
  }
  do {
    map<char, int> moji_map;
    REP(i, moji.size()) {
      moji_map[moji[i]] = i;
    }
    VLL N_dash(3);
    bool num_ok = true;
    REP(i, 3) {
      REP(j, S[i].size()) {
        char tmp = S[i][j];
        if(j == 0 && moji_map[tmp] == 0) num_ok = false;
        N_dash[i].push_back(moji_map[tmp]);
      }
    }
    if(!num_ok) continue;
    VL N(3);
    REP(i, 3) {
      ll mul = 1;
      N[i] = 0;
      reverse(N_dash[i].begin(), N_dash[i].end());
      REP(j, N_dash[i].size()) {
        N[i] += N_dash[i][j] * mul;
        mul *= 10;
      }
    }
    if(N[0] + N[1] == N[2]) {
      REP(i, 3) {
        cout << N[i] << endl;
      }
      return;
    }
  } while(next_permutation(moji.begin(), moji.end()));
  cout << "UNSOLVABLE" << endl;
  return;
}

int main() {
  std::vector<std::string> S(3);
  for(int i = 0; i < 3; i++) {
    std::cin >> S[i];
  }
  solve(std::move(S));
  return 0;
}


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

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define p push
#define pp pop

#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define Si size()
#define C count()
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define mp make_pair()
typedef long long ll;
#define V(type) vector<type>
#define PQ(type) priority_queue<type>
#define pll pair<ll, ll>
#define F first
#define S second
#define rep(i,n) for(ll i=0;i<n;i++)

#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n;i>0;i--)

#define mod 1000000007
#define INF 9223372036854775807
const double delta = 0.0000000001;
const double pi = 3.1415926535;

void FAST() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
ll fact(ll n)
{
	if(n<2)return 1;
	else return n*fact(n-1);
}
ll xi(ll x,ll y,ll p){            //gives (x^y)%p
	ll r=1;
	x=x%p;
	while(y>0){
		if(y%2==0){
			x*=x;
			x=x%p;
			y/=2;
		}
	else {
		r=((r%p)*(x%p))%p;
		y--;
	}

	}
	return r;
}
ll countBits(ll n) {
	ll count = 0;
	while (n) {
		count++;
		n >>= 1;
	}
	return count;
}

ll isP(ll n) {               //returns 1 if prime
	if (n == 0 || n == 1) return 0;
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) return 0;
	}
	return 1;
}

int main()
{
ll n;
cin>>n;
V(ll) arr(n);
rep(i,n)
{cin>>arr[i];}
ll ans=0;
sort(arr.B,arr.E);
for(ll i=n-1;i>=0;i--)
{
	ans+=((arr[i]*i)-(arr[i]*(n-i-1)));
}
cout<<ans;
return 0;
}

/*
	Auth: Loxilante
	Date: 2021-02-13 20:18:37
	Prog: B.cpp
*/

#define F_C
#include <bits/extc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif

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

	int k, m, ans = 0;
	cin>>k>>m;
	if (!m) return cout<<1<<endl, 0;
	if (m == 1) return cout<<1+(k != 0)<<endl, 0;
	if (m == 2) return cout<<2+(k != 0)<<endl, 0;
	if (k > 0)
	{
		int minn = -k-(m-1)/2;
		int maxx = k+(m-2)/2;
		int pmin = max(0LL, k-m/2);
		int pmax = min(-1LL, -k+(m-1)/2);
		D(minn, maxx, pmin, pmax, pmax);
		ans = -k-minn+1+maxx-pmin+1+pmax+k;
	}
	else if (!k) ans = m;
	else
	{
		int minn = k-m/2;
		int maxx = -(k-(m-1)/2);
		int pmin = max(0LL, -k-(m-1)/2);
		int pmin2 = min(-1LL, k+(m-2)/2);
		ans = k-minn+1+maxx-pmin+1+pmin2-k;
	}
	cout<<ans<<endl;

	return 0;
}
/*
 */


#include<bits/stdc++.h>
#define il inline
#define db double
const int N=105;

int n,tot; char g[N][N]; bool ok[N]; db ans;

il void dfs(int u)
{
	ok[u]=1,tot++; int v;
	for (v=1; v<=n; v++) if (!ok[v]&&g[v][u]>48) dfs(v);
}

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

	for (i=1; i<=n; i++) memset(ok,0,n+1),tot=0,dfs(i),ans+=1.0/tot;
	printf("%.12lf\n",ans);

	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	int a[n];
	map<int,int> m;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		m[a[i]]++;
	}
	long long ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=(n-i-1)-(m[a[i]]-1);
		m[a[i]]--;
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);

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

	int n;
	cin>>n;
	string s;
	cin>>s;
	int m = n+1;
	int a[m];
	int k = 1e9;
	for(int i=0;i<m;i++)cin>>a[i];
	for(int i=1;i<m;i++)chmin(k,abs(a[i]-a[i-1]));
	cout << k << endl;
	vector<vector<int>> ans(k);
	for(int i=0;i<k;i++){
		for(int j=0;j<m;j++){
			ans[i].push_back(a[j]/k);
		}
	}
	int rem[m]={};
	for(int i=0;i<m;i++)rem[i] = a[i] % k;
	for(int i=0;i<k;i++){
		for(int j=0;j<m;j++){
			if(rem[j]){
				ans[i][j]+=1;
				rem[j]--;
			}
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
}

#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll INF = 1001002003004005006ll;
constexpr int n_max = 2e5+10;

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<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;};
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); };

void LINE_OUT() {
  cout << "--------------" << endl;
};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif

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

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

vvi f(vi &A, string &s, int k) {
  int N = s.size();
  vvi ans(k, vi(N+1));
  rep(i,0,N+1) {
    int a = A[i];
    int q = a/k;
    int re = a%k;
    rep(j,0,k) {
      ans[j][i] += q;
    }
    rep(j,0,k) {
      if (re) {
        ans[j][i] += 1; re--;
      } else break;
    }
  }
  return ans;
};

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

  int N; cin >> N;
  string s; cin >> s;
  vi A(N+1); rep(i,0,N+1) cin >> A[i];

  int k = INF;
  rep(i,0,N) chmin(k, abs(A[i]-A[i+1]));

  vvi ans = f(A, s, k);

  cout << ans.size() << endl;
  for (vi &a: ans) {
    rep(i,0,N+1) {
      cout << a[i];
      if (i < N) cout << " ";
    }
    cout << endl;
  }

  return 0;
};


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

int main()
{
	#ifndef  ONLINE_JUDGE
		freopen("tpl.txt","r",stdin);
	#endif
	int n; cin >> n;
  	vector<int> vc;
  	for(int i = 0; i < 1 << n; i++)
    {
    	int tmp; cin >> tmp;
      	vc.push_back(tmp);
    }
  	int max_pos = max_element(vc.begin(),vc.end()) - vc.begin();
  	int half = 1 << (n-1);
  	auto start = max_pos < half ? vc.begin() + half : vc.begin();
  	int ans = max_element(start,start + half) - vc.begin();
  	cout << ans + 1<< endl;
  	return 0;
}

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

const int N = 2e5 + 5;

int n, ans, top = 0, stk[N];
char s[N];

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

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

    read(n);
    scanf("%s", s + 1);
    ans = n;
    for (int i = 1; i <= n; i++) {
        if (s[i] == 'f') {
            stk[++top] = i;
        } else if (s[i] == 'o') {
            if (s[stk[top]] == 'o') top = 0;
            else stk[++top] = i;
        } else if (s[i] == 'x') {
            if (top < 2) top = 0;
            else {
                if (s[stk[top - 1]] = 'f' && s[stk[top]] == 'o') {
                    top -= 2;
                    ans -= 3;
                } else top = 0;
            }
        } else top = 0;
    }
    printf("%d\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001001001001;
const int MOD = 1000000007;

int main(){
  int n;cin>>n;
  vector<ll> r;
  vector<ll> g;
  vector<ll> b;
  for(int i=0;i<2*n;i++) {
    ll a;char c;cin>>a>>c;
    if(c=='R') r.push_back(a);
    else if(c=='G') g.push_back(a);
    else if(c=='B') b.push_back(a);
  }
  sort(r.begin(),r.end());
  sort(g.begin(),g.end());
  sort(b.begin(),b.end());
  if(r.size()%2==0 && g.size()%2==0 && b.size()%2==0) cout << 0 << endl;
  else {
    if(r.size()%2==0) swap(r,b);
    else if(g.size()%2==0) swap(g,b);
    ll mi = INF;
    ll rbmi = INF;
    ll gbmi = INF;
    int rsize = r.size();
    int gsize = g.size();
    int bsize = b.size();
    if(bsize!=0) {
    for(int i=0;i<rsize;i++) {
      int idx = lower_bound(b.begin(),b.end(),r.at(i)) - b.begin();
      if(idx!=0 && idx!=bsize) {
        ll temp = min(abs(r.at(i)-b.at(idx)),
                      abs(r.at(i)-b.at(idx-1)));
        rbmi = min(rbmi,temp);
      } else if(idx==bsize) {
        ll temp = abs(r.at(i)-b.at(idx-1));
        rbmi = min(rbmi,temp);
      } else {
        ll temp = abs(r.at(i)-b.at(idx));
        rbmi = min(rbmi,temp);
      }
    }
    for(int i=0;i<gsize;i++) {
      int idx = lower_bound(b.begin(),b.end(),g.at(i)) - b.begin();
      if(idx!=0 && idx!=bsize) {
        ll temp = min(abs(g.at(i)-b.at(idx)),
                      abs(g.at(i)-b.at(idx-1)));
        gbmi = min(gbmi,temp);
      } else if(idx==bsize) {
        ll temp = abs(g.at(i)-b.at(idx-1));
        gbmi = min(gbmi,temp);
      } else {
        ll temp = abs(g.at(i)-b.at(idx));
        gbmi = min(gbmi,temp);
      }
    }
    mi = min(mi,rbmi + gbmi);
    }

    for(int i=0;i<rsize;i++) {
      int idx = lower_bound(g.begin(),g.end(),r.at(i)) - g.begin();
      ll mi2;
      if(idx!=0 && idx!=gsize) mi2 = min(abs(r.at(i)-g.at(idx)),
                                            abs(r.at(i)-g.at(idx-1)));
      else if(idx==gsize) mi2 = abs(r.at(i)-g.at(idx-1));
      else mi2 = abs(r.at(i)-g.at(idx));
      mi = min(mi,mi2);
    }
    cout << mi << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define int long long int
#define popcount(x) __builtin_popcountll(x)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define fr first
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define ld long double
// const int INF = __LONG_LONG_MAX__;
#define rall(a) (a).rbegin(),(a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroint-loops")

int power(int b,int e,int m)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
int power( int b, int e)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}
bool isPowerOfTwo(int x)
{
    // x wiint check if x == 0 and !(x & (x - 1)) wiint check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
}

int collinear(int x1, int y1, int x2,
               int y2, int x3, int y3)
{
    // Calculation the area of
    // triangle. We have skipped
    // multiplication with 0.5
    // to avoid floating point
    // computations
    int a = x1 * (y2 - y3) +
            x2 * (y3 - y1) +
            x3 * (y1 - y2);

    if (a == 0)
        return 1;
    else
        return 0;
}

void solve()
{
  int n;
  cin>>n;
  vector <pair<int,int> > v;
  for(int i=0;i<n;i++)
  {
    int a,b;
    cin>>a>>b;
    v.pb({a,b});
  }
  for(int i=0;i<n-2;i++)
  {
    for(int j=i+1;j<n-1;j++)
    {
      for(int k=j+1;k<n;k++)
      {
        if(collinear(v[i].fr,v[i].sc,v[j].fr,v[j].sc,v[k].fr,v[k].sc))
        {
          cout<<"Yes";
          return;
        }
      }
    }
  }
  cout<<"No";
}

signed main()
{
  fastio
  int tt=1;
  // cin>>tt;
  //  freopen("input.txt", "r" , stdin);
  // freopen("output.txt", "w", stdout);
  while(tt--)
  {
      solve();
      cout<<"\n";
  }
  return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
int n,m;
LL ans=0;
int main(){
	scanf("%d%d",&n,&m);
	char s[30];
	int sum=0;
	fo(i,1,n){
		scanf("%s",s);
		int u=0;
		fo(j,1,m){
			if(s[j-1]=='1')++u;
		}
		if(u&1){
			ans+=i-sum-1;
			++sum;
		}
		else ans+=sum;
	}
	printf("%lld",ans);
	return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
//using Graph = vector<vector<int>>;
typedef long long ll;
using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;

const int dy[4]={0,1,0,-1};
const int dx[4]={1,0,-1,0};
const ll INF=1e10;

int main(){
    ll n; cin>>n;
    vector<ll>a(n);
        map<ll,ll>mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }

    vector<bool>f(200010,true);
    rep(i,n){
        f[a[i]]=false;
    }
    ll maxdiff=0;
    rep(i,n+1){
        if(f[i]==true){
            maxdiff=i;
            break;
        }
    }
    vector<ll>ans(n);
    ans[0]=maxdiff;
    for(int i=1;i<n;i++){
        if(a[n-i]>=maxdiff){
            ans[i]=maxdiff;
        }
        else{
            if(mp[a[n-i]]==1){
                ans[i]=a[n-i];
                maxdiff=a[n-i];
                mp[a[n-i]]--;
            }
            else{
                mp[a[n-i]]--;
                ans[i]=maxdiff;
            }
        }
    }
    reverse(all(ans));
    rep(i,n){
        cout<<ans[i]<<endl;
    }

}

#include <iostream>
#include <cstring>
#include <cstdio>
#define LL long long
#define maxn 210005

using namespace std;

int n,a[maxn];
bool vis[maxn];

int main()
{
    memset(vis,0,sizeof(vis));
    scanf("%d",&n);
    for (int i=0;i<n;i++) scanf("%d",&a[i]);
    int now=0;
    for (int i=0;i<n;i++)
    {
        vis[a[i]]=1;
        while (vis[now]) now++;
        printf("%d\n",now);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	cout << ( A + B + C - min( { A, B, C } ) ) << endl;
	return 0;
}

// Created by Pratik
// NIT PATNA

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;

using namespace std;
#define M                    1000000007
#define pi                   3.14159265358979323846
#define ll                   long long
#define lld                  long double

// Pair
#define pii                  pair<int, int>
#define pll                  pair<ll, ll>

// Vector
#define vl                   vector<ll >
#define vi                   vector<int>
#define vpi                  vector<pii>
#define vpl                  vector<pll>
#define pb                   push_back
#define mp                   make_pair

// Search
#define lb                   lower_bound
#define ub                   upper_bound
#define mina                 *min_element
#define mama                 *max_element
#define bsrch                binary_search

////////
#define F                    first
#define S                    second
#define cel(x,a)             (((x) + (a) - 1) / (a))
#define all(v)               v.begin(), v.end()
#define allrev(v)            v.rbegin(), v.rend()
#define lcm(m, n)            ((m / __gcd(m, n))*n)
#define deb(...)             cerr << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__)
#define ms(arr, v)           memset(arr, v, sizeof(arr))
#define ps(x,y)              fixed << setprecision(y) << x
#define _X_                  ios_base::sync_with_stdio(false); cin.tie(NULL)

//pbds
#define ordered                 tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

// Input / Output
#define scn(str)             scanf("%s", str)
#define pri(str)             printf("%s\n", str)

const int N = 2.5e6 + 4;

inline void  dbg()           { cerr << endl; }

template <typename T, typename... V>
inline void  dbg(T t, V... v) {cerr << ' ' << t; dbg(v...);}

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

void solve()
{
    //int n;
    //cin>> n;
    int arr[3];
    for(int &i:arr)cin >> i;
    sort(arr,arr+3);
    cout << arr[2]+arr[1] << "\n";

}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    // clock_t time_req = clock();

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

   }

    // time_req = clock() - time_req;
    // cout << (float)time_req / CLOCKS_PER_SEC;
   return 0;
}


// a(i) a(i+1)
// a(i+1)+1  a(i)-1
//
// a(i) + i
//
// A =        8 5 4 7 4 5
// A(i) + i = 8 6 6 10 8 10
// B(i) + i = 10 6 8 10 8 6
//
// B =        10 5 6 7 4 1

#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i)
#define FORD(i, a, b) for (int i = (a), _##i = (b); i >= _##i; --i)
#define REP(i, a) for (int i = 0, _##i = (a); i < _##i; ++i)

#define DEBUG(X) { auto _X = (X); cerr << "L" << __LINE__ << ": " << #X << " = " << (_X) << endl; }
#define PR(A, n) { cerr << "L" << __LINE__ << ": " << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << "L" << __LINE__ << ": " << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define TWO(x) (1LL<<(x))
inline int gcd(int a, int b) {int r; while (b) {r = a % b; a = b; b = r;} return a;}

// for 64-bit, use mt19937_64
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// use shuffle instead of random_shuffle
#define random_shuffle askcjaljc

const int MN = 200111;
int a[MN], b[MN], bit[MN];
int n;
map<int, vector<int>> ids;

void update(int u) {
    for (int x = u; x <= n; x += x & -x) {
        bit[x]++;
    }
}

int get(int u) {
    int res = 0;
    for (int x = u; x > 0; x -= x & -x) {
        res += bit[x];
    }
    return res;
}

int32_t main() {
    ios::sync_with_stdio(0);
    while (cin >> n) {
        ids.clear();
        memset(bit, 0, sizeof bit);

        FOR(i,1,n) {
            cin >> a[i];
            a[i] += i;

            ids[a[i]].push_back(i);
        }
        FOR(i,1,n) {
            cin >> b[i];
            b[i] += i;
        }

        try {
            int res = 0;
            FORD(i,n,1) {
                if (ids[b[i]].empty()) {
                    throw 1;
                }

                int x = ids[b[i]].back();
                ids[b[i]].pop_back();

                res += get(x-1);
                update(x);
            }
            cout << res << endl;
        } catch (...) {
            cout << -1 << endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int n,a[maxn],b[maxn];
ll sum1,sum2;
int tot,head[maxn],pos[maxn];
unordered_map<int,int>mapp;
vector<int>qwq[maxn],Tmp;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),sum1+=a[i];
	for(int i=1;i<=n;++i) scanf("%d",&b[i]),sum2+=b[i];
	if(sum1!=sum2) puts("-1"),exit(0);
	for(int i=1;i<=n;++i) {
		if(!mapp[a[i]+i]) mapp[a[i]+i]=++tot;
		qwq[mapp[a[i]+i]].push_back(i);
	}
	int flag=1;
	for(int i=1;i<=n;++i) {
		int p=mapp[b[i]+i];
		if(head[p]==qwq[p].size()) flag=0;
		else pos[i]=qwq[p][head[p]],head[p]++;
		Tmp.push_back(i);
	}
	if(!flag) puts("-1"),exit(0);
	ll ans=0;
	for(int i=1;i<=n;++i) {
		int p=lower_bound(Tmp.begin(),Tmp.end(),pos[i])-Tmp.begin();
		ans+=p;
		Tmp.erase(Tmp.begin()+p);
	}
	printf("%lld\n",ans);
	return 0;
}


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

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

  vector<ll>A(N+1,0);
  for (int i=1;i<A.size();i++)
    cin>>A.at(i);

  vector<ll>p(N+1,0);
  vector<ll>q(N+1,0);
  for (int i=0;i<A.size()-1;i++){
    p.at(i+1)=p.at(i)+A.at(i+1);
    q.at(i+1)=q.at(i)>p.at(i+1)?q.at(i):p.at(i+1);
  }

  ll x=p.at(0);
  ll ans=q.at(0);
  for (int i=1;i<A.size();i++){
    ans=ans>x+q.at(i)?ans:x+q.at(i);
    x+=p.at(i);
  }

  cout<<ans<<endl;

  return 0;
}

/*
 *author:DJ
 *CODE GIVEN ABOVE ;)
 */
#pragma GCC optimize "trapv"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define sq(a) a*a
const double pi = 2 * acos(0.0) ;
using namespace std ;
using ll = long long ;
template<typename... T>
void read(T&... args){
    ((cin >> args),...) ;
}

int main(){
#ifdef LOCAL
    freopen("in1","r",stdin) ;
#endif
    ios::sync_with_stdio(0) ;
    cin.tie(nullptr) ;
    int a,b,c ; read(a,b,c) ;
    cout << a + (c-b) << "\n" ;

#ifdef LOCAL
    cerr <<"The time elapsed is: " << 1.0 * clock()/CLOCKS_PER_SEC << "s.\n" ;
#endif
	return 0 ;
}


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

string s;
bool ch1,ch2;

int main(){
	cin>>s;
	ch1=true;
    ch2=true;
	for(int i = 0;i < s.size();i+=2){
		if(s[i] >='a' && s[i] <= 'z') continue;
		else{
			ch1=false;
			break;
		}
	}
	for(int i = 1;i < s.size();i+=2){
		if(s[i] >= 'A'&& s[i] <= 'Z') continue;
		else{
			ch2=false;
			break;
		}
	}
	if(ch1 & ch2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    cout<<n-1<<endl;
}


// Problem: B - Gentle Pairs
// Contest: AtCoder - AtCoder Beginner Contest 187
// URL: https://atcoder.jp/contests/abc187/tasks/abc187_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

const int max_n = 1e5 + 9;
const int mod = 1e9 + 7;
const int inf = 1e9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}

int check(pair<int , int> x , pair<int , int> y){
	return abs(x.ff - y.ff) >= abs(x.ss - y.ss);
}

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

	pair<int , int> a[n];
	for(int i = 0 ; i < n ; i++){
		int x , y;
		cin >> x >> y;
		a[i] = {x , y};
	}

	int ans = 0;
	for(int i = 0 ; i < n ; i++){
		for(int j = i+1 ; j < n ; j++){
			// if(i == j)continue;
			ans += check(a[i] , a[j]);
			debug(i , j , check(a[i] , a[j]));
		}
	}

	cout << ans << "\n";
}
signed main(){
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ; i++){
		solve();
	}
}

//git pull --rebase origin master
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define 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 wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
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);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
ll int gcd(ll int a, ll int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int tc=1;
void solve()
    {
        ll int n;
        cin>>n;
        if(n%2)
        {
            cout<<"Black\n";
        }
        else
        {
            cout<<"White\n";
        }

    }

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

    // wi(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);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


#include <stdio.h>
#include <iostream>
#include <vector>
// #include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,k,n) for(ll i=k; i<(ll)(n); i++)
#define Q 1000000007

ll max(vector<ll> a) {
    return *max_element(a.begin(), a.end());
}

ll max_index(vector<ll> a) {
    vector<ll>::iterator max_it = max_element(a.begin(), a.end());
    return distance(a.begin(), max_it);
}

int main(){
    ll r1,r2,c1,c2;
    cin >> r1 >> c1;
    cin >> r2 >> c2;

    ll r = r1-r2, c = c1-c2;
    ll ans = 3;
    if(r==0 && c==0) ans = 0;
    else if(r==c || r+c==0 || abs(r)+abs(c)<=3) ans = 1;
    else if((r1+r2+c1+c2)%2==0 || abs(r)+abs(c)<=6 || abs(r+c)<=3 || abs(r-c)<=3) ans = 2;

    cout << ans << endl;

    return 0;
}

	/*It is better to taste failure
	  than to regret*/

            #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;

        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define Test(){int t;cin >> t;for(int i=1;i<=t;i++){cout << "Case #" << i << ": ";solve();}}
        #define test(){int t; cin>>t; for(int i=1;i<=t;i++){solve();}}
        #define vi vector<int>
        #define vii vector<pair<int,int> >
        #define vci vector<pair<char,int> >
        #define vic vector<pair<int,char> >
        #define N 200005
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;

        int maxSumsubarray(int arr[], int n, int maxSum){
   int sum = arr[0], overallMax = 0, start = 0;
   for (int i = 1; i < n; i++) {
      if (sum <= maxSum)
      overallMax = max(overallMax, sum);
      while (sum + arr[i] > maxSum && start < i) {
         sum -= arr[start];
         start++;
      }
      sum += arr[i];
   }
   if (sum <= maxSum)
      overallMax = max(overallMax, sum);
   return overallMax;
}
        void solve()
        {

        	int a,b,c,d;
	cin >>a>>b>>c>>d;
	if(a==c && b==d){
		cout << "0\n";
		return;
	}
	if(a-b == c-d || a+b == c+d){
		cout << "1\n";
		return;
	}
	else if(abs(a-c) + abs(b-d) <= 3){
		cout << "1\n";
		return;
	}
	if((a+b)%2 == (c+d)%2){
		cout << "2\n";
	}
	else{

		for(int i=-3;i<=3;i++){
			for(int j=-3;j<=3;j++){
				int x = c + i;
				int y = d + j;
				if(abs(c-x) + abs(d-y) <= 3){
					if(x-y == a-b || x+y == a+b){
						cout << "2\n";
						return;
					}
				}
			}
		}
		cout << "3\n";
	}

		}
        signed main()
        {
        //	test();
        solve();
		}


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

// input
int N;
vi A;

void input() {
    cin >> N;
    A = vi(N);
    rep(i, N) cin >> A[i];
}

int main() {
    input();
    ll ans = 0;
    ll x = 0;
    ll s = 0;
    ll mx = 0;
    rep(i, N) {
        s += A[i];
        mx = max(mx, s);
        ans = max(ans, x + mx);
        x += s;
    }
    cout << ans << endl;
}

//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
struct Init { Init(){
    cin.tie(0); ios::sync_with_stdio(false);
} } init;
//}}}

int main(){
    // for(int i = 1; i < 1000; i++){
    //     int e = 0, o = 0;
    //     for(int j = 1; j <= i; j++){
    //         if(i % j == 0){
    //             (j & 1 ? o : e)++;
    //         }
    //     }
    //     printe(i, e, o, e < o ? "Odd" : e == o ? "Same" : "Even");
    // }
    int t; cin >> t;
    vector<string> strs({"Even", "Odd", "Same", "Odd"});
    for(int _ = 0; _ < t; _++){
        ll n; cin >> n;
        cout << strs[n & 3] << '\n';
    }
}


#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

template<typename T>
void printArray(vector<T> &printVec) {
    if(printVec.empty()) return;
    cout << printVec[0];
    for(int i = 1; i < printVec.size(); ++i) cout << " " << printVec[i];
    cout << endl;
}

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;

    int res = INF;
    vector<int> a(N), b(N);
    for(int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
        res = min(res, a[i] + b[i]);
    }

    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            if(i == j) continue;
            res = min(res, max(a[i], b[j]));
        }
    }
    cout << res << endl;

    return 0;
}

#include<cstdio>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
using namespace std;
const int N=1005,INF=0x3fffffff;
template<typename T>void read(T &x)
{
	bool neg=false;
	unsigned char c=getchar();
	for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
	for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
	if(neg)x=-x;
}
int n,a[N],b[N],min=INF,ans=INF;
int main()
{
	read(n);F(i,0,n)read(a[i]),read(b[i]);
	F(i,0,n)
	{
		if(b[i]<ans&&min<ans)ans=b[i]>min?b[i]:min;
		if(b[i]+a[i]<ans)ans=b[i]+a[i];
		min=a[i]<min?a[i]:min;
	}
	min=INF;
	for(int i=n-1;~i;--i)
	{
		if(b[i]<ans&&min<ans)ans=b[i]>min?b[i]:min;
		if(b[i]+a[i]<ans)ans=b[i]+a[i];
		min=a[i]<min?a[i]:min;
	}
	printf("%d\n",ans);
	return 0;
}


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

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

    if(a == b && b == c)cout << "Won";
    else cout << "Lost";
}

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<queue>
#include<stack>
#include<utility>
#include<map>
using namespace std;

typedef long long ll;
typedef long double lb;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

using Graph = vector<vector<int>>;

#define FOR(i, a, b) for(ll i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

const ll INF=2e9+1;	//for some test case (near inf)
const ll INFLL=1e18;
const ll MOD=998244353;

int main(void){
	string S;
	cin >> S;
	if(S[0]==S[1]&&S[1]==S[2]) cout << "Won" << endl;
	else cout << "Lost" << endl;

	return 0;
}


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

//using int = long long int;
using ll = long long int;
using pii = pair < int, int >;

#define ff first
#define ss second
#define endl '\n'
#define pb push_back

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, j, n)	for(int i = j; i < n; i++)
#define ren(i, j, n)	for(int i = n-1; i >= j; i--)

#define cerr cout
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v) {
    cerr << t; if(sizeof...(v)) cerr << ", "; _print(v...);
}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

const int mod = 1000000007;

void io_set(){
    #ifndef ONLINE_JUDGE
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
    #endif
}

void solve(){
    int a, b, c;	cin >> a >> b >> c;
    cout << (((c*c - a*a - b*b) > 0)? "Yes" : "No") << endl;
}

signed main(int argc, char **argv){
    //io_set();
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if( A*A + B*B < C*C ) cout << "Yes";
  else cout << "No";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
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; }
//mod Inverse
long long modInverse(long long a, long long m)   //m and a should be coprime.
{
    long long m0 = m;
    long long y = 0, x = 1;
    if (m == 1)
      return -1;
    while (a > 1)
    {
        long long q = a / m;
        long long t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}
// HERE a = numerator, b = denominator, m = mod;
long long modDivide(long long a, long long b, int m)
{
    a = a % m;
    long long inv = modInverse(b, m);
    if (inv == -1)
       return -1;
    else    {
        long long ans = (inv * a) % m;
        return ans;
    }
}
int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, s, k;
        cin >> n >> s >> k;
        ll g = __gcd(k, n);
        if(s%g != 0)    {
            cout << "-1" << "\n";
        }
        else    {
            n /= g, k /= g, s /= g;
            ll a = n-s;
            ll b = k;
            cout << modDivide(a, b, n) << "\n";
        }
    }

}

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <queue>

#define	INF   1010101010LL
#define INFLL 1010101010101010101LL

using namespace std;

const int mod = 1000000007;
//const int mod = 998244353;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n), p(n), x(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> p[i] >> x[i];
	}

	int mn = INF;
	for (int i = 0; i < n; i++) {
		if (x[i] - a[i] > 0) {
			mn = min(mn, p[i]);
		}
	}
	cout << (mn == INF ? -1 : mn) << endl;

	return 0;
}


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

int main() {
    char S, T;
    cin >> S >> T;

    if(S=='Y'){
        char s = toupper(T);
        cout <<s<< endl;
    }else{
        cout << T << endl;
    }
}

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[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;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

bool is_sum_overflow(ll a, ll b)
{
    if (a < LLONG_MAX / 2)
    {
        if (b < LLONG_MAX / 2)
            return false;
        else
            return ((b - LLONG_MAX / 2) + a > LLONG_MAX / 2);
    }
    else
    {
        if (b < LLONG_MAX / 2)
            return true;
        else
            return ((a - LLONG_MAX / 2) + b > LLONG_MAX / 2);
    }
}
bool isOK(ll mid, string X, ll M)
{
    ll sum = 0;
    for (int i = X.size() - 1; i >= 0; i--)
    {

        ll tmp = X[i] - '0';
        for (int j = 0; j < X.size() - i - 1; j++)
        {
            ll prev = tmp;

            if (tmp >= LLONG_MAX / mid)
            {
                // 多分オーバーフローしたからMは超えてる
                return true;
            }
            tmp *= mid;
        }

        if (is_sum_overflow(sum, tmp))
        {
            // overflow下からMは超えてる
            return true;
        }
        sum += tmp;
    }

    if (sum > M)
    {

        return true;
    }
    else
    {
        return false;
    }
}

void solve(std::string X, long long M)
{
    if (X.length() == 1)
    {
        ll d = (X[0] - '0');
        if (d <= M)
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return;
    }
    ll d = 0;
    for (int i = 0; i < X.size(); i++)
    {
        d = max(d, (ll)(X[i] - '0'));
    }
    ll left = d;
    ll right = 1e18;
    right += 10;

    while (right - left > 1)
    {
        ll mid = left + (right - left) / 2;
        if (isOK(mid, X, M))
            right = mid;
        else
            left = mid;
    }
    cerr << left << endl;
    cout << left - (d + 1) + 1 << endl;
}

int main()
{

    std::string X;
    std::cin >> X;
    long long M;
    scanf("%lld", &M);
    solve(X, M);
    return 0;
}


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

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> w(N);
    REP(i, N) cin >> w[i];
    vector<ll> l(M), v(M);
    REP(i, M) cin >> l[i] >> v[i];
    vector<ll> vec = v;
    sort(ALL(vec));
    vec.erase(unique(ALL(vec)), vec.end());
    int sz = vec.size();
    vector<ll> mi(sz + 1);
    REP(i, M) {
        int idx = lower_bound(ALL(vec), v[i]) - vec.begin();
        chmax(mi[idx], l[i]);
    }
    REP(i, sz) chmax(mi[i + 1], mi[i]);
    vector<int> perm(N);
    iota(ALL(perm), 0);
    ll ans = INF;
    do {
        vector<ll> pos(N);
        vector<vector<PII>> G(N, vector<PII>());
        bool NG = 0;
        REP(i, N) {
            ll sum = 0;
            FOR(j, i, N) {
                sum += w[perm[j]];
                int idx = lower_bound(ALL(vec), sum) - vec.begin();
                if (idx > 0) {
                    if (i == j) {
                        cout << -1 << endl;
                        return 0;
                    }
                    G[i].emplace_back(j, mi[idx - 1]);
                }
            }
        }
        REP(i, N) {
            for (auto [to, len] : G[i]) {
                chmax(pos[to], pos[i] + len);
            }
        }
        chmin(ans, pos[N - 1]);
    } while (next_permutation(ALL(perm)));
    cout << ans << endl;
}

#include<bits/stdc++.h>
#define llinf 4154118101919364364

using namespace std;

long long n,m;
long long w[32],l[131072],v[131072];
long long res=llinf;
long long sigw[1024]={0};
map<long long,long long> mp;

long long find(long long wei){
  if(mp[wei]!=-1){return mp[wei];}
  long long d=0;
  for(int i=0;i<m;i++){
    if(v[i]<wei){d=max(l[i],d);}
  }
  mp[wei]=d;
  return mp[wei];
}

long long p[16],d[16];
void rep(long long fl,long long cnt){
  //cerr << fl << ' ' << d[cnt-1] << '\n';
  if(cnt==n){
    res=min(d[n-1],res);
    return;
  }
  for(int i=0;i<n;i++){
    if(!(fl&(1ll<<i))){continue;}
    p[cnt]=i;
    d[cnt]=0;
    long long cw=0;
    for(int j=0;j<cnt;j++){
      cw+=w[p[j]];
    }
    cw+=w[i];
    for(int j=0;j<cnt;j++){
      //cout << fl << ' ' << j << ' ' << cw  << ' ' << find(cw)<< '\n';
      d[cnt]=max(d[j]+find(cw),d[cnt]);
      cw-=w[p[j]];
    }
    rep(fl^(1ll<<i),cnt+1);
  }
  return;
}

int main(){
  long long mr=0;
  scanf("%lld%lld",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%lld",&w[i]);
    mr=max(w[i],mr);
  }
  for(int i=0;i<m;i++){
    scanf("%lld%lld",&l[i],&v[i]);
    if(v[i]<mr){puts("-1");return 0;}
  }
  mp[0]=0;
  for(int i=1;i<(1ll<<n);i++){
    for(int j=0;j<n;j++){
      if(i&(1ll<<j)){sigw[i]+=w[j];}
    }
    mp[sigw[i]]=-1;
    //cout << sigw[i] << '\n';
  }
  rep((1ll<<n)-1,0);
  printf("%lld\n",res);
  return 0;
}


#include <bits/stdc++.h>
#define mod 1000000007
#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vi vector<int>
#define vl vector<ll>
#define REP(s, e) for (auto i = s; i <= e; i++)
#define show(s) cout<<s<<" "
#define MAXI 2147483647
#define MAXL 9223372036854775807
#define FOR(a,b) for (ll i = a; i < b; i++)
using namespace std;
typedef signed long long int ll;

int main() {
    fast_io;
    int a,b,c; cin >> a >> b >> c;
    cout << 21 - (a+b+c);
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout <<"\n"<< (#x) << " = " << (x) << "\n"
using pi = pair<int,int>;
using vi = vector<int>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi> ;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define loop(i,a,b) for(int i = (a); i <=(b); ++i)
#define loopr(i,a,b) for(int i = (a); i >= (b); --i)
#define trav(a,x) for (auto& a: x)
#define rep(i,n) for(int i = 0 ; i<n ; ++i)
#define max3(a,b,c) max(a,max(b,c))
const int MOD = 1e9+7; // 998244353;
const int INF = 1e18;
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; // for every grid problem!!

/*

*/

void solve()
{
	int a,b,x,y;
	cin>>a>>b>>x>>y;

	int ans=x ;

	if(a==b)
	{
		cout<<ans<<"\n";
		return;
	}
	else if(a<b)
	{
		int op1=(b-a)*y;
		int op2=(b-a)*2*x;
		ans=ans+min(op2,op1);
		cout<<ans<<"\n";
		return ;
	}
	else
	{
		ans=0;
		int op1=(a-b-1)*y+x;
		int op2=2*(a-b-1)*x+x ;
		// deb(op2);
		ans=ans+min(op1,op2);
		cout<<ans<<"\n";
		return;
	}

}

int32_t main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int t=1;
// cin>>t;
while(t--){
	solve();
}
	return 0;
}


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include<numeric>//gcd(,),lcm(,)
#include<cmath>//sin(),cos(),tan()  kodoho
#include<ctime>//jikan(clock.())
#include <stdio.h>
#include <cstring>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 10000000;
using ll = long long;

int main() {

	set<int>mar;
	set<int>bat;
	for (int i = 0; i < 10; i++) {
		char k;
		cin >> k;
		if (k == 'o') {

			mar.insert(i);
		}
		if (k == 'x') {

			bat.insert(i);
		}

	}
	ll ans = 0;
	for (int i = 0; i <= 9999; i++) {
		set<int>L = mar;

		bool OK = true;
		for (int h = 0; h<4; h++) {
			int c = pow(10, h);
			int G = i /c ;
			G = G % 10;
			if (L.count(G)) {
				L.erase(G);
			}
			if (bat.count(G)) {
				OK = false;
				break;
			}

		}
		if (OK == true) {
			if (L.empty()) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}

class SegTree {
public:
  ////////////////////////////////////////////////////////
  // monoid
  using X = long long;
  X X_dot_X(const X &v1, const X &v2) {
    return v1 + v2;
  }
  const X X_unit = 0;
  ////////////////////////////////////////////////////////
  typedef size_t idx_type;

  vector<X> data;

  idx_type n;

  SegTree(idx_type n_) {
    n = 1;
    while(n <= size_t(n_)) {
      n *= 2;
    }
    data.resize(n * 2 - 1, X_unit);
  }
  ~SegTree() {}

  X query(idx_type a, idx_type b, idx_type k, idx_type l, idx_type r) {
    if(r <= a || b <= l) {
      return X_unit;
    }

    if(a <= l && r <= b) {
      return data[k];
    }
    else {
      X vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      X vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return X_dot_X(vl, vr);
    }
  }

  X query(idx_type a, idx_type b) {
    return query(a, b, 0, 0, n);
  }

  void update(idx_type i, X x) {
    i += n - 1;
    data[i] = x;
    while(i > 0) {
      i = (i - 1) / 2;
      data[i] = X_dot_X(data[i*2+1], data[i*2+2]);
    }
  }
};

int main(int argc, char *argv[]) {
  i64 H, W, M, i, x;
  cin >> H >> W >> M;
  map<i64, vi> D;
  REP(0, M, i) {
    i64 x, y;
    cin >> y >> x;
    x--; y--;
    D[y].pb(x);
  }
  for(auto &p: D) {
    sort(all(p.second));
  }

  if(D.empty()) {
    cout << H*W << endl;
    return 0;
  }

  i64 y_prev = -1;
  i64 ans = 0;
  bool blk = false;
  SegTree tree(W);
  REP(0, W, x) {
    tree.update(x, 1);
  }
  for(auto &d: D) {
    const i64 &y = d.first;
    vi &v = d.second;
    if(y == 0) {
      i64 x0 = v[0];
      REP(x0, W, x) {
        tree.update(x, 0);
      }
      ans += x0;
    }
    else {
      i64 dy = y - y_prev - 1;
      if(blk) {
        ans += dy * tree.query(0, W);
        //cerr << "interval " << dy * tree.query(0, W) << endl;
      }
      else {
        ans += dy * W;
        //cerr << "interval " << dy * W << endl;
      }
      for(auto &vv: v) {
        tree.update(vv, 0);
      }

      i64 x0 = v[0];
      if(x0 == 0) {
        blk = true;
      }

      if(blk) {
        ans += tree.query(0, W);
      }
      else {
        ans += tree.query(x0, W) + x0;
      }
      //cerr << "y " << tree.query(x0, W) + x0 << endl;
    }
    //cerr << y_prev << " " << y << " " << ans << endl;
    y_prev = y;
  }
  if(blk) {
    ans += (H - y_prev - 1) * tree.query(0, W);
  }
  else {
    ans += (H - y_prev - 1) * W;
  }
  cout << ans << endl;

  return 0;
}


#include <iostream>
#include <string>
#include <math.h>
using namespace std;
typedef long long llong;

int main()
{
    string s;
    llong sum = 0;
    llong i = 0;
    cin >> s;
    int n = s.length() - 1;
    for (i = 0; i <= n - 1; i++)
    {
        sum += (llong)((pow(10, i + 1) - pow(10, i)) * (i / 3));
    }
    llong t = stoll(s);
    sum += (t - pow(10, i) + 1) * (i / 3);
    cout << sum << endl;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
typedef long long ll;
const int N=1e5+10;
int n,a[N],b[N],c[N],x;ll ans;
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i),ans+=a[i];
	rep(i,1,n) scanf("%d",&x),i&1?b[i+1>>1]=x-a[i]:c[i>>1]=x-a[i];
	sort(b+1,b+(n>>1)+1);sort(c+1,c+(n>>1)+1);
	rep(i,1,n>>1) if(b[i]+c[i]>0) ans+=b[i]+c[i];
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl ("\n")
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

int32_t main(){
    fast
    int t=1;
    // cin>>t;
    while(t--){
        int n, k;cin>>n>>k;
        vector<pair<int, int>>vv, v;
        map<int, int>mm;
        set<int>s;
        rep(i, n){
            int x, y;cin>>x>>y;
            mm[x]+=y;
            s.insert(x);
        }

        for(auto i:s){
            v.pb({i, mm[i]});
        }

        // for(auto i:v){
        //     cout<<i.ff<<" "<<i.ss<<endl;
        // }
        sort(all(v));
        int pre[v.size()+1]={0};
        int val[v.size()+1]={0};
        pre[0]=v[0].ff, val[0]=v[0].ss;
        for(int i=1;i<v.size();i++){
            pre[i]=v[i].ff+pre[i-1];
            val[i]=v[i].ss+val[i-1];
        }

        int ans=k, stop=0;;
        for(int i=0;i<v.size();i++){
            if(ans>=(v[i].ff-stop) and stop!=v[i].ff){
                ans =k+val[i];
                ans-=v[i].ff;
                stop=v[i].ff;
            }
            else if(stop==v[i].ff){
                ans+=v[i].ss;
            }
            else break;
        }
        // cout<<stop<<" "<<ans<<endl;
        cout<<stop+ans<<endl;
    }
    return 0;
}