#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

template <typename Iter>
Iter partition(Iter begin, Iter end, Iter pivot) {
  if (distance(pivot, end) != 1) {
    iter_swap(end -1, pivot);
    pivot = end - 1;
  }
  auto x = end;
  for (auto it = begin; it != end; ++it) {
    if (it != pivot && *it <= *pivot) {
      x = (x == end) ? begin : x + 1;
      if (x != it) {
        iter_swap(x, it);
      }
    }
  }
  x = (x == end) ? begin : x + 1;
  iter_swap(x, pivot);
  return x;
}

int main() {
  int n;
  cin >> n;
  vector<int> nums;
  for (int t, i = 0; i < n; ++i) {
    cin >> t;
    nums.push_back(t);
  }
  auto pivot = partition(nums.begin(), nums.end(), nums.end() - 1);
  bool first = true;
  for (auto it = nums.begin(); it != nums.end(); ++it) {
    if (!first)
      cout << " ";
    first = false;
    bool is_pivot = it == pivot;
    if (is_pivot)
      cout << "[";
    cout << *it;
    if (is_pivot)
      cout << "]";
  }
  cout << endl;
}

#include <bits/stdc++.h>
#include<math.h>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
using PL = pair<ll, ll> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int modpow(ll a, ll n){
    if(n == 0) return 1 ;
    if(n == 1) return a % mod ;
    if(n % 2) return (a * modpow(a, n-1))%mod ;
    ll t = modpow(a, n/2) ;
    return (t*t) % mod ;
}

int main() {
    ll n ;
    cin >> n ;
    vector<ll> a (n) ;
    vector<ll> c (60) ;
    rep(i, n) {
        cin >> a[i] ;
        rep(j, 60){
            if(a[i] >> j & 1){
                c[j]++ ;
            }
        }
    }
    ll ans = 0 ;
    ll k =  n;
    rep(i, n){
        rep(j, 60){
            if(a[i] >> j & 1){
                ans += modpow(2,j)*(k - c[j]) ;
                ans %= mod ;
                c[j]-- ;
            }
            else {
                ans += modpow(2,j)*c[j] ;
            }
        }
        k-- ;
    }
    cout << ans << endl ;
}


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

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 1001001001;
  rep(i,n) {
    int cnt = 0;
    while(a[i] % 2 == 0) {
      a[i] /= 2;
      cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;
const int N = 3e3 + 5;
const long long INF = 1e18;
const int mod = 998244353;//786433;//998244353;
const double Pi = acos(-1);

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

int n;
int a[200005];
map <int, int> M;

int main()
{
	int t = 0;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		M[a[i]]++;
	}
	sort(a + 1, a + n + 1);
	for(int i = n; i >= 1; i--)
	{
		if(M[a[i]] == 0)
		{
			continue;
		}
		int temp = log2(a[i]);
		temp = 1 << (temp + 1);
		M[a[i]]--;
		if(M[temp - a[i]] > 0)
		{
			t++;
			M[temp - a[i]]--;
		}
	}
	cout << t;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << x << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;

#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

bool srt(pi a, pi b){
    return a.e1+a.e2 < b.e1+b.e2;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    sc(n);
    pi a[n];
    FORR(i,a)
        sc(i.e1,i.e2);
    sort(a,a+n,srt);
    ll dp[n+1];
    ll LINF = 1e18;
    FORR(i,dp)
        i = LINF;
    dp[0] = 0;
    FORR(i,a){
        /* whatis(i) */
        for(int x = n-1; x >= 0; --x){
            /* whatis(x) */
            /* whatis(dp[x]) */
            if(dp[x] == LINF) continue;
            if(dp[x] > i.e1) continue;
            /* if(dp[ */
            dp[x+1] = min(dp[x+1],dp[x]+i.e2);
        }
    }
    for(int i = n+1; --i;)
        if(dp[i] != LINF) REE(i)
}

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef vector<int> vi;
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 5050;
const int INF = 0x3f3f3f3f;
int dp[MAXN][MAXN];
vector<pii> prt;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n;
	cin >> n;
	rep (i, 1, n) {
		int h, p;
		cin >> h >> p;
		prt.emplace_back(h, p);
	}
	sort(all(prt), [&] (pii a, pii b) {
		return a.fst + a.sed < b.fst + b.sed;
	});
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	auto chkMin = [&] (int & a, int b) {
		a = ~a ? min(a, b) : b;
	};
	int res = 0;
	rep (i, 1, n) {
		int h = prt[i - 1].fst;
		int p = prt[i - 1].sed;
		rep (j, 0, i - 1) if (~dp[i - 1][j]) {
			chkMin(dp[i][j], dp[i - 1][j]);
			if (dp[i - 1][j] <= h) {
				res = max(res, j + 1);
				chkMin(dp[i][j + 1], dp[i - 1][j] + p);
			}
		}
	}
	cout << res << endl;
	return 0;
}


//Author: AnandRaj anand873
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 998244353,MAX = 1e6+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++)
	{
    	if (is_prime[i])
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

int main()
{
	int n,k;
	cin>>n>>k;
	vi A(n);
	take(A,0,n);
	sort(all(A));
	int gcd = 0;
	for(int i=0;i<n;i++) gcd = __gcd(gcd,A[i]);

	bool can=false;
	for(int i=n-1;i>=0;i--)
	{
		if(A[i]>=k&&(A[i]-k)%gcd==0) can=true;
	}
	if(can) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
int read(){
	int i;
	scanf("%lld",&i);
	return i;
}
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()

int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}

signed main(){
	int n=read(),k=read();
	vi a(n);
	REP(i,n)a[i]=read();
	int mx=*max_element(ALL(a));
	FOR(i,1,n)
		a[0]=gcd(a[0],a[i]);
	if(k%a[0]==0&&k<=mx)
		cout<<"POSSIBLE"<<endl;
	else
		cout<<"IMPOSSIBLE"<<endl;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

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

#define pb push_back
#define F first
#define S second

#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5+5, LG = 17, MOD = 998244353;
const int SQ = 390;
const long double EPS = 1e-7;
int n, x[N], L;
int tb[N][17];
int32_t main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE
  cin >> n;
  f(i,0,n){
    cin >> x[i];
  }
  cin >> L;
  for(int i = 0, j = 0; i < n; i++){
    while(j<n&&x[j]-x[i]<=L)j++;
    tb[i][0] = j - 1;
  }

  f(k,1,17)
    for(int i = 0; i <n; i++)
      tb[i][k] = tb[tb[i][k-1]][k-1];

  int q; cin >> q;
  while(q--){
    int x, y; cin >> x >> y;  --x,--y;
    if(x>y)swap(x,y);
    int ans = 0;
    for(int k = 16; k >= 0; --k)
    if(tb[x][k] < y){
      x = tb[x][k];
      ans += (1 << k);
    }
    cout <<ans+1<<'\n';
  }

  return 0;
}

#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

static const int MAX = 100000;

vector<int> graph[MAX];
vector<bool> discovered(MAX, false);
vector<int> prenum(MAX, 0), parent(MAX, 0), lowest(MAX, 0);
int V, E;
int t = 0;

void dfs(int vertex, int prev)
{
    prenum[vertex] = lowest[vertex] = ++t;
    discovered[vertex] = true;

    for (auto it = graph[vertex].begin(); it != graph[vertex].end(); ++it) {
        if (!discovered[*it]) {
            parent[*it] = vertex;
            dfs(*it, vertex);
            lowest[vertex] = min(lowest[vertex], lowest[*it]);
        } else if (*it != prev) {
            lowest[vertex] = min(lowest[vertex], prenum[*it]);
        }
    }
}

set<int> arts;
void art_points()
{
    dfs(0, -1);

    int num_root_children = 0;
    for (int i = 1; i < V; i++) {
        int p = parent[i];
        if (p == 0)
            num_root_children++;
        else if (prenum[p] <= lowest[i]) {
            arts.insert(p);
        }
    }

    if (num_root_children > 1) {
        arts.insert(0);
    }

    for (auto it = arts.begin(); it != arts.end(); ++it)
        cout << *it << endl;
}

int main()
{
    cin >> V >> E;

    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }
    art_points();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    if(X == 1 && Y == 1) ans += 400000;
    if(X == 1) ans += 300000;
    if(X == 2) ans += 200000;
    if(X == 3) ans += 100000;
    if(Y == 1) ans += 300000;
    if(Y == 2) ans += 200000;
    if(Y == 3) ans += 100000;

    cout << ans << endl;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i,0,n)
#define BFOR(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define BREP(bit,n) BFOR(bit,0,n)
using namespace std;
using ll = long long;

int main() {
  ll x;
  cin >> x;
  ll ans = (x/11) * 2;

  if(x%11 > 0 && x%11 <= 6) ans += 1;
  if(x%11 >= 7) ans += 2;

  cout << ans << endl;

}

