#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()
template<ll MOD = 998244353>
struct mint{
    ll x;
    ll mod = MOD;
    mint(ll x=0):x(x%MOD){}
    mint& operator+=(const mint a){
        if((x+=a.x)>=MOD) x-=MOD;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += MOD-a.x)>=MOD) x-=MOD;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=MOD;
        return *this;
    }
    mint operator+(const mint a) const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const{
        mint res(*this);
        return res*=a;
    }
    mint power(ll t) const{
        if(!t) return 1;
        mint a = power(t>>1);
        a*=a;
        if(t&1) a*=*this;
        return a;
    }

    mint inv() const{
        return power(MOD-2);
    }
    mint& operator/=(const mint a){
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const{
        mint res(*this);
        return res/=a;
    }
};
template<ll mod>
ostream & operator << (ostream & output,const mint<mod> & a){
        output<<a.x;
        return output;
}
template<ll mod>
istream & operator >> (istream & input, mint<mod>& a){
        input>>a.x;
        return input;
}

using mll=mint<>;
const ll N=1e6;
mll fact[N+1];
mll ifact[N+1];

void init(){
    fact[0]=fact[1]=1;
    FOR(i,2,N+1){
        fact[i]=fact[i-1]*i;
    }
    ifact[0]=1;
    ifact[1]=1;
    ifact[1]/=1;
    FOR(i,2,N+1){
        ifact[i]=1;
        ifact[i]/=i;
        ifact[i]*=ifact[i-1];
    }
}

mll pnc(ll n, ll r){
    mll a=fact[n];
    a*=ifact[r];
    a*=ifact[n-r];
    return a;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    init();
    ll n,m,k;
    cin>>n>>m>>k;
    mll ans=0;
    if(n==1){
        for(ll i=1;i<=k;i++){
            mll temp=mll(k-i+1).power(m);
            temp-=mll(k-i).power(m);
            ans+=temp;
        }
        cout<<ans<<endl;
        return 0;
    }
    if(m==1){
        for(ll i=1;i<=k;i++){
            mll temp=mll(i).power(n);
            temp-=mll(i-1).power(n);
            ans+=temp;
        }
        cout<<ans<<endl;
        return 0;
    }
    for(ll i=1;i<=k;i++){
        mll temp=mll(i).power(n);
        temp-=mll(i-1).power(n);
        temp*=mll(k-i+1).power(m);
        ans+=temp;
    }
    cout<<ans<<endl;
}

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 1;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

struct edge {
	int to;ll cost;
};
void solve() {
	int n; cin >> n;
	vector<vector<edge>> G(n);
	rep(i, n - 1) {
		int a, b;ll c; cin >> a >> b >> c; a--; b--;
		G[a].push_back({ b,c });
		G[b].push_back({ a,c });
	}
	vector<ll> depth(n);
	function<void(int, int)> dfs = [&](int id, int fr) {
		for (edge e : G[id]) {
			if (e.to == fr)continue;
			depth[e.to] = depth[id] ^ e.cost;
			dfs(e.to, id);
		}
	}; dfs(0, -1);
	ll ans = 0;
	rep(i, 60) {
		ll c = 0;
		rep(j, n)if (depth[j] & (1ll << i))c++;
		ll r = n - c;
		ll num = c * r; num %= mod;
		ll z = (1ll << i)%mod;
		ans += num * z; ans %= mod;
	}
	cout << ans << "\n";
}

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


/*
Miles Morales : When will I know I'm ready?
Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
*/
//KEEP IT SIMPLE STUPID

#include <bits/stdc++.h>

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

#define ll long long
#define MP make_pair
#define ERR cout << "================================================\n"
#define fi first
#define se second
#define PB push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define print(v)          \
    for (auto x : v)      \
    {                     \
        cout << x << " "; \
    }
#define umin(...) min({__VA_ARGS__})
#define umax(...) max({__VA_ARGS__})
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define SP << " " <<
#define W(t)  \
    ll t;     \
    cin >> t; \
    while (t--)
#define FIO                           \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

using namespace std;

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

const ll INF = 1e18;
const ll NEG_INF = -1 * (1e18);
using namespace std;

void usaco(string prob)
{
    freopen((prob + ".in").c_str(), "r", stdin);
    freopen((prob + ".out").c_str(), "w", stdout);
}

/* Function to check primality in O(sqrt(n)) */
bool prime(int n)
{
    if (n < 2)
        return false;
    for (int x = 2; x * x <= n; x++)
    {
        if (n % x == 0)
            return false;
    }
    return true;
}

/* Function to get prime factorization of n */
vector<int> getFactors(int n)
{
    vector<int> f;
    for (int x = 2; x * x <= n; x++)
    {
        while (n % x == 0)
        {
            f.push_back(x);
            n /= x;
        }
    }
    if (n > 1)
        f.push_back(n);
    return f;
}

void solve()
{
    string x;
    cin >> x;
    ll pt = 0;
    reverse(all(x));
    while (pt < x.length() && x[pt] != '.')
    {
        ++pt;
    }
    if (pt >= x.length())
    {
        reverse(all(x));
        cout << x << "\n";
    }
    else
    {
        string ans = "";
        for (ll i = pt + 1; i < x.length(); i++)
        {
            ans += x[i];
        }
        reverse(all(ans));
        cout << ans << "\n";
    }
}

