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

#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> ii;

double a, b, c, d;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    cout << fixed << setprecision(12);
    cout << a + b*(c-a)/(b+d) << '\n';
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T>
void read(T &x) {
	x = 0; char c = getchar(); int f = 0;
	for (; !isdigit(c); c = getchar())
		f |= c == '-';
	for (; isdigit(c); c = getchar())
		x = x * 10 + (c ^ '0');
	if (f) x = -x;
}

template <typename T>
void write(T x, char ed = '\n') {
	if (x < 0) putchar('-'), x = -x;
	static short st[30], tp;
	do st[++tp] = x % 10, x /= 10; while (x);
	while (tp) putchar(st[tp--] | '0');
	putchar(ed);
}

int ans[23453], cnt, lim = 90;
ll f[43242], n;
int main() {
	//srand((ll)new char ^ time(0));
	//n = (1e18) - rand();
	read(n);
	f[0] = f[1] = 1;
	for (int i = 2;i <= lim; ++i) f[i] = f[i - 1] + f[i - 2];
	for (int i = 1;i <= lim; ++i) {
		if (n >= f[lim - i + 1]) ans[++cnt] = 2 - (i & 1), n -= f[lim - i + 1];
		if (cnt) ans[++cnt] = 3 + (i & 1);
	}
	write(cnt);
	for (int i = 1;i <= cnt; ++i) write(ans[i]);
	//ll x = 0, y = 0;
	//for (int i = 1;i <= cnt; ++i) {
		//if (ans[i] == 1) ++x;
		//else if (ans[i] == 2) ++y;
		//else if (ans[i] == 3) x += y;
		//else y += x;
	//}
	//write(x, ' '), write(y);
	return 0;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll A[200001], B[200001], tmp[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
const int CM = 400001, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

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

	int N = getint();
	rep(i, N) {
		A[i] = ll(i) << 32 | getint();
		B[i] = ll(i) << 32 | getint();
	}
	pakuri_sort(N, A);
	pakuri_sort(N, B);

	const ll ma = (1ll << 32) - 1;
	rep(i, N) {
		auto tmp = (A[i] & ma) < (B[N - 1 - i] & ma);
		cn[A[i] >> 31] = tmp;
		cn[B[N - 1 - i] >> 31 | 1] = tmp;
	}

	int c = -1, pn = 0;
	rep(i, N << 1) {
		if (c != -1 && pn == cn[i]) {
			cn[c] = '(';
			cn[i] = ')';
			c = tmp[c];
			pn ^= 1;
		}
		else {
			pn = cn[i];
			tmp[i] = c;
			c = i;
		}
	}
	fwrite(cn, 1, N << 1, stdout);

	Would you please return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long; //mp::int128_t; //mp::_int512_tなど //256, 1024
#define sz(x) int(x.size()) //size_tはunsigned
using P = pair<int,char>;

int main() {
    string s;
    cin >> s;
    char last;
    bool first = true;
    int ssize = sz(s);
    ll ans=0;
    vector<P> v;
    for(int i=0;i<ssize-2;i++) {
        if(s[i] == s[i+1] && s[i] != s[i+2]) {
            v.push_back({i+2,s[i]});
        }
    }
    int vsize = sz(v);
    if(vsize == 0) {
        cout << 0 << endl;
        return 0;
    }
    last = v.back().second;
    v.pop_back();
    int c = 0;
    for(int i=ssize-1;i>=2;i--) {
        if(last == s[i]) c++;
        if(s[i-2] == s[i-1] && s[i-1] != s[i]) {
            // last = s[i-1];
            string tmp = s.substr(i,ssize-i);
            // int t = count(tmp.cbegin(),tmp.cend(), last);
            ans += ssize - i -c;
            // string rp(ssize-t,last);
            // s.replace(i,ssize-t,rp);
            if(sz(v) == 0) break;
            char h = v.back().second;
            v.pop_back();
            if(h==last) c=ssize-i;
            else c=0;
            last = h;
        }
    }

    // for(int i=ssize-1;i>=2;i--) {
    //     if(s[i-2] == s[i-1] && s[i-1] != s[i]) {
    //         last = s[i-1];
    //         string tmp = s.substr(i,ssize-i);
    //         int t = count(tmp.cbegin(),tmp.cend(), last);
    //         ans += ssize - i -t;
    //         string rp(ssize-t,last);
    //         s.replace(i,ssize-t,rp);

    //     }
    // }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
//sort(myVec.begin(),myVec.end(),[](const vector<int> &alpha,const vector<int> &beta){return alpha[0] < beta[0];});
using ll = long long;
using ldb = long double;

int main() {
  int N; cin >> N;
  int s = N*1.08;
  if( s == 206) {
    cout << "so-so" << endl;
  }
  else if( s > 206) {
    cout << ":(" << endl;
  }
  else if( s < 206) {
    cout << "Yay!" << endl;
  }

}

#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 n;
	cin >> n;
	int res = (n * 1.08) * 1;
	if (res < 206) cout << "Yay!" << endl;
	else if (res == 206) cout << "so-so" << endl;
	else cout << ":(";
}

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 <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	int N;
	cin >> N;
	set<string> memo;
	rep(i, N)
	{
		string S;
		cin >> S;
		auto it = memo.find(S);
		if (it != memo.end()) {
			auto ans = (*it)[0] == '!' ? it->substr(1) : *it;
			cout << ans << endl;
			return 0;
		}
		memo.insert(S[0] == '!' ? S.substr(1) : "!" + S);
	}
	cout << "satisfiable" << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED                       \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);

// Aakash

int32_t main() {
     SPEED;

	int n;
	cin>>n;
	vector<int> a(3,0);
	int temp=n;
    int digit=0;
    int sum=0;
    while(temp>0)
    {
        a[(temp%10)%3]++;
        sum+=temp%10;
        temp/=10;
        digit++;
    }

    if(sum%3==0)
    cout<<0;

    else if(sum%3==1)
    {
        if(a[1]>0 && digit!=1)
        {
            cout<<1;
        }
        else if(a[1]>0 && digit==1)
        {
            cout<<-1;
        }
        else
        {
            if(a[2]>1 && digit>2 )
            {
                cout<<2;
            }
            else
            {
                cout<<-1;
            }

        }
    }
    else if(sum%3==2)
    {
        if(a[2]>0 && digit!=1)
        {
            cout<<1;
        }
        else if(a[2]>0 && digit==1)
        {
            cout<<-1;
        }
        else
        {
            if(a[1]>1 && digit>2)
            {
                cout<<2;
            }
            else
            {
                cout<<-1;
            }
        }
    }
    return 0;
}


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

int N;
string S, X;
vector<int> v;

int main() {
    cin >> N >> S >> X;
    v.resize(N);
    for (int i = N - 1, a = 1; i >= 0; i--, a = a * 10 % 7) {
        v[i] = a * (S[i] - '0') % 7;
    }
    vector<vector<bool>> dp(N + 1, vector<bool>(7));
    dp[N][0] = true;
    for (int i = N - 1; i >= 0; i--) {
        if (X[i] == 'T') {
            for (int j = 0; j < 7; j++) {
                dp[i][j] = dp[i+1][j] || dp[i+1][(j-v[i]+7) % 7];
            }
        } else {
            for (int j = 0; j < 7; j++) {
                dp[i][j] = dp[i+1][j] && dp[i+1][(j-v[i]+7) % 7];
            }
        }
    }
    cout << (dp[0][0] ? "Takahashi" : "Aoki") << endl;
}

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

int main() {
	int r1, r2, c1, c2;
	int result = 0;

	cin >> r1 >> c1;
	cin >> r2 >> c2;

	if (r1 == r2 && c1 == c2) {
		result = 0;
	}
	else if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2 || abs(r1 - r2) + abs(c1 - c2) <= 3) {
		result = 1;
	}
	else if((r1+c1)%2==(r2+c2)%2||abs(r1-r2+c1-c2)<=3||abs(r1-r2-c1+c2)<=3){
		result = 2;
	}
	else {
		result = 3;
	}

	cout << result;
	return 0;
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 400005;
const int INF = 1e12;
signed main()
{
    FAST
    int tc=1;
    // cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        ld r,x,y;
        cin>>r>>x>>y;
        x *= x;
        y *= y;
        ld d = sqrt(x+y);
        int ans = d/r;
        ans += (1 + (!ans))*(ans*r != d);
        cout<<ans<<endl;
    }
    return 0;
}

//
#include <bits/stdc++.h>
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	int a,b,x,y;
	cin>>a>>b>>x>>y;
	if(b>a){
		if(2*x<y)
			cout<<(b-a)*2*x+x<<endl;
		else
			cout<<(b-a)*y+x<<endl;
	}
	else if(a==b)
		cout<<x<<endl;
	else{
		if(2*x<y)
			cout<<(a-b-1)*2*x+x<<endl;
		else
			cout<<(a-b-1)*y+x<<endl;
	}
	return 0;
}


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

int main() {
int n;
  cin>>n;
  vector<pair<ll,int>>x(n),y(n);

  rep(i,n){
  cin>>x[i].first>>y[i].first;
    x[i].second=i+1;
    y[i].second=i+1;
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());

  ll ans;
  ll ans1=max((abs(x[1].first-x[n-1].first)),(abs(x[0].first-x[n-2].first)));
    ll ans2=max((abs(y[1].first-y[n-1].first)),(abs(y[0].first-y[n-2].first)));
   ans=max(ans1,ans2);
  if(x[0].second==y[0].second&&x[n-1].second==y[n-1].second){
    cout<<ans<<endl;
  return 0;
  }
  if(abs(x[0].first-x[n-1].first)<ans||abs(y[0].first-y[n-1].first)<ans){
  cout<<ans<<endl;
    return 0;
  }
  cout<<min((abs(x[0].first-x[n-1].first)),(abs(y[0].first-y[n-1].first)))<<endl;

}

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