#include<iostream>
using namespace std;
int main()
{
        int a,sum,e,f;
        cin>>a;
        e=a*a;
        f=e*a;
        sum=a+e+f;
        cout<<sum<<endl;
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, x[N], y[N], ansd = INT_MAX;
char d[N];
void solvelr()
{
	vector<int> a[N], b[N];
	for (int i = 0; i < n; ++i)
	{
		if (d[i] == 'L')
			a[y[i]].push_back(x[i]);
		else if (d[i] == 'R')
			b[y[i]].push_back(x[i]);
	}
	for (int i = 0; i < N; ++i)
	{
		sort(a[i].begin(), a[i].end());
		sort(b[i].begin(), b[i].end());
	}
	for (int i = 0; i < N; ++i)
	{
		for (int xc: b[i])
		{
			auto it = upper_bound(a[i].begin(), a[i].end(), xc);
			if (it == a[i].end())
				continue;
			else
			{
				int d = *it - xc;
				d *= 5;
				ansd = min(ansd, d);
			}
		}
	}
}
void solveud()
{
	vector<int> a[N], b[N];
	for (int i = 0; i < n; ++i)
	{
		if (d[i] == 'U')
			a[x[i]].push_back(y[i]);
		else if (d[i] == 'D')
			b[x[i]].push_back(y[i]);
	}
	for (int i = 0; i < N; ++i)
	{
		sort(a[i].begin(), a[i].end());
		sort(b[i].begin(), b[i].end());
	}
	for (int i = 0; i < N; ++i)
	{
		for (int yc: a[i])
		{
			auto it = upper_bound(b[i].begin(), b[i].end(), yc);
			if (it == b[i].end())
				continue;
			else
			{
				int d = *it - yc;
				d *= 5;
				ansd = min(ansd, d);
			}
		}
	}
}
bool cmp(pair<int, int> lhs, pair<int, int> rhs)
{
	return lhs.first < rhs.first;
}
void solve1()
{
	vector<pair<int, int> > a[2 * N];
	for (int i = 0; i < n; ++i)
	{
		int dif = x[i] - y[i];
		a[dif + 200000].push_back(make_pair(x[i], d[i]));
	}
	for (int i = 0; i < 2 * N; ++i)
	{
		int l = -1, r = -1, u = -1, d = -1;
		sort(a[i].begin(), a[i].end(), cmp);
		for (pair<int, int> p: a[i])
		{
			if (p.second == 'L')
			{
				if (u != -1)
					ansd = min(ansd, 10 * (p.first - u));
				l = p.first;
			}
			else if (p.second == 'R')
				r = p.first;
			else if (p.second == 'U')
				u = p.first;
			else if (p.second == 'D')
			{
				if (r != -1)
					ansd = min(ansd, 10 * (p.first - r));
				d = p.first;
			}
		}
	}
}
void solve2()
{
	vector<pair<int, int> > a[2 * N];
	for (int i = 0; i < n; ++i)
	{
		int dif = x[i] + y[i];
		a[dif].push_back(make_pair(x[i], d[i]));
	}
	for (int i = 0; i < 2 * N; ++i)
	{
		int l = -1, r = -1, u = -1, d = -1;
		sort(a[i].begin(), a[i].end(), cmp);
		for (pair<int, int> p: a[i])
		{
			if (p.second == 'L')
			{
				if (d != -1)
					ansd = min(ansd, 10 * (p.first - d));
				l = p.first;
			}
			else if (p.second == 'R')
				r = p.first;
			else if (p.second == 'U')
			{
				if (r != -1)
					ansd = min(ansd, 10 * (p.first - r));
				u = p.first;
			}
			else
				d = p.first;
		}

	}
}
int main(int argc, char const *argv[])
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i] >> y[i] >> d[i];
	}
	solvelr();
	solveud();
	solve1();
	solve2();
	if (ansd == INT_MAX)
		cout << "SAFE" << '\n';
	else
		cout << ansd << '\n';
	return 0;
}


#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

int n,q;
int a=0;
int c=0;
int s[10000]={};
int t[10000]={};

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
	cin>>s[i];
	}

	cin>>q;
	for(int j=0;j<q;j++)
	{
	cin>>t[j];
	}

	for(int k=0;k<n;k++)
	{
	for(int l=0;l<q;l++)
	{
	a=s[k]^t[l];
	if(a==0)
	{
	c+=1;
	t[l]=-1;
	}
	}

	}
	cout<<c<<endl;
	return 0;
}

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

int main(){
  long long N,a,c=1,A[100002]={};A[0]=3;
  cin>>N;
  for(int i=0;i<N;i++){
    scanf("%d",&a);
    c*=(A[a]-A[a+1]++);
    c%=1000000007;
  }
  cout<<c<<endl;
}


#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	for (int e, m; (e = m = in());) {
		for (int z = cbrt(e) + 0.00001; z >= 0; z--) {
			int te = e - z * z * z;
			int y = (int)sqrt(te);
			int tm = z + y + te - y * y;
			if (y > m)
				break;
			m = min(m, tm);
		}
		out(m, '\n');
	}
}

#include <iostream>
#define MAXN 1000001;
using namespace std;
int m,e,sum1,sum2,x,y,z,minn;
int main(){
	while(1){
		cin >>e;
		if(e==0)break;
		x=y=z=0;
		minn=MAXN;
		while(1){
			sum1=z*z*z;
			if(e<sum1)break;
			y=0;
			while(1){
				sum2=sum1+y*y;
				if(e<sum2)break;
				if(y+z+(e-sum2)<minn)minn=y+z+(e-sum2);
				y++;
			}
			z++;
		}
		cout <<minn<<endl;
	}
}


#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
//typedef complex<double> P;
typedef pair<int, int> P;
const int MAX_V = 100010;
const int INF = 1e9 + 7;

int dijkstra(const vector< vector<P> > &cost, int s, int t, int V){
  priority_queue<P, vector<P>, greater<P> > open;
  open.push(P(s, 0));
  int closed[MAX_V];
  REP(i, V) closed[i] = INF;
  while(!open.empty()){
    P tmp = open.top(); open.pop();
    int now = tmp.first, c = tmp.second;
    if(closed[now] < c) continue;
    closed[now] = c;
    REP(i, cost[now].size()){
      int next = cost[now][i].first, nc = cost[now][i].second;
      if(nc == INF || c + nc >= closed[next]) continue;
      closed[next] = c + nc;
      open.push(P(next, closed[next]));
    }
  }
  REP(i, V){
    if(closed[i] == INF) cout <<"INF" <<endl;
    else cout <<closed[i] <<endl;
  }
  return closed[t];
}

int main() {
  int V, E, r;
  cin >>V >>E >>r;
  vector< vector<P> > cost(V);
  REP(i, E){
    int f, t, c; cin >>f >>t >>c;
    cost[f].push_back(P(t, c));
  }
  //REP(i, E){
  //  if((int)cost[i].size() <= 0) continue;
  //  SORT(cost[i]);
  //  vector<P> tmp;
  //  int now = cost[i][0].first;
  //  tmp.push_back(cost[i][0]);
  //  FOR(j, 1, cost[i].size()){
  //    if(now == cost[i][j].first) continue;
  //    now = cost[i][j].first;
  //    tmp.push_back(cost[i][j]);
  //  }
  //  cost[i] = tmp;
  //}
  dijkstra(cost, r, -1, V);
  return 0;
}

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

struct edge{ int u,v,cost; };

vector<edge> edges;

int uf_par[10000];
int uf_rank[10000];

void uf_init(int uf_n){
	for(int i = 0;i < uf_n;i++){
		uf_par[i] = i;
		uf_rank[i] = 0;
	}
}

int uf_find(int uf_x){
	if(uf_par[uf_x] == uf_x) return uf_x;
	else return uf_par[uf_x] = uf_find(uf_par[uf_x]);
}

void uf_unite(int uf_x,int uf_y){
	uf_x = uf_find(uf_x);
	uf_y = uf_find(uf_y);
	if(uf_x == uf_y) return;
	if(uf_rank[uf_x] < uf_rank[uf_y]){
		uf_par[uf_x] = uf_y;
	}else{
		uf_par[uf_y] = uf_x;
		if(uf_rank[uf_x] == uf_rank[uf_y]) uf_rank[uf_x]++;
	}
}

bool uf_same(int uf_x,int uf_y){
	return uf_find(uf_x) == uf_find(uf_y);
}

bool krus_comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

int kruskal(int V){
	sort(edges.begin(),edges.end(),krus_comp);
	uf_init(V);
	int krus_res = 0;
	for(int i = 0;i < edges.size();i++){
		edge krus_e = edges[i];
		if(!uf_same(krus_e.u,krus_e.v)){
			uf_unite(krus_e.u,krus_e.v);
			krus_res += krus_e.cost;
		}
	}
	return krus_res;
}

int main(){
	int V,E;
	cin >> V >> E;
	for(int i = 0;i < E;i++){
		int a,b,c;
		cin >> a >> b >> c;
		edges.push_back({a,b,c});
	}
	cout << kruskal(V) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

vector<ll> used(100010), tp;
vector<vector<ll>> G(100010);
/*
void dfs(ll v){
    if(used[v]) return;
    used[v] = 1;
    for(auto& u:G[v]){
        dfs(u);
    }
    tp.push_back(v);
}*/

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> rc(N),deg(N);
    ll a,b;
    rep(i,N-1+M){
        cin >> a >> b;
        a--;b--;
        rc[b]++;
        G[a].push_back(b);
        deg[b]++;
    }
    ll root;
    rep(i,N){
        if(rc[i] == 0){
            root = i;
            break;
        }
    }
    queue<ll> que;
    vector<ll> par(N,-1);
    que.push(root);
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(auto& u:G[v]){
            deg[u]--;
            if(deg[u] == 0){
                par[u] = v;
                que.push(u);
            }
        }
    }
    rep(i,N){
        cout << par[i]+1 << endl;
    }
    /*dfs(root);
    vector<ll> v(N);
    rep(i,N){
        v[tp[i]] = i;
    }
    //PR(v,N);
    vector<ll> ans(N,-1);
    rep(i,N){
        for(auto& u:G[i]){
            if(v[i] > v[u]){
                //cout << u+ << endl;
                ans[i] = u;
                break;
            }
        }
    }
    rep(i,N){
        cout << ans[i]+1 << endl;
    }
    /*queue<ll> que;
    que.push(root);
    prev[root] = -1;
    used[root] = 1;*/
    /*
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(auto& u:G[v]){
            if(used[u] != 0){
                G[prev[u]].erase(lower_bound(G[prev[u]].begin(),G[prev[u]].end(),u));
                prev[u] = v;
                que.push(u);
                continue;
            }
            used[u] = 1;
            prev[u] = v;
            que.push(u);
        }
    }*/
    /*rep(i,N){
        cout << prev[i]+1 << endl;
    }*/
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec s(M), c(M);
    REP(i,0,M) {
        cin >> s[i] >> c[i];
        --s[i];
    }

    ll d = 1;
    bool f = true;
    REP(i,0,N) d *= 10;
    REP(i,N==1?0:d/10,d) {
        string S = to_string(i);
        f = true;
        REP(j,0,M) {
            if(!(s[j] < SZ(S) && S[s[j]]-'0' == c[j])) {
                f = false;
                break;
            }
        }
        if(f) {
            PR(i);
            break;
        }
    }
    if(!f) PR(-1);

    return 0;
}