int main()
{
    //FIO
    FAST

        //usaco("cowlands");

        ll TC = 1;
    /*
	Uncomment when multiple test cases
	*/

    //cin >> TC;
    for1(tt, TC)
    {
        solve();
    }
    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5;
char s[maxN + 1];
map<int, int> cnt;

int main()
{
  while (scanf(" %s", s) != EOF)
  {
    cnt.clear();
    int n = strlen(s);
    for (int i = 0; i < n; i++)
    {
      int val = s[i] - '0';
      if (!cnt.count(val))
        cnt[val] = 0;
      cnt[val]++;
    }

    if (n == 1)
      printf("%s\n", s[0] == '8' ? "Yes" : "No");
    else if (n == 2)
    {
      int a = s[0] - '0', b = s[1] - '0';
      bool is = (10*a + b) % 8 == 0 || (10*b + a) % 8 == 0;
      printf("%s\n", is ? "Yes" : "No");
    }
    else
    {
      /*
      The last three digits are divisible by 8.

      Add four times the hundreds digit to twice the tens digit to the ones digit. The result must be divisible by 8.
      */
      vector<int> digits;
      for (auto i: cnt)
        for (int j = 0; j < min(i.second, 3); j++)
          digits.push_back(i.first);

      bool can = false;
      for (int i = 0; i < digits.size(); i++)
        for (int j = i + 1; j < digits.size(); j++)
          for (int k = j + 1; k < digits.size(); k++)
          {
            vector<int> hehe = {digits[i], digits[j], digits[k]};
            sort(hehe.begin(), hehe.end());
            do
            {
              int num = hehe[0]*4 + hehe[1]*2 + hehe[2];
              if (num % 8 == 0)
                can = true;
            } while (next_permutation(hehe.begin(), hehe.end()));
          }
      printf("%s\n", can ? "Yes" : "No");
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 10000000000000000 //10^16
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll X, Y;
    cin >> X >> Y;
    if(min(X,Y) + 3 > max(X, Y)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	if (abs(x - y) < 3) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


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

const long long ANS=1e10;
string t;
int n;

bool into_string(string t,string a){
    for (int i=0; i<t.size(); i++)
        if (a[i%3] != t[i])
            return false;

	return true;
}

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

    if (n==0){
        cout<<0<<endl;
        return 0;
    }
    else{
        if (n==1 && t[0]=='1')
        {
            cout<<ANS*2<<endl;
            return 0;
        }
    }

    int usin_block=0;
    if (into_string(t,"101")==true)
        usin_block=1+ceil((float)(n-2)/3);
    else
    {
        if (into_string(t,"110")==true)
            usin_block=ceil((float)n/3);
        if (into_string(t,"011")==true)
            usin_block=1+ceil((float)(n-1)/3);
    }

    if (usin_block==0)
    {
        cout<<0;
        return 0;
    }

    cout<<(long long)ANS-usin_block+1;
}

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef long double ld;

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

	ll n;
	cin>>n;
	string t;
	cin>>t;
	ll ans = 0;
	ll N = 3e10l;
	for (ll o=0; o<3; ++o) {
	    string s = "";
	    while (s.size()<n+10) s+="110";
	    s = s.substr(o, n);
	    if (t!=s) continue;
	    ll l = N-n;
	    while (l%3!=o) --l;
	    ans += (l-o)/3 + 1;
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

vector<ll> count_divisor(ll& n) {
	vector<ll> ret;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			ret.push_back(i);
			if (n / i != i)
				ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	return ret;
}

int main(void) {
	ll N; cin >> N;
	auto res = count_divisor(N);
	for (ll& r : res)
		cout << r << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL <<60;
const long long Mo=1000000007;

long long gcn(long long x,long long y){
  if(x%y==0){
    return y;
  }
  else{
    return gcn(y,x%y);
  }
}

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main(void){
  long long tmp,res=0,cnt=0;
  long long i,j;
  long long n,k;

  cin>>n;
  tmp=pow(n,0.5);
  long long div[2*tmp+1]={};
  for(i=1;i<=tmp;i++){
    if(n%i==0){
      if((i*i)!=n){
        div[cnt]=i;
        div[cnt+1]=n/i;
        cnt+=2;
      }
      else {
        div[cnt]=i;
        cnt++;
      }
    }
  }
  sort(div,div+(2*tmp+1));
  for(i=0;i<2*tmp+1;i++){
    if(div[i]>0){
      cout<<div[i]<<endl;
    }
  }

  cout<<endl;

  //precision(15)<<res<<endl;
  //cout<<res<<endl;

  return 0;
}


#include <bits/stdc++.h>

#define ms(a,b) memset(a, b, sizeof(a))
#define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++)
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define m_p(a,b) make_pair(a, b)
#define lson l,mid,o << 1
#define rson mid + 1,r,o << 1 | 1
#define ls o << 1
#define rs o << 1 | 1
#define inf 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

inline bool isdigit(char& ch) {
	return ch >= '0' && ch <= '9';
}
template<class T>
void read(T &x) {
	x = 0;
	ll f = 1;char ch = getchar();
	for (;!isdigit(ch);ch = getchar())
		if (ch == '-') f = -1;
	for (; isdigit(ch);ch = getchar())
		x = (x << 1) + (x << 3) + ch - '0';
	x *= f;
}
template<class T>
inline void write(T x) {
	if (x == 0) {putchar('0');return ;}
	if (x < 0) {putchar('-');x = -x;}
	int _stk[65],_top = 0;
	for (;x;x /= 10) _stk[++_top] = x % 10 + 48;
	for (;_top;_top--)putchar(_stk[_top]);
}

ll a, b, c, d;
int main () {
	cin >> a >> b >> c >> d;
	ll s = a + b + c + d;
	if ((a == s - a) || (b == s - b) || (c == s - c) || (d == s - d))
		cout << "Yes";
	else if ((a + b) == (s - a - b) || (a + c) == (s - a - c) || (a + d) == (s - a - d) || (b + c == s - b - c) || (b + d == s - b - d))
		cout << "Yes";
	else
		cout << "No";
	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

const int CM = 1 << 17, 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;
	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;
	return tmp;
}
const int MAX = 1000;
char C[MAX * 4];
const int dm = 1 << 17;
char* dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(int A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	if (A >= 1000) {
		int dig = 1;
		if (A >= 100000) dig = 3;
		else if (A >= 10000) dig = 2;
		memcpy(di, C + A / 1000 * 4 + 3 - dig, dig);
		memcpy(di + dig, C + A % 1000 * 4, 4);
		di += dig + 4;
	}
	else {
		int dig = 1;
		if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, C + A * 4 + 3 - dig, dig + 1);
		di += dig + 1;
	}
}

int N, Q;
int D[200001], dmemo[200001];
int ne[200001], he[200001];
int ne2[200001], he2[200001];
int dcnt[200001];
int que[200001], q, d;

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

	N = getint();
	for (int i = 2; i <= N; i++) {
		int a = getint();
		ne[i] = he[a];
		he[a] = i;
	}
	Q = getint();
	rep1(q, Q) {
		int u = getint();
		ne2[q] = he2[u];
		he2[u] = q;
		D[q] = getint();
	}
	que[q++] = 1;
	while (q) {
		int p = que[q - 1];
		if (p > 0) {
			que[q - 1] = -p;
			for (int i = he2[p]; i; i = ne2[i]) {
				dmemo[i] = dcnt[D[i]];
			}
			dcnt[d]++;
			d++;
			for (int i = he[p]; i; i = ne[i]) {
				que[q++] = i;
			}
		}
		else {
			for (int i = he2[-p]; i; i = ne2[i]) {
				dmemo[i] = dcnt[D[i]] - dmemo[i];
			}
			d--;
			q--;
		}
	}

	rep(i, MAX) {
		int X = i;
		rep(j, 3) {
			C[i * 4 + 2 - j] = '0' + X % 10;
			X /= 10;
		}
		C[i * 4 + 3] = ' ';
	}
	rep1(i, Q) putint(dmemo[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v(4);
  int sum = 0;
  for (int i = 0; i < 4; i++) cin >> v[i], sum += v[i];
  for (int i = 0; i < 16; i++) {
    int t = 0;
    for (int j = 0; j < 4; j++) {
      t += ((i >> j) & 1) * v[j];
    }
    if (t == sum - t) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

#include <bits/stdc++.h>

#define endl "\n"

using namespace std;

void setup() {
    #ifdef LOCAL
    freopen("input", "r", stdin);
    #else
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif
}

int main() {
    setup();
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int res = 0;
    if (A == C && B == D);
    else if (abs(A - C) + abs(B - D) <= 3) res = 1;
    else if (A + B == C + D || A - B == C - D) res = 1;
    else if (abs(A - C) + abs(B - D) <= 6) res = 2;
    else if (abs(A - B - C + D) <= 3 || abs(A + B - C - D) <= 3) res = 2;
    else if ((A + B) % 2 == (C + D) % 2) res = 2;
    else res = 3;
    cout << res << endl;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <array>
#include <random>
#include <cmath>
#include <chrono>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <climits>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define trav(a, x) for(auto& a : x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use rng() to get unsigned int
// mt19937_64 for random long longs

void solve() {
	string x;
	int n;
	cin >> n;
	cin >> x;
	if (x[0] != x.back()) {
		cout << 1 << endl;
		return;
	}
	// int n = sz(x);
	rep(i, 1, n-2) {
		if (x[i] != x[0] && x[i + 1] != x[0]) {
			cout << 2 << endl;
			return;
		}
	}
	cout << -1 << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
char s[200200];
int main(void) {
    int n; scanf("%d%s",&n,s);
    int top=0;
    for (int i=0;i<n;i++) {
        if (top < 2) {
            s[top++]=s[i];
        } else {
            if (s[i] == 'x') {
                if (s[top-2] == 'f' && s[top-1] == 'o') top -= 2;
                else s[top++]=s[i];
            } else s[top++]=s[i];
        }
    }
    printf("%d\n",top);
    return 0;
}


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

struct Da{
    int x , y;
    int dot , tim;
    int dc(Da b){
       return x * b.x + y * b.y;
    }
    int tc(Da b){
        return x * b.y - y * b.x;
    }
};

int main(){
    #ifdef LOCAL
    freopen("input.txt" , "r" , stdin);
    #endif
    int n ; Da a[110] , b[110];
    cin >> n;
    for(int i = 0 ; i < n ; i ++ ) cin >> a[i].x >> a[i].y ;
    for(int i = 0 ; i < n ; i ++ ) cin >> b[i].x >> b[i].y;
    for(int i = n ; i > 0 ; i -- ) a[i].x -= a[0].x , a[i].y -= a[0].y;
    set<pair<int,int>> s;
    if(n == 1){
        puts("Yes");
        return 0;
    }
    for(int i = 2 ; i < n ; i ++ ){
        s.insert({a[1].dc(a[i]) ,a[1].tc(a[i])});
    }
    // cout << "*" << endl;
    // for(auto it : s){
    //     cout << it.first << " " << it.second << endl;
    // }
    for(int i = 0 ; i < n ; i ++ ){
        for(int j = 0 ; j < n ; j ++ ){
            if(i == j) continue;
            int dx = b[i].x - b[j].x , dy = b[i].y - b[j].y;
            if(dx * dx + dy * dy != a[1].x * a[1].x + a[1].y * a[1].y) continue;
            bool f = 1;
            for(int k = 0 ; k < n ; k ++ ) if(k != i)b[k].x -= b[i].x , b[k].y -= b[i].y;
            b[i].x = b[i].y = 0;
            for(int k = 0 ; k < n ; k ++ ){
                if(k == i || k == j) continue;
                if(!s.count({b[j].dc(b[k]) , b[j].tc(b[k])})){
                    f = 0;
                    break;
                }
            }
            if(f){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int n;
const int N=1e6;
struct moun{
    int a;
    string b;
}a[N];
bool cmp(moun a,moun b){
    return a.a<b.a;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i].b>>a[i].a;
    sort(a+1,a+1+n,cmp);
    cout<<a[n-1].b<<endl;
    // system("pause");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

class RangeMexQuery {
private:
    int n, m;
    vector<array<int, 3> > ptr;
    vector<int> arr, st;
    int update(const int prv, const int id, const int val, const int l, const int r){
        const int cur = (int)ptr.size();
        ptr.push_back({0, 0, id});
        if(r - l == 1) return cur;
        const int mid = (l + r) / 2;
        if(val < mid){
            const int res = update(ptr[prv][0], id, val, l, mid);
            ptr[cur][0] = res, ptr[cur][1] = ptr[prv][1];
        }else{
            const int res = update(ptr[prv][1], id, val, mid, r);
            ptr[cur][0] = ptr[prv][0], ptr[cur][1] = res;
        }
        ptr[cur][2] = min(ptr[ptr[cur][0]][2], ptr[ptr[cur][1]][2]);
        return cur;
    }
    void preprocessing(const vector<int>& vec){
        arr[0] = 0;
        for(int i = 0; i < n; ++i) arr[2 * i + 1] = vec[i], arr[2 * i + 2] = vec[i] + 1;
        sort(arr.begin(), arr.end());
        arr.erase(unique(arr.begin(), arr.end()), arr.end());
        m = (int)arr.size(), st[0] = 0, ptr.push_back({0, 0, -1});
        for(int i = 0; i < n; ++i){
            const int val = (int)(lower_bound(arr.begin(), arr.end(), vec[i]) - arr.begin());
            st[i + 1] = update(st[i], i, val, 0, m);
        }
    }
    int query(const int cur, const int cri, const int l, const int r){
        if(cur == 0 || r - l == 1) return arr[l];
        const int mid = (l + r) / 2;
        if(ptr[ptr[cur][0]][2] < cri) return query(ptr[cur][0], cri, l, mid);
        else return query(ptr[cur][1], cri, mid, r);
    }
public:
    RangeMexQuery(const vector<int>& vec) : n((int)vec.size()), arr(2 * n + 1), st(n + 1){
        preprocessing(vec);
    }
    int query(const int l, const int r){
        return query(st[r], l, 0, m);
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    RangeMexQuery rmq(a);
    int mi = inf;
    rep(i,n-m+1){
        chmin(mi,rmq.query(i,i+m));
    }
    cout << mi << endl;
    return 0;
}

#include <bits/stdc++.h>
#include <unordered_set>
#include <cmath>

// URL: https://atcoder.jp/contests/abc195/tasks/abc195_d

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

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

#define repll(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repsll(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)

#define ALL(a) (a).begin(), (a).end()

#define pb push_back
#define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)

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

const ll INFL = 1e18;
const int INF = 1e9;

int main(){
  optimize_cin();

  ll N, M, Q;
  cin >> N >> M >> Q;

  //vector<pll> WV(N);
  //vll W(N), V(N);
  vector<pll> VW(N);
  vll X(M), L(Q), R(Q);

  rep(i, N){
  ll W, V;
  // cin >> W[i] >> V[i];
  cin >> W >> V;
  VW[i] = make_pair(V, W);
  // WV[i].first() = W;
  // WV[i].second() = V;
  }
  rep(i, M) cin >> X[i];
  rep(i, Q) cin >> L[i] >> R[i];

  sort(ALL(VW));
  reverse(ALL(VW));

  // ll max = 0;

  rep(i, Q) {
  vector<bool> box(M, true);
  for(int j = L[i] - 1; j <= R[i] - 1; j++){
  box[j] = false;
  }
  vll avail;
  rep(j, M){
  if(box[j]){
  avail.pb(X[j]);
  }
  }
  sort(ALL(avail));
  // reverse(ALL(avail));
  vll used(avail.size(), false);
  int cnt = avail.size();
  ll max = 0;
  rep(j, N)
  {
  rep(k, avail.size()){
  if(cnt > 0 && !used[k] && VW[j].second <= avail[k]){
  max += VW[j].first;
  used[k] = true;
  cnt--;
  break;
  }
  }
  }
  cout << max << endl;

}

  return 0;
}


#include<cstdio>
#include<algorithm>
#include<vector>
#define SZ 262144
using namespace std;
int n, M, A[2010];
long long Mod = 1000000007, Inv[101000];

long long Pow(long long a, long long b){
    long long r=1;
    while(b){
        if(b&1)r=r*a%Mod;
        a=a*a%Mod;b>>=1;
    }
    return r;
}

long long Comb(int a, int b){
    int i;
    long long r=1;
    for(i=1;i<=b;i++){
        r=r*(a-i+1)%Mod;
        r=r*Pow(i,Mod-2)%Mod;
    }
    return r;
}

int main(){
    int i;
    for(i=1;i<=100000;i++)Inv[i]=Pow(i,Mod-2);
    scanf("%d%d",&n,&M);
    long long r=1;
    int H = 0, s = 0;
    for(i=1;i<=n;i++){
        scanf("%d",&A[i]);
        H+=A[i]+1;
        s+=A[i];
    }
    if(s>M){
        puts("0");
        return 0;
    }
    printf("%lld\n",Comb(H+M-s, H));
}

// atcoder/abc185/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

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

  int n, m;
  while (cin >> n >> m) {
    vec<int> a(n);
    vec<int> b(m);
    cin >> a >> b;
    const int N = 1000 + 3;
    static int dp[N][N];
    const int inf = 1 << 29;
    fill(&dp[0][0], &dp[N - 1][N - 1] + 1, inf);
    dp[0][0] = 0;
    for (int i = 0; i <= n; ++i) {
      for (int j = 0; j <= m; ++j) {
        if (i < n && j < m) {
          if (a[i] == b[j]) {
            setmin(dp[i + 1][j + 1], dp[i][j]);
          } else {
            setmin(dp[i + 1][j + 1], dp[i][j] + 1);
          }
        }
        if (j < m) setmin(dp[i][j + 1], dp[i][j] + 1);
        if (i < n) setmin(dp[i + 1][j], dp[i][j] + 1);
      }
    }
    cout << dp[n][m] << endl;
  }

  return 0;
}


#include<algorithm>
#include<functional> // for hash
#include<climits> // all useful constants
#include<cmath>
#include<cstdio>
#include<cstdlib> // random
#include<ctime>
#include<iostream>
#include<sstream>
#include<iomanip> // right justifying std::right and std::setw(width)
/*** Data Structure ***/
#include<deque> // double ended queue
#include<list>
#include<queue> // including priority_queue
#include<stack>
#include<string>
#include<map>
#include<vector>
#include<numeric>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long N;
  cin>>N;
  for(long long i=1;i<1000000000;i++){
    if((i*(i+1)/2) >= N){
      cout<<i<<endl;
      break;
    }
  }

}

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

using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
using pl = pair<ll, ll>;
using vl = vector<ll>;

#define all(v) (v).begin(), (v).end()
#define ar array
#define PB push_back
#define sz(x) (int)(x).size()

template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
    os << '{';
    string sep;
    for (const T &x : v)
        os << sep << x, sep = ", ";
    return os << '}';
}
void dbg_out()
{
    cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

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

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

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

void solve()
{
	ll n;
	cin >> n;
	ll l = 1, r = 1e6, ans = 0;
	while(l<=r){
		ll m = l+(r-l)/2;
		if (m*(m+1)/2>=n){
			ans = m;
			r = m-1;
		}else l = m+1;
	}
	cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int testcase=1;
    //cin >> testcase;
    while (testcase--)
    {
        solve();
    }
}


#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define F first
#define S second
#define all(x) begin(x), end(x)
using namespace std;

typedef pair<int,int> pii;

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

vector<int> G[maxn] = {};
vector<int> chart[maxn] = {};

int P[maxn][20] = {};
int dep[maxn] = {};
int in[maxn] = {};

int tick = 0;
void dfs(int x, int d) {
    in[x] = ++tick;
    chart[d].PB(x);
    dep[x] = d;
    for (auto y : G[x]) {
        dfs(y, d+1);
    }
}

int anc(int x, int k) {
    for (int i=19; i>=0; i--) {
        if (dep[P[x][i]] >= k) {
            x = P[x][i];
        }
    }

    return x;
}

int BS(int l, int r, int U,int D) {
    // printf("1(%lld, %lld)\n", l, r);
    if (l == r)
        return l;
    int m = (l + r) / 2;
    if (in[anc(chart[D][m], dep[U])] >= in[U])
        return BS(l, m, U, D);
    else
        return BS(m+1, r, U, D);
}

int BS2(int l, int r, int U,int D) {
    // printf("2(%lld, %lld)\n", l, r);
    if (l == r)
        return l;
    int m = (l + r) / 2;
    if (in[anc(chart[D][m], dep[U])] > in[U])
        return BS2(l, m, U, D);
    else
        return BS2(m+1, r, U, D);
}

int cmp1(int a, int b, int k) {
    return in[anc(a, k)] < in[anc(b, k)];
}

int32_t main() {
    int N,Q;

    cin >> N;
    for (int i=2; i<=N; i++) {
        cin >> P[i][0];
        G[P[i][0]].PB(i);
    }
    dep[0] = -1;
    dfs(1, 0);

    for (int i=1; i<20; i++) {
        for (int j=1; j<=N; j++) {
            P[j][i] = P[ P[j][i-1] ][i-1];
        }
    }

    // for (int i=1; i<=N; i++) {
    //     printf("%lld >>> ", i);
    //     for (int j=0; j<5; j++) {
    //         printf("%lld ", P[i][j]);
    //     }
    //     printf("\n");
    // }

    cin >> Q;
    while (Q--) {
        int U, D;
        cin >> U >> D;
        if (dep[U] > D) {
            printf("0\n");
            continue;
        } else if (dep[U] == D) {
            printf("1\n");
            continue;
        } else {
            int L = BS(0, chart[D].size(), U, D);
            int R = BS2(0, chart[D].size(), U, D);
            int ans = R - L;
            // printf("[%lld, %lld)\n", L, R);
            printf("%lld\n", ans);
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        ll lower,higher;
        cin>>lower>>higher;
        ll term=max(higher-2*lower+1,0ll);
        ll n=term;
        ll ans=n*(2+(n-1));
        ans/=2;
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
// #pragma optimize("-O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,avx,mmx,tune=native")
// #define ll long long
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
#define vvi vector<vector<ll>>
#define vi vector<ll>
#define sz(a) ll((a).size())
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1)
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// typedef tree<
// ll,
// null_type,
// less<ll>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;
#define int long long
const ll MOD =  998244353;
const ll BIG_INF = 4e18;
const ll INF = 1e9;
const ll mod =  998244353;
ll fast_exp(ll a, ll b)
{
    if(b <= 0)
       return 1;
    else
    {
       ll res = 1;
       res = fast_exp(a,b/2);
       res = res % mod;
       res = (res*res)%mod;
       if(b%2 == 1)
          res = (res*a)%mod;
       return res;

    }
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//shuffle(v.begin(),v.end(),rng);

ll true_rand(ll n) {
    // Returns a random number between 0 and n - 1 inclusive using mt19937.
    uniform_int_distribution<ll> uid(0, n - 1);
    return uid(rng);
}

// gambler's ruin: A has i, B has N-i
// P[i] = A wins = (1 - (q/p)^i)/(1 - (q/p)^n)

// ll fact[N] = {};
// ll fac_inv[N] = {};
// void precompute_factorial()
// {
//     fact[0] = 1;
//     fac_inv[0] = 1;
//     for(ll i = 1; i < N; i++)
//     {
//         fact[i] = (fact[i-1] * i) % mod;
//         fac_inv[i] = (fast_exp(i,mod-2) * fac_inv[i-1]) % mod;
//     }
// }
// ll binom(ll n, ll r)
// {
//   if(r < 0 || r > n || n < 0)
//       return 0;
//   ll ans = fact[n];
//   ans = (ans * fac_inv[n-r]) % mod;
//   ans = (ans * fac_inv[r]) % mod;
//   return ans;
// }

const ll N = 1e5+1000;
typedef double ld;
const long double pi = acos(-1.0);
using cd = complex<double>;
const double PI = acos(-1);

int dp[102][102][5005] = {};

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("list_of_clgs_icpc.txt","r",stdin);
    int n;
    cin >> n;
    int w[n + 1] = {};
    int sum = 0;
    ll fac[200] = {};
    fac[0] = 1;
    for(int i = 1; i < 200; i++)
    {
      fac[i] = (i * fac[i-1]) % mod;
    }
    for(int i = 1; i <= n; i++)
    {
      cin >> w[i];
      sum += w[i];
    }
    if(sum % 2 == 1)
    {
      cout << 0 << endl;
      return 0;
    }
   dp[0][0][0] = 1;
   int targ = sum / 2;
   for(int i = 1; i <= n; i++)
   {
       for(int j = 0; j < n; j++)
       {
         for(int s = 0; s <= targ; s++)
         {
            dp[i][j][s] += dp[i-1][j][s];
            if(dp[i][j][s] > mod)
               dp[i][j][s] -= mod;

            if(s + w[i] <= targ)
            {
               dp[i][j+1][s + w[i]] += dp[i-1][j][s];
               if(dp[i][j+1][s + w[i]] > mod)
                  dp[i][j + 1][s + w[i]] -= mod;
            }
         }
       }
   }

      ll ans = 0;
      for(int j = 1; j < n; j++)
      {
         ll ways = dp[n][j][targ];
         ways = (ways * fac[j]) % mod;
         ways = (ways * fac[n - j]) % mod;
         ans = (ans + ways) % mod;
      }

       cout << ans << endl;

   return 0;

}

#include <bits/stdc++.h>

using namespace std;

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

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

#define mp make_pair

const int p = 1e9 + 7;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

mt19937 rnd(time(0));

const int N = 1000005;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}

/*struct DSU
{
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU (int n)
    {
        parent.resize(n);
        sz.resize(n);
        for (int i = 0; i<n; i++) make_set(i);
    }
};*/

int f(char c)
{
    if (c=='A') return 0; else return 1;
}

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

    int n;
    char caa, cab, cba, cbb;
    cin>>n>>caa>>cab>>cba>>cbb;

    int aa, ab, ba, bb;
    aa = f(caa); ab = f(cab); ba = f(cba); bb = f(cbb);

    vector<int> fin(n+1);
    fin[0] = 1;
    fin[1] = 1;
    for (int i = 2; i<=n; i++) fin[i] = add(fin[i-1], fin[i-2]);

    if (ab == 0)
    {
        if (aa==0) {cout<<1; return 0;}
        //now ab = 0, aa = 1
        if (ba==1)
        {
            cout<<po(2, n-3); return 0;
        }
        cout<<fin[n-2]; return 0;
        //now ba = 0
    }
    else
    {
        if (bb==1) {cout<<1; return 0;}
        //now ab = 1; bb = 0
        if (ba==0)
        {
            cout<<po(2, n-3); return 0;
        }
        cout<<fin[n-2]; return 0;
    }
}

/*
3 2
1 2 3
2 3 3
 */


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

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

int main() {
    int N;
    cin>>N;
    vector<int> A(N),B(N);
    rep(i,N){
        cin>>A[i]>>B[i];
    }
    int ans=1000000;
    rep(i,N){
        rep(j,N){
            int memo;
            if(i==j){
                memo=A[i]+B[i];
            }
            else{
                memo=max(A[i],B[j]);
            }
            ans=min(ans,memo);
        }
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	int a[n][2];
	int c[n*n];
	for(int i=0;i<n;++i){
		int max=0;
		for(int j=0;j<2;++j){
			cin>>a[i][j];
			max=max+a[i][j];
		}
		c[i]=max;
	}
	int b=n;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			if(i!=j){
				c[b]=max(a[i][0],a[j][1]);
				++b;
		}
		}
	}
	sort(c,c+n*n);
	cout<<c[0];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
  owo
	int h,w;
	cin>>h>>w;
	VII grid(h+2,vector<ll>(w+2)),grid2(h+2,vector<ll>(w+2));
	int n,m;
	cin>>n>>m;
	VII row(h+1),col(w+1);
	vector<pii>a(n);
	for(int i=0;i<n;i++){
		cin>>a[i].fi>>a[i].se;
	}
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		row[x].pb(y);
		col[y].pb(x);
	}
	//cout<<'\n';
	for(int i=1;i<=h;i++){row[i].pb(0);row[i].pb(w+1);sort(all(row[i]));}
	for(int i=1;i<=w;i++){col[i].pb(0);col[i].pb(h+1);sort(all(col[i]));}
	for(int i=0;i<n;i++){
		int x = a[i].fi;
		int y = a[i].se;
		int p = ub(all(row[x]),y)-row[x].begin();
		int l = row[x][p-1]+1;
		int r = row[x][p];
		//cout<<l<<" "<<r<<'\n';
		grid[x][l]++;
		grid[x][r]--;
	    p = ub(all(col[y]),x)-col[y].begin();
		l = col[y][p-1]+1;
		r = col[y][p];
		//cout<<l<<" "<<r<<'\n';
		grid2[l][y]++;
		grid2[r][y]--;
		//cout<<'\n';
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
		   grid[i][j]+=grid[i][j-1];
		}
	}

	for(int j=1;j<=w;j++){
		for(int i=1;i<=h;i++){
			grid2[i][j]+=grid2[i-1][j];
		}
	}
	ll ans = 0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(grid[i][j]+grid2[i][j])ans++;
			//cout<<grid[i][j]+grid2[i][j]<<" ";
		}
		//cout<<'\n';
	}
	cout<<ans;

}

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MAX_H = 1500;
const static int MAX_W = 1500;
bool is_wall_or_light[MAX_H][MAX_W];

int main(){
    unsigned H, W, N, M;
    scanf("%u %u %u %u", &H, &W, &N, &M);
    vector<int> light_row[H], light_column[W];
    vector<int> wall_row[H], wall_column[W];
    unsigned answer = N;
    int a, b, c, d;
    for (unsigned i = 0; i < N; i++){
        scanf("%d %d", &a, &b);
        a--, b--;
        light_row[a].push_back(b);
        light_column[b].push_back(a);
        is_wall_or_light[a][b] = true;
    }
    for (unsigned i = 0; i < M; i++){
        scanf("%d %d", &c, &d);
        c--, d--;
        wall_row[c].push_back(d);
        wall_column[d].push_back(c);
        is_wall_or_light[c][d] = true;
    }
    for (unsigned i = 0; i < H; i++){
        light_row[i].push_back(-2);
        light_row[i].push_back(W+1);
        wall_row[i].push_back(-1);
        wall_row[i].push_back(W);
        sort(light_row[i].begin(), light_row[i].end());
        sort(wall_row[i].begin(), wall_row[i].end());
    }
    for (unsigned i = 0; i < W; i++){
        light_column[i].push_back(-2);
        light_column[i].push_back(H+1);
        wall_column[i].push_back(-1);
        wall_column[i].push_back(H);
        sort(light_column[i].begin(), light_column[i].end());
        sort(wall_column[i].begin(), wall_column[i].end());
    }
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            if(is_wall_or_light[i][j]) continue;
            if(auto it_light = lower_bound(light_row[i].begin(), light_row[i].end(), j), it_wall = lower_bound(wall_row[i].begin(), wall_row[i].end(), j);
            *it_light < *it_wall || *(--it_light) > *(--it_wall)){
                answer++;
                continue;
            }
            if(auto it_light = lower_bound(light_column[j].begin(), light_column[j].end(), i), it_wall = lower_bound(wall_column[j].begin(), wall_column[j].end(), i);
            *it_light < *it_wall || *(--it_light) > *(--it_wall)){
                answer++;
                continue;
            }
        }
    }
    printf("%u\n", answer);
	return 0;
}


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

#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
#define PI 3.14159265359
const long long INF = 1LL << 60;
long long MOD = 1000000007;
long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a; }
long long lcm (int a, int b){return  (long long) a*b /gcd(a,b);}

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

    vector<int>ab,cd;

    for(int i = 2; i<=2*N ; i++){
        if(i - K >= 2 && i- K <= 2*N){
            ab.push_back(i);
            cd.push_back(i-K);
        }
    }

    long long ans = 0;
    for(int i = 0; i<ab.size(); i++){
        long long x,y;
        if(ab[i] <= N+1) x = ab[i]-1;
        else x = (N+1)*2 - ab[i] -1;

        if(cd[i] <= N+1) y = cd[i]-1;
        else y = (N+1)*2 -cd[i] -1;

        ans +=  x * y;
    }

    cout << ans << endl;

}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

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

//    int tc; cin >> tc;
//    TC(tc) solve();
	ll n, k;
	cin >> n >> k;
	k = abs(k);
	ll a, b, c, d, ans = 0;
	FORN(i, 2, 2 * n - k) {
        b = min(n, (ll)i - 1), a = (ll)i - b;
        d = min(n, (ll)i + k - 1), c = (ll)i + k - d;
        ans += (b - a + 1) * (d - c + 1);
    }
	OUT(ans);
    return 0;
}


#include <bits/stdc++.h>

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int a,b;
  cin>>a>>b;
  cout<<Fixed(10)<<double(double(a-b)/double(a))*100<<'\n';
  return 0;
}

#include <cstdint>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cctype>
#include <limits> // INT_MAX ...

using namespace std;

struct fast_ios {
  fast_ios() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout << fixed << setprecision(10);
  }
} fast_ios_;

int main() {
  int N, K;
  cin >> N >> K;
  int64_t res = N;
  while (K-- > 0) {
    if (res % 200 == 0) res /= 200;
    else if (K > 0) res = res * 5 + 1, K--;
    else res = res * 1000 + 200;
  }
  cout << res << '\n';

  return 0;
}


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

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0);
    double sx, sy, ex, ey;
    cin>>sx>>sy>>ex>>ey;
    printf("%.9f", sx+sy*((ex-sx)/(ey+sy)));
    return 0;
}