P get_max(vector <P> vec){
	int n=vec.size();
	vector <P> vx(n),vy(n);
	for(int i=0;i<n;i++) vx[i]=P(vec[i].first,i);
	for(int i=0;i<n;i++) vy[i]=P(vec[i].second,i);
	sort(vx.begin(),vx.end());
	sort(vy.begin(),vy.end());
	if(vx[n-1].first-vx[0].first>=vy[n-1].first-vy[0].first){
		return P(vx[0].second,vx[n-1].second);
	}
	return P(vy[0].second,vy[n-1].second);
}
int dist(vector <P> vec,P p){
	int x=p.first,y=p.second;
	return max(abs(vec[x].first-vec[y].first),abs(vec[x].second-vec[y].second));
}
int main(){
	int n;
	scanf("%d",&n);
	vector <P> vec;
	for(int i=0;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		vec.push_back(P(x,y));
	}
	P p=get_max(vec);
	vector <P> v1,v2;
	for(int i=0;i<vec.size();i++){
		if(i!=p.first) v1.push_back(vec[i]);
		if(i!=p.second) v2.push_back(vec[i]);
	}
	P q=get_max(v1),r=get_max(v2);
	printf("%d\n",max(dist(v1,q),dist(v2,r)));
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

typedef long long ll;
typedef long double ld;
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPR(i,a,b) for(int i = b; i >= a; i--)
#define all(a)              a.begin(), a.end()
#define alln(a, n)          (a, a+n)
#define sz(x) (int)(x).size()
#define MAX                 10000007
#define MIN                 -10000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mii             map<int,int>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf 1e18
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef set<int> si;
const int MOD=1e9+7;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b,ll MOD){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2,MOD) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2,MOD);}
ll fact[1],inv[1];
void factorial(ll n){
  fact[0]=1;
  for(ll i=1;i<=n;i++){
    fact[i]=fact[i-1]*i;
    if(fact[i]>=MOD)
      fact[i]%=MOD;
  }
}
ll ncr(ll n,ll r){
  if(n<r||n<0||r<0)
    return 0;
  ll b=inv[n-r];
  ll c=inv[r];
  ll a=fact[n]*b;
  if(a>=MOD)
    a%=MOD;
  a*=c;
  if(a>=MOD)
    a%=MOD;
  return a;
}
vector<char> is_prime(100001, true);
void sieve(ll n){
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
        if (is_prime[i] && (long long)i * i <= n) {
            for (int j = i * i; j <= n; j += i)
                  is_prime[j] = false;
        }
  }
}

int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;
    t=1;
    cout<<fixed<<setprecision(0);
     //  cin>>t;
    while(t--){
            int n,m,ans=0;
            cin>>n>>m;
            char a[n][m];
            REP(i,0,n-1) REP(j,0,m-1) cin>>a[i][j];
            REP(i,0,n-1){
              REP(j,0,m-1){
                if(i+1<=n-1&&a[i][j]=='.'&&a[i+1][j]=='.') ans++;
                if(j+1<=m-1&&a[i][j]=='.'&&a[i][j+1]=='.') ans++;
              }
            }
            cout<<ans<<"\n";

             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// === debug ===
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// === end ===

int main() {
  int H, W;
  ins(H, W);

  vector<string> S(H);
  rep(i, H) {
    cin >> S[i];
  }
  int ans = 0;
  rep(i, H) rep(j, W-1) {
    if (S[i][j] == '.' && S[i][j+1] == '.')
      ++ans;
  }
  rep(i, H-1) rep(j, W) {
    if (S[i][j] == '.' && S[i+1][j] == '.')
      ++ans;
  }
  cout << ans << endl;

  return 0;
}


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

const int bound = 10000;

bool visited[10010];

int main(){
	int N; cin >> N;
	cout << 6 << " " << 10 << " " << 15;

	N -= 3;

	for(int j = 12; j <= bound; j += 6){
		if(!visited[j] && N > 0){
			cout << " " << j;
			visited[j] = true;
			N--;
		}
	}

	for(int j = 20; j <= bound; j += 10){
		if(!visited[j] && N > 0){
			cout << " " << j;
			visited[j] = true;
			N--;
		}
	}

	for(int j = 30; j <= bound; j += 15){
		if(!visited[j] && N > 0){
			cout << " " << j;
			visited[j] = true;
			N--;
		}
	}

	cout << '\n';
}


#define _DEBUG
#include "bits/stdc++.h"
//#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define PI acosl(-1)
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba emplace_back
#define pubamp(a,b) emplace_back(mp(a,b))
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int L[2001],R[2001];
	scan(N);
	rep(i,N){
		int t,l,r;
		scan(t>>l>>r);
		l*=2,r*=2;
		if(t<=2) L[i]=l;
		else L[i]=l+1;
		if(t%2) R[i]=r;
		else R[i]=r-1;
	}
	int ans=0;
	rep(i,N){
		for(int j=i+1;j<N;j++){
			//debug(L[i],R[i],L[j],R[j]);
			if(R[i]<L[j]||R[j]<L[i]){

			}
			else ans++;
		}
	}
	prin(ans);
	return 0;
}

/*君は今なにをして生きる
君は今なにをして生きてる？

いつまでたっても君は相も変わらず暮らしているようで
本音　深い暗い沼の底で
溜まりに溜まって溢れそうです

光景　あの時の思い出
美化に美化　重ねてしまった
いいないいなあの子は楽しそう
嫌いなあの子は

わたしはわたしでがんばった
あなたはあなたで何していた？
気づいた時には粉々の鏡
あなたにきづいてほしかったな

まだかな　まだかな
待っていたのに　待っていたのに
愛していたのに　愛していたのに

永遠の愛はメーデーの中
永遠の愛はたしかにどこにももうない*/

#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define siz(a) int((a).size())
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define endl "\n"
#define pi 3.14159265
const ll mod = 1000 * 1000 * 1000 + 7;
const ll mod1 = 998244353;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
using namespace std;

ll power(ll x, ll y)
{
   ll res = 1;

    while (y > 0)
    {

        if (y & 1)
            res = (long long)(res*x);

        y = y>>1;

        x = (long long)(x*x);

        //cout<<x<<'\n';
    }
    return res;
}

// Stolen Templates
template <typename T>
T MIN(T first) { return first; }

template <typename T, typename... Args>
T MIN(T first, Args... args) { return min(first, MIN(args...)); }

template <typename T>
T MAX(T first) { return first; }

template <typename T, typename... Args>

T MAX(T first, Args... args) { return max(first, MAX(args...)); }
// Stolen Templates end here

int main()
{

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

fastio();
    ll n;
    cin>>n;

    ll a[n][n];
    ll sum = 0;

    For(i,0,n) {
        For(j,0,n) {
            cin>>a[i][j];
            sum+=a[i][j];
        }
    }

        // if (sum%n!=0) {
        //     cout<<"No";
        //     return 0;
        // }

        vector <pii> val;

        ll cu = a[0][0]; ll pos = 0;
        for(int j=1;j<n;j++){
            ll cur = a[0][j-1] - a[0][j];
            for(int i=1;i<n;i++) {
                if (cur!=a[i][j-1]-a[i][j]) {
                    cout<<"No";
                    return 0;
                }
            }
            if (a[j][0] < cu) {
                cu = a[j][0];
                pos = j;
            }
        }

        cout<<"Yes"<<endl;

        for(int i = 0; i < n; i++)
            cout<<a[i][i] - a[pos][i]<<' ';

        cout<<endl;

        for(int i = 0; i < n; i++)
            cout<<a[pos][i]<<' ';

return 0;
}

// check all product based operations for integer overflow
// careful of renamed variables especially in loops


#include <bits/stdc++.h>
using namespace std;
struct BIT{
    vector<long long> num;
    int N;
    BIT(int n){
        N = n;
        num.resize(N + 1, 0);
    }
    long long sum(long long t){
        long long res = 0;
        while(t > 0){
            res += num[t];
            t -= t & -t;
        }
        return res;
    }
    void add(int ind, long long t){
        ind++;
        while(ind <= N){
            num[ind] += t;
            ind += ind & -ind;
        }
    }
};
int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    BIT bit(N);
    vector<int> ind(N);
    for(int i = 0; i < N; i++) ind[i] = i;
    sort(ind.begin(), ind.end(), [&](int x, int y){
        return P[x] < P[y];
    });
    long long sum1 = 0;
    for(int i = 0; i < N; i++){
        bit.add(ind[i], 1);
        sum1 += bit.sum(N) - bit.sum(ind[i] + 1);
    }
    if(sum1 != N - 1){
        cout << -1 << endl;
        return 0;
    }
    vector<int> ans;
    set<int> s;
    int ind2 = N - 1;
    while(1){
        if(ind2 < 0) break;
        int tem = ind[ind2];
        for(int i = 0; i < ind2 - tem; i++){
            ans.push_back(ind[ind2]);
            if(s.count(ind[ind2])){
                cout << -1 << endl;
                return 0;
            }
            s.insert(ind[ind2]);
            swap(ind[ind2], ind[P[ind[ind2] + 1]]);
        }
        ind2--;
    }
    for(int i = 0; i < (int)ans.size(); i++){
        cout << ans[i] + 1 << endl;
    }
}