/*

*/


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main() {
    string S;
    cin >> S;
    cout << S.substr(0, S.size() - string("FESTIVAL").size()) << endl;
}


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

#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
const int MAXN=100005;

int n,m;
int co[MAXN];
bool vis[MAXN];
vector<int> E[MAXN];

bool dfs(int u){
    bool tag=1;
    vis[u]=1;
    for(int i=0;i<(int)E[u].size();i++){
        int v=E[u][i];
        if(vis[v]) tag&=(co[v]!=co[u]);
        else{
            co[v]=co[u]^1;
            tag&=dfs(v);
        }
    }
    return tag;
}

int main(){
    //freopen("squared.in","r",stdin);
    //freopen("squared.out","w",stdout);

    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        E[u].push_back(v);
        E[v].push_back(u);
    }
    int cnt=0,p=0,q=0;
    for(int i=1;i<=n;i++){
        if(vis[i]) continue;
        if(!E[i].size()) cnt++;
        else{
            if(dfs(i)) q++;
            else p++;
        }
    }
    printf("%lld\n",(ll)cnt*cnt+2ll*cnt*(n-cnt)+p*p+2ll*p*q+2ll*q*q);

    fclose(stdin);
    fclose(stdout);
}

#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int t[101];
int pri[26];
int res = 0;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}
void solv() {

	int n;
	cin >> n;
	uini(n);
	pair<ll, int> xr[100010];
	pair<ll, int> yr[100010];
	for (size_t i = 1; i <= n; i++)
	{
		ll x, y;
		cin >> x >> y;
		xr[i] = pair<ll, int>(x, i);
		yr[i] = pair<ll, int>(y, i);
	}

	sort(xr, xr + n + 1);
	sort(yr, yr + n + 1);
	map<ll, vector<pair<int, int>>> mx;
	for (int i = 2; i <= n; i++)
	{
		ll rem = abs( xr[i].first - xr[i - 1].first);
		mx[rem].push_back(pii(xr[i].second, xr[i - 1].second));

		ll remy = abs(yr[i].first - yr[i - 1].first);
		mx[remy].push_back(pii(yr[i].second, yr[i - 1].second));
	}
	ll res = 0;
	for (map<ll, vector<pii>>::iterator i = mx.begin(); i != mx.end(); i++)
	{
		ll val = i->first;
		vector<pii> v = i->second;
		for (int j = 0; j < v.size(); j++)
		{
			if (unit(v[j].first, v[j].second)) {
				res += val;
			}
		}
	}
	cout << res << endl;
}

int main() {
	solv();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

int main(){

    int n;
    ll T;
    cin >> n >> T;
    ll ans = 0;
    vector<ll> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int i = 1; i < n; i++){
        ans += min(T, v[i] - v[i-1]);
    }
    ans += T;
    cout << ans << endl;

    return 0;
}

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

typedef uint64_t ull;
typedef  int64_t sll;

static const ull MOD = 1000000007LL;

int n;
int k;
int q;

ull a[200019];

ull umin (ull a, ull b) {
	return (a < b) ? a : b;
}
ull umax (ull a, ull b) {
	return (a > b) ? a : b;
}

ull solve () {
	sll i, j, ki;
	ull res = 0;

	ull allxor = 0;
	for (i = 0; i < n; i++) {
		allxor ^= a[i];
	}
	for (i = 0; i < n; i++) {
		a[i] &= ~allxor;
	}

	ull rank = 0;
	for (i = 59; i >= 0; i--) {
		for (j = rank; j < n; j++) {
			if (a[j] & (1LL << i)) break;
		}
		if (j == n) {
			continue;
		}

		if (j > rank) a[rank] ^= a[j];
		for (j = rank + 1; j < n; j++) {
			a[j] = umin(a[j], a[j] ^ a[rank]);
		}

		rank++;
	}
	ull x = 0;
	for (i = 0; i < n; i++) {
		x = umax(x, x ^ a[i]);
	}

	res = (x * 2) + allxor;

	return res;
}

int main(void){

	scanf("%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}

	printf("%lld\n", solve());

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

bool b[501];
int main(){
	int n, m, t1,t2;
	while(1){
		stack<int> s[501];
		scanf("%d%d", &n, &m);
		if(!n)break;
		fill(b, b+501, false);
		rep(i,m){
			scanf("%d%d", &t1, &t2);
			s[t1].push(t2);
			s[t2].push(t1);
		}
		while(!s[1].empty()){
			t1 = s[1].top();s[1].pop();
			b[t1] = 1;
			while(!s[t1].empty()){
				t2 = s[t1].top();s[t1].pop();
				b[t2] = true;
			}
		}
		int ans = 0;
		rrep(i,n)if(b[i]&&i!=1)ans++;
		printf("%d\n", ans);
	}
	return 0;
}

#include <iostream>
#include <string>
using namespace std;
int countup_days(int m, int d) // m月d日が、1月1日から何日目か返す
{
    int         sum     = 0;
    const int   month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,};
    for (int i=1; i<m; i++) {
        sum += month[i];
    }
    return sum + d -1;
}
string what_day(int days) // 1/1からdays日後は何曜日か文字列を返す
{
    string day[]   = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};
    return day[days%7];
}
int main()
{
    int m, d;
    while (true) {
        cin >> m >> d;
        if (m==0 && d==0)
            break;
        cout << what_day(countup_days(m, d)) << endl;
    }
}


#include <climits>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

typedef std::vector<int> TList;
long long int c;
void merge(TList& A, int left, int mid, int right)
{
  int n1 = mid - left;
  int n2 = right - mid;
  TList L(A.begin() + left, A.begin() + left + n1);
  L.push_back(INT_MAX);

  TList R(n2+1);
  for(int i = 0; i < n2; ++i){
    R[i] = A[mid + i];
  }
  R[n2] = INT_MAX;

  int i = 0;
  int j = 0;
  for(int k = left; k < right; ++k){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{
      A[k] = R[j];
      j = j + 1;
      c += L.size() - 1 - i;
    }
  }
}

void mergeSort(TList& A, int left, int right)
{
  if(left+1 < right){
    int mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main()
{
    int n;
    std::cin >> n;
    TList A(n);
    for(std::size_t i = 0; i < n; ++i){
        std::cin >> A[i];
    }
    c = 0;
    mergeSort(A, 0, n);
    std::cout << c << std::endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l-1);
  }
};

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

  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];

  auto b=a;
  vsort(b);
  b.erase(unique(all(b)),b.end());
  // rep(i,b.size()) cout<<b[i]<<' ';
  // cout<<endl;
  BIT<ll> bit(b.size()+5);

  ll ans=0;
  rep(i,n){
    ll rank=lower_bound(all(b),a[i])-b.begin()+1;
    // cout<<rank<<endl;
    ans+=i-bit.sum(rank);
    bit.add(rank);
  }

  cout<<ans<<endl;

}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N  = 5100;
int n,tot; ll a[N][N];
int vis[N * 20],pri[N];
void init()
{
	vis[1] = 1;
	for(int i = 2;i <= 10000;i ++)
	{
		if(!vis[i]) pri[++ tot] = i;
		for(int j = 1;j <= tot && pri[j] * i <= 10000;j ++)
		{
			vis[i * pri[j]] = 1;
			if(i % pri[j] == 0) break;
		}
	}
}
ll gcd(ll x,ll y){return y ? gcd(y,x % y) : x;}
ll lcm(ll x,ll y){if(!x || !y) return x | y; return x / gcd(x,y) * y;}
int main()
{
	n = read(); init();
	if(n == 2) {puts("4 7\n23 10"); return 0;}
	for(int i = 1;i <= n;i ++)
		for(int j = (i + 1 & 1) + 1;j <= n;j += 2)
			a[i][j] = pri[(i + j) / 2] * pri[n + (i - j) / 2 + (n + 1) / 2];
	for(int i = 1;i <= n;i ++)
		for(int j = (i & 1) + 1;j <= n;j += 2)
			a[i][j] = lcm(lcm(a[i - 1][j],a[i][j - 1]),lcm(a[i][j + 1],a[i + 1][j])) + 1;

	for(int i = 1;i <= n;i ++,cout << "\n") for(int j = 1;j <= n;j ++) cout << a[i][j] << " ";
	return 0;
}


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

#define SENTINEL 2000000000

long long merge(vector<int>& array, int left, int mid, int right) {
    long long cnt = 0;          // 転倒数を数える
    // 分割した配列LとRを生成
    int n1 = mid - left;        // Lの大きさ
    int n2 = right - mid;       // Rの大きさ
    vector<int> L(n1 + 1);
    vector<int> R(n2 + 1);
    for (int i = 0; i < n1; ++i) {
        L[i] = array[left + i];
    }
    for (int i = 0; i < n2; ++i) {
        R[i] = array[mid + i];
    }
    L[n1] = SENTINEL;
    R[n2] = SENTINEL;

    // LとRを比べて，もとの配列へソート
    int i = 0, j = 0;
    for (int k = left; k < right; ++k) {
        if (L[i] <= R[j]) {
            array[k] = L[i++];
        } else {
            array[k] = R[j++];
            cnt += n1 - i;
        }
    }

    return cnt;
}