//:::: Alien :::://
// Muhammad Eid //
#include <bits/stdc++.h>
using namespace std;

void Mo35() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

int main() {  Mo35();

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int mx = -2e9;
    for (int x = a; x <= b; ++x) {
        for (int y = c; y <= d; ++y)
            mx = max(mx, x - y);
    }
    cout << mx;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int s0,t0,st;
int main(){
	int n;cin>>n;
	string s,t;cin>>s>>t;
	for(int i=0;i<n;i++){
		if(s[i]=='0') s0++;
		if(t[i]=='0') t0++;
		if(s[i]=='0'&&t[i]=='0'&&t0==s0)st++;
 	}
 	if(s0!=t0) cout<<-1;
 	else cout<<s0-st;
	return 0;
}

#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int n,i,j,k,l;
char S[500001];
char T[500001];
int s1[500001],s2[500001];
int ans,sum;

int main()
{
	#ifdef file
	freopen("b.in","r",stdin);
	#endif

	scanf("%d",&n);
	scanf("%s",S+1);
	scanf("%s",T+1);

	fo(i,1,n)
	{
		s1[i]=s1[i-1]+(S[i]=='0');
		s2[i]=s2[i-1]+(T[i]=='0');
	}
	fo(i,1,n) sum+=S[i]=='0';
	ans=sum;
	fo(i,1,n) sum-=T[i]=='0';
	if (sum) {printf("-1\n");return 0;}

	fo(i,1,n)
	if (S[i]==T[i] && S[i]=='0' && s1[i]==s2[i])
	--ans;

	printf("%d\n",ans);

	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include <set>
#include <map>
#include <iostream>
using namespace std;

void add(multimap<long long, long long>& D, long long dist, long long i1, long long i2) {
    D.emplace(dist, i1 > i2 ? i2 << 32 | i1 : i1 << 32 | i2);
}

int main(void){
    // Your code here!
    long long N;
    multimap<long long, long long> X;
    multimap<long long, long long> Y;
    multimap<long long, long long> D;

    cin>> N;

    for (int i = 0; i < N; i++) {
        long long x, y;
        cin >> x >> y;
        X.emplace(x, i);
        Y.emplace(y, i);
    }

    auto xb = X.begin();
    auto xr = X.rbegin();
    auto yb = Y.begin();
    auto yr = Y.rbegin();

    add(D, abs(xr->first - xb->first), xr->second, xb->second);
    xr++;
    add(D, abs(xr->first - xb->first), xr->second, xb->second);
    xr = X.rbegin();
    xb++;
    add(D, abs(xr->first - xb->first), xr->second, xb->second);

    add(D, abs(yr->first - yb->first), yr->second, yb->second);
    yr++;
    add(D, abs(yr->first - yb->first), yr->second, yb->second);
    yr = Y.rbegin();
    yb++;
    add(D, abs(yr->first - yb->first), yr->second, yb->second);

    auto d = D.rbegin();
    long long i = d->second;
//    cout <<  d->first << d->second << endl;
    d++;
//    cout <<  d->first << d->second << endl;
    if (i == d->second) {
        d++;
//    cout <<  d->first << d->second << endl;
    }

    cout <<  d->first;

}

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

class A2ndGreatestDistance {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> x(N), y(N);
        vector<pair<int, int>> vx(N), vy(N);
        REP(i, N) {
            cin >> x[i] >> y[i];
            vx[i] = {x[i], i};
            vy[i] = {y[i], i};
        }
        sort(vx.begin(), vx.end());
        sort(vy.begin(), vy.end());
        vector<int> cand;
        cand.push_back(vx[0].second);
        cand.push_back(vx[1].second);
        cand.push_back(vx[N - 1].second);
        cand.push_back(vx[N - 2].second);
        cand.push_back(vy[0].second);
        cand.push_back(vy[1].second);
        cand.push_back(vy[N - 1].second);
        cand.push_back(vy[N - 2].second);
        sort(cand.begin(), cand.end());
        cand.erase(unique(cand.begin(), cand.end()), cand.end());
        vector<int> res;
        REP(ci, cand.size()) {
            int i = cand[ci];
            FOR(cj, ci + 1, cand.size() - 1) {
                int j = cand[cj];
                res.push_back(max(abs(x[i] - x[j]), abs(y[i] - y[j])));
            }
        }
        sort(res.rbegin(), res.rend());
        cout << res[1] << endl;
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    A2ndGreatestDistance solver;
    solver.solve(in, out);
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<math.h>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rrep(i,l,r) for(int i=l;i<=r;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define unq(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define mod 1000000007
//#define mod 998244353
#define ad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
void readv(vector<ll> &a,ll n){
	rep(i,n){
		ll x;
		cin>>x;
		a.push_back(x);
	}
}
void outv(vector<ll> &a,ll n){
	rep(i,n){
		if(i>0)cout<<" ";
		cout<<a[i];
	}
	cout<<"\n";
}
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define FACMAX 200010
ll fac[FACMAX],inv[FACMAX],ivf[FACMAX];
void initfac(){
	fac[0]=ivf[0]=inv[1]=1;
	for(ll i=1;i<FACMAX;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=1;i<FACMAX;i++){
		if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
		ivf[i]=po(fac[i],mod-2);
	}
}
ll P(ll n,ll k){
	if(n<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod;
}
ll C(ll n,ll k){
	if(k<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll H(ll n,ll k){
	return C(n+k-1,k);
}
ll n,m,a[10010],b[10010],c[110];
vector<ll> eid[110];
ll ans[10010];
bool ans_ok[10010];
vector<ll> g[110];
ll p[110],d[110];
bool vis[110];
void dfs(ll x,ll from,ll dep){
	if(vis[x])return;
	vis[x]=1;
	d[x]=dep;
	p[x]=from;
	for(auto y:g[x])if(y!=from){
		dfs(y,x,dep+1);
	}
}
vector<ll> to[110];
ll dfs2(ll x){
	if(vis[x])return 0;
	ll res=1;
	vis[x]=1;
	for(auto y:to[x])res+=dfs2(y);
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>m;
	rep(i,m){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
	}
	rep(i,n)cin>>c[i];
	rep(i,m){
		if(c[a[i]]==c[b[i]]){
			eid[c[a[i]]].pb(i);
		}
		else{
			if(c[a[i]]>c[b[i]])ans[i]=0;
			else ans[i]=1;
		}
		ans_ok[i]=0;
	}
	for(int l=1;l<=n;l++){
		rep(i,n)g[i].clear();
		for(auto i:eid[l]){
			g[a[i]].pb(b[i]);
			g[b[i]].pb(a[i]);
		}
		for(int s=0;s<n;s++){
			rep(i,n)vis[i]=0,p[i]=-1,d[i]=-1;
			dfs(s,-1,0);
			vector<ll> comp;
			rep(i,n)if(vis[i])comp.pb(i);
			vector<ll> es;
			for(auto i:eid[l]){
				if(vis[a[i]]==1&&vis[b[i]]==1)es.pb(i);
			}
			rep(i,n)to[i].clear();
			for(auto i:es){
				if(ans_ok[i])continue;
				if(p[a[i]]==b[i]){
					to[b[i]].pb(a[i]);
					ans[i]=1;
				}
				else if(p[b[i]]==a[i]){
					to[a[i]].pb(b[i]);
					ans[i]=0;
				}
				else if(d[a[i]]<d[b[i]]){
					to[b[i]].pb(a[i]);
					ans[i]=1;
				}
				else{
					to[a[i]].pb(b[i]);
					ans[i]=0;
				}
			}
			bool renketsu=1;
			for(auto t:comp){
				for(auto i:comp)vis[i]=0;
				renketsu&=(dfs2(t)==(ll)comp.size());
			}
			if(renketsu){
				for(auto i:es)ans_ok[i]=1;
			}
		}
	}
	rep(i,m){
		cout<<(ans[i]==0?"->":"<-")<<"\n";
	}
}

#include <bits/stdc++.h>

#define     boost            ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pb               push_back
#define     pob              pop_back
#define     pof              pop_front
#define     pf               push_front
#define     mp               make_pair
#define     ff               first
#define     ss               second
#define     endl             "\n"

#define     rep(i,a,b)       for(ll i=a; i<b; i++)
#define     rev(i,a,b)       for(ll i=a; i>=b; i--)

#define     decimal(n)       fixed << setprecision(n)
#define     all(v)           v.begin(), v.end()
#define     rall(v)          v.rbegin(), v.rend()
#define     sz(v)            v.size()
#define     total_sum(v)     accumulate(all(v),0)

#define     make_unique(v)   v.erase(unique(all(v)),v.end())
#define     n_p(v)           next_permutation(all(v))
#define     p_p(v)           prev_permutation(all(v))

#define     for_each(it, X)  for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)

#define     re               return

using namespace std;

typedef     long long              ll;
typedef     unsigned long long     ull;
typedef     pair < int, int >      pii;
typedef     pair < ll, ll >        pll;
typedef     vector < pii >         vii;
typedef     vector < pll >         vll;
typedef     vector < int >         vi;
typedef     vector < ll >          vl;
typedef     vector < string >      vs;

ll gcd ( ll , ll );

ll lcm ( ll  , ll );

bool isPrime( ll );

ll power( ll , ll );

ll fact( ll );

void sieve_of_eratosthenes ( ll , vl &a);

//---------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------

void solve()
{
	ll a,b,c;
	cin>>a>>b>>c;

	if(c) {

		if(b<=a) {
			c=1;
		}

		else
		c=0;

	}

	else {
		if(a<=b) {
			c=0;
		}

		else
		c=1;
	}

	if(c) {
		cout<<"Takahashi";
	}

	else
	cout<<"Aoki";
}

int main()
{
    boost;
    ll t=1;
//	cin>>t;

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

}

//---------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------

// HCF

ll gcd ( ll a , ll b )  {

	return __gcd ( a , b ) ;

	/*

	if ( a==0 )
	return b ;

	return gcd ( b%a , a ) ;

	*/
}

// LCM

ll lcm ( ll a , ll b )  {

	return ( a * b ) / ( __gcd ( a , b ) ) ;

}

// PRIME

bool isPrime( ll n )
{
    ll i=2;

    for( i ; i*i<=n ; i++)
	{
        if( n % i == 0)
        return false;
    }

    return true;
}

// POWER

ll power( ll b , ll a ) {

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

	ll c=1;

	rep(i,0,a) {
		c*=b;
	}

	return c;

}

// FACTORIAL

ll fact(ll n) {

	ll c=1;

	while(n>1) {
		c*=n;
		n--;
	}

	return c;

}

// SIEVE of ERATOSTHENES

void sieve_of_eratosthenes (ll n, vl &a) {

	a[1]=0;

	for(ll i=2; i*i<=n ; i++) {
		if(a[i]==1) {
			for(ll j=i+i; j<=n ; j+=i) {
				a[j]=0;
			}
		}
	}

}

//-------------------------------------------------------------*/--------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------


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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
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;}
//-------------------------------------------------------

int N;
vector<vector<int>> E;
ll vis[202020];
int have[202020];

ll id=1;
pair<int,int> farthest(vector<vector<int>>& E, int cur,int pre,int d,vector<int>& D) {
	D[cur]=d;
	pair<int,int> r={d,cur};
	FORR(e,E[cur]) if(e!=pre) r=max(r, farthest(E,e,cur,d+1,D));
	return r;
}

pair<int,vector<int>> diameter(vector<vector<int>>& E) { // diameter,center
	vector<int> D[2];
	D[0].resize(E.size());
	D[1].resize(E.size());
	auto v1=farthest(E,0,0,0,D[0]);
	auto v2=farthest(E,v1.second,v1.second,0,D[0]);
	farthest(E,v2.second,v2.second,0,D[1]);
	pair<int,vector<int>> R;
	R.first = v2.first;
	//両端を取る場合
	R.second.push_back(v1.second);
	R.second.push_back(v2.second);

	return R;
}

int dfs1(int cur,int pre,int tar) {
	if(cur==tar) have[cur]=1;
	vis[cur]=id;
	FORR(e,E[cur]) if(e!=pre) {
		have[cur]|=dfs1(e,cur,tar);
	}
	return have[cur];
}
void dfs2(int cur,int pre) {

	vis[cur]=id;
	FORR(e,E[cur]) if(e!=pre) {
		if(have[e]==0) {
			id++;
			dfs2(e,cur);
		}
	}
	FORR(e,E[cur]) if(e!=pre) {
		if(have[e]) {
			id++;
			dfs2(e,cur);
		}
	}
	id++;
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N;
	E.resize(N);
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}

	auto a=diameter(E);

	x=a.second[0];
	y=a.second[1];
	dfs1(x,x,y);
	dfs2(x,x);
	FOR(i,N) cout<<vis[i]<<" ";
	cout<<endl;
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include <cstdio>
#include <vector>
const int maxn = 2e5+5;
int n,ans[maxn],maxx,X,Y;
int head[maxn],tot;
struct Edge{
	int next,to;
}e[maxn<<1];
void add_edge(int x,int y){
	e[++tot].next = head[x];
	e[tot].to = y,head[x] = tot;
}
int fa[maxn],top[maxn],siz[maxn],dep[maxn],son[maxn],Flag[maxn];
void dfs1(int u,int F){
	siz[u] = 1,fa[u] = F,dep[u] = dep[F] + 1;
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next){
		if(v == F)continue;
		dfs1(v,u);
		siz[u] += siz[v];
		if(siz[v] > siz[son[u]])son[u] = v;
	}
}
void dfs2(int u,int T){
	top[u] = T;
	if(son[u])dfs2(son[u],T);
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next)
		if(v != son[u] && v != fa[u])
			dfs2(v,v);
}
int LCA(int x,int y){
	while(top[x]^top[y]){
		if(dep[top[x]]<dep[top[y]])x^=y^=x^=y;
		x = fa[top[x]];
	}return dep[x]<dep[y]?x:y;
}
void getchain(int u,int F){
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next){
		if(v == F)continue;
		getchain(v,u);
		if(Flag[v])Flag[u] = 1;
	}
}
int Dis(int x,int y){return dep[x]+dep[y]-2*dep[LCA(x,y)];}
int nowans,pre;
void getans(int u,int F){
	ans[u] = (nowans+=Dis(u,pre)),pre = u;
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next)
		if(Flag[v] == 0 && v != F)
			getans(v,u);
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next)
		if(v != F && Flag[v] == 1)
			getans(v,u);
}
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<n;++i)
		scanf("%d %d",&x,&y),add_edge(x,y),add_edge(y,x);
	dfs1(1,0),maxx = 0;
	for(int i=1;i<=n;++i)if(maxx < dep[i])maxx = dep[i],X = i;
	for(int i=1;i<=n;++i)fa[i] = son[i] = dep[i] = siz[i] = 0;
	dfs1(X,0),maxx = 0,dfs2(X,X);
	for(int i=1;i<=n;++i)if(maxx < dep[i])maxx = dep[i],Y = i;
	Flag[Y] = 1,getchain(X,0);
	nowans = 1,pre = X,getans(X,0);
	for(int i=1;i<=n;++i)printf("%d ",ans[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
constexpr long long mod = 998244353;

long long modpow(int n, int r) {
    long long ret = 1; long long tmp = (long long) n;
    while (r != 0) {
        if (r % 2) ret *= tmp;
        tmp *= tmp; tmp %= mod; ret %= mod;
        r /= 2;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    long long Ans = 0;
    vector<long long> M_pow(N+1, 1);
    for (int i = 0; i < N; i++) {
        M_pow[i+1] = M_pow[i] * M % mod;
    }
    for (int min_val = 1; min_val <= M; min_val++) {
        for (int interval = 2; interval <= N; interval++) {
            long long fac = N - interval + 1;
            long long tmp = modpow(M - min_val, interval - 2) * M_pow[N - interval] % mod;
            Ans += fac * tmp % mod;
            Ans %= mod;
            // cout << min_val << " " << interval << " " <<  fac << tmp % mod << "\n";
        }
    }
    Ans = mod + M_pow[N] * N % mod - Ans;
    cout << Ans % mod << "\n";
    return 0;
}

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

using num = modnum<998244353>;

vector<num> fact, ifact;

void init(){
	int N = 1100000;
	fact = {1};
	for(int i = 1; i < N; i++) fact.push_back(i * fact[i-1]);
	ifact.resize(N);
	ifact.back() = 1 / fact.back();
	for(int i = N - 1; i > 0; i--) ifact[i-1] = i * ifact[i];
}

num ncr(int n, int k){
	if(k < 0 || k > n) return 0;
	return fact[n] * ifact[k] * ifact[n-k];
}

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	init();
	int n, m;
	cin >> n >> m;
	num ans = pow(num(m), n) * n;
	vector<num> r(m, 1);
	for(int len = 1; len < n; len++){
		num mult = pow(num(m), n-1-len) * (n-len);
		num v = 0;
		for(int a = 0; a < m; a++){
			v += r[a];
			r[a] *= a;
		}
		ans -= mult * v;
	}
	cout << ans << '\n';
}


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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
#define MOD             998244353
//#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }

template<class T>
class UnionFind
{
private:
	vector<T> parentNo;
	vector<T> parentRank;
	vector<T> parentSize;

public:
	// コンストラクタ
	UnionFind(int n)
	{
		parentNo.resize(n);
		parentRank.resize(n, 0);
		parentSize.resize(n, 1);
		for (int i = 0; i < n; i++) {
			// 始めは全部ROOT
			parentNo[i] = i;
		}
	}

	int root(T x)
	{
		if (parentNo[x] == x) {
			return x;
		} else {
			T rootParentNo = root(parentNo[x]);
			parentNo[x] = rootParentNo;
			return rootParentNo;
		}
	}

	bool same(T x, T y)
	{
		return root(x) == root(y);
	}

	int size(T x)
	{
		return parentSize[root(x)];
	}

	void unite(T xc, T yc)
	{
		T xr = root(xc);
		T yr = root(yc);
		if (xr == yr) {
			return;
		}
		if (parentRank[xr] < parentRank[yr]) {
			parentNo[xr] = yr;
			parentSize[yr] += parentSize[xr];
		} else {
			parentNo[yr] = xr;
			parentSize[xr] += parentSize[yr];
			if (parentRank[xr] == parentRank[yr]) {
				parentRank[xr]++;
			}
		}
	}
};

void Solve()
{
	ll N;
	cin >> N;
	vector<P> xy(N);
	REP(i, N) cin >> xy[i].first >> xy[i].second;
	sort(ALL(xy));

	auto compExec = [&](double mid) {
		ll s = N;
		ll t = N + 1;
		UnionFind<ll> uf(N + 2);
		REP(i, N) {
			if (100 - xy[i].second < mid) {
				uf.unite(i, s);
			}
			if (100 + xy[i].second< mid) {
				uf.unite(i, t);
			}
		}

		REP(i, N) {
			REP(j, N) {
				if (i == j) continue;
				auto a = xy[i];
				auto b = xy[j];
				double distOne = pow(b.first - a.first, 2) + pow(b.second - a.second, 2);
				if (distOne < pow(mid, 2)) {
					uf.unite(i, j);
				}
			}
		}

		return !uf.same(s, t);
	};

	double lb = 0;
	double lu = 200;
	double mid = 0;
	REP(i, 121) {
		mid = (lb + lu) / 2;
		if (compExec(mid)) {
			lb = mid;
		} else {
			lu = mid;
		}
	}

	cout << lb / 2 << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpl = vector<pair<ll, ll>>;
using pll = pair<ll, ll>;
#define rep(i, k, n) for(ll i = k; i < n; i++)
#define pb push_back
#define mp make_pair

int main(){
    ld n; cin >> n;
    ld x0, y0; cin >> x0 >> y0;
    ld xn, yn; cin >> xn >> yn;
    const long double pi = 3.141592653589793238462643;

    ld dx = x0-xn;
    ld dy = y0-yn;

    long double theta = (long double)(pi) / (long double)(n);

    // cout << theta << endl;

    ld dx1 = dx*(ld)(cos(theta)) - dy*(ld)(sin(theta));
    ld dy1 = dx*(ld)(sin(theta)) + dy*(ld)(cos(theta));

    ld x1 = xn + dx1*(ld)(cos(theta));
    ld y1 = yn + dy1*(ld)(cos(theta));

    cout << fixed << setprecision(10) << x1;
    cout << " ";
    cout << fixed << setprecision(10) << y1 << endl;
}


#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#include <numeric>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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; }

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

#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
  char S,T;
  cin>>S>>T;
  if(S=='Y')
     {
       if(T=='a')
         cout<<"A";
       else if(T=='b')
         cout<<"B";
       else if(T=='c')
         cout<<"C";
       else
         cout<<T;
     }
  else
    cout<<T;
  return 0;
}


#include<iostream>
#include<map>
using namespace std;
int a[70000];
int main(){
	int n,ans;cin>>n;map<int,bool>mp;
	for(int i=0;i<(1<<n);++i)cin>>a[i];
	for(int i=0;i<n;++i){int x=0,y=1;
		for(int j=0;j<(1<<(n-i-1));++j){
			while(mp[x])++x;
			while(mp[y]||y<=x)++y;
			if(a[x]>a[y])mp[y]=1,ans=y,x=y+1,y=x+1;
			else mp[x]=1,ans=x,x=y+1,y=x+1;
		}
	}
	cout<<ans+1<<endl;
	return 0;
}

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#define rg register
inline int read(){
	rg int x=0,fh=1;
	rg char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*fh;
}
const int maxn=1e6+5;
int n,a[maxn],mmax,mmax2,cs1,cs2,jl1,jl2;
int main(){
	n=read();
	mmax=(1<<n);
	mmax2=mmax/2;
	for(rg int i=1;i<=mmax;i++) a[i]=read();
	for(rg int i=1;i<=mmax2;i++){
		if(a[i]>cs1){
			cs1=a[i];
			jl1=i;
		}
	}
	for(rg int i=mmax2+1;i<=mmax;i++){
		if(a[i]>cs2){
			cs2=a[i];
			jl2=i;
		}
	}
	if(a[jl1]>a[jl2]) printf("%d\n",jl2);
	else printf("%d\n",jl1);
	return 0;
}


#include <iostream>
#include <algorithm>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

const int MAX = 1000000;
int n, K;
int cnt_ijk[MAX * 3];
int cnt_jk[MAX * 2];
int r_cnt_jk[MAX * 2];

signed main() {
	int s, i, j, k;

	cin >> n >> K;

	//j + k = s, 0 <= j, k < n
	for (s = 0; s <= 2 * n - 2; s++) {
		if (s < n) cnt_jk[s] = s + 1;
		else cnt_jk[s] = 2 * n - 1 - s;
	}

	//j + k < s, 0 <= j, k < n
	for (s = 1; s <= 2 * n - 1; s++) {
		r_cnt_jk[s] = r_cnt_jk[s - 1] + cnt_jk[s - 1];
	}

	//i + j + k = s, 0 <= i, j, k < n
	for (s = 0; s <= 3 * n - 3; s++) {
		//l <= j + k && j + k <= r
		int l = max(0LL, s - (n - 1));
		int r = min(2 * n - 2, s);
		cnt_ijk[s] = r_cnt_jk[r + 1] - r_cnt_jk[l];
	}

	//detect. s = i + j + k
	for (s = 0; s <= 3 * n - 3; s++) {
		K -= cnt_ijk[s];
		if (K <= 0) break;
	}
	K += cnt_ijk[s];
	//cout << "s = " << s << ", K = " << K << endl;

	//detect. i
	for (i = 0; i < n; i++) {
		//let's count : j + k = s - i, 0 <= j, k < n
		if (s - i < 0 || s - i >= 2 * n - 1) continue;
		K -= cnt_jk[s - i];
		if (K <= 0) break;
	}
	K += cnt_jk[s - i];
	//cout << "i = " << i << ", K = " << K << endl;

	//detect. j
	for (j = 0; j < n; j++) {
		k = s - i - j;
		if (0 <= k && k < n) K--;
		if (K == 0) break;
	}

	//cout << "j = " << j << ", K = " << K << endl;
	k = s - i - j;

	//to 1-index
	i++; j++; k++;

	cout << i << " " << j << " " << k << endl;
	return 0;
}


	//----------BHAVIK DIWANI(PICT_COMP)---------------
	#include<bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	#define test ll t; cin>>t; while(t--)
	#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define mod 1000000007
	#define ll long long
	#define int long long
	#define ull unsigned long long
	#define MAX 1000005
	#define pb push_back
	#define mkp make_pair
	#define vi vector<int>
	#define pii pair<int,int>
	#define endl '\n'
	#define vs vector<string>
	#define mii map<int,int>
	#define msi map<string,int>
	#define vpii vector< pair<int, int > >
	#define vpsi vector< pair< string ,int > >
	#define forci(p,q) for(int i=p;i<q;i++)
	ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
	ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
	ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
	ll modmul(ll x, ll y){return (x*y)%mod;}
	ll modadd(ll x, ll y){return (x+y)%mod;}
	ll modsub(ll x, ll y){return (x-y+mod)%mod;}
	ll fact[1000007]={0};
	void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
	ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
	ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
	inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
	inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
	inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
	const int inf=1e9;
	/*bool prime[MAX];
	ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
	}*/
	/*
	int inv[1000001]={0};int invf[1000001]={0};
	void findinverse(){
		inv[0]=1;
		inv[1] = 1;
		for(int i = 2; i <=1e6 ; ++i)
			inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
		invf[0]=1;invf[1]=1;
		for(int i=2;i<=1e6;i++){
			invf[i]=invf[i-1]*inv[i]%mod;
		}
	}*/
	using namespace std;
	using namespace __gnu_pbds;
	typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
	typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
	int solve()
	{
		int n,x;
		cin>>n>>x;
		int alcohol=0;
		for(int i=1;i<=n;i++){
			int v,p;
			cin>>v>>p;
			alcohol+=(v*p);
			if(alcohol>x*100LL){
				cout<<i<<endl;
				return 0;
			}
		}
		cout<<"-1"<<endl;
		cout<<endl;
		return 0;
	}
	signed main()
	{
		fastio;
	//	test
			solve();
	}

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

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

    X = X * 100;

    vector<pair<int, int>> V;

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

        V.push_back(make_pair(v,p));
    }

    int total_intake = 0;

    for(int i = 0; i < N; i++)
    {
        int intake = V[i].first * V[i].second;
        total_intake += intake;

        if(total_intake > X)
        {
            cout<<i + 1<<endl;
            return 0;
        }
    }

    cout<<-1<<endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#define rep(i, s, n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
	int A, B;
	cin >> A >> B;

	cout << 2 * A + 100 - B;
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
//#define int long long
const int P=1e9+7; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}

const int MN=4e6+5;
int fac[MN],ifac[MN];
int C(int n,int m) {
	if(n<m||n<0||m<0) return 0; int ans=1,t=1;
	For(i,n-m+1,n) mulmod(ans,i);
	For(i,1,m) mulmod(t,i);
	return mul(ans,inv(t));
}
int n,m,A[MN];
signed main() {
	#ifndef ONLINE_JUDGE
		file("pro");
	#endif
	n=read(),m=read(); int sum=0;
	For(i,1,n) A[i]=read(),sum+=A[i];
	cout<<C(m+n,sum+n)<<endl;
	return FastIO::Fflush(),0;
}


#include <bits/stdc++.h>

using namespace std;

using tint = long long;
using ld = long double;

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

using pi = pair<int,int>;
using pl = pair<tint,tint>;
using vi = vector<int>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vl = vector<tint>;
using vb = vector<bool>;

#define pb push_back
#define pf push_front
#define rsz resize
#define all(x) begin(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
#define ins insert

#define f first
#define s second
#define mp make_pair

#define DBG(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9+7;
const tint mod = 998244353;
const int MX = 2e5+5;
const tint INF = 1e18;
const int inf = 2e9;
const ld PI = acos(ld(-1));
const ld eps = 1e-5;

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

template<class T> void remDup(vector<T> &v){
	sort(all(v)); v.erase(unique(all(v)),end(v));
}

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

bool valid(int x, int y, int n, int m){
	return (0<=x && x<n && 0<=y && y<m);
}

int cdiv(int a, int b) { return a/b+((a^b)>0&&a%b); } //redondea p arriba
int fdiv(int a, int b) { return a/b-((a^b)<0&&a%b); } //redondea p abajo

void NACHO(string name = ""){
	ios_base::sync_with_stdio(0); cin.tie(0);
	if(sz(name)){
		freopen((name+".in").c_str(), "r", stdin);
		freopen((name+".out").c_str(), "w", stdout);
	}
}

pair<pl, tint> a[MX];
tint b[2*MX];
vl todo;
map<tint, tint> m;

int main(){
	NACHO();
	tint n, c; cin >> n >> c;
	F0R(i, n){
		cin >> a[i].f.f >> a[i].f.s >> a[i].s;
		todo.pb(a[i].f.f);
		todo.pb(a[i].f.s+1);
	}
	remDup(todo);
	trav(u, todo){
		m[u] = sz(m);
	}
	F0R(i, n){
		b[m[a[i].f.f]] += a[i].s;
		b[m[a[i].f.s+1]] -= a[i].s;
	}
	FOR(i, 1, 2*n+1) b[i] += b[i-1];
	tint ret = 0;
	F0R(i, sz(todo)-1) ret += min(b[i], c)*(todo[i+1]-todo[i]);
	cout << ret << "\n";
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <optional>
#include <utility>
#include <vector>
// #include <atcoder/all>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(16);

    int n, k; std::cin >> n >> k;
    std::vector<std::vector<int>> T(n, std::vector<int>(n));
    for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) std::cin >> T[i][j];
    std::vector<int> Lp(n - 1); for(int i = 0; i < n - 1; ++i) Lp[i] = i + 1;
    int res = 0;
    do{
        int d = T[0][Lp.front()] + T[Lp.back()][0];
        for(int i = 0; i + 1 < n - 1; ++i) d += T[Lp[i]][Lp[i + 1]];
        if(d == k) ++res;
    } while(std::next_permutation(Lp.begin(), Lp.end()));
    std::cout << res << '\n';

    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define N 200005
#define MOD 1000000007
using namespace std;
int n,d[N],ans;
vector<int> to[N],w[N];
void add(int u,int v,int wt){to[u].push_back(v),w[u].push_back(wt);}
void dfs(int u,int fa){
	for(int i=0,v;i<to[u].size();i++)
		if((v=to[u][i])!=fa)d[v]=d[u]^w[u][i],dfs(v,u);
}
signed main(){
	cin>>n;
	for(int i=1,u,v,wt;i<n;i++)scanf("%lld%lld%lld",&u,&v,&wt),add(u,v,wt),add(v,u,wt);
	dfs(1,0);
	for(int k=0;k<60;k++){
		int a=0;
		for(int i=1;i<=n;i++)a+=((d[i]>>k)&1);
		ans=(ans+a*(n-a)%MOD*((1ll<<k)%MOD)%MOD)%MOD;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ffor(i, a, b) for (int i = a ; i <= (int) b ; i++)
#define rfor(i, a, b) for (int i = (int) a ; i >= b ; i--)

#define vec vector
#define PB push_back

#define MP make_pair
#define MT make_tuple
#define F first
#define S second

using ll = long long int; // watch out for overflows in your code
using pii = pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void debug() { cout << "\n"; };
template <typename T, typename... Targs>
void debug(T t, Targs... args) {
    cout << t << " ";
    debug(args...);
}

template <typename T1, typename T2>
inline ostream& operator << (ostream& os, const pair<T1,T2>& p) {
    return os << "(" << p.F << ", " << p.S << ")";
}

template <typename T>
inline ostream& operator << (ostream& os, const vec<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename T>
inline ostream& operator << (ostream& os, const vec<vec<T>>& m) {
    for(auto& v : m) {
        for(auto& t : v) {
            os << t << " ";
        }
        os << "\n";
    }
    return os;
}

template <typename T>
inline ostream& operator << (ostream& os, const set<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename K, typename V>
inline ostream& operator << (ostream& os, const map<K,V>& m) {
    for(auto& p : m) {
        os << p.F << " -> " << p.S << "\n";
    }
    return os;
}
////////////////////////////////////////////////////////////////////////

template <ll mod>
class modular_int {
    private:
    ll x;

    public:
    modular_int(ll y) : x( (y % mod + mod) % mod) {}
    modular_int() : x(0LL) {}

    ll rpr() const { return x; }

    modular_int<mod>& operator += (const modular_int<mod>& rhs) {
        x = (x + rhs.x) % mod;
        return *this;
    }

    friend modular_int<mod> operator + (modular_int<mod> lhs, const modular_int<mod>& rhs) {
        lhs += rhs;
        return lhs;
    }

    modular_int<mod>& operator *= (const modular_int<mod>& rhs) {
        x = (x * rhs.x) % mod;
        return *this;
    }

    friend modular_int<mod> operator * (modular_int<mod> lhs, const modular_int<mod>& rhs) {
        lhs *= rhs;
        return lhs;
    }

    modular_int<mod>& operator -= (const modular_int<mod>& rhs) {
        x = ((x - rhs.x) % mod + mod) % mod;
        return *this;
    }

    friend modular_int<mod> operator - (modular_int<mod> lhs, const modular_int<mod>& rhs) {
        lhs -= rhs;
        return lhs;
    }
};

const ll MOD = 1e9 + 7;
using mint = modular_int<MOD>;

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

using edge = pair<int, ll>;

int N;
vec<vec<edge>> g;
vec<ll> d;

void bfs() {
    d.assign(N+1, -1);
    queue<edge> q;
    q.push({1,0});
    d[1] = 0;
    while(!q.empty()) {
        auto [u, pw] = q.front(); q.pop();
        for(auto [v, w] : g[u]) {
            if(d[v] != -1) continue;
            d[v] = pw ^ w;
            q.push({v, d[v]});
        }
    }
}

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

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

    cin >> N;
    g.assign(N+1, vec<edge>());
    ffor(i, 1, N) {
        int u, v; ll w;
        cin >> u >> v >> w;
        g[u].PB({v, w});
        g[v].PB({u, w});
    }

    bfs();
    //debug("d=", d);
    mint ans(0LL);
    ffor(k, 0, 60) {
        mint p(1LL << k);
        ll ones = 0LL, zeros = 0LL;
        ffor(u, 1, N) {
            if(d[u] & (1LL << k)) {
                ones++;
            }
            else {
                zeros++;
            }
        }
        ans += p * mint(ones) * mint(zeros);
        //debug(k, ones, zeros, ans.rpr());
    }
    cout << ans.rpr() << "\n";
}


// Coder: @SumitRaut
#include <bits/stdc++.h>

#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(12)
using namespace std;

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

using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
#define sbc __builtin_popcount
#define pb push_back
#define pbk pop_back
#define em emplace
#define emb emplace_back
#define ff first
#define ss second
#define ll long long
const ll mod = 1e9 + 7;

template<typename T> void smax(T& a, T b) { if(a<b) a=b; }
template<typename T> void smin(T& a, T b) { if(a>b) a=b; }
template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; }
template<typename T> T pwm(T a,T b,T md=mod) { T p=1,one=1; while(b) { if(b&one) p=p*a%md; a=a*a%md; b >>=1; } return p; }

template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (auto &it:v)
        is >> it;
    return is;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &it) {
    os << it.first << ' ' << it.second;
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const array<T, 2> &v) {
    for (auto &it : v) os << it << ' ';
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (auto &it : v)
        os << it << ' ';
    return os;
}

#ifndef ONLINE_JUDGE
class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } };
void debug() { cerr << '\n'; }

template<typename T, typename... Args>
void debug(T print, Args... args) {
    cerr << ' ' << print;
    debug(args...);
}

#define deb(...) cerr << "[" << #__VA_ARGS__ << "]" << " --> ", debug(__VA_ARGS__)
#else
#define deb(...) void(0)
#endif

void solve() {
    int a, b, x, y;
    cin>>a>>b>>x>>y;
    if(a==b||a==b+1) {
    	cout<<x<<'\n';
		return;
	}
	if(a>b) --a;
	cout<<x+min(2*x,y)*(abs(a-b))<<'\n';
}

int main() {
#ifndef ONLINE_JUDGE
    Timer timer;
#endif
    speedup;
    //int t; cin>>t; while(t--)
    solve();
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

#define debug(x) cout << #x << " is " << x << endl
#define inc(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;
const int INF = 0x3f3f3f3f;

int a, b, x, y;

int main()
{
	scanf("%d%d%d%d", &a, &b, &x, &y);
	if (a > b) printf("%d\n", min(2 * (a - b - 1) * x + x, (a - b - 1) * y + x));
	else printf("%d\n", min(2 * (b - a) * x, (b - a) * y) + x);
    return 0;
}