#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) cout<<i<<" ";puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
	ll x=0,f=1;char c=getchar();
	while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
	if (c=='-') f=-1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}

const int N = 2e5+10;
int n,a[N],pos[N];

bool vis[N];
poly ans;
inline void Swap(int x,int y){
	if (vis[x]){
		puts("-1");
		exit(0);
	}
	vis[x]=1,swap(pos[a[x]],pos[a[y]]),swap(a[x],a[y]);
	ans.pb(x);
}

int main(){
	n=read();
	For(i,1,n) a[i]=read(),pos[a[i]]=i;
	FOR(i,1,n){
		while (a[i]!=i) Swap(pos[i]-1,pos[i]);
	}
	if (siz(ans)!=n-1) return puts("-1"),0;
	For(i,1,n-1) printf("%d\n",ans[i-1]);
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define rf(i, a, b) for (ll i = a; i >= b; i--)
typedef std::vector<long long> vi;
#define F first
#define S second
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(), a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
const ll INF = LLONG_MAX / 2;
const ll N = 2e5 + 1;
using namespace std;
ll n, maxid = 0, m;
ll pow1(ll n, ll p)
{
    if (p == 0)
        return 1;
    ll x = pow1(n, p / 2);
    if (x > m || x >= 1000000001)
        return INF;
    x = (x * x);
    if (x > m)
        return INF;
    if (p % 2 == 0)
        return x;
    else
    {
        if (x * n > m)
            return INF;
        return (x * n);
    }
}
string x;
bool check(ll k)
{
    ll j = 0, ans = 0;
    rf(i, n - 1, 0)
    {
        if (pow1(k, j) == INF)
            return false;
        if (pow1(k, j) + ans > m || ans > m)
            return false;
        ans += (pow1(k, j) * ((ll)(x[i] - '0')));
        j++;
    }
    if (ans > m)
        return false;
    return true;
}
int main()
{
    fast;
    ll t = 1;
    // std::cin >> t;
    while (t--)
    {
        cin >> x;
        n = x.length();
        cin >> m;
        if (x.length() == 1)
        {
            ll c = x[0] - '0';
            if (m < c)
                cout << 0 << "\n";
            else
                cout << 1 << "\n";
            continue;
        }
        fr(i, 0, n)
            maxid = max(maxid, (ll)(x[i] - '0'));
        ll l = maxid + 1, r = m + 1;
        // cout << l << "\n";
        // cout << maxid << "\n";
        while (l <= r)
        {
            ll mid = (l + r) / 2;
            if (check(mid))
            {
                l = mid + 1;
            }
            else
            {
                r = mid - 1;
            }
        }
        cout << l - 1 - maxid << "\n";
    }
}

  #include <bits/stdc++.h>
  using namespace std;
  typedef long long ll;
  typedef vector<int> vi;
  typedef pair<int,int> pii;
  #define pii pair<int,int>
  #define fi first
  #define se second

  #define pb push_back
  #define rep(i,n) for (int i=1;i <=int(n);i++)
  #define ffor(i,n) for (int i=0;i <int(n);i++)
  #define all(x) x.begin(),x.end()

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

pii a[200005]; pii b[200005];
  int main(){

      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
       int n; cin >> n;
       rep(i,n){ cin >> a[i].fi >> b[i].fi;
            a[i].se = i ; b[i].se = i;}
       map<pii,int> cnt;
       sort(a+1,a+1+n);
       sort(b+1,b+1+n);
       int res = a[n].fi- a[1].fi;
       vector<pair<ll,pii>> ans ;
       int res1 = min(a[n].se,a[1].se); int res2 = max(a[n].se,a[1].se);
       ans.pb({res,{res1,res2}});

       res = a[n-1].fi - a[1].fi;
         res1 = min(a[n-1].se,a[1].se); res2 = max(a[n-1].se,a[1].se);
           ans.pb({res,{res1,res2}});

         res = a[n].fi - a[2].fi;
       res1 = min(a[n].se,a[2].se); res2 = max(a[n].se,a[2].se);
                 ans.pb({res,{res1,res2}});
       swap(a,b);
        res = a[n].fi- a[1].fi;

             res1 = min(a[n].se,a[1].se);  res2 = max(a[n].se,a[1].se);
            ans.pb({res,{res1,res2}});

            res = a[n-1].fi - a[1].fi;
              res1 = min(a[n-1].se,a[1].se); res2 = max(a[n-1].se,a[1].se);
                ans.pb({res,{res1,res2}});

              res = a[n].fi - a[2].fi;
            res1 = min(a[n].se,a[2].se); res2 = max(a[n].se,a[2].se);
                      ans.pb({res,{res1,res2}});

       sort(all(ans));
       reverse(all(ans));
       int num=0;
       for (auto p: ans){

                 int  a1 = min(p.se.fi,p.se.se);
                 int a2 = max(p.se.fi,p.se.se);
            if (cnt[{a1,a2}]) continue;
            cnt[{a1,a2}]++;
            num++;
            if (num==2){
                 cout << p.fi << '\n'; return 0;
            }

       }

        return 0;
  }


#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve(){
  int n; cin>>n;
  vector<int> v;
  for(int i = 1; i*i <= n; i++){
    if(n%i == 0){
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(v.begin(), v.end());
  for(int i : v) cout << i << "\n";
}

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

// Problem: C - Secret Number
// Contest: AtCoder - Mynavi Programming Contest 2021（AtCoder Beginner Contest 201）
// URL: https://atcoder.jp/contests/abc201/tasks/abc201_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms

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

int main() {
	string str;
	cin >> str;
	int ans = 0;
	for (int i = 0; i < 10000; ++i) {
		bool flag = true;
		for (int k = 1; k <= 1000; k *= 10) {
			if (str[i / k % 10] == 'x') flag = false;
		}
		for (int j = 0; j < 10; ++j) {
			bool vis = false;
			if (str[j] == 'o') {
				for (int k = 1; k <= 1000; k *= 10) {
					if (i / k % 10 == j) vis = true;
				}
				if (!vis) flag = false;
			}
		}
		if (flag) ++ans;
	}
	cout << ans;
	return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int A, B;

void MAIN() {
    scanf("%d%d", &A, &B);
    if (A+B >= 15 && B >= 8) {
	puts("1");
    } else if (A+B >= 10 && B >= 3) {
	puts("2");
    } else if (A+B >= 3) {
	puts("3");
    } else {
	puts("4");
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define mp make_pair
#define parll pair<ll,ll>
#define parii pair<int,int>
#define min3( brp1, brp2, brp3 ) min( min( brp1, brp2 ), brp3 )
#define min4( brp1, brp2, brp3, brp4 ) min( min( brp1, brp2 ), min( brp3, brp4 ) )

ll a,b;

int main()
{
    ios;

    cin >> a >> b;

    if ( a+b >= 15 && b >= 8 )
    {
        cout << 1;
        return 0;
    }
    if ( a+b >= 10 && b >= 3 )
    {
        cout << 2;
        return 0;
    }
    if ( a+b >= 3 )
    {
        cout << 3;
        return 0;
    }
    cout << 4;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define setbits(x) __builtin_popcountll(x)
#define md (ll)1e9 + 7
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define f(i, j, n) for (ll i = j; i < n; i++)
#define r(i, j, n) for (ll i = n - 1; i >= j; i--)

void solve()
{
    ll b,c;
    cin>>b>>c;
    ll p=c,n=c-1;
    if(b<0)
        swap(p,n);
    else if(b==0)
        p=c,n=c;
    b=abs(b);
    ll l1=b+(n-1)/2;
    ll r1=b-p/2;
    ll l2=-(b-(p-1)/2);
    ll r2=-b-n/2;
    ll ans=l1-r1+1 + l2-r2+1;
    ans-=max(0ll,l2-r1+1);
    cout<<ans;

}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
#endif
    ll test_cases = 1;
    //cin >> test_cases;
    for (ll t = 1; t <= test_cases; t++)
        solve(),cout<<"\n";;
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
using vi64 = vector<i64>;
using vvi64 = vector<vi64>;
using vvvi64 = vector<vvi64>;
using u64 = uint64_t;

#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

void run() {
  i64 n;
  cin >> n;
  vi64 as(n);
  rep(i, 0, n) { cin >> as[i]; }
  sort(begin(as), end(as));
  i64 ret{0}, pre{0};
  rep(i, 1, n) {
    pre += (as[i] - as[i - 1]) * i;
    ret += pre;
  }
  cout << ret << endl;
}

int main() {
  cin.tie(nullptr);
  cout.precision(std::numeric_limits<double>::max_digits10);
  run();
  return 0;
}


// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

bool dp[200010][10];
bool visited[200010][10];
int main() {
    int N; cin >> N;
    string S, X; cin >> S >> X;

    auto calc = [&](auto &&f, int idx, int mod) {
                    if(visited[idx][mod])
                        return dp[idx][mod];
                    visited[idx][mod] = true;
                    if(idx + 1 == N) {
                        int m1 = (mod * 10 + 0) % 7;
                        int m2 = (mod * 10 + (S[idx] - '0')) % 7;
                        if(X[idx] == 'T' and (m1 == 0 or m2 == 0))
                            return dp[idx][mod] = true;
                        if(X[idx] == 'A' and (m1 != 0 or m2 != 0))
                            return dp[idx][mod] = true;
                        return dp[idx][mod] = false;
                    }
                    else {
                        int m1 = (mod * 10 + 0) % 7;
                        int m2 = (mod * 10 + (S[idx] - '0')) % 7;
                        bool b1 = f(f, idx+1, m1);
                        bool b2 = f(f, idx+1, m2);
                        if(X[idx] == X[idx+1] and (b1 or b2)) {
                            return dp[idx][mod] = true;
                        }
                        else if(X[idx] != X[idx+1] and (!b1 or !b2)) {
                            return dp[idx][mod] = true;
                        }
                        return dp[idx][mod] = false;
                    }
                };
    bool a = calc(calc, 0, 0);
    if(X.front() == 'T') {
        cout << (a ? "Takahashi" : "Aoki") << endl;
    }
    else {
        cout << (a ? "Aoki" : "Takahashi") << endl;
    }
    return 0;
}

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

#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif

#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;

string solveCase(int64_t N, string S, string X)
{
    // TODO: edit here
    vector<int> win_t(7);
    win_t[0] = 1;
    reverse(all(S));
    reverse(all(X));
    int curr = 1;
    for (size_t i = 0; i < N; i++)
    {
        int val = ((S[i] - '0') * curr) % 7;
        vector<int> win_next_t(7);
        for (size_t j = 0; j < 7; j++)
        {
            if (X[i] == 'T')
            {
                int now = (j + val) % 7;
                if (win_t[now])
                    win_next_t[j] = 1;
                else
                    win_next_t[j] = win_t[j];
            }
            else
            {
                int now = (j + val) % 7;
                if (!win_t[now])
                    win_next_t[j] = 0;
                else
                    win_next_t[j] = win_t[j];
            }
        }
        curr = (curr * 10) % 7;
        win_t = win_next_t;
        db(i, win_t, curr, val);
    }
    if (win_t[0])
        return "Takahashi";
    return "Aoki";
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main()
{
#ifndef LOCAL
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    constexpr char endl = '\n';
    int N;
    string X, S;
    cin >> N >> S >> X;
    auto ans = solveCase(N, S, X);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define forr(i, a, n) for (int i = a; i < n; i++)
#define rep(i, n) forr(i, 0, n)
#define repp(i, n) forr(i, 1, n + 1)
#define foreach(it, t) for (__typeof(t.begin()) it = t.begin(); it != t.end(); it++)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define init(a, i) memset(a, i, sizeof(a))
#define pii pair<int, int>
#define vvi vector<vector<int>>
#define MAXN 0x3f3f3f3f
int min(int a, int b)
{
    if (a < b)
        return a;
    else
        return b;
}
int max(int a, int b)
{
    if (a > b)
        return a;
    else
        return b;
}
int n, p, q, u, d[200005], cur = -1, B;
int l[200005], r[200005];
int deep[200005], num[200005], cnt[200005], ans[200005];
vvi v;
vector<pair<pii, int>> s;
void dfs(int k, int dp)
{
    cur++;
    deep[cur] = dp;
    num[k] = cur;
    l[num[k]] = cur;
    rep(i, v[k].size()) dfs(v[k][i], dp + 1);
    r[num[k]] = cur;
}
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b)
{
    int a1 = a.first.first, b1 = a.first.second, a2 = b.first.first, b2 = b.first.second;
    if (a1 / B != a2 / B)
        return a1 / B < a2 / B;
    if (b1 != b2)
        return b1 < b2;
    return a1 < a2;
}
void solve()
{
    cin >> n;
    B = sqrt(n);
    v.resize(n);
    rep(i, n - 1)
    {
        cin >> p;
        v[p - 1].pb(i + 1);
    }
    dfs(0, 0);
    cin >> q;
    rep(i, q)
    {
        cin >> u >> d[i];
        u--;
        u = num[u];
        s.pb(mp(mp(l[u], r[u]), i));
    }
    sort(s.begin(), s.end(), cmp);
    int x = 0, y = -1;
    rep(i, q)
    {
        int L = s[i].first.first, R = s[i].first.second;
        while (y < R)
            cnt[deep[++y]]++;
        while (y > R)
            cnt[deep[y--]]--;
        while (x < L)
            cnt[deep[x++]]--;
        while (x > L)
            cnt[deep[--x]]++;
        ans[s[i].second] = cnt[d[s[i].second]];
    }
    rep(i, q) cout << ans[i] << endl;
}
int main()
{
    int T;
    T = 1;
    //cin>>T;
    while (T--)
        solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
double dp[100][100][100];
double dfs(ll a,ll b,ll c){
    if(a==99 && b==99 && c==99)return 1.0;
    if(a==100 || b==100 || c==100)return 0.0;
    if(dp[a][b][c]!=0)return dp[a][b][c];
    double ans=0.0;
    if(a>0)ans+=((double)a/(a+b+c))*(1+dfs(a+1,b,c));
    if(b>0)ans+=((double)b/(a+b+c))*(1+dfs(a,b+1,c));
    if(c>0)ans+=((double)c/(a+b+c))*(1+dfs(a,b,c+1));
    //cout<<a<<" "<<b<<" "<<c<<" "<<ans<<endl;
    return dp[a][b][c]=ans;
}
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    memset(dp,0,sizeof(dp));
    double ans=dfs(a,b,c);
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

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

    ll n; cin >> n;
    char c[2][2]; cin >> c[0][0] >> c[0][1] >> c[1][0] >> c[1][1];
    if(n <= 3){print(1) return 0;}

    ll x = 1; zep(i, 0, n - 3){x *= 2; x %= MOD;}

    ll dp[n][2]; memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    zep(i, 1, n - 1){
        dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        dp[i][1] = dp[i - 1][0];
    }

    if(c[0][1] == 'A'){
        if(c[0][0] == 'A'){
            print(1)
        }else{
            if(c[1][0] == 'B'){
                print(x)
            }else{
                print(dp[n - 2][0])
            }
        }
    }else{
        if(c[1][1] == 'B'){
            print(1)
        }else{
            if(c[1][0] == 'A'){
                print(x)
            }else{
                print(dp[n - 2][0])
            }
        }
    }

    return 0;
}

#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 5005, p = 998244353;

char w[MAX_N][MAX_N];

int n, m, k;

ll dp[MAX_N][MAX_N];

constexpr ll bin_pow(ll v, ll t) {
	ll res = 1;
	for (;t;t>>=1, v = v * v % p)
		if (t&1) res = res * v % p;
	return res;
}
constexpr ll inv(ll v) { return bin_pow(v, p - 2); }

const int i3 = inv(3);

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> k;
	for (int x, y, c, i = 0;i < k;++i) {
		cin >> x >> y;
		cin >> w[x][y];
	}
	if (w[n][m] == 0) {
		w[n][m] = 'X';
	}
	dp[1][1] = bin_pow(3, n * m - k);

	DE(i3 * 3 % p);

	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= m;++j) {
			dp[i][j] %= p;
			if (w[i][j] == 'R')
				dp[i][j + 1] += dp[i][j];
			if (w[i][j] == 'D')
				dp[i + 1][j] += dp[i][j];
			if (w[i][j] == 'X') {
				dp[i][j + 1] += dp[i][j];
				dp[i + 1][j] += dp[i][j];
			}
			if (w[i][j] == 0) {

				dp[i][j] = dp[i][j] * i3 % p;

				dp[i + 1][j] += 2 * dp[i][j];
				dp[i][j + 1] += 2 * dp[i][j];

			}
				//DE(i, j, dp[i][j]);
		}

	cout << dp[n][m] << '\n';
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

ll calcNumOfCombination(ll n, ll r){
  ll num = 1;
  for(ll i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main() {
  int a, b;
  ll k;
  cin >> a >> b >> k;
  k--;
  string ans;
  ll now = 0;
  int ua = 0, ub = 0;
  rep(i, a+b) {
    if(ub == b) {
      ans.push_back('a');
      continue;
    } else if(ua == a) {
      ans.push_back('b');
      continue;
    }
    int z = a+b - (i+1);
    ll p = calcNumOfCombination(z, a-ua-1);
    // cerr << i << " " << p << " " << now << endl;
    if(now+p <= k) {
      now += p;
      ans.push_back('b');
      ub++;
    } else {
      ans.push_back('a');
      ua++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

long long int mem[40][40];

void comb(vector<vector<long long int> > &v) {
    for (int i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int k = 1; k < v.size(); k++) {
        for (int j = 1; j < k; j++) {
            v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
        }
    }
}

int main() {
    memset(mem, -1, sizeof(mem));
    vector<vector<long long int> > v(63, vector<long long int>(63, 0));
    comb(v);
    long long int a, b, k;
    cin >> a >> b >> k;
    int l = a + b;
    for (int i = 0; i < l; i++) {
        long long int c = v[a + b - 1][b];
        if (c >= k) {
            cout << 'a';
            a--;
        } else {
            k -= c;
            cout << 'b';
            b--;
        }
    }
    cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    double D,H;
    cin>>n>>D>>H;
    double ans=0;
    rep(i,n){
        double d,h;
        cin>>d>>h;
        double tmp=(D*h-d*H)/(D-d);
        ans=max(ans,tmp);
    }

    cout<<setprecision(10)<<ans<<endl;
}

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

int main(void)
{
  vector<int> A(3);
  rep(i, 3) cin >> A.at(i);
  sort(A.begin(), A.end());
  do {
    if (A.at(0) - A.at(1) == A.at(1) - A.at(2)) {
      cout << "Yes" << endl; return 0;
    }
  } while (next_permutation(A.begin(), A.end()));
  cout << "No" << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
namespace atcoder {}
using namespace atcoder;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
#define int long long int

void solve(long long N, long long M, std::vector<long long> A,
           std::vector<long long> B) {
  vector<int> count(10000);
  for (auto c : A)
    count[c]++;
  for (auto c : B)
    count[c]++;
  rep(i, 10000) {
    if (count[i] == 1) {
      cout << i << " ";
    }
  }
}

signed main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(A), std::move(B));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define V vector
#define TP template <class o>
#define TPP template <typename t1, typename t2>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = b; i >= a; i--)
#define FOR(i, n) rep(i, 1, n)
#define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl
using namespace std;
typedef double db;
typedef unsigned ui;
typedef long long ll;
typedef long double ld;

// char buf[1 << 20],*p1=buf,*p2=buf;
TP void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
template <class o, class... O> void qr(o& x, O&... y) { qr(x), qr(y...); }
TP void qw(o x) {
    if (x < 0)
        putchar('-'), x = -x;
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
TP void pr1(o x) { qw(x), putchar(' '); }
template <class o, class... O> void pr1(o x, O... y) { pr1(x), pr1(y...); }
TP void pr2(o x) { qw(x), putchar(10); }
template <class o, class... O> void pr2(o x, O... y) { pr2(x), pr2(y...); }
TP bool cmax(o& x, o y) { return (x < y ? x = y, 1 : 0); }
TP bool cmin(o& x, o y) { return (x > y ? x = y, 1 : 0); }

const int mod = 998244353;
TPP void ad(t1& x, t2 y) { (x += y) >= mod && (x -= mod); }
TPP void dl(t1& x, t2 y) { (x -= y) < 0 && (x += mod); }

const int N = 2e5 + 10, inf = 2e9;
const ll INF = 1e15;
int n, a[N], b[N];

void solve() {
    qr(n);
    int x = 0, y = 1000;
    FOR(i, n) qr(a[i]), cmax(x, a[i]);
    FOR(i, n) qr(b[i]), cmin(y, b[i]);
    pr2(max(y - x + 1, 0));
}

int main() {
#ifndef ONLINE_JUDGE
    clock_t start_time = clock();
#endif
    int T = 1;
    // qr(T);
    while (T--)
        solve();
#ifndef ONLINE_JUDGE
    cerr << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << ' ' << 's' << endl;
#endif
    return 0;
}

#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
const int MAXN = 1e7 + 1;
int spf[MAXN];
int d,x,y;
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;
	}
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
vector<string> split(string line, char dil){
    vector <string> tokens;
    stringstream check1(line);
    string intermediate;
    while(getline(check1, intermediate,dil)){
        tokens.push_back(intermediate);
    }
    return tokens;
}

void read(vector<ll>&v){
	for(int i =0;i<v.size();i++)cin>>v[i];
}
void solve(){
	ll y,x,a,b;
	cin>>x>>y>>a>>b;
	ll ans = 0;
	while( (double)a*x<=2e18 && x*a<=x+b && x*a<y){
		ans++;
		x *= a;
	}
	ans += (y-x-1)/b;
	cout<<ans<<endl;
}
int main(){
	SLAY
	while(_--){
		solve();
	}
	return 0;
}
// 2.2360679775
// 2.236067977499790


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=INF;
const ll MAX=200010;
const double PI=acos(-1.0);

//dijkstra(O(ElogV))
//0-indexed
void dijkstra(ll n,ll s,vector<vector<pll> >&G,vector<ll> &d){
    priority_queue<pll,vector<pll>,greater<pll> >pq;
    rep(i,n){
        d[i]=inf;
    }
    d[s]=0;
    pq.push(mp(0,s));
    while(!pq.empty()){
        pll k=pq.top();pq.pop();
        ll v=k.second;
        if(d[v]<k.first)continue;
        for(auto e:G[v]){
            if(e.fi<0)continue;
            if(d[e.first]>d[v]+e.second){
                d[e.first]=d[v]+e.second;
                pq.push(mp(d[e.first],e.first));
            }
        }
    }
}

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

signed main(){
    int n=30;
    int N=n*n;
    int T=1000;
    vector<vector<pll> >G(N);

    rep(i,n){
        rep(j,n){
            ll v=i*n+j;
            rep(k,4){
                ll nx=i+dx[k],ny=j+dy[k];
                ll nv=nx*n+ny;
                ll x=1;
                if(nx<0||nx>=n||ny<0||ny>=n){
                    G[v].pb(mp(-1,x));
                }else{
                    G[v].pb(mp(nv,x));
                }
            }
        }
    }
    vector<ll>dist(N);
    while(T--){
        ll a,b,c,d;cin>>a>>b>>c>>d;
        string res="";
        ll s=a*n+b,t=c*n+d;
        ll nxt=t;
        dijkstra(N,s,G,dist);
        ll x=dist[t];
        vector<ll>used(N);
        while(nxt!=s){
            used[nxt]=1;
            ll idx=-1;
            rep(i,N){
                if(used[i])continue;
                ll c=inf;
                for(auto e:G[i]){
                    if(e.fi==nxt)c=e.se;
                }
                if(dist[i]+c==dist[nxt])idx=i;
            }
            if(nxt-idx==1){
                res+='R';
            }
            if(nxt-idx==-1){
                res+='L';
            }
            if(nxt-idx==n){
                res+='D';
            }
            if(nxt-idx==-n){
                res+='U';
            }
            nxt=idx;
        }
        reverse(all(res));
        cout<<res<<endl;
        ll score;cin>>score;
        ll mean=score/(ll)res.size();
        rep(i,res.size()){
            if(res[i]=='R'){
                G[s][0].se=mean;
                G[s+1][2].se=mean;
                s++;
            }
            if(res[i]=='L'){
                G[s][2].se=mean;
                G[s-1][0].se=mean;
                s--;
            }
            if(res[i]=='U'){
                G[s][3].se=mean;
                G[s-n][1].se=mean;
                s-=n;
            }
            if(res[i]=='D'){
                G[s][1].se=mean;
                G[s+n][3].se=mean;
                s+=n;
            }
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acosl(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

template<typename T>
struct BIT{
    int N;
    vector<T> dat;
    BIT(int siz):N(siz+1),dat(siz+1,0){}

    void add(int i,T x){
        for(int idx=i;idx<N;idx+=(idx & -idx)){
            dat[idx]+=x;
        }
    }

    T sum(int i){
        T res=0;
        for(int idx=i;idx>0;idx-=(idx & -idx)){
            res+=dat[idx];
        }
        return res;
    }
};

int main(){//cout<<fixed<<setprecision(20);
  long long n;
  cin>>n;
  BIT<long long> bit(n);
  vll a(n);
  rep(i,0,n)cin>>a[i];
  ll ans=0;
  rep(i,0,n){
    a[i]++;
    ans+=bit.sum(n)-bit.sum(a[i]);
    bit.add(a[i],1);
  }
  cout<<ans<<endl;
  rep(i,0,n-1){
    ans+=n+1-2*a[i];
    cout<<ans<<endl;
  }
}


#include <iostream>
#include <iostream>
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define li longll
#define pp pair<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define fr first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define mod 1000000007
#define all(x) x.begin(), x.end()
using namespace std;
int main()
{
	fast;
	int n;
	cin>>n;
	string s;
	cin>>s;
	int t;
	cin>>t;
	int c=0;
	string s1=s.substr(0,n);
	string s2=s.substr(n,n);
	while(t--)
	{

		int x,a,b;
		cin>>x>>a>>b;
		if(x==1)
		{
			a--,b--;
			if(a<n && b<n)
			swap(s1[a],s1[b]);
			else if(a>=n && b>=n)
			swap(s2[a-n],s2[b-n]);
			else
			swap(s1[a],s2[b-n]);
		}
		else
		{
		   swap(s1,s2);
		}
	}
	cout<<s1+s2<<endl;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; //required
using namespace std;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << #x << " is " << x << endl
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
typedef long long ll;
const int MOD = 1e9 + 7;
int dp[200005][7];
int main(){
    fast;
    int n;
    cin >> n;
    string s, x;
    cin >> s >> x;
    // 1: Takahashi -1: Aoki
    for (int i = 0; i < 7; ++i){
        if (i){
            dp[n][i] = -1;
        }
        else{
            dp[n][i] = 1;
        }
    }
    int num, turn, mod1, mod2;
    for (int i = n - 1; i >= 0; --i){
        num = s[i] - '0';
        turn = x[i] == 'T' ? 1 : 0; // 1: Takahashi 0: Aoki
        for (int k = 0; k < 7; ++k){
            mod1 = (k * 10) % 7;
            mod2 = (mod1 + num) % 7;
            if (turn){ // T
                if (dp[i+1][mod1] == 1 or dp[i+1][mod2] == 1){
                    dp[i][k] = 1;
                }
                else{
                    dp[i][k] = -1;
                }
            }
            else{ // A
                if (dp[i+1][mod1] == -1 or dp[i+1][mod2] == -1){
                    dp[i][k] = -1;
                }
                else{
                    dp[i][k] = 1;
                }
            }
        }

    }
    if (dp[0][0] == 1){
        cout << "Takahashi" << endl;
    }
    else{
        cout << "Aoki" << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int x[N];
    int y[N];

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

    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++) {
                int x_diff, y_diff;
                int x_diff2, y_diff2;

                if(x[i] < x[j] && x[i] < x[k]) {
                    x_diff  = x[j] - x[i];
                    y_diff  = y[j] - y[i];
                    x_diff2 = x[k] - x[i];
                    y_diff2 = y[k] - y[i];
                } else if(x[j] < x[k]) {
                    x_diff  = x[i] - x[j];
                    y_diff  = y[i] - y[j];
                    x_diff2 = x[k] - x[j];
                    y_diff2 = y[k] - y[j];
                } else {
                    x_diff  = x[i] - x[k];
                    y_diff  = y[i] - y[k];
                    x_diff2 = x[j] - x[k];
                    y_diff2 = y[j] - y[k];
                }

                if(x_diff == 0 && x_diff2 == 0) {
                    // cout << "x:" << x_diff << ", " << x_diff2 << endl;
                    // cout << i << "," << j << "," << k << endl;
                    cout << "Yes" << endl;
                    return 0;
                } else if(y_diff == 0 && y_diff2 == 0) {
                    // cout << "y:" << y_diff << ", " << y_diff2 << endl;
                    // cout << i << "," << j << "," << k << endl;
                    cout << "Yes" << endl;
                    return 0;
                } else if(((float)x_diff2/x_diff) == ((float)y_diff2/y_diff)) {
                    // cout << "x:" << x_diff << ", " << x_diff2 << endl;
                    // cout << "y:" << y_diff << ", " << y_diff2 << endl;
                    // cout << "i:" << ((float)x_diff2/x_diff) << ", " << ((float)y_diff2/y_diff) << endl;
                    // cout << i << "," << j << "," << k << endl;
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

#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()

void fin(string s){
  cout<<s<<endl;
  exit(0);
}

signed main(){
  int n;cin>>n;
  vector<int> x(n),y(n);
  REP(i,n)cin>>x[i]>>y[i];
  auto check=[&](int i,int j,int k){
    if(i==j||j==k||k==i)return false;
    return (x[i]-x[j])*(y[i]-y[k])==(x[i]-x[k])*(y[i]-y[j]);
  };
  REP(i,n)REP(j,n)REP(k,n)if(check(i,j,k))fin("Yes");
  fin("No");
}


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

int main() {
	int n; cin >> n;
	string t; cin >> t;
	string s = "110";
	long long res = 0;
	REP(i, 3) {
		bool ok = true;
		REP(j, n) ok = ok && s[(i+j)%3] == t[j];
		if (ok) res += 1e10 - (n+i+2)/3 + 1;
	}
	cout << res << '\n';
	return 0;
}

// #include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define BIT(n, k) ((n >> k) & 1)
#define LEN(s) (int)s.size()
#define RANGE(a) a.begin(), a.end()
#define RRANGE(a) a.rbegin(), a.rend()
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

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

  deque<int> idx1;
  rep(i, n) if (s[i] == '1') idx1.push_back(i);

  ll ans = 0;
  rep(i, n) {
    if (s[i] == '1') idx1.pop_front();
    if (s[i] == t[i]) continue;
    if (s[i] == '1') {
      if (idx1.size() == 0) {
        ans = -1;
        break;
      }
      int j = idx1.front();
      ans += j - i;
      s[j] = '0';
      idx1.pop_front();

    } else if (s[i] == '0') {
      if (idx1.size() == 0) {
        ans = -1;
        break;
      }
      int j = idx1.front();
      ans += j - i;
      s[j] = '0';
      idx1.pop_front();
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {if (val < 0) val += MOD;}
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {return val ? MOD - val : 0;}
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {val += r.val;if (val >= MOD) val -= MOD;return *this;}
    constexpr Fp& operator -= (const Fp& r) noexcept {val -= r.val;if (val < 0) val += MOD;return *this;}
    constexpr Fp& operator *= (const Fp& r) noexcept {val = val * r.val % MOD;return *this;}
    constexpr Fp& operator /= (const Fp& r) noexcept {long long a = r.val, b = MOD, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}val = val * u % MOD;if (val < 0) val += MOD;return *this;}
    constexpr bool operator == (const Fp& r) const noexcept {return this->val == r.val;}
    constexpr bool operator != (const Fp& r) const noexcept {return this->val != r.val;}
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {return os << x.val;}
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {if (n == 0) return 1;auto t = modpow(a, n / 2);t = t * t;if (n & 1) t = t * a;return t;}
};

using mint = Fp<MOD>;

int main() {
    int N;
    cin >> N;
    int K;
    cin >> K;
    veci A(N);
    REP(i,N) cin >> A[i];
    sort(A.begin(),A.end());

    vecveci Box(K);

    int now;
    int i = 0;
    while(i < N) {
        int j = i;
        now = A[i];
        while(now == A[j]) {
            Box[(j-i)%K].push_back(now);
            j++;
        }
        i = j;
    }

    // REP(i,K) {
    //     for(int x : Box[i]) cout << x << " ";
    //     cout << endl;
    // }

    set<int> st;

    REP(i,N+1) st.insert(i);
    ll ans = 0;

    REP(i,K) {
        for(int x : Box[i]) if(st.count(x)) st.erase(x);
        auto itr = st.begin();
        ans += *itr;
        for(int x : Box[i]) st.insert(x);
    }

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

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

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
// using namespace atcoder;

void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n);
	ll ans=0;
	map<ll,ll>mp;
	rep(i,n){
		cin>>a[i];
		mp[a[i]]++;
	}
	ll pre=min(k,mp[0]);
	REP(i,1,n){
		if(pre>mp[i]){
			ans+=1LL*(pre-mp[i])*i;
			pre=mp[i];
		}
	}
	cout<<ans;
}

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


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tiii = tuple<int, int, int>;
using str = string;
using ld = long double;

#define FOR(i,a,b) for(int i = (a);i < (b);i ++)
#define ROF(i,a,b) for(int i = (a);i >= (b);i --)
#define trav(a, b) for(auto& a : b)

#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define mk make_pair
#define mt make_tuple
#define f first
#define s second

#define LOCAL
#ifdef LOCAL
	#define nme(x) #x << " : " << x << ' '
#else
	#define cerr if(false)cerr
	#define nme(x) #x << " : " << x << ' '
#endif

template<class T> void maxself(T& x, const T& y){x = (y > x ? y : x);}
template<class T> void minself(T& x, const T& y){x = (y < x ? y : x);}

const ld PI = 3.141592653589793238462643;
const ll mod = 1000000007;
struct mi{
	ll val;explicit operator int() const {return val;}
	mi():val(0){}
	mi(ll v):val(v % mod){}
};
mi operator+(const mi& a, const mi& b){return (a.val + b.val) % mod;}
mi operator*(const mi& a, const mi& b){return (a.val * b.val) % mod;}
mi operator-(const mi& a, const mi& b){return (a.val - b.val + mod) % mod;}

const int N = 10000;
int n, a[N], lef[N], rigt[N];

void solve(){
	cin >> n;
	FOR(i,0,n){
		cin >> a[i];
	}

	vector<pii> st;
	FOR(i,0,n){
		while(sz(st) && st.back().f >= a[i]){
			st.pop_back();
		}
		if(sz(st)) lef[i] = st.back().s;
		else lef[i] = -1;
		st.eb(a[i], i);
	}
	st.clear();
	ROF(i,n - 1,0){
		while(sz(st) && st.back().f >= a[i]) st.pop_back();
		if(sz(st)) rigt[i] = st.back().s;
		else rigt[i] = n;
		st.eb(a[i], i);
	}
	int ans = 0;
	FOR(i,0,n){
		maxself(ans, a[i] * (rigt[i] - lef[i] - 1));
	}
	cout << ans << '\n';
}

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

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

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 998244353;
const int maxn = 1e6 + 3;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'

/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;*/

//cout << fixed << setprecision(0) << ans <<endl;

ll prime[4000005];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll sod(ll x);
ll countdigit(ll n);
ll mySqrt(ll x);
vector<ll>ft;
int ans = 0;

int findMin(int arr[], int n)
{
    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += arr[i];
    bool dp[n+1][sum+1];
    for (int i = 0; i <= n; i++)
        dp[i][0] = true;
    for (int i = 1; i <= sum; i++)
        dp[0][i] = false;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=sum; j++)
        {

            dp[i][j] = dp[i-1][j];

            // If i'th element is included
            if (arr[i-1] <= j)
                dp[i][j] |= dp[i-1][j-arr[i-1]];
        }
    }
    int diff = INT_MAX;
    for (int j=sum/2; j>=0; j--)
    {
        // Find the
        if (dp[n][j] == true)
        {
            //cout << 2*j << " " << sum-j << endl;
            ans = max(j,sum-j);
            diff = sum-2*j;
            break;
        }
    }
    return diff;
}

int main()
{
    flash;
    ll t=1;
   // sieve(4000003);
    //ft.pb(1);
    //fact(10000001);
    //cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int v[n];
        rep(i,0,n)cin >> v[i];
        ll i = 0, j = n-1;
        int res = findMin(v,n);
        cout << ans << endl;

    }
}

//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res%mod;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}
ll sod(ll x){
    ll s = 0;
    while (x != 0) {
      s = s + x % 10;
      x = x / 10;
   }
   return s;
}
ll mySqrt(ll x)
{
    if (x == 0 || x == 1)
    {
        return x;
    }
    ll start = 1, end = x / 2;
    // standard binary search template
    while (start + 1 < end)
    {
        ll mid = start + (end - start) / 2;
        // why not mid * mid <= x? because it may cause overflow when mid is very large
        if (mid <= x / mid)
        {
            start = mid;
        }
        else
        {
            end = mid - 1;
        }
    }
    return end <= x / end ? end : start;
}


#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
using namespace std;
typedef long long ll;
const int INF = 1000000000;

vector<ll> res;

vector<ll> enum_divisors(ll N) {
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

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

    enum_divisors(2*N);

    int ans = 0;
    REP(i, SIZE(res)){
        if(res[i]%2 == 1){
            if(N%res[i] == 0){
                ans++;
            }
        }
        else {
            if((N%res[i])*2 == res[i]) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans;
int main(){
	cin>>n;
	for(ll i=1;i*i<=n+n;i++){
		ll S=n+n-i*(i-1);
		if(S%(i+i)!=0)continue;
		ll l=S/(i+i);
		if(l<=0)continue;
		ans++;
	}
	ans<<=1;
	cout<<ans<<endl;
	return 0;
}


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

typedef long long ll;

int n, m, a, b, ans = 0;
int vis[21][21];

void dfs(int x,int y)
{
	if(x==n+1)
	{
		if(a==0 && b==0) ans++;
		return;
	}

	if(vis[x][y]==1)
	{
		if(y==m) dfs(x+1,1);
		else dfs(x,y+1);
		return;
	}

	if(b)
	{
		--b;
		vis[x][y]=1;
		if(y==m) dfs(x+1,1);
		else dfs(x,y+1);
		vis[x][y]=0;
		++b;
	}

	if(a)
	{
		--a;
		vis[x][y]=1;
		if(vis[x+1][y]==0)
		{
			vis[x+1][y]=1;
			if(y==m) dfs(x+1,1);
			else dfs(x,y+1);
			vis[x+1][y]=0;
		}

		if(vis[x][y+1]==0)
		{
			vis[x][y+1]=1;
			if(y==m) dfs(x+1,1);
			else dfs(x,y+1);
			vis[x][y+1]=0;
		}
		++a;
		vis[x][y]=0;
	}
}

int main()
{
	cin >> n >> m >> a >> b;
	dfs(1,1);
	cout << ans << endl;
	return 0;
}

/**
 *    author:  naniwazu
**/
#include<bits/stdc++.h>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template< typename T >
int64_t largest_rectangle(vector< T > height)
{
  stack< int > st;
  height.push_back(0);
  vector< int > left(height.size());
  int64_t ret = 0;
  for(int i = 0; i < height.size(); i++) {
    while(!st.empty() && height[st.top()] >= height[i]) {
      ret = max(ret, (int64_t) (i - left[st.top()] - 1) * height[st.top()]);
      st.pop();
    }
    left[i] = st.empty() ? -1 : st.top();
    st.emplace(i);
  }
  return (ret);
}
int popcount(int x)
{
    int cnt = 0;
    while(x) cnt+=x&1, x>>=1;
    return cnt;
}

void solve(){
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  int ans = 0;
  rep(bit, 1 << (2*H*W-H-W)){
    bool flag = true;
    if(!(popcount(bit) == A)){
      continue;
    }
    vector<int> S(H*W,0);
  rep(i,H){
    rep(j,W-1){
      if (bit >> (i*(W-1)+j) & 1){
                if (S[i*W+j] or S[i*W+j+1]){
                    flag = false;
                }
                S[i*W+j] = 1;
                S[i*W+j+1] = 1;
      }
    }
  }
  rep(j,W){
    rep(i,H-1){
      if (bit >> (j*(H-1)+i+H*(W-1)) & 1){
                if (S[i*W+j] or S[i*W+j+W]){
                    flag = false;
                }
                S[i*W+j] = 1;
                S[i*W+j+W] = 1;
      }
    }
  }
  if (flag){
    ans++;
  }
  }
  cout << ans << "\n";
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define repE(i,a,b) for(int i=a;i<=b;i+=1)

#define pb push_back
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5, M = 10;
const ll WE = 1e5;
const ll maxV = 1e3;
const ll INF = 1e18;

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

int s(int n) {
    int sum = 0;

    while (n) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

void solve() {

    int a, b;
    cin >> a >> b;

    int suma = s(a);
    int sumb = s(b);

    cout << max(sumb, suma) << "\n";
}
int main()
{

    ios::sync_with_stdio (0);

    cin.tie (NULL);

    int t = 1;
    // cin >> t;

    // compute();

    // sieve();

    while (t--) {
        solve();

    }

    return 0;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>

const ll mod = 1000000007;
const ll INF = 1001001001001001001;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    vector<int> w(m);
    rep(i, n) cin >> h[i];
    rep(i, m) cin >> w[i];
    sort(h.begin(), h.end());
    vector<ll> l(n/2+1), r(n/2+1);
    l[0] = 0;
    r[0] = 0;
    rep(i, n/2){
        l[i+1] = l[i] + (h[2*i+1] - h[2*i]);
    }
    rep(i, n/2){
        r[i+1] = r[i] + (h[2*i+2] - h[2*i+1]);
    }
    // rep(i, n/2+1){
    //     cout << l[i] << " ";
    // }cout << endl;
    // rep(i, n/2+1){
    //     cout << r[i] << " ";
    // }cout << endl;

    ll ans = INF;
    rep(i, m){
        int idx = upper_bound(h.begin(), h.end(), w[i]) - h.begin();
        ll ans_ = 0;
        if(idx%2 == 1){
            ans_ = l[idx/2] + (w[i] - h[idx-1]) + (r[n/2] - r[idx/2]);
        }else {
            ans_ = l[idx/2] + (h[idx] - w[i]) + (r[n/2] - r[idx/2]);
        }
        ans = min(ans, ans_);
        // cout << ans_ << " " << idx << endl;
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n;cin >> n;
    vector<set<ll>> dp(n+1);
    vl ans(n+1);
    repl(i,1,n+1){
        ll p=1;while(dp[i].count(p))p++;
        ans[i]=p;
        for(int j=i;j<=n;j+=i)dp[j].insert(ans[i]);
    }
    repl(i,1,n+1)cout << ans[i] <<" ";cout << endl;
}


/*#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")*/
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<"\n";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  1e+9 + 7;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

ld n, x, y, a, b;
ld str, res, cnt;

void MAIN(int tc){
    cin >> x >> y >> a >> b;
    ld mul = 1;
    res = floor((y - x)/b)- (fmod(y - x, b) == 0);
    for(ld k = 1; k <= 100; k++){
        mul *= a;
        ld nx = x * mul;
        if(nx >= y) {
            res = max(res, k - 1);
            break;
        }
        ld rem = floor((y - nx) / b) - (fmod(y - nx, b) == 0);
        res = max(res, k + rem);
    }
    deb1((ll)res);
}

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

    int test_cases = 1;
    //cin>>test_cases;
    for(int i = 1; i <= test_cases; i++){
        MAIN(i);
    }
}

/**
 *    Author:  Sanchit Sinha
 *    Created: 17.10.2020 16:38:47
**/
#include "bits/stdc++.h"
using namespace std;

#define ll unsigned long long
ll powermod(ll x,ll ex,ll md){ll ans=1ll;while(ex>0){if(ex&1ll) ans=(ans*x)%md; ex>>=1ll;x=(x*x)%md;}return ans;}
inline ll gcd(ll a,ll b) {if(b==0)return a;a%=b;return gcd(b,a);}
inline ll max(ll a,ll b) {return((a>b)?a:b);}
inline ll min(ll a,ll b) {return((a>b)?b:a);}

int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll x,y,a,b;
        cin>>x>>y>>a>>b;
        ll ans=0;
        while(x<y){
                if(x>=y/a && x+a>=y) break;
                if(x>=y/a){
                        ll div=(y-1-x)/b;
                        ans+=max(div,0);
                        break;
                }
                ll x1=x*a;
                ll x2=x+b;
                if(x1<=x2){
                        x*=a;
                        if(x<y)ans++;
                        else break;
                }
                else{
                        ll div=(y-1-x)/b;
                        ans+=max(div,0);
                        break;
                }
        }
        cout<<ans<<"\n";
        return 0;
}


#include <bits/stdc++.h>

#define mid(l,r) ((l + r) >> 1)
#define lsb(x) (x & (-x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FOR(X,L,R) for(int X=L;X<R;++X)
#define endl '\n'
#define int long long
#define MOD ((int)1e9 + 7)
#define INF (0x3f3f3f3f)
#define LLINF (0x3f3f3f3f3f3f3f3fLL)

using namespace std;

template<typename T>
inline void input(vector<T>& v)
{
    for(T& x: v)
        cin >> x;
}

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

    if((1000 * w  + b - 1) / b > (1000 * w) / a) cout << "UNSATISFIABLE" << endl;
    else cout << (1000 * w  + b - 1) / b << " " << (1000 * w) / a << endl;
}

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

    #if defined(CODEFORCES) || defined(CF)
        int t; cin >> t;
        while(t--) solve();
    #else
        solve();
    #endif

    return 0;
}

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

int solve_naive(const int n, const int s, const int k){
    int cnt = 0;
    ll now = s;
    while (now % n != 0 && cnt < n){
        now += k;
        cnt += 1;
    }
    if (cnt >= n){
        return -1;
    }
    return cnt;
}

ll _gcd(ll a, ll b){ return (a%b) ? _gcd(b, a%b) : b; }
pair<ll, ll> extgcd(ll a, ll b){
    // ax+by=gcd(a, b)なるx, yを求める
    if(a%b==0)return {0, 1}; // a*0+b*1=b
    const auto [x, y] = extgcd(b, a%b); // b*x + (a-a/b*b)*y = gcd(a, b)
    return {y, x-a/b*y}; // a*y + b*(x+a/b*y) = gcd(a, b)
}
ll powmod(ll x, ll n, ll p){
    // return (x ** n) mod p
    if (n==0)return 1;
    if(n==1)return x%p;
    const auto y = powmod(x, n/2, p);
    return (y*y%p)*powmod(x, n%2, p)%p;
}

int solve(int n, int s, int k){
    // s + a * k == 0 mod n なる最小の a を求める
    const auto g = _gcd(k, n);
    if(s%g!=0){
        // k, n が g の倍数なので s は g の倍数である必要がある
        return -1;
    }
    if(g>1){
        return solve(n/g, s/g, k/g);
    }
    // k*a == 1 mod n なる a を求める
    const auto [a, _] = extgcd(k, n);
    return ((n-s)*a%n+n)%n;
}

int main()
{
    int t;
    cin >> t;
    for(int ti=0; ti<t; ti++){
        int n,s,k;
        cin >> n >> s >> k;
        cout << solve(n, s, k) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repp(i, l, n) for (int i = (l); i < (int)(n); i++)
using ll = long long;
int main(){
    int n; cin>>n;
    cout << n-1 << endl;
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define endl '\n';
#define sz(s) int(s.size())
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define mem(x,y) memset(x,y,sizeof(x))
#define Ceil(x,y)  ((x+y-1)/y)
typedef long long ll;
typedef double dl;
using namespace std;
void Selim()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
/***************************************************/
void solve(){
	int n;
	cin >> n;
	cout << n - 1 << endl;
}
int main()
{
	Selim();
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>

#define iter_all(x) x.begin(), c.end()
#define umap unordered_map
#define uset unordered_set

using namespace std;

typedef long long int ll;

auto io_speed = []() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();

ll pow_mod(ll a, ll e, ll mod) {
    ll res = 1;
    while(e) {
        if(e&1) res = res * a%mod;
        e>>=1;
        a=a*a%mod;
    }
    return res;
}

ll inv_mod(ll b, ll m) {
    ll a=m, x=0, y=1, r, q;
    while(b) {
        r = a%b;
        q = a/b;
        a = b;
        b = r;
        r = x;
        x = y;
        y = r-q*y;
    }
    x+=m;
    return x%m;
}

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

ll rec(ll x, ll y, map<ll, ll> &dp) {
    auto itr = dp.find(y);
    if(itr == dp.end()) {
        if(y <= x) dp[y] = x-y;
        else {
            ll res = y-x;
            if(y&1) {
                res = min(res, rec(x, y+1, dp) + 1);
                res = min(res, rec(x, y-1, dp) + 1);
            } else {
                res = min(res, rec(x, y>>1, dp) + 1);
            }
            dp[y] = res;
        }
    }
    return dp[y];
}

void solve() {
    ll x, y;
    cin >> x >> y;
    map<ll, ll> dp;
    cout << rec(x, y, dp) << endl;
}

int main() {
    int t = 1;
    // cin >> t;
    for(int i = 1; i <=t; i++) {
        // cout << "Case #"<<i<<": ";
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define INF 10000000000000000
#define ff first
#define ss second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.141592653589793238462643383279
#define PYES cout<<"YES"<<endl
#define PNO cout<<"NO"<<endl
#define SB(a) sort(a.begin(),a.end(),greater<ll>());
#define SS(a) sort(a.begin(),a.end());
#define vll vector<ll>
#define vpll vector<pll>
vector<bool> prime;
vector<ll> fact,inv,primes,factors,pf;
void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
void factorize(ll a)
{
	factors.clear();
	for(ll i=1;i*i<=a;i++)
	{
		if (i*i==a) factors.pb(i);
		else if (a%i==0)
		{
			factors.pb(i);
			factors.pb(a/i);
		}
	}
	sort(factors.begin(),factors.end());
}
ll power(ll a,ll b)
{
	if(a==1||b==0)	return 1;
	ll c=power(a,b/2);
	ll res=1;
	res=c*c;
	if(res>=mod)	res%=mod;
	if(b%2)	res*=a;
	if(res>=mod)	res%=mod;
	return res;
}
ll modInv(int a)
{
	return power(a,mod-2);
}
void factorial(ll n)
{
	fact.resize(n+1);
	fact[0]=1;
	for(ll i=1;i<=n;i++)
	{
		fact[i]=fact[i-1]*i;
		if(fact[i]>=mod)	fact[i]%=mod;
	}
}
void InvFactorial(ll n)
{
	inv.resize(n+1);
	inv[0]=1;
	for(ll i=1;i<=n;i++)	inv[i]=modInv(fact[i]);
}
ll ncr(ll n,ll r)
{
	if(n<r||n<0||r<0)	return 0;
	ll b=inv[n-r];
	ll c=inv[r];
	ll a=fact[n]*b;
	if(a>=mod)	a%=mod;
	a*=c;
	if(a>=mod)	a%=mod;
	return a;
}
void remove_duplicates(vpll &v)
{
	sort(v.begin(),v.end());
	ll _size=unique(v.begin(),v.end())-v.begin();
	v.resize(_size);
}
unsigned ll gcd(unsigned ll u, unsigned ll v)
{
    if(u==0||v==0) return max(u,v);
    unsigned ll shift=__builtin_ctz(u|v);
	u>>=__builtin_ctz(u);
    do{
    	v>>=__builtin_ctz(v);
    	if(u>v)	swap(u,v);
    	v-=u;
    }while(v!=0);
    return u<<shift;
}
void sieve(ll n)
{
    prime.assign(n+1,1);
	prime[1]=false;
    for(ll p=2;p*p<=n;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<=n;i+=p)	prime[i]=false;
		}
	}
    for(ll i=2;i<n+1;i++)
	{
		if(prime[i]) primes.push_back(i);
	}
}
void prime_sieve(ll n)
{
	pf.assign(n+1,0);
	rep(i,n+1) pf[i]=i;
	for(ll i=2;i<=n;i++)
	{
		if (pf[i]==i)
		{
			for(ll j=i;j<=n;j+=i) pf[j]=i;
		}
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
// Always remember: if (condition) if (condition) statement; This doesn't work !!
// Always increase boundaries for global or frequency questions
// pow((ll)10,i) doesn't work sometimes. It is better to use multiple of 10 in arrays. Always remember this.
// delete values when defining global if there are multiple testcases
// don't try to be smart and make stupid mistakes
void solve()
{
	ll n;
	cin>>n;
	vll a(n),psum(n,0);
	rep(i,n) cin>>a[i];
	SS(a);
	rep(i,n)
	{
		if (!i) psum[i]=a[i];
		else psum[i]=psum[i-1]+a[i];
	}
	double ans=INF;
	ans=psum[n-1]*n;
	rep(i,n)
	{
		double a11=a[i];
		double p=a11/2;
		double q=p*n;
		double r=psum[n-1]-psum[i];
		ans=min(ans,q+r-2*p*(n-1-i));
	}
	cout.precision(20);
	cout<<ans/n<<endl;
}
int main()
{
	fast();
	ll T=1;
	//cin>>T;
	for(ll z=1;z<=T;z++) solve();
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
namespace do_while_true {
	#define ld double
	#define ll long long
	#define re register
	#define pb push_back
	#define fir first
	#define sec second
	#define pp std::pair<int, int>
	#define mp std::make_pair
	const ll mod = 1000000007;
	template <typename T>
	inline T Max(re T x, re T y) { return x > y ? x : y; }
	template <typename T>
	inline T Min(re T x, re T y) { return x < y ? x : y; }
	template <typename T>
	inline T Abs(re T x) {	return x < 0 ? -x : x; }
	template <typename T>
	inline void read(re T& r) {
		r = 0; bool w = 0; char ch = getchar();
		while(ch < '0' || ch > '9') w = ch == '-' ? 1 : 0, ch = getchar();
		while(ch >= '0' && ch <= '9') r = r * 10 + (ch ^ 48), ch = getchar();
		r = w ? -r : r;
	}
	template <typename T>
	inline T qpow(re T x, re T y) {
		re T sumq = 1; x %= mod;
		while(y) {
			if(y&1) sumq = sumq * x % mod;
			x = x * x % mod;
			y >>= 1;
		}
		return sumq;
	}
}
using namespace do_while_true;

const int N = 10010;

int n, m, k;
int a[N], b[N], c[N][2];
bool vis[N];

void solve() {
	read(n); read(m);
	for(int i = 1; i <= m; ++i) read(a[i]), read(b[i]);
	read(k); int ans = 0;
	for(int i = 1; i <= k; ++i) read(c[i][0]), read(c[i][1]);
	for(int i = 0; i < (1 << k); ++i) {
		for(int j = 1; j <= n; ++j) vis[j] = 0;
		for(int j = 1; j <= k; ++j) {
			int p = (1 << (j-1)) & i;
			p = p>0;
			vis[c[j][p]] = 1;
		}
		int sumq = 0;
		for(int j = 1; j <= m; ++j)
			if(vis[a[j]] && vis[b[j]])
				++sumq;
		ans = Max(ans, sumq);
	}
	printf("%d\n", ans);
}

signed main() {
	#ifndef ONLINE_JUDGE
//	freopen("in.txt", "r", stdin);
	#endif
//	freopen("out1.txt", "w", stdout);
	int T = 1;
//	read(T);
	while(T--)
		solve();
	fclose(stdin);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e2+5;

char s[N],t[N];

inline char get(char a,char b){
	if(a == b) return a;
	if(a == 'P' && b == 'R') return 'P';
	if(a == 'R' && b == 'P') return 'P';
	if(a == 'S' && b == 'P') return 'S';
	if(a == 'P' && b == 'S') return 'S';
	if(a == 'R' && b == 'S') return 'R';
	if(a == 'S' && b == 'R') return 'R';
}

inline void change(int n){
	for(int i = 0;i < n;++i) t[i] = s[i];
	for(int i = n;i < n*2;++i) t[i] = s[i-n];

	for(int i = 0;i < n;++i)
		s[i] = get(t[i*2],t[i*2+1]);
	return ;
}

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	scanf("%s",s);

	while(k){
		change(n);
		k--;
	}
	printf("%c",s[0]);
	return 0;
}