long long mergeSort(vector<int>& array, int left, int right) {
    int mid;
    long long cnt1, cnt2, cnt3;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        cnt1 = mergeSort(array, left, mid);
        cnt2 = mergeSort(array, mid, right);
        cnt3 = merge(array, left, mid, right);
        return cnt1 + cnt2 + cnt3;
    } else {
        return 0;
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> array(n);
    for (int i = 0; i < n; ++i) {
        cin >> array[i];
    }

    long long ans = mergeSort(array, 0, n);

    cout << ans << endl;

    return 0;
}

#include <stdio.h>
#include <limits.h>

#define MAX 200000
#define INF INT_MAX
typedef long long ll;

void merge(int*, int, int, int);
void mergesort(int*, int, int);

ll ans;

int n, a[MAX];

int main(){
  int i;

  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d" ,a + i);
  }
  mergesort(a,0,n);
  printf("%lld\n" ,ans);

  return 0;
}

void merge(int a[], int left, int mid, int right){
  int n1 = mid - left, n2 = right - mid;
  int L[n1+1], R[n2+1], i, j, k;

  for(i = 0 ; i < n1 ; i++){
    L[i] = a[left + i];
  }

  for(i = 0 ; i < n2 ; i++){
    R[i] = a[mid + i];
  }

  L[n1] = R[n2] = INF;

  for(i = 0, j = 0, k = left ; k < right ; k++){
    if(i < n1 && (j == n2 || L[i] <= R[j])){
      a[k] = L[i++];
    }else{
      ans += (n1 + n2) / 2 - i;
      a[k] = R[j++];
    }
  }
}

void mergesort(int a[], int left, int right){
  int mid;

  if(left + 1 < right){
    mid = (left + right) / 2;
    mergesort(a, left, mid);
    mergesort(a, mid, right);
    merge(a, left, mid, right);
  }
}


#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int n,memo;
    priority_queue<int,vector<int>,greater<int> > que;
    cin >> n;
    int a[n];

    rep(i,0,n){
        cin >> a[i];
    }

    sort(a,a+n);

    rep(i,1,sqrt(a[n-1])+1){
        rep(j,0,n){
            if(a[j] % i)break;
            else if(j == n-1)que.push(i);
        }

        if(a[n-1]/i == i)continue;

        rep(j,0,n){
            if(a[j] % (a[n-1]/i))break;
            else if(j == n-1)que.push(a[n-1]/i);
        }
    }

    while(!que.empty()){
        if(que.top() == memo){
            que.pop();
            continue;
        }
        memo = que.top(); que.pop();

        cout << memo << endl;
    }
}

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

ll gcd(ll a, ll b){
    //cout << "a : " << a << "b : " << b << endl;
    if(b == 0)
        return a;
    else
        return gcd(b, a % b);
}

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

int main(){
    int n;
    cin >> n;
    set<int>  s;
    if (n == 2){
        ll a, b;
        cin >> a >> b;
        ll g = gcd(a, b);
        for (int i = 1; i <= sqrt(g); i++){
            if(g % i==0){
                s.insert(i);
                s.insert(g / i);
            }
        }
        for (auto itr = s.begin(); itr != s.end(); itr++){
            cout << *itr << endl;
        }
    }else{
        ll a, b, c;
        cin >> a >> b >> c;
        ll g = gcd(a, b);
        //cout << g << endl;
        g = gcd(g, c);
        //cout << g << endl;
        for (int i = 1; i <= sqrt(g); i++)
        {
            if(g % i==0){
                s.insert(i);
                s.insert(g / i);
            }
        }
        for (auto itr = s.begin(); itr != s.end(); itr++){
            cout << *itr << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;

string convert(string str) {
    int idx = 0;
    for (;;) {
        idx = str.find("Hoshino", idx);
        if (idx == string::npos) break;
        str.replace(idx, 7, "Hoshina");
        idx += 7;
    }
    return str;
}

int main() {
    int n;
    string str;
    getline(cin, str);
    n = atoi(str.c_str());
    for (int i = 0; i < n; i++) {
        getline(cin, str);
        cout << convert(str) << endl;
    }
    return 0;
}

#include <stdio.h>
#include <string.h>

int main()
{
	int n;
	char *p;
	char str[1000];
	scanf("%d\n",&n);
	while(n--){
	gets(str);
	for(p;p=strstr(str,"Hoshino");)p[6]='a';
	puts(str);
	}
	return 0;
}


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

int main(){
    long long n,ans = 1;
    map<int,long long> prime;
    cin >> n;
    for(int num = n;2 <= num;num--){
        int buf = num;
        for(int i = 2;i * i<= n;i++){
            int count = 0;
            while(buf % i == 0)buf /= i,count++;
            prime[i] += count;
        }
        if(buf != 1)prime[buf]++;
    }
    for(auto pri : prime){
        ans = ans * (pri.second + 1) % MOD;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n;
char s[maxn];
typedef long long ll;
const ll mod = 1e9 + 7;
ll fac(int x) { ll ret = 1; for(int i = 1; i <= x; ++i) ret = ret * i % mod; return ret;}
ll f(int i, int j)
{
	if(i == 0) return j == 0;
	if(s[i] == 'B')
	{
		if(j & 1)
			return f(i - 1, j - 1);
		else
			return f(i - 1, j + 1) * (j + 1) % mod;
	}
	else
	{
		if(j & 1)
			return f(i - 1, j + 1) * (j + 1) % mod;
		else if(j > 0)
			return f(i - 1, j - 1);
		else
			return 0;
	}
}
int main()
{
	scanf("%d", &n);
	scanf("%s", s + 1);
	cout << f(2 * n, 0) * fac(n) % mod << endl;
	return 0;
}


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

char Decryption(int k, char s) {
  char station[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
                    'n','o','p','q','r','s','t','u','v','w','x','y','z',
                    'A','B','C','D','E','F','G','H','I','J','K','L','M',
                    'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  int num;

  for(int i = 0; i < 52; i++) {
    if(s >= 'a' && s <= 'z')
      num = s - 'a';
    else
      num = s - 39;
  }
  return station[(52 + num - k) % 52];
}

int main() {
  vector<int> K;
  int n;
  string s_in;
  string s_out;

  while(1) {
    cin >> n;
    if(n == 0)
      break;

    for(int i = 0; i < n; i++) {
      int k;
      cin >> k;
      K.push_back(k);
    }

    cin >> s_in;

    for(int i = 0; i < s_in.size(); i++) {
      s_out += Decryption(K[i%n], s_in[i]);
    }

    cout << s_out << endl;

    s_out.erase();
    K.clear();
  }
  return 0;
}

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

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		int a[100];
		lp(i,n){
			cin>>a[i];
		}
		int count=0;
		char x;
		scanf("%c",&x);
		while(1){
			scanf("%c",&x);
			if('A'<=x&&'z'>=x){
				lp(i,a[count]){
					x--;
					if(x==64) x=122;
					if(x==96) x=90;
				}
				cout<<x;
				count++;
				if(count==n) count=0;
			}
			else break;
		}
		cout<<endl;
	}
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	map<string, int>mp;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		mp[s]++;
	}
	int M;
	cin >> M;
	for (int i = 0; i < M; ++i) {
		string s;
		cin >> s;
		mp[s]--;
	}
	int ans = 0;
	for (auto x : mp) {
		ans = max(ans, max(0, x.second));
	}
	cout << ans << endl;
	return 0;
}

//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007

int main() {
	ll ans = 0;
	int tmp;
	int n;
	cin >> n;
	map<int, int> o, e;
	REP(i, n){
		cin >> tmp;
		if(i %2 == 0) e[tmp] ++;
		else o[tmp]++;
	}
	vector< pair <int, int >> od , ev;
	for(auto it = e.begin(); it != e.end(); it++){
		ev.push_back(make_pair(it->second, it->first));
	}
	for(auto it = o.begin(); it != o.end(); it++){
		od.push_back(make_pair(it->second, it->first));
	}
	ev.push_back(make_pair(0, -1));
	od.push_back(make_pair(0, -1));
	sort(ev.begin(), ev.end(), greater<pair<int, int>>());
	sort(od.begin(), od.end(), greater<pair<int, int>>());
	if(ev[0].second != od[0].second){
		cout << n - ev[0].first - od[0].first;
	}
	else{
		cout << min(n - ev[1].first - od[0].first, n - ev[0].first - od[1].first);
	}
	//cout << ans << endl;
}


# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int a[202020], n;

struct BIT {
	int bit[202020];
	void init() {
		REP(i, 202020)bit[i] = 0;
	}
	int sum(int i) {
		int s = 0;
		while (i>0) {
			s += bit[i];
			i -= i& -i;
		}
		return s;
	}
	void add(int i, int x) {
		while (i <= 202020) {
			bit[i] += x;
			i += i& -i;
		}
	}
};

vector<pair<LL,LL>> v;

int main() {
	BIT bit;
	bit.init();
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		v.emplace_back(make_pair(a[i],i));
	}
	sort(ALL(v));
	REP(i, n) {
		a[v[i].second] = i + 1;
	}
	LL ans = 0;
	for (int j = 0; j < n; j++) {
		ans += j - bit.sum(a[j]);
		bit.add(a[j], 1);
	}
	cout << ans << endl;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
using namespace std;

long long cnt = 0;

void merge(vector<int> &v, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  vector<int> l(n1 + 1);
  vector<int> r(n2 + 1);
  int i, j, k;
  for(int i=0;i<n1;i++){
    l[i] = v[left + i];
  }
  for(int i=0;i<n2;i++){
    r[i] = v[mid + i];
  }
  l[n1] = r[n2] = 1000000007;
  i = j = 0;
  for(k = left;k < right;k++){
    if(l[i] <= r[j]){
      v[k] = l[i++];
      cnt += j;
    }else{
      v[k] = r[j++];
    }
  }
}

void mergeSort(vector<int> &a, int left, int right){
  if(left+1 < right){
    int mid = (left + right)/2;
    mergeSort(a, left, mid);
    mergeSort(a, mid, right);
    merge(a, left, mid, right);
  }
}

int main(void){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++)
    cin >> v[i];

  mergeSort(v, 0, n);
  cout << cnt << endl;
  return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A.at(i);

  for(int k=0;k<K;k++){
    vector<int> B(N+1,0);

    for(int i=0;i<N;i++){
      int left = max(0,i-A.at(i));
      int right = min(i+A.at(i)+1,N);
      B.at(left) ++;
      B.at(right) --;
    }
    for(int i=1;i<=N;i++){
      B.at(i) += B.at(i-1);
    }
    if(A==B) break;
    A = B;
  }
  for(int i=0;i<N;i++){
    cout << A.at(i) << endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値

double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}

int main() {
ll n,p;
cin>>n>>p;
ll ca=0;
ll a[n+2]={};
ll b[n+2]={};
ll m=0;
ll f=0;
for(ll i=1; i<n+1; i++){
cin>>a[i];}
for(ll i=0; i<p; i++){

for(ll k=1; k<=n; k++){
if(k-a[k]<=0){
b[0]++;}
else{
b[k-a[k]]++;}
if(k+a[k]>=n){
b[n+1]--;}
else{
b[k+a[k]+1]--;}}
ca=b[0];
b[0]=0;
for(ll k=1; k<=n; k++){
ca+=b[k];
b[k]=0;
a[k]=ca;
if(a[k]==n){
m++;}
}
if(m==n) {f++; break;}
m=0;
ca=0;}
for(ll i=1; i<=n; i++){
cout << a[i] << " ";}
cout << endl;}


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

int main()
{
	int l[10], v1, v2, cnt;
	double n, d, t;
	char ch;
	while (cin>>l[0]>>ch){
		n = l[0];
		for (int i = 1; i < 10; i++)
		{
		    cin >> l[i] >> ch;
		    n += l[i];
		}
		cin >> v1 >> ch >> v2;
		t=n/(v1+v2);
		d=v1*t;    //列車1の動く距離
		cnt=0;
		while(d>0){
			d -= l[cnt];
			cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}


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

using ll = long long;

// Z algorithm O(|S|)
vector<int> Z_algorithm(vector<int> &s) {
  vector<int> Z(s.size());
  Z[0] = s.size();

  int i = 1, j = 0;
  while (i < s.size()) {
    while (i + j < s.size() && s[j] == s[i + j]) j++;
    Z[i] = j;
    if (j == 0) {
      i++;
      continue;
    }
    int k = 1;
    while (k < j && k + Z[k] < j) {
      Z[i + k] = Z[k];
      k++;
    }
    i += k;
    j -= k;
  }
  return Z;
}

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

  int n;
  cin >> n;

  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  for (int i = 0; i < n; i++) cin >> b.at(i);

  vector<int> keep(n);
  for (int i = 0; i < 30; i++) {
    vector<int> x, y;
    for (int j = 0; j < n; j++) {
      if (b.at(j) & (1 << i)) {
        x.emplace_back(1);
        y.emplace_back(1);
      }
      else {
        x.emplace_back(0);
        y.emplace_back(0);
      }
    }
    for (int j = 0; j < n; j++) {
      if (a.at(j) & (1 << i)) {
        x.emplace_back(1);
        y.emplace_back(0);
      }
      else {
        x.emplace_back(0);
        y.emplace_back(1);
      }
    }
    for (int j = 0; j < n; j++) {
      if (a.at(j) & (1 << i)) {
        x.emplace_back(1);
        y.emplace_back(0);
      }
      else {
        x.emplace_back(0);
        y.emplace_back(1);
      }
    }
    vector<int> xret = Z_algorithm(x), yret = Z_algorithm(y);
    for (int j = n; j < 2 * n; j++) {
      if (xret.at(j) >= n || yret.at(j) >= n) keep.at(j - n)++;
    }
  }

  for (int i = 0; i < n; i++) {
    if (keep.at(i) == 30) {
      cout << i << " " << (a.at(i) ^ b.at(0)) << '\n';
    }
  }
}

//\\//\\ * * * //\\// ||
#include <bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

template <typename T>
class fenwick {
 public:
  vector<T> fenw;
  int n;

  fenwick(int _n) : n(_n) {
    fenw.resize(n);
  }

  void modify(int x, T v) {
    while (x < n) {
      fenw[x] += v;
      x |= (x + 1);
    }
  }

  T get(int x) {
    T v{};
    while (x >= 0) {
      v += fenw[x];
      x = (x & (x + 1)) - 1;
    }
    return v;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, tt;
  cin >> n >> tt;
  fenwick<ll> fenw(n);
  auto Get = [&](int l, int r) {
    return (l == 0 ? fenw.get(r) : fenw.get(r) - fenw.get(l - 1));
  };
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    fenw.modify(i, x);
  }
  while (tt--) {
    int q;
    cin >> q;
    if (q == 1) {
      int l, r;
      cin >> l >> r;
      cout << Get(l, r - 1) << '\n';
    } else {
      int p;
      cin >> p;
      ll x;
      cin >> x;
      fenw.modify(p, x);
    }
  }
  return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)

typedef long long ll;

#define MAX_N 100

int n;
int k[MAX_N];
string s;
string str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

vector<string> ans_list;

int main(){

  while(true){
    cin >> n;
    if(n == 0)
      break;
    for(int i = 0; i < n; i++){
      cin >> k[i];
    }
    cin >> s;
    string ans;
    int num = 0;
    for(int i = 0; i < s.length(); i++, num++){
      if(num == n)
	num = 0;
      int tmp;
      for(tmp = 0; tmp < 52; tmp++){
	if(str[tmp] == s[i])
	  break;
      }
      tmp -= k[num];
      if(tmp < 0)
	tmp += 52;
      ans += str[tmp];
    }
    ans_list.push_back(ans);
  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }

  return 0;

}

#include <stdio.h>

int main(void){
	int n, a[100], i, j;
	char c, s[53] = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
	while(1){
		scanf("%d",&n);
		if(!n) break;
		for(i = 0;i < n;i++)
			scanf("%d",&a[i]);
		getchar();
		for(i = 0;(c = getchar()) != '\n';i++){
			for(j = 0;j < 52;j++){
				if(s[j] == c)
					printf("%c",s[(52 + j - a[i % n]) % 52]);
			}
		}
		printf("\n");
	}
	return 0;
}


#include<cstdio>

int main(){
	int n,max,sum,t;
	scanf("%d", &n);
	while(n){
		scanf("%d", &t);
		max = sum = t;
		for(int i = 1; i < n; i++){
			if(sum < 0){
				sum = 0;
			}
			scanf("%d", &t);
			sum += t;
			if(sum > max){
				max = sum;
			}
		}
		printf("%d\n", max);
		scanf("%d", &n);
	}
	return 0;
}

#include <bits/stdc++.h>
#define iso ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
int main()
{ iso
    unsigned ll n,s=0,w=0;
    cin>>n;
    vector<unsigned ll>vec;
    while(n--)
    {
        ll x;
        cin>>x;
        vec.push_back(x);
        s+=x;
    }

    for(int i=0;i<vec.size();i++)
    {
        s-=vec[i];
        w+=s%1000000007*vec[i]%1000000007;
        w%=1000000007;
    }
    cout<<w<<"\n";

    return 0;
}


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

int main() {
  int N,k;
  cin >> N >>k;
  int sum;
  if(k==1){
	sum = N+1;
  }
  else if(k==2||k==3||k==4){
    if (N==1){
      sum = 2;
    }
    else{
    sum = 4 + k*(N-2);
    }
  }
  else if(k==5||k==6||k==7){
    if (N==1){
      sum = 2;
    }
    else if(N==2){
      sum = 4;
    }
    else{
    sum = 8 + k*(N-3);
    }
  }
  else{
    if (N==1){
      sum = 2;
    }
    else if (N==2){
      sum = 4;
    }
    else if (N==3){
      sum = 8;
    }
    else{
    sum = 16 + k*(N-4);
    }
  }
  cout<<sum<<endl;
}

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

 int main()
{

 long long n,k,sum=0;
 cin>>n>>k;

 long long ans = 1;

  while(n--){

  long long ans2 = ans*2;
  long long ani = ans+k;

  if(ans2 < ani)
    ans = ans2;
  else ans = ani;

  }

  cout<<ans<<endl;

 return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  int n,a,b;
  cin>>n>>a>>b;
  if(n==1)
    cout<<"Hello World\n";
  else
    cout<<a+b<<nl;
}

int main()
{
    su;
    f();
    return 0;
}

#include <iostream>
using namespace std;

int main()
{
  int n;
  cin >> n;
  if(n - 1)
  {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  else
  {
    cout << "Hello World" << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

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

using namespace std;

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

int main() {
  int n;
  cin >> n;
  int res;
  for (int i = n; i <= 999; i++) {
    string str = to_string(i);
    bool ok = true;
    for (int j = 0; j < str.length() - 1; j++) {
      if (str[j] != str[j + 1]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      res = i;
      break;
    }
  }
  cout << res << endl;
  return 0;
}

/*ॐॐ*/
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different.
Change variable names or change some Data structres or anything just make sure MOSS do not
Detect Anything.
Yours Faithfully
Shobhit Yadav */

/* I do not fear this new challenge. Rather like a true warrior I will rise to meet it.
                                       -Prince Vegeta  */

 /* “Strength is the only thing that matters in this world. Everything else is just a delusion for the weak.” – Vegeta */

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

ll N;
/*ll freq[200005];*/
void solve(){
   /*memset(freq,0,sizeof(freq));*/
  string s;
  map<string , int> days;
  days["MON"] = 1;
  days["TUE"] = 2;
  days["WED"] = 3 ; days["THU"] = 4; days["FRI"] = 5; days["SAT"] = 6;
  days["SUN"] = 0;

  cin>>s;

  cout<<7-days[s]<<'\n';

}

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

   solve();

  return 0;
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}

ll powM(ll a,ll b,ll m )
{
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll poww(ll a,ll b)
{

  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e5+5;

ll vis[600][600];

ll n,m,s,cnt,k;

//cnt goes from 1 to s-k.

char ch[600][600];

bool valid(ll x,ll y){
  if(vis[x][y])return false;
  if(ch[x][y]=='#')return false;
  if(x<1||x>n||y<1||y>m)return false;
  return true;
}

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

void dfs(ll x,ll y){
  cnt++;
  if(cnt>s-k)return;
  //cnt++;
  vis[x][y]=1;

  FOR(i,4){
    ll nx=x+dx[i],ny=y+dy[i];
    if(valid(nx,ny))dfs(nx,ny);
  }

}

int main()
{

IOS;

ll n;cin>>n;
//ll ans=0;

vl a(n),b(n);

ll ans=0;

vl score(n);

FOR(i,n)cin>>a[i]>>b[i],score[i]=a[i]+b[i],ans-=b[i];

sort(all(score),greater<>());

FOR(i,n){
  //if(i&1)ans-=2*b[i];
  if(i%2==0)ans+=score[i];
}

d1(ans);

//end_routine();

return 0;

 }

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <list>
#include <string.h>
#include <functional>
//#include <Windows.h>
//#include "Library.h"
//#include "Math.h"
using namespace std;
typedef long long int ll; typedef pair <int, int> P; typedef pair<int, P> P1; typedef vector <int> vecint; typedef vector <vecint> dvecint; typedef vector <dvecint> ddvecint;
const int INF = 2000000000;
const double EPS = 10e-9;
vecint a;
ll mergesort(vecint &a)
{
	int n = a.size();
	if (n <= 1) return 0;
	ll res = 0;
	vecint b(a.begin(), a.begin() + n / 2);
	vecint c(a.begin() + n / 2, a.end());
	res += mergesort(b);
	res += mergesort(c);
	int ai = 0, bi = 0, ci = 0;
	while (ai < n)
	{
		if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci]))
		{
			a[ai++] = b[bi++];
		}
		else
		{
			a[ai++] = c[ci++];
			res += n / 2 - bi;
		}
	}
	return res;
}
int main()
{
	int n; cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << mergesort(a) << endl;
	return 0;
}


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

int main(){
	vector<int> v(1001);
	int cnt=0;
	for(int i=1; i<1002; i++){
		if(i%3==0) cnt++;
		v[i]=cnt;
	}
	int n; cin>>n;
	cout<<v[n]<<endl;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res;

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

    println(n / 3);

}


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

string s;

int main(void){
    cin >> s;
    stack<char> st;
    lli ans = s.size();
    rep(i, s.size()){
        if(s[i] == 'S'){
            st.push('S');
        }else if(s[i] == 'T'){
            if(!st.empty() && st.top() == 'S'){
                ans-=2;
                st.pop();
            }else st.push('T');
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    //
    string str;
    vector<int> vec(26, 0);

    cin >> str;

    if (str == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1;
    } else if (str.size() == 26) {
        string tmp = str;
        next_permutation(str.begin(), str.end());

        string kekka = "";
        for (int i = 0; i < str.size(); i++) {
            kekka += str.at(i);
            if (str.at(i) > tmp.at(i)) break;
        }

        cout << kekka;
    } else {
        for (int i = 0; i < str.size(); i++) vec.at(str.at(i) - 'a')++;

        for (int i = 0; i < vec.size(); i++) {
            if (vec.at(i) == 0) {
                cout << str << (char)(i + 'a');
                break;
            }
        }
    }

    //
}


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

int	main()
{
    int M;
    cin >> M;
    vector<int64_t> d_vec(M), c_vec(M);
    for (int i = 0; i < M; ++i)
        cin >> d_vec.at(i) >> c_vec.at(i);
    int64_t sum_digit = 0;
    int64_t num_digit = 0;
    for (int i = 0; i < M; ++i) {
        sum_digit += d_vec.at(i) * c_vec.at(i);
        num_digit += c_vec.at(i);
    }
    cout << num_digit - 1 + (sum_digit - 1) / 9 << endl;
}

#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){

  // read problem
  long long int M, tmp1, tmp2;
  std::vector<long long int> d, c;

  scanf("%lld", &M);

  for(long long int i = 0; i < M; i++){
    scanf("%lld%lld", &tmp1, &tmp2);
    d.push_back(tmp1);
    c.push_back(tmp2);
  }

  /*std::cerr << "M: " << M << std::endl;
  std::cerr << "d: " << std::endl;
  for(long long int i = 0; i < M; i++){
    std::cerr << d[i] << " ";
  }std::cerr << std::endl;
  std::cerr << "c: " << std::endl;
  for(long long int i = 0; i < M; i++){
    std::cerr << c[i] << " ";
  }std::cerr << std::endl;*/

  // solve problem
  long long int carryover = 0;
  long long int topdigit, period, tmp_pos;
  long long int ans = 0;
  std::vector<long long int> tmp_digits(10);

  for(long long int i = 0; i < M; i++){
    //std::cerr << "i: " << i << " carryover: " << carryover << std::endl;
    // calculate carryover
    topdigit = d[i];
    while(carryover>0){
      ans++;
      topdigit = topdigit+carryover;
      carryover = topdigit/10;
      topdigit = (topdigit+10)%10;
    }

    //std::cerr << "carryover is done" << std::endl;

    // calculate one period
    tmp_digits[0] = topdigit;
    for(long long int j = 1; j < 10; j++){
      tmp_digits[j] = d[i];
    }
    tmp_pos = 0;
    period = 0;
    for(long long int tmp_pos = 0; tmp_pos < 9; tmp_pos++){
      while(tmp_digits[tmp_pos] > 0){
        period++;
        tmp_digits[tmp_pos+1] = tmp_digits[tmp_pos] + tmp_digits[tmp_pos+1];
        tmp_digits[tmp_pos] = tmp_digits[tmp_pos+1]/10;
        tmp_digits[tmp_pos+1] = (tmp_digits[tmp_pos+1]+10)%10;
      }
      /*for(long long int k = 0; k < 10; k++){
        std::cerr << tmp_digits[k];
      }std::cerr << std::endl;*/
    }

    ans += period*((c[i]-1)/9);
    //std::cerr << "one period calculated" << std::endl;

    // calculate amari
    tmp_pos = 9 - ((c[i]+8)%9);
    if(tmp_pos == 0){
      continue;
    }
    tmp_digits[tmp_pos] = topdigit;
    for(long long int j = tmp_pos+1; j < 10; j++){
      tmp_digits[j] = d[i];
    }
    for(long long int tmp_pos = 0; tmp_pos < 9; tmp_pos++){
      while(tmp_digits[tmp_pos] > 0){
        ans++;
        tmp_digits[tmp_pos+1] = tmp_digits[tmp_pos] + tmp_digits[tmp_pos+1];
        tmp_digits[tmp_pos] = tmp_digits[tmp_pos+1]/10;
        tmp_digits[tmp_pos+1] = (tmp_digits[tmp_pos+1]+10)%10;
      }
    }

    //std::cerr << "amari calculated" << std::endl;

    carryover = tmp_digits[9];
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;
}


#include <bits/stdc++.h>

//{{{ graph.hpp
#ifndef INCLUDE_GRAPH_HPP
#define INCLUDE_GRAPH_HPP
#include <vector>
namespace orislib {
struct Edge {
  typedef int weight_t;
  int from, to;
  weight_t w;
  Edge(int from, int to, weight_t w) : from(from), to(to), w(w) {}
  bool operator<(const Edge& e) const {
    return w > e.w;
  }
};
typedef std::vector<Edge> Edges;
typedef std::vector<Edges> Graph;
}
#endif
//}}}

using namespace orislib;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
//{{{ templates
#define TMPINL_(...) template<__VA_ARGS__>inline
#define TT_ TMPINL_(typename T)
#define TTF_ TMPINL_(typename T,typename F)
#define TTTS_ TMPINL_(typename T,typename...Ts)
#define TITS_ TMPINL_(size_t I=0,typename...Ts)
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TITS_ typename enable_if<I==tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t));}
TITS_ typename enable_if<I<tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t))+s+join<I+1>(s,t);}
TT_ string join(string s,T t){return to_string(t);}
TTTS_ string join(string s,T t,Ts...ts){return join(s,t)+s+join(s,ts...);}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
inline int puts(const string&s){ return puts(s.c_str()); }
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;

void dijkstra(const Graph& g, int s, vector<Edge::weight_t>& dist, vector<int>& prev)
{
  const int V = g.size();
  const Edge::weight_t INF = INT_MAX;
  prev.assign(V, -1);
  dist.assign(V, INF);
  dist[s] = 0;
  priority_queue<Edge> pq;
  for (pq.push(Edge(-2, s, 0)); !pq.empty(); pq.pop()){
    Edge c = pq.top();
    if (prev[c.to] != -1) continue;
    prev[c.to] = c.from;
    dist[c.to] = c.w;
    for (const auto& e : g[c.to]){
      pq.push(Edge(e.from, e.to, e.w + c.w));
    }
  }
}

int main()
{
  int V, E, r;
  V = in(), E = in(), r = in();
  Graph g(V);
  for (int i = 0; i < E; i++){
    int s, t, d;
    s = in(), t = in(), d = in();
    g[s].emplace_back(s, t, d);
  }
  vector<Edge::weight_t> ws;
  vector<int> prev;

  dijkstra(g, r, ws, prev);
  show(ws, [](int v){
      if (v == INT_MAX) cout << "INF";
      else cout << v;
  }, "\n");
  return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int V,E,r;
const int Inf = 10000*100000+100;
ll C[100010];
int main(){
	while(cin >> V >> E >> r && V >0){
		vector< vector< P > > v(V+10);
		for(int i=0;i<E;i++){
			ll s,t,d;
			cin >> s >> t >> d;
			v[s].push_back(make_pair(d,t));
		}
		priority_queue<P> Q;
		Q.push(P(0,r));
		for(int i=0;i<V;i++){
			C[i] = Inf;
		}
		C[r] = 0;
		while(!Q.empty()){
			P t = Q.top();
			ll s = t.second;
			Q.pop();
			if(C[s] < t.first) continue;
			for(int i=0;i<v[s].size();i++){
				P e = v[s][i];
				if(C[e.second] > C[s] + e.first){
					C[e.second] = C[s] + e.first;
					Q.push(make_pair(-C[e.second],e.second));
				}
			}
		}
		for(int i=0;i<V;i++){
			if(C[i] < Inf) cout << C[i] << endl;
			else cout << "INF" << endl;
		}
	}
}
#if 0
所要時間45分程度。ほとんどの部分はテキストを見ながら自力で書いたがうまくいかず，
蟻本(プログラミングコンテストチャレンジブック)(最近友人から譲ってもらった)を見て28行目を追加しAC
「確定しているので無視」ということの意味があまりわかっていなかったらしい。
#endif


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

#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    multiset<ll>st;
    f (n) {
        int x;
        cin >> x;
        st.insert(x);
    }
    int ans = 0;
    while (st.size()) {
        int x = *(--st.end());
        st.erase(st.lower_bound(x));
        for (int i = (1<<30) ; i ; i>>=1){
            if (i <= x) {
                break;
            }
            if (st.find(i-x) != st.end()) {
                ans++;
                st.erase(st.lower_bound(i-x));
                break;
            }
        }
    }
    cout << ans << '\n';
}

#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using ld = long double;
int INF = 1e9;

int main(){
  int n;cin >> n;
  vector<int> a(n),b(n),c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  vector<int> bc(n),ab(n);
  int ind = 0;
  rep(i,n){
    while(b[i]>=c[ind]) {
      if(ind == n) break;
      ind++;
    }
    bc[i] = n-ind;
  }
  ind = 0;
  rep(i,n){
    while(a[i] >= b[ind]){
      if(ind == n) break;
      ind++;
    }
    ab[ind]++;
  }
  rep(i,n-1) ab[i+1] += ab[i];
  ll ans = 0;
  rep(i,n) ans += ll(ab[i])*ll(bc[i]);
  cout << ans << endl;

}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;

int n, m, a, b;
int grid[N][N];

void solve() {
    cin >> n >> m >> a >> b;
    memset(grid, 0, sizeof(grid));
    for(int i = 1; i <= b; i++) {
        for(int j = 1; j <= a; j++) {
            grid[i][j] = 1;
        }
    }
    for(int i = b + 1; i <= n; i++) {
        for(int j = a + 1; j <= m; j++) {
            grid[i][j] = 1;
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cout << grid[i][j];
        }
        cout << "\n";
    }
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    solve();
}

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

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

	/*

	A
	001111B
	001111
	110000
	110000
	110000

	*/
	int H, W, A, B;
	scanf("%d %d %d %d", &H, &W, &A, &B);

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if ((i < B) ^ (j < A)) {
				cout << 1;
			} else {
				cout << 0;
			}
		}
		cout << "\n";
	}
	return 0;
}


#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second

using namespace std;

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

typedef pair<double, double> dP;

int main(){

  string line;
  int l[10];

  while(~scanf("%d,", l)){
    int v1, v2;
    vector <dP> t1(10);
    vector <dP> t2(10);
    int l1[10] = {}, l2[10] = {};

    for(int i = 1; i < 10; i++)
      scanf("%d,", l + i);
    scanf("%d,%d", &v1, &v2);

    l1[0] = l[0], l2[9] = l[9];
    for(int i = 1; i < 10; i++){
      l1[i] += l1[i - 1] + l[i];
      l2[9 - i] += l2[9 - i + 1] + l[9 - i];
    }

    double begin = 0;
    for(int i = 0; i < 10; i++){
      t1[i].fr = begin;
      t1[i].sc = (double)l1[i] / v1;
      begin = (double)l1[i] / v1;
    }

    begin = 0;
    for(int i = 9; i >= 0; i--){
      t2[i].fr = begin;
      t2[i].sc = (double)l2[i] / v2;
      begin = (double)l2[i] / v2;
    }

    for(int i = 0; i < 10; i++){
      if(!(t1[i].fr > t2[i].sc || t2[i].fr > t1[i].sc)){
        cout << i + 1 << endl;
        break;
      }
    }
  }
}

#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int cnt = 0;
vector<int> g;

void insertionSort(vector<int> &a, int g)
{
	for (int i = g; i < a.size(); i++)
	{
		int v = a[i];
		int j = i - g;
		for (; j >= 0 && a[j] > v;)
		{
			a[j + g] = a[j];
			j -= g;
			cnt++;
		}
		a[j + g] = v;
	}
}

void shellSort(vector<int> &a)
{
	for (int i = 1; i <= a.size(); i = 3 * i + 1)
	{
		g.push_back(i);
	}

	for (int i = g.size() - 1; i >= 0; i--)
	{
		insertionSort(a, g.at(i));
	}
}

int main()
{
	int n;
	vector<int> a;
	for (cin >> n; n--;)
	{
		int x;
		cin >> x;

		a.push_back(x);
	}

	shellSort(a);

	cout << g.size() << endl;
	for (int i = g.size() - 1; i >= 0; i--)
	{
		cout << g.at(i) << (i == 0 ? "" : " ");
	}

	cout << endl;
	cout << cnt << endl;

	for (int i = 0; i < a.size(); i++)
	{
		cout << a.at(i) << endl;
	}
}


#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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

int main(){
    string S; cin >> S;
    int w; cin >> w;
    REP(i, S.length()){
        cout << S[i];
        i += w - 1;
    }
    cout << endl;
    return 0;
}

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

int main(){
  string S;
  int w;
  cin >> S >> w;
  for(int i=0;i<S.size();i++){
    if(i%w==0){
      cout << S.at(i);
    }
  }
  cout << endl;
  return 0;
}


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

int main(){
    int x,y; cin >> x >> y;
    int ans = 0;
    if(x>0){
        if(y>0){
            if(x>y){
                ans++; // x -> -x
                ans += abs(x-y); // x -> -y
                ans++; // x-> y
            }else if(x < y){
                ans+= y-x; // x->y
            }
        }else if(y<0){
            if(abs(x) > abs(y)){
                ans++; // x->-x
                ans+= abs(x) - abs(y); // x->-y
            }else if(abs(x) < abs(y)){
                ans+= abs(y) - abs(x); // x->y
                ans++;   // x -> -y
            }else{
                ans++;
            }
        }else{
            ans++;
            ans+= x;
        }
    }else if(x<0){
        if(y>0){
            if(abs(x)>abs(y)){
                ans += abs(x) -abs(y);
                ans++;
            }else if(abs(x)<abs(y)){
                ans++;
                ans += abs(y) - abs(x);
            }else{
                ans++;
            }
        }else if(y<0){
            if(abs(x)>abs(y)){
                ans += abs(x) -abs(y);
            }else if(abs(x)<abs(y)){
                ans++;
                ans += abs(y) - abs(x);
                ans++;
            }
        }else{
            ans+=abs(x);
        }
    }else{
        if(y>0) ans+=y;
        else if(y<0) ans+= abs(y) + 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

  int64_t x, y; cin >> x >> y;

  if (0 < x && 0 < y) {
    if (x < y) cout << y - x << endl;
    else cout << abs(y - x) + 2 << endl;
  }

  if (x == 0) {
    if (x < y) cout << y << endl;
    else cout << abs(y) + 1 << endl;
  }

  if (y == 0) {
    if (x < y) cout << abs(x) << endl;
    else cout << x + 1 << endl;
  }

  if (x < 0 && y < 0) {
    if (x < y) cout << y - x << endl;
    else cout << abs(y) - abs(x) + 2 << endl;
  }

  if (x < 0 && 0 < y) {
    cout << min(abs(x) + abs(y), abs(abs(y) - abs(x)) + 1) << endl;
  }

  if (y < 0 && 0 < x) {
    cout << abs(abs(y) - abs(x)) + 1 << endl;
  }

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main() {
    int n;
    scanf("%d", &n);
    string s;
    cin >> s;

    int count[n + 1];
    // i文字目までにWがいくつあるか(1-indexed)

    // 累積和テーブル
    count[0] = 0;
    rep(i, n) {
        // その地点までの累積和だから前のcount[i]を代入してる
        count[i + 1] = count[i];
        // もしwなら加算
        if (s[i] == 'W') ++count[i + 1];
    }

    int ans = n;
    for (int i = 1; i <= n; ++i) {
        // 自分より西にいて西を向いている人が
        //  count[i-1]人
        // 自分より東にいて東を向いている人が
        //  (n-i)-(count[n]-count[i])人
        ans = min(ans, count[i - 1] + (n - i) - (count[n] - count[i]));
    }

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

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define TLE() cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms.\n";
const ll MOD = 1E9+7;
const ll IINF = 1E18;
const int INF = 1e9;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

const int N=1e5+5;
int n,a[N];
int bit[N];

void upd(int x,int v){
	for(;x<N;x=x|(x+1))
		bit[x]=max(bit[x],v);
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	vector<int> c;
	REP(i,n){
		cin>>a[i];
		c.pb(a[i]);
	}
	sort(all(c));
	int res=0;
	reverse(a,a+n);
	REP(i,n){
		int x=lower_bound(all(c),a[i])-c.begin();
		int len=get(x)+1;
		upd(x,len);
		res=max(res,len);
	}
	cout<<res<<'\n';
}


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

int main(){
  vector<int> outp;
  int icn;
  int icd;
  int g;
  vector<int> ice;
  for(g = 0;;g++){
    vector<int> ice(10,0);
    cin >> icn;
    if(icn == 0){
      break;
    }else{
    for(int a = 0;a< icn;a++){
      cin >> icd;
      ice[icd] += 1;
    }
    outp.insert(outp.end(),ice.begin(),ice.end());
  }
  }
  for(int n = 0;n<g * 10;n++){
    if(outp[n] == 0){
      cout << "-";
    }else{
      for(int c = 0;c<outp[n];c++){
        cout << "*" ;
      }
    }
    cout << endl;
  }
  return 0;
}

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

struct data{
    int a, b, c;
    data(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
};

int main(){
    int a, b, c;
    while(cin >> a >> b >> c){
        if(a + b + c == 0)  break;

        int da[a], db[b], dc[c];
        for(int i = 0; i < a; i++) da[i] = 0;
        for(int i = 0; i < b; i++) db[i] = 0;
        for(int i = 0; i < c; i++) dc[i] = 0;

        vector<data> fault;

        int n;
        cin >> n;

        while(n-- > 0){
            int i, j, k, r;
            cin >> i >> j >> k >> r;
            if(r == 0)  fault.push_back(data(i,j,k));
            else        da[i-1] = db[j-a-1] = dc[k-a-b-1] = 1;
        }

        bool update = true;
        while(update){
            update = false;
            for(data d : fault){
                if(da[d.a-1] > 1 || db[d.b-a-1] > 1 || dc[d.c-a-b-1] > 1)
                   continue;
                if(da[d.a-1] + db[d.b-a-1] + dc[d.c-a-b-1] == 2){
                    update = true;
                    if(da[d.a-1] == 1 && db[d.b-a-1] == 1)         dc[d.c-a-b-1] = 2;
                    else if(db[d.b-a-1] == 1 && dc[d.c-a-b-1] == 1)    da[d.a-1] = 2;
                    else if(dc[d.c-a-b-1] == 1 && da[d.a-1] == 1)    db[d.b-a-1] = 2;
                }
            }
        }

        for(int i = 0; i < a; i++)  cout << 2-da[i] << endl;
        for(int i = 0; i < b; i++)  cout << 2-db[i] << endl;
        for(int i = 0; i < c; i++)  cout << 2-dc[i] << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

int main()
{

    lint h, w, a, b;

    scanf("%lld", &h);
    scanf("%lld", &w);
    scanf("%lld", &a);
    scanf("%lld", &b);

    for (int i = 0; i < h; ++i)
    {
        if (i < h - b)
            printf("%s\n", (std::string((w - a), '1') + std::string(a, '0')).c_str());
        else
            printf("%s\n", (std::string((w - a), '0') + std::string(a, '1')).c_str());
    }
    return 0;
}

#include<iostream>

using namespace std;

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if((i<=B && j<=A) || (i>B && j>A)){
                cout << 0;
            } else{
                cout << 1;
            }
        }
        cout << endl;
    }

}


/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
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;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n, m;
	cin >> n >> m;
	Vec a(n), b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];
	sort(all(a));
	sort(all(b));
	reverse(all(a));
	reverse(all(b));
	a.pb(0), b.pb(0);

	ll pos1 = 0, pos2 = 0;
	ll ans = 1, space = 0;
	repnr(i, n*m){
		if(i == a[pos1] && i == b[pos2]){
			space += pos1+pos2;
			pos1++, pos2++;
		}else if(i == a[pos1]){
			ans *= pos2;
			ans %= MOD;
			space += pos2-1;
			pos1++;
		}else if(i == b[pos2]){
			ans *= pos1;
			ans %= MOD;
			space += pos1-1;
			pos2++;
		}else{
			ans *= space;
			ans %= MOD;
			space--;
		}
	}
	if(pos1 == n && pos2 == m) co(ans);
	else co(0);

	return 0;
}

#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;
//0->決定
//1->xのみ決定
//2->yのみ決定
//3->x,yの範囲のみ決定
struct query {
	ll type;
	pll p1, p2;
};

ll H, W;
vector<ll> A, B;
vector<vector<pll>> DP;
vector<query> DP2;

int main() {
	cin >> H >> W;
	A.resize(H + 1);
	for (ll y = 1; y <= H; y++)cin >> A[y];
	sort(A.begin(), A.end(), [](ll a, ll b) {return a < b; });
	B.resize(W + 1);
	for (ll x = 1; x <= W; x++)cin >> B[x];
	sort(B.begin(), B.end(), [](ll a, ll b) {return a < b; });
	for (ll x = W; x > 1; x--) {
		if (B[x] == B[x - 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (ll y = H; y > 1; y--) {
		if (A[y] == A[y - 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	DP.resize(W * H + 1, vector<pll>(2, pll(0, 0)));
	DP2.resize(W * H + 1);
	ll xuse = W, yuse = H;
	for (ll p = W * H; p >= 1; p--) {
		if (A[yuse] == p && B[xuse] == p) {
			DP[p][0] = pll(xuse, yuse);
			DP[p][1] = pll(xuse, yuse);
			xuse--;
			yuse--;
			DP2[p] = { 0,pll(xuse,yuse),pll(-1,-1) };
		}
		else if (A[yuse] == p) {
			DP[p][0] = pll(xuse + 1, yuse);
			DP[p][1] = pll(W, yuse);
			DP2[p] = { 2,pll(xuse + 1, yuse),pll(W, yuse) };
			yuse--;
		}
		else if (B[xuse] == p) {
			DP[p][0] = pll(xuse, yuse + 1);
			DP[p][1] = pll(xuse, H);
			DP2[p] = { 1,pll(xuse, yuse + 1) ,pll(xuse, H) };
			xuse--;
		}
		else {
			DP[p][0] = pll(xuse+1, yuse+1);
			DP[p][1] = pll(W, H);
			DP2[p] = { 3,pll(xuse + 1, yuse + 1) ,pll(W, H) };
		}
	}
	ll ans = 1;
	for (ll p = W * H; p >= 1; p--) {
		if (DP[p][0] == DP[p][1])continue;
		else if (DP[p][0].second == DP[p][1].second) {
			ans = (ans * (DP[p][1].first - DP[p][0].first + 1)) % MOD;
		}
		else if (DP[p][0].first == DP[p][1].first) {
			ans = (ans * (DP[p][1].second - DP[p][0].second + 1)) % MOD;
		}
	}
	for (ll p = W * H; p >= 1; p--) {
		if (DP[p][0].first == DP[p][1].first ||
			DP[p][0].second == DP[p][1].second)continue;
		ans = (ans * ((W - DP[p][0].first+1) * (H - DP[p][0].second+1)-(W*H-p))) % MOD;
	}
	ans = 1;
	for (ll p = W * H; p >= 1; p--) {
		if (DP2[p].type == 0)continue;
		else if (DP2[p].type == 1) {
			ll left = DP2[p].p2.second - DP2[p].p1.second + 1;
			ans = (ans * left) % MOD;
		}
		else if (DP2[p].type == 2) {
			ll left = DP2[p].p2.first - DP2[p].p1.first + 1;
			ans = (ans * left) % MOD;
		}
		else {
			ll left = (W - DP[p][0].first + 1) * (H - DP[p][0].second + 1) - (W * H - p);
			ans = (ans * left) % MOD;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  if(s.size()==3){
	for(int i=2;i>=0;i--){
      cout << s.at(i);
    }
    cout << endl;
  }
  else{
    cout << s << endl;
  }
}

#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  string S;
  cin >> S;
  if(S.size()==3){
    reverse(ALL(S));
  }
  cout << S << endl;
}


//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define N 100005
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1 == p2)?EOF:*p1++)
using namespace std ;
//char buf[(1 << 22)] , *p1 = buf , *p2 = buf ;
inline int read ()
{
    char c = getchar () ; int x = 0 , f = 1 ;
    while (c < '0' || c > '9') { if (c == '-') f = -1 ; c = getchar () ; }
    while (c >= '0' && c <= '9'){ x = x * 10 + c - '0' ; c = getchar () ; }
    return x * f ;
}
map <int , int> mp[N << 3] ; //mp[u][w]:u属性为w的虚点编号
vector <pair <int , int> > edge[N << 3] ;
int dis[N << 3] , vis[N << 3] , n , m ;
queue <int> q ;
void spfa (int s)
{
    int tim = 0 ;
    for (int i = 0 ; i <= (N << 3) - 5 ; i ++) dis[i] = 1e9 ;
	// fill (dis , dis + (N << 2) , 1e9) ;
	dis[s] = 0 ;
	vis[s] = 1 ;
	q.push (s) ;
	while (! q.empty ())
	{
        // printf ("The %d time\n" , ++ tim) ;
		int x = q.front () ;
		q.pop () ;
		for (int i = 0 ; i < edge[x].size () ; i ++)
		{
			int y = edge[x][i].first ;
			if (dis[y] > dis[x] + edge[x][i].second)
			{
				dis[y] = dis[x] + edge[x][i].second ;
				if (! vis[y])
				{
					vis[y] = 1 ;
					q.push (y) ;
				}
			}
		}
        vis[x] = 0 ;
	}
}
int main ()
{
//    freopen (".in" , "r" , stdin) ; freopen (".out" , "w" , stdout) ;
	n = read () , m = read () ;
    int tot = n ;
	for (int i = 1 ; i <= m ; i ++)
	{
		int u = read () , v = read () , w = read () ;
        if (! mp[u].count (w))
        {
            mp[u][w] = ++ tot ;
            edge[u].push_back (make_pair (tot , 1)) ;
            edge[tot].push_back (make_pair (u , 1)) ;
        }
        if (! mp[v].count (w))
        {
            mp[v][w] = ++ tot ;
            edge[v].push_back (make_pair (tot , 1)) ;
            edge[tot].push_back (make_pair (v , 1)) ;
        }
        edge[mp[u][w]].push_back (make_pair (mp[v][w] , 0)) ;
        edge[mp[v][w]].push_back (make_pair (mp[u][w] , 0)) ;
    }
    spfa (1) ;
    if (dis[n] == 1e9) return puts ("-1") , 0 ;
    cout << dis[n] / 2 ;
}