//Code by Ritik Agarwal
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define int long long int
#define loop(i,a,b) for(int i=a;i<b;i++)
#define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define pb push_back
#define ff first
#define ss second
#define all(aa) aa.begin(), aa.end()
#define rall(a) a.rbegin() , a.rend()
#define read(a,b) int a,b;  cin>>a>>b
#define readt(a,b,c) int a,b,c; cin>>a>>b>>c
#define readf(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d;
#define print(v) for(auto x:v) cout<<x<<" ";cout<<endl
#define printPair(res) for(pair<int,int>& p:res) cout<<p.first<<" "<<p.second<<endl;
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
//*****  Constants  *****
const int mod = 1000000007; /* 1e9 + 7*/
const int MAXN = 1500005; /*1e6 +5 */
const int mod1= 998244353;
const int NAX=2E5+5;
int vis[MAXN]={0};
int fac[300001];
void fact(int m){fac[0]=1;for(int i=1;i<=300000;i++) fac[i]=(fac[i-1]%m * i%m)%m;}
/* Iterative Function to calculate (x^y)%p in O(log y)*/
long long power( long long x,  int y, int p){   long long res = 1;
x = x % p; while (y > 0) { if (y & 1)  res = (res * x) % p;  y = y >> 1; x = (x * x) % p;} return res;}
// Returns n^(-1) mod p
long long modInverse( long long n, int p) {  return power(n, p - 2, p); }
long long nCr( long long n,int r, int p) { if (r == 0) return 1; if(n<r) return 0;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; }

int binarySearch(vi arr, int l, int r, int x) {
if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid;
if (arr[mid] > x)  return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x); } return -1; }
bool sortGrt(const pair<int,int> &a,
              const pair<int,int> &b)
{

    return (a.second > b.second);

}
void solve(int test)
{

  int n , ans=0;cin>>n;
  vi a(n);
  scan(a,n);
  sort(rall(a));

  loop(i,0,n)
  {
    ans+= ((a[i])*(n-1-i) - (a[i]*i));
  }

  cout<<ans;
}

int32_t main()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
      #endif
      faster;
      fact(mod);
      int t=1;
      //cin>>t;
      for(int test=1;test<=t;test++)
      {
          solve(test);
      }
}

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#define rg register
inline int read(){
	rg int x=0,fh=1;
	rg char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*fh;
}
const int maxn=2e5+5;
int n,a[maxn];
long long ans=0,sum=0;
int main(){
	n=read();
	for(rg int i=1;i<=n;i++){
		a[i]=read();
	}
	std::sort(a+1,a+1+n);
	for(rg int i=1;i<=n;i++){
		ans+=1LL*a[i]*(i-1)-sum;
		sum+=a[i];
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, a) for(auto &x: (a))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PR pair
#define X first
#define Y second

void solve(){
	vector<ll> vec;
	ll akt = 0;
	int n;
	cin >> n;
	FOR(i, 0, n){
		int a, b;
		cin >> a >> b;
		akt -= a;
		vec.PB(2ll*a+b);
	}
	sort(vec.rbegin(), vec.rend());
	int ans = 0;
	TRAV(x, vec){
		if(akt <= 0){
			ans++;
			akt += x;
		}
	}
	cout << ans << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int tt; cin >> tt;
	// FOR(te, 0, tt){
	// 	// cout << "Case #" << te+1 << ": ";
	// 	solve();
	// }
	solve();
	return 0;
}

// Problem D

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <cassert>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <iomanip>

#define MAXN 1000
#define pb push_back
#define mp make_pair

using namespace std;

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

double p[101][101][101];
int a0, b0, c0;
int main() {
  cin >> a0 >> b0 >> c0;
  for (int a=0; a<=100; a++)
    for (int b=0; b<=100; b++)
      for (int c=0; c<=100; c++) {
	if (a<a0 || b<b0 || c<c0) p[a][b][c] = 0;
	else if (a == a0 && b == b0 && c == c0) p[a][b][c] = 1;
	else {
	  if (a > a0 && b!=100 && c!=100) p[a][b][c] += ((a-1)*p[a-1][b][c] / (a+b+c-1));
	  if (b > b0 && a!=100 && c!=100) p[a][b][c] += ((b-1)*p[a][b-1][c] / (a+b+c-1));
	  if (c > c0 && a!=100 && b!=100) p[a][b][c] += ((c-1)*p[a][b][c-1] / (a+b+c-1));
	  //~ cout << a << " " << b << " " << c << " " << p[a][b][c] << endl;
	}
      }
  double res = 0;
  int a, b, c;
  a = 100;
  for (b = b0; b<100; b++)
    for (c=c0; c<100; c++)
      res += p[a][b][c] * (a+b+c-a0-b0-c0);
  b = 100;
  for (a = a0; a<100; a++)
    for (c=c0; c<100; c++)
      res += p[a][b][c] * (a+b+c-a0-b0-c0);
  c = 100;
  for (b = b0; b<100; b++)
    for (a=a0; a<100; a++)
      res += p[a][b][c] * (a+b+c-a0-b0-c0);

  cout << std::setprecision(10) << res << endl;
  return 0;
}


#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )
#define rep2(n) for( int j = 0 ; j < n ; j++ )
#define REP2(n) for( int j = 1 ; j <= n ; j++ )
#define repll2(n) for( ll j = 0 ; j < n ; j++ )
#define REPll2(n) for( ll j = 1 ; j <= n ; j++ )

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , w;
    cin >> n >> w;
    cout << n / w;
}

#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
ll fastpow(ll x,ll y,ll p){
    ll res=1,tmp=x;
    while(y){
        if(y&1){
            res=res*tmp%p;
        }
        tmp=tmp*tmp%p;
        y>>=1;
    }
    return res;
}
int main(){
    ll n,m;
    cin>>n>>m;
    cout<<int(floor(fastpow(10,n,m*m)/m))%m<<endl;
    return 0;
}


/*
 * -----Joy Matubber ----10/6/2021----
 */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double dl;
typedef string St;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define pb push_back
#define F first
#define S second
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;             //(abs(a-b)<eps) check the two double value is equal or not;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction(a) cout.unsetf(ios::floatfield); cout.precision(a); cout.setf(ios::fixed,ios::floatfield); //dosomik er por koy ghor ta dekhabe

//**************************************************D E B U G G E R OR OUTPUT ******************************************************************;

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

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
    cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
    for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
    cerr << arg << ' ';
    faltu(rest...);
}

//************************************************************* C O D E ***********************************************************************
int main() {
    optimize();
    ll a,b,c;
    cin>>a>>b>>c;
    if(c==0)
    {
        if(a==b)
        {
            cout<<"Aoki"<<endl;
        }
        else if(a>b)
        {
            cout<<"Takahashi"<<endl;
        }
        else
        {
            cout<<"Aoki"<<endl;
        }
    }
    else
    {
        if(a==b)
        {
            cout<<"Takahashi"<<endl;
        }
        else if(a>b)
        {
            cout<<"Takahashi"<<endl;
        }
        else
        {
            cout<<"Aoki"<<endl;
        }

    }

}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(c)
    if(a >= b) cout << "Takahashi\n";
    else cout << "Aoki\n";
    else if(a > b) cout << "Takahashi\n";
    else cout << "Aoki\n";
}


#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)
#define int long long

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 300013, M = N << 1;

int n, w;

namespace BIT
{
	int tr[N];
	int lowbit(int i) {return i & (-i);}
	void add(int u, int val)
	{
		++u;
		for (int i = u; i <= 300001; i += lowbit(i)) tr[i] += val;
	}
	int query(int u)
	{
		int res = 0;
		++u;
		for (int i = u; i; i -= lowbit(i)) res += tr[i];
		return res;
	}
} //namespace BIT

signed main()
{
	//File("");
    n = gi <int> ();
  cout << max(0ll, n) << endl;
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;

int main() {
  int n,k;
  cin >> n >> k;
  int x = 0;
  rep(i,n)rep(j,k) x += (i+1)*100+j+1;
  cout << x << endl;
}


#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll N;
ll A[100005];
ll B[100005];

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

    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, N) {
        cin >> B[i];
    }

    ll ans = 0;
    priority_queue<ll> q0, q1;
    REP(i, N) {
        ans += A[i];
        ll d = B[i] - A[i];
        if (i % 2 == 0)
            q0.push(d);
        else
            q1.push(d);
    }

    while (!q0.empty() && !q1.empty()) {
        ll d = q0.top() + q1.top();
        q0.pop();
        q1.pop();
        if (d < 0)
            break;
        ans += d;
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;
#define fi first
#define se second
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);
void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M;
string S[int(1e5 + 5)];
ll cntOdd, cntEven;

int main(){
  cin >> N >> M;
  for (int i = 0; i < N; i++){
    cin >> S[i];
    int cnt = 0;
    for (int j = 0; j < M; j++){
      if (S[i][j] == '0') cnt++;
    }
    if (cnt % 2 != 0) cntOdd++;
    else cntEven++;
  }
  cout << cntOdd * cntEven << endl;

  return 0;
}


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

#include <bits/stdc++.h>

using namespace std;

#define pb	push_back
#define mp	make_pair
#define gcd __gcd
#define F   first
#define S   second
#define pii pair<int,int>

using ll = long long;

bool isSubsequence(string s, string t) {
	int index = 0;
	if(s.length() == 0) {
		return true;
	}
	for(int i = 0; i < (int) t.length(); i++) {
		if(s.at(index) == t.at(i)){
			index++;
		}
		if(index == (int) s.length()) {
			return true;
		}
	}
	return false;
}

bool isPrime(int n) {
	for(int i = 2; i < int(sqrt(n))+1; i++) {
		if(n%i==0) {
			return false;
		}
	}
	return true;
}

bool isPrime(ll n) {
	for(ll i = 2; i < ll(sqrt(n))+1; i++) {
		if(n%i==0) {
			return false;
		}
	}
	return true;
}

bool isInt(double n) {
	if(floor(n) == ceil(n)) {
		return true;
	}
	return false;
}

bool isPalindrome(string s) {
	int n = s.length();
	for(int i = 0; i < n/2; i++) {
		if(s.at(i) != s.at(n-i-1)) {
			return false;
		}
	}
	return true;
}

bool distinctDigits(int n) {
	string s = to_string(n);
	for(int i = 0; i < (int) s.length(); i++) {
		for(int j = i+1; j < (int) s.length(); j++) {
			if(s.at(i)==s.at(j)) {
				return false;
			}
		}
	}
	return true;
}

bool distinctDigits(string s) {
	for(int i = 0; i < (int) s.length(); i++) {
		for(int j = i+1; j < (int) s.length(); j++) {
			if(s.at(i)==s.at(j)) {
				return false;
			}
		}
	}
	return true;
}

int digitSum(int n) {
	int ans = 0;
	string s = to_string(n);
	for(int i = 0; i < (int) s.length(); i++) {
		ans += stoi(s.substr(i, 1));
	}
	return ans;
}

int swapBits(int n, int p1, int p2) {
	int bit1 = (n >> p1) & 1;
	int bit2 = (n >> p2) & 1;

	int x = bit1 ^ bit2;
	x = (x << p1) | (x << p2);

	return n ^ x;
}

void display(vector<auto> a) {
	for(auto element : a) {
		cout << element << ' ';
	}
	cout << endl;
}

void solve()
{
	ll n;
	cin >> n;
	vector<ll> x(n);
	vector<ll> y(n);

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

	vector<vector<ll>> houses;
	for(int i = 0; i < n; i++) {
		houses.pb({x[i], y[i], i});
	}

	vector<vector<ll>> maxes;

	sort(houses.begin(), houses.end(),
		[] (vector<ll> a, vector<ll> b) {
			return a[0] > b[0];
		});

	// for(int i = 0; i < n; i++) {
	// 	display(houses[i]);
	// }

	maxes.pb({houses[0][0] - houses[n-1][0], houses[0][2], houses[n-1][2]});
	maxes.pb({houses[0][0] - houses[n-2][0], houses[0][2], houses[n-2][2]});
	maxes.pb({houses[1][0] - houses[n-1][0], houses[1][2], houses[n-1][2]});

	sort(houses.begin(), houses.end(),
		[] (vector<ll> a, vector<ll> b) {
			return a[1] > b[1];
		});

	// for(int i = 0; i < n; i++) {
	// 	display(houses[i]);
	// }

	maxes.pb({houses[0][1] - houses[n-1][1], houses[0][2], houses[n-1][2]});
	maxes.pb({houses[0][1] - houses[n-2][1], houses[0][2], houses[n-2][2]});
	maxes.pb({houses[1][1] - houses[n-1][1], houses[1][2], houses[n-1][2]});

	sort(maxes.begin(), maxes.end(),
		[] (vector<ll> a, vector<ll> b) {
			return a[0] > b[0];
		});

	// for(int i = 0; i < 6; i++) {
	// 	display(maxes[i]);
	// }

	if(maxes[1][1] == maxes[0][1] && maxes[1][2] == maxes[0][2]) {
		cout << maxes[2][0];
	} else {
		cout << maxes[1][0];
	}
}

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

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

	solve();

	cout.flush();
	return 0;
}

/*
			Saturday 29 May 2021 05:32:07 PM IST
					@uthor::astrainL3gi0N
*/

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

typedef long long int ll;
typedef std::vector<int> vi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<ll> vl;

#define pb push_back
#define mp make_pair
#define debg(x)	std::cerr<<(#x)<<" => "<<x<<'\n';
#define debgg(x,y)	std::cerr<<(#x)<<" => "<<x<<'\t'<<(#y)<<' '<<y<<'\n';
#define len(a) (int)(a).size()
#define all(x) x.begin(),x.end()
const int mod = 1000000007;
//const int mod = 998244353;

bool comp (ii x, ii y) {
    if (x.second == y.second)
        return x.first < y.first;
    return x.second < y.second;
}
template < typename T> void  printv (T &a) {
    cout<<'\n';
    for (auto it = a.begin(); it != a.end(); ++it)
        cout<<it->first<<' '<<it->second<<'\n';
}
int gint() {
    int n;  cin>>n;
    return n;
}
//int t[510][510];
ll ans;

void solve () {
    map <ii,int> hmp;
    map <int,ii> mph;
    int n = gint();
    vii vpr;
    for (int i = 0;i < n;++i) {
        int x = gint();
        int y = gint();
        vpr.pb(mp(x,y));
        hmp[mp(x,y)] = i+1;
        mph[i+1] = mp(x,y);
    }
    vi vr;
    set <int> hsh;

    sort(all(vpr));
    hsh.insert(hmp[vpr[0]]);
    hsh.insert(hmp[vpr[1]]);
    hsh.insert(hmp[vpr[n-1]]);
    hsh.insert(hmp[vpr[n-2]]);
    for (auto &v: vpr) {
        swap(v.first,v.second);
    }
    sort(all(vpr));

    hsh.insert(hmp[mp(vpr[0].second,vpr[0].first)]);
    hsh.insert(hmp[mp(vpr[1].second,vpr[1].first)]);
    hsh.insert(hmp[mp(vpr[n-1].second,vpr[n-1].first)]);
    hsh.insert(hmp[mp(vpr[n-2].second,vpr[n-2].first)]);
    for (auto &v: vpr) {
        swap(v.first,v.second);
    }
    vii vrr;
    for (auto v: vpr) {
        if (hsh.count(hmp[v]))
            vrr.pb(v);
    }

    for (int i = 0; i < len(vrr); ++i) {
        for (int j = i+1; j < len(vrr); ++j) {
            vr.pb(max(abs(vrr[i].first-vrr[j].first),
                    abs(vrr[i].second-vrr[j].second)));
        }
    }
    sort(all(vr));
    cout<<vr[len(vr)-2];

}
void sol () {
    //test
    //cout << setprecision(15) << fixed;
}

int main () {
    int testcases = 1;
    for (int t = 0; t < testcases; ++t) {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(a*a+b*b<c*c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll M=998244353;
    a=((a*(a+1))/2)%M;
    b=((b*(b+1))/2)%M;
    c=((c*(c+1))/2)%M;
    ll ans=a;
    ans=(ans*b)%M;
    ans=(ans*c)%M;
    cout<<ans<<"\n";
}

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


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define irreps(i, m, n) for (int i = ((int)(n)-1); i > (int)(m); ++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 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) (int)(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>;
using ld = long double;

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

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

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

// 3人選ぶ
// 3最大値で圧縮 => 5つの内の最小値を最大化
// ある1個の値に着目した時、その値が最終値に成り得るか
// 2数の和を求める
// ｘが作れるか ＝＞
// 最大値をとって最小値をとる
// 2組を決める
// もう1人は、5つのパラメータそれぞれについてソートしておけば
// 最小値について降順にソートしておく idxももつ
// 2組を決めた時、5つのうちどれを最小値とするか

int n;
vc<vc<int>> a;

bool isOk(ll mid){
  vc<int> used(1<<5), X;
  rep(i,n){
    int x=0;
    rep(j,5){
      if(a[i][j]>=mid) x+=(1<<j);
    }
    if(!used[x]){
      used[x]=1;
      X.push_back(x);
    }
  }
  // cout<<X.size()<<endl;
  int all=(1<<5)-1;
  rep(i,X.size()){
    int x=X[i];
    if(x==all) return 1;
    irep(j,i+1,X.size()){
      int y=x|X[j];
      if(y==all) return 1;
      irep(k,j+1,X.size()){
        int z=y|X[k];
        if(all==z) return 1;
      }
    }
  }
  return 0;
}

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

  cin>>n;
  a = vc<vc<int>>(n,vc<int>(5));
  rep(i,n) rep(j,5) cin>>a[i][j];

  ll ng=1e9+1, ok=1;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    // cout<<ok<<' '<<ng<<' '<<mid<<endl;
    if(isOk(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 2e3 + 5;

int n, a[N];
inline int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }

set <int> s;
set <int> :: iterator it;
inline void divide(int num)
{
	for (int i = 1; i <= sqrt(num); i++)
	if (num % i == 0) {
		s.insert(i);
		s.insert(num / i);
	}
}

int main()
{
	scanf ("%d", &n);
	int minv = 0x3f3f3f3f;
	for (int i = 1; i <= n; i++) {
		scanf ("%d", &a[i]);
		minv = min(minv, a[i]);
		divide(a[i]);
	}

	int ans = 1;
	for (it = s.begin(); it != s.end(); it++)
	{
		int num = (*it);
		if (num >= minv) break;

		int val = 0;
		for (int i = 1; i <= n; i++)
		if (a[i] % num == 0) val = gcd(val, a[i]);

		if (val == num) ans++;
	}
	printf ("%d\n", ans);
  	return 0;
}


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

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

bool ABC(char c) {
    int i = c - 'A';
    return 0<=i && i<26;
}

bool abc(char c) {
    int i = c - 'a';
    return 0<=i && i<26;
}

int main() {
    string S; cin >> S;
    ll N = S.size();
    rep(i,N) {
        bool OK = false;
        if (i%2) OK = ABC(S[i]);
        else OK = abc(S[i]);
        if (!OK) No();
    }
    Yes();
}

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

string f(string s){

    for(int i=0;i<s.size();i+=2){
        if(s[i]<'a' || s[i]>'z') return "No";
    }

for(int i=1;i<s.size();i+=2){
        if(s[i]<'A' || s[i]>'Z') return "No";
    }
    return "Yes";
}

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

    string s;
    cin>>s;

    cout<<f(s)<<endl;

}


#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define eps 1e-18
#define pi acos(-1)

using namespace std;
const int M = 5;

void done(int tc){
  int a,b,c; cin >> a >> b >> c;
  if(c==0){
    if(a==b)cout<<"Aoki\n";
    else if(a>b)cout<<"Takahashi\n";
    else cout<<"Aoki\n";
  }
  if(c==1){
    if(a==b)cout<<"Takahashi\n";
    else if(a<b)cout<<"Aoki\n";
    else cout<<"Takahashi\n";
  }
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t; t = 1;
 // cin >> t;
  for(int i=1;i<=t;++i)done(i);
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define amax(a, b) a = std::max(a, b)
#define amin(a, b) a = std::min(a, b)

using ll = long long;

int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
    for ( ; a >= 0 && b >= 0; c ^= 1) {
        if (c) b--;
        else a--;
    }
    std::cout << (c ? "Aoki" : "Takahashi") << '\n';
    return 0;
}


/*HAR HAR MAHADEV
ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
# include   <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

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

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;//typedef for datatype and #define for macro

# define    fast                ios_base::sync_with_stdio(false);cin.tie(NULL);
# define    MOD                 1000000007
# define    endl                '\n'
# define    FOR(i, a, b)        for (int i=a; i<(b); i++)
# define    F0R(i, a)           for (int i=0; i<(a); i++)
# define    FORd(i,a,b)         for (int i = (b)-1; i >= a; i--)
# define    F0Rd(i,a)           for (int i = (a)-1; i >= 0; i--)
# define    INF                 9e18
# define    PI                  3.14159265358979323846
# define    lb                  lower_bound
# define    ub                  upper_bound
# define    mp                  make_pair
# define    pb                  push_back
# define    fi                  first
# define    se                  second
# define    all(a)              a.begin(), a.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
    fast;
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n, sum = 0;
        cin >> n;
        while (n--)
        {
            ll a, b;
            cin >> a >> b;
            sum += ((b * (b + 1)) / 2) - ((a * (a + 1)) / 2) + a;
        }
        cout << sum << endl;
        return 0;
    }
    return 0;
}
/* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
  * WRITE STUFF DOWN
  * DON'T GET STUCK ON ONE APPROACH
*/

  #include<bits/stdc++.h>

/*

shinchanCoder Here!!

*/

using namespace std;

#define endll "\n"
#define pb push_back
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define forn(i,n) for(ll i=0;i<(n);i++)

#define sz(x) (int)(x).size()

#define ff first
#define ss second

#define mpr make_pair

#define len(x) x.length()

#define ll long long
#define ld long double
#define lli long long int

#define mod 1000000007

ll powmod(ll a,  ll b){
    if(b==0){
        return 1 ;
    }
    ll x = powmod(a,b/2);
    x = (x*x)%mod ;
    if(b%2){
        x = (a*x)%mod ;
    }
    return x;
}

ll power(ll x, ll y) {
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

vector<ll> prm;

void Sieve(ll n) {
  bool prime[n+1];
  memset(prime,true, sizeof(prime));
  for(ll p=2;p*p<=n;p++) {
    if(prime[p]==true) {
      for(ll i=p*p;i<=n;i+=p) {
        prime[i]=false;
      }
    }
  }
  if(!prm.empty()) {
    prm.clear();
  }
  for(ll p=2;p<=n;p++) {
    if(prime[p]) {
      prm.pb(p);
    }
  }
}

ll fact(ll n) {
    ll res = 1;
    for(ll i=2;i<=n;i++) {
        res*=i;
    }
    return res;
}

ll _lcm(ll x,ll y) {
    return x*y/__gcd(x,y);
}

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

ll nCr(ll n,ll r) {
    return (ld)fact(n)/(ld)(fact(r)*fact(n-r));
}

bool isCoPrime(ll z,ll a[],ll n) {
    for(ll i=0;i<n;i++) {
        if(_gcd(a[i],z)==1) {
            return 1;
        }
    }
    return 0;
}

ll solve(ll prm[15],ll i,ll res,ll a[],ll n) {
    if(i==15) {
        if(!isCoPrime(res,a,n)) {
            return res;
        }else {
            return 1e18;
        }
    }
    return min(solve(prm,i+1,res*prm[i],a,n),solve(prm,i+1,res,a,n));
}

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //Sieve(1000000);
    ll prm[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++) {
        cin>>a[i];
    }
    cout<<solve(prm,0,1,a,n);
    return 0;
}


#include<bits/stdc++.h>
#define ll              long long
#define ull             unsigned long long
#define pb              push_back
#define fastread()      (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
    fastread();
    //freopen("input.txt","r", stdin);

    int n,a[1001];
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    sort(a,a+n);
    map<int,int>mp;
    map<int,int>:: iterator itr;
    for(int i=2; i<=1000; i++){
        for(int j=0; j<n; j++){
            if(a[j] % i == 0){
                mp[i]++;
            }
        }
    }
    int ans = 0,freq = 0;
    for(itr = mp.begin(); itr!=mp.end(); itr++){
        if(itr->second > freq){
            freq = itr->second;
            ans = itr->first;
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin >> n;
	vi a(n);
	f(i, 0, n - 1) {
		cin >> a[i];
	}
	ll cur = 0, ans;
	f(i, 2, 1000) {
		ll cnt = 0;
		f(j, 0, n - 1) {
			if (a[j] % i == 0) {
				cnt++;
			}
		}
		if (cnt > cur) {
			cur = cnt;
			ans = i;
		}
	}
	cout << ans << "\n";
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>

using namespace std;

int sol(string s, string t){
    int res = 0;
    int q = 0;
    for (int i = 0; i < s.size(); ++ i){
        if (s[i] == '0'){
            if (t[i] == '0'){
                if (q != 0){
                    res += 1;
                }
            }
            else{
                q += 1;
            }
        }
        else{
            if (t[i] == '0'){
                q -= 1;
                res += 1;
            }
        }
    }
    return res + q;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
    int n; cin >> n;
    string s, t; cin >> s >> t;
    vector <int> cntt(2), cnts(2);
    for (char c : s) cnts[c - '0'] += 1;
    for (char c : t) cntt[c - '0'] += 1;
    int ans = sol(s, t);
    /*for (char &c : s) c = char(((c - '0') ^ 1) + '0');
    for (char &c : t) c = char(((c - '0') ^ 1) + '0');
    ans = min(ans, sol(s, t));*/
    if (cntt[0] != cnts[0] || cntt[1] != cnts[1]) return cout << -1, 0;
    cout << ans;
}

//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <array>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>
#include<fstream>
#include<assert.h>

#include<stdio.h>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

int get_gcd(int n, int m) {
	if (n < m) swap(n, m);
	while (m) {
		swap(n, m);
		m %= n;
	}
	return n;
}

int get_lcm(int n, int m) {
	return n / get_gcd(n, m)*m;
}

struct BIT //0-indexed
{
	vector<int> node;
	int mn;

	BIT(int mn)
	{
		this->mn = mn;
		node.resize(mn + 1, 0);
	}

	void add(int i, int x)
	{
		i++;
		while (i <= mn)
		{
			node[i] += x;
			i += (i&-i);
		}
	}

	int sum(int i)
	{
		i++;
		int res = 0;
		while (i > 0)
		{
			res += node[i];
			i -= (i&-i);
		}
		return res;
	}

	//k:0-indexed
	int get(long long k) {
		++k;
		int res = 0;
		int N = 1; while (N < (int)node.size()) N *= 2;

		for (int i = N / 2; i > 0; i /= 2) {
			if (res + i < (int)node.size() && node[res + i] < k) {
				k = k - node[res + i];
				res = res + i;
			}
		}
		return res;
	}
};

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

	int H, W, M;
	cin >> H >> W >> M;

	int ans = H * W;
	vector<int> R(H, W), C(W, H);
	int X, Y;
	vector<pii> P(M);
	rep(i, 0, M)
	{
		cin >> Y >> X;
		Y--, X--;
		chmin(R[Y], X);
		chmin(C[X], Y);
		P[i] = mp(X, Y);
	}

	sort(all(P));
	vector<bool> USED(H, false);
	int pi = 0;

	BIT bit(H + 3);

	int mi = INF;
	rep(i, 0, W)
	{
		while (pi < M&&P[pi].first <= i)
		{
			if (!USED[P[pi].second])
			{
				USED[P[pi].second] = true;
				bit.add(P[pi].second, 1);
			}
			pi++;
		}
		chmin(mi, C[i]);

		int ma = max(C[0], mi == 0 ? 0 : C[i]);
		int res = H - ma;
		res += bit.sum(ma - 1);
		if (mi != 0 && C[i] > 0)res -= bit.sum(C[i] - 1);
		ans -= res;
	}

	/*int mi = W;
	rep(i, 0, H)
	{
		chmin(mi, R[i]);
		if (mi == 0)break;
		ans += R[i];
	}
	mi = H;
	rep(i, 0, W)
	{
		chmin(mi, C[i]);
		if (mi == 0)break;
		ans += C[i];
	}

	mi = W;
	rep(i, 0, H)
	{
		chmin(mi, R[i]);
		ans -= mi;
	}*/

	cout << ans << endl;

	return 0;
}


/***

   * Author : SUARABH UPADHAYAY
   * Institution : IET LUCKNOW

***/

#include<bits/stdc++.h>
//#include <boost/math/common_factor.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define lll cpp_int
#define ull unsigned long long
#define ll long long
#define ui unsigned int
#define ldb long double
//#define lcm(o,g) boost::math::lcm(o,g)
#define mod 1000000007
#define mod1 1000003
#define mod2 998244353
#define pi acos(-1)
#define full INT_MAX
#define llfull LLONG_MAX
#define V vector
#define VL vector<ll>
#define L list
#define LL list<ll>
#define D deque
#define DL deque<ll>
#define PQL priority_queue<ll>
#define SL set<ll>
#define SC set<char>
#define USL unordered_set<ll>
#define M map
#define MLL map<ll,ll>
#define SS stringstream
#define mkp make_pair
#define mkt make_tuple
#define er equal_range
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define np next_permutation
#define ln length()
#define DO greater<ll>()
#define DM greater<ll>
#define pb push_back
#define in insert
#define pob pop_back()
#define bg begin()
#define ed end()
#define sz size()
#define all(o) ((o).bg,(o).ed)
#define F first
#define S second
#define stf shrink_to_fit()
#define ig cin.ignore(1,'\n');
#define cg(g) getline(cin,(g))
#define f(g,h,o) for(ll g=h;g<o;g++)
#define f1(g,h,o) for(ll g=h;g>o;g--)
#define f2(g) for(auto E : (g))
#define fm(g) for(auto [X,Y] : (g))
#define it(g) ::iterator E=(g).bg
#define AI(g,o) ll g[o]; f(i,0,o)cin>>g[i]
#define AO(g,o) f(i,0,o)cout<<g[i]<<" "
#define T ui t; cin>>t; while(t--)
#define T1(g) ui g; cin>>g; while(g--)

int main(){

/*	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);  */

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

    //cout<<fixed<<setprecision(10)

    ll  n;
    cin>>n;
    string s;
    cin>>s;

    if(n==1&&s=="1"){
        cout<<20000000000;
        return 0;
    }

    string k;
    ll p=0;

    while(p<200011){
        k.in(p,"110");
        p+=3;
    }

    ll ans=0;

    ll q;
    if(n%3==0)
    q=((n/3)+1)*3;
    else
    q=((n/3)+2)*3;

    f(i,0,q-n+1){
        if(k.substr(i,n)==s)
        ans++;
    }

    if(ans>0)
    cout<<ans+10000000000-(q/3);
    else
    cout<<0;

}

constexpr bool isDebugMode = false;
int testcase = 1;
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007; //998244353;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
const string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void enu(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void enu2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b, a % b) : b;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

void solve();

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

void solve(){
    char s, t; cin >> s >> t;
    if (s == 'Y' && t == 'a')
        pt("A");
    if (s == 'Y' && t == 'b')
        pt("B");
    if (s == 'Y' && t == 'c')
        pt("C");
    if(s == 'N') pt(t);

}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test lli t;cin>>t;while(t--)
#define vll vector<lli>
#define mll map<lli,lli>
#define vvll vector<vector<lli>>
#define vpll vector<pair<lli,lli>>
#define vvpll vector<vector<pair<lli,lli>>>
#define mpll map<pair<lli,lli>,lli>
#define pll pair<lli,lli>
#define sll stack<lli>
#define qll queqe<lli>
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define mod 1000000007
#define ma 1000000000000000000
#define mi -1000000000000000000
lli h, w, n, m, i, j, k, l, d = 0, x, y;
queue<pll>q;
lli b[1501][1501] = {0};
lli mp[1501][1501] = {0};
vpll v;
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio
  cin >> h >> w >> n >> m;
  while (n--)
  {
    cin >> i >> j;
    v.pb({i, j});
    b[i][j] = 1;
    d++;
    //cout << i << " " << j << endl;
  }
  while (m--)
  {
    cin >> i >> j;
    mp[i][j] = 1;
  }
  for (auto k : v)
  {
    i = k.ff;
    j = k.ss;
    x = i + 1; y = j;
    while (x <= h)
    {
      if (  b[x][y] == 0 && mp[x][y] == 0)
      {
        b[x][y] = 1;
        d++;
        //cout << x << " " << y << endl;
        x++;

      }
      else
        break;
    }
    x = i - 1; y = j;
    while (x > 0)
    {
      if (  b[x][y] == 0 && mp[x][y] == 0)
      {
        b[x][y] = 1;
        d++;
        //cout << x << " " << y << endl;
        x--;
        //cout << i + 1 << " a" << j << endl;
      }
      else
        break;
    }
  }
  for (auto k : v)
  {
    i = k.ff;
    j = k.ss;
    x = i; y = j + 1;
    while (y <= w)
    {
      if (  b[x][y] != 2 && mp[x][y] == 0)
      {
        if (b[x][y] == 0)
          d++;
        b[x][y] = 2;
        //cout << x << " " << y << endl;
        y++;
        //cout << i + 1 << " a" << j << endl;
      }
      else
        break;
    }
    x = i; y = j - 1;
    while (y > 0)
    {
      if (  b[x][y] != 2 && mp[x][y] == 0)
      {
        if (b[x][y] == 0)
          d++;
        b[x][y] = 2;

        // cout << x << " " << y << endl;
        y--;
        //cout << i + 1 << " a" << j << endl;
      }
      else
        break;
    }

  }
  cout << d;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, e) for (int i = 0; i < (e); ++i)
#define REP3(i, b, e) for (int i = (b); i < (e); ++i)
#define RREP(i, b, e) for (int i = (b)-1; i >= e; --i)

inline void print(void) {
  cout << '\n';
}

template <class T, class... U>
inline void print(const T &x, const U &...y) {
  cout << x;
  if (sizeof...(U) != 0) {
    cout << ' ';
  }
  print(y...);
}

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<int> t(n);
  REP(i, n) cin >> a[i] >> t[i];

  int q;
  cin >> q;
  vector<long long> x(q);
  REP(i, q) cin >> x[i];

  long long lo = -1000000000LL;
  long long hi = 1000000000LL;

  long long s = 0;
  REP(i, n) {
    if (t[i] == 1) {
      s += a[i];
      lo += a[i];
      hi += a[i];
    } else if (t[i] == 2) {
      lo = max(lo, a[i]);
      hi = max(hi, a[i]);
    } else if (t[i] == 3) {
      lo = min(lo, a[i]);
      hi = min(hi, a[i]);
    }
  }

  REP(i, q) {
    if (x[i] + s <= lo) {
      print(lo);
    } else if (x[i] + s >= hi) {
      print(hi);
    } else {
      print(x[i] + s);
    }
  }

  return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    long long ans = 0;
    for(long long ab = 2; ab <= 2 * n; ++ab) {
        long long cd = ab - k;
        if(cd < 2) continue;
        long long A = ab - 1 - (max(0LL, (ab - 1) - n)) * 2;
        long long C = cd - 1 - (max(0LL, (cd - 1) - n)) * 2;
        if(A <= 0 || C <= 0) continue;
        ans += A * C;
    }
    cout << ans << '\n';
    return 0;
}

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

typedef long long ll;

inline ll ways(ll c, ll &n)
{
	if (c < 2 || c > 2*n) return 0;
	if (c <= n+1) return c-1;
	return 2*n-c+1;
}

int main()
{
	ll n, k;
	scanf("%lld%lld", &n, &k);
	ll ans = 0;
	for (ll z = 2; z <= 2*n; ++z) {
		ans += ways(z, n)*ways(z+k, n);
	}
	printf("%lld\n", ans);
}


#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 998244353
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c;cin>>a>>b>>c;
  a = (a*(a+1)/2)%MOD;
  b = (b*(b+1)/2)%MOD;
  c = (c*(c+1)/2)%MOD;

  cout<<(((a*b)%MOD)*c)%MOD<<endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 46;
ll A[MAX_N];
vector<ll> B;

int main()
{
	ll N,T;
	cin >> N >> T;
	rep(i,N)
	{
		cin >> A[i];
	}

	for (int i = 0; i < (1 << (N/2)); ++i)
	{
		ll temp = 0;
		rep(j,N/2)
		{
			if (i & (1 << j)) temp += A[j];
		}
		B.push_back(temp);
	}

	sort(B.begin(), B.end());

	ll ans = 0;
	for (int i = 0; i < (1 << (N-N/2)); ++i)
	{
		ll temp = 0;
		rep(j,N-N/2)
		{
			if (i & (1 << j)) temp += A[j+N/2];
		}
		auto it = upper_bound(B.begin(), B.end(), T-temp);
		if (it != B.begin())
		{
			it--;
			temp += *it;
			ans = max(ans,temp);
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define PLL pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vll (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define pu push
#define sz(x) int(x.size())
#define vij v[i][j]
// ll p = 1e9+7;
// ll p = 998244353;
// n do -> n*pi/180
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

vi bt;
int m=1;
// i -> vi
void init(int i,int x){
  // place
  int now=i+m-1;
  // operate
  bt[now]^=x;

  while(now){
    int par=(now-1)/2;
    int chi=par*2+1;
    if(now==chi)chi++;

    bt[par]=bt[now]^bt[chi];
    now=par;
  }
}

int f(int s,int t,int now=0,int l=0,int r=m){
  // 完全に違う時
  if(r<=s or t<=l)return 0;
  // 完全に収まりきってる時
  if(s<=l and r<=t)return bt[now];

  int hf=(l+r)/2;
  int cl=f(s,t,now*2+1,l,hf);
  int cr=f(s,t,now*2+2,hf,r);
  return cl^cr;
}

int main(){
  cci(n,q);
  reciv(v,n);

  while(m<n)m*=2;
  // 初期化
  bt.rz(m*2-1,0);

  rep(i,0,n){
    // 代入と同時にテーブル造り
    // ２回更新されていくことになるが確実
    init(i,v[i]);
  }

  vi res;
  rep(i,0,q){
    cii(t);
    cci(x,y);
    x--;

   if(t==1)init(x,y);

    else {
      int ans=f(x,y,0,0,m);
      res.pb(ans);
    }
  }

  for(int ans:res)co(ans);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

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

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}

ll tree[300010];

ll query(ll idx)
{
    ll sum=0;

    while(idx>0)
    {
        sum^=tree[idx];

        idx-= idx & (-idx);

    }

    return sum;
}

void update(ll idx,ll x,ll n)
{
    while(idx<=n)
    {
        tree[idx]^=x;

        idx+= idx & (-idx);
    }
}

int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      cin>>n>>t;

      ll ara[n+2];

      for(i=1; i<=n; i++)
        {
            cin>>ara[i];

            update(i,ara[i],n);
        }

      ll test;

      while(t--)
      {

            cin>>test>>a>>b;

            if(test==1)
            {
                update(a,ara[a],n);

                ara[a]=(ara[a]^b);

                update(a,ara[a],n);
            }
            else
            {
                cout<<(query(b)^query(a-1))<<endl;
            }
      }

}


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

using namespace std;
typedef long long ll;

ll INF = 1LL << 60;

struct C{
  int x, y;
  C( int x = 0, int y = 0 ): x(x), y(y) {}
  C operator*( const C& a ) const {
	return C( x*a.x - y*a.y, x*a.y+y*a.x );
  }
  C operator-( const C&a ) const{
	return C( x-a.x , y-a.y );
  }
  bool operator<( const C& a ) const{
	if( x == a.x ) return y < a.y;
	return x < a.x;
  }
  bool operator==( const C& a ) const{
	return x == a.x && y == a.y;
  }
  int norm() const {
	return x*x+y*y;
  }

};

vector<C> MoveRot( vector<C> p, C move, C rot ){

  int N = p.size();
  for( int i = 0; i < N; i++ ){
	p[i] = p[i] - move;
  }
  for( int i = 0; i < N; i++ ){
	p[i] = p[i] * rot;
  }
  sort( p.begin(), p.end() );
  return p;

}

int main(){

  ll N;
  cin >> N;
  vector<C> a(N), b(N);
  for( int i = 0; i < N; i++ ){
	int x, y;
	cin >> x >> y;
	a[i] = C(x,y);
  }
  for( int i = 0; i < N; i++ ){
	int x, y;
	cin >> x >> y;
	b[i] = C(x,y);
  }

  if( N == 1 ){
	cout << "Yes" << endl;
	return 0;
  }

  for( int i = 0; i < N; i++ ){
	for( int j = 0; j < N; j++ ){

	  if( i == j ) continue;
	  if( (a[1]-a[0]).norm() != (b[j]-b[i]).norm() ) continue;

	  vector<C> ap = MoveRot( a, a[0], b[j]-b[i] );
	  vector<C> bp = MoveRot( b, b[i], a[1]-a[0] );
	  if( ap == bp ){
		cout << "Yes" << endl;
		return 0;
	  }

	}
  }

  cout << "No" << endl;

  return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int dot(int x1, int y1, int x2, int y2){
    return x1*x2+y1*y2;
}

int det(int x1, int y1, int x2, int y2){
    return x1*y2-x2*y1;
}

int main(){
    int N; cin >> N;
    if(N == 1) {cout << "Yes\n"; return 0;}

    vector<int> a(N), b(N), c(N), d(N);

    rep(i, N) cin >> a[i] >> b[i];
    rep(i, N) cin >> c[i] >> d[i];

    int x1 = a[1]-a[0], y1 = b[1]-b[0];
    int r = dot(x1, y1, x1, y1);

    vector<pii> p;
    rep2(i, 2, N-1){
        int x2 = a[i]-a[0], y2 = b[i]-b[0];
        p.eb(dot(x1, y1, x2, y2), det(x1, y1, x2, y2));
    }
    sort(all(p));

    rep(i, N) rep(j, N){
        if(i == j) continue;
        int X1 = c[j]-c[i], Y1 = d[j]-d[i];
        int R = dot(X1, Y1, X1, Y1);
        if(r != R) continue;
        //cout << i << ' ' << j << '\n';

        vector<pii> q;
        rep(k, N){
            if(k == i || k == j) continue;
            int X2 = c[k]-c[i], Y2 = d[k]-d[i];
            q.eb(dot(X1, Y1, X2, Y2), det(X1, Y1, X2, Y2));
        }

        sort(all(q));
        if(p == q) {cout << "Yes\n"; return 0;}
    }

    cout << "No\n";
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (b), _a = (a); i >= _a; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = (n) - 1; i >= 0; i--)
#define debug(x) cout<<"debug : "<<x<<endl
#define debug2(x,y) cout<<"debug : "<<x<<" | "<<y<<endl
#define debug3(x,y,z) cout<<"debug : "<<x<<" | "<<y<<" | "<<z<<endl
#define debug4(x,y,z,w) cout<<"debug : "<<x<<" | "<<y<<" | "<<z<<" | "<<w<<endl
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define M 1000000007          // 1e9+7
#define INF 1e9    // 1e9

typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<int> vint;
typedef vector<string> vs;
typedef vector<vi> vvi;

bool cus(pair<int,int> a, pair<int,int> b){
    if(a.ff<b.ff)
        return true;
    if(a.ff>b.ff)
        return false;
    return a.ss<b.ss;
}

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

bool edg[19][19];
bool valid[1 << 18];

void solve(){
    ll n, m;
    cin >> n >> m;

    ll a, b;
    rep(i, m){
        cin >> a >> b;
        --a, --b;
        edg[a][b] = true;
        edg[b][a] = true;
    }

    for(ll i = 1; i < (1 << n); ++i){
    	vi tmp;
    	rep(j, 18){
    		if(i & (1 << j)) tmp.pb(j);
    	}

    	bool flg = true;
    	rep(j, tmp.size()){
    		rep(k, j){
    			if(!edg[tmp[j]][tmp[k]]) flg = false;
    		}
    	}
    	valid[i] = flg;
    }

    //debug("here");

    ll dp[1 << n];
    rep(i, 1 << n) dp[i] = INF;
    dp[0] = 0;
    fr(i, 1, (1<<n)-1){
    	if(valid[i]) dp[i] = 1;
    	else {
    		for(ll j = i;j;j = (j-1)&i){
    			dp[i] = min(dp[i], dp[j]+dp[i^j]);
    		}
    	}
    }

    cout << dp[(1 << n)-1] << endl;
}

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(11);

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

    return 0;
}

#include <bits/stdc++.h>

#define INF 10000000000000000LL

constexpr long long MOD = 1000000007;

//Get-Content input | ./a.exe > output

using namespace std;

void redirect_io() {
    freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
}

void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

template <typename Head>
void print(Head&& h) {
    std::cout << h << std::endl;
}

template <typename Head, typename... Tail>
void print(Head&& h, Tail&&... t) {
    std::cout << h << " ";
    print(std::forward<Tail&&>(t)...);
}

int main() {
    // redirect_io();
    fast_io();
	int n, q, k, t, m, a, b;
    cin >> n >> m;
    vector<vector<int>> gr(n, vector<int>(n));
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        a--;b--;
        gr[a][b] = gr[b][a] = 1;
    }

    int mx = (1 << n);
    vector<int> f(mx, MOD);

    for(int i = 1; i < mx; i++) {
        vector<int> nodes;
        for(int j = 0; j < n; j++) {
            if((i >> j) & 1) {nodes.push_back(j);}
        }
        f[i] = 1;
        for(int j = 0; j < nodes.size(); j++) {
            for(int k = j + 1; k < nodes.size(); k++) {
                if(gr[nodes[j]][nodes[k]] == 0) {f[i] = MOD; break;}
            }
        }
    }
    f[0] = 0;

    for(int i  = 0; i < mx; i++) {
        for(int j = i; j > 0; j = (j - 1) & i) {
            f[i] = min(f[i],  f[j] +  f[i ^ j]);
        }
    }

    cout << f[mx - 1] << "\n";

    return 0;
}


// E - Count Descendants
#include <bits/stdc++.h>
using namespace std;

#define MAX 200000
vector<int> adj[MAX], T[MAX];
int L[MAX], R[MAX];
int depth, timer;

void dfs(int p){
	L[p] = timer++;
	T[depth].push_back(L[p]);
	depth++;
	for(int&c:adj[p]) dfs(c);
	depth--;
	R[p] = timer++;
}

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

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

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

	dfs(0);

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

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
ll st[MAX],en[MAX],lv[MAX],sz[MAX],idx=1;
vector<int>adj[MAX],v[MAX];
void dfs(int src,int par)
{
    st[src]=idx++;
    v[lv[src]].push_back(st[src]);
    int f=0;
    for(auto i:adj[src])
    {
        if(i==par)
            continue;
        lv[i]=lv[src]+1;
        dfs(i,src);
    }
    en[src]=idx++;
}

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=2; i<=n; i++)
    {
        int u=i,v;
        cin>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1,0);
    int q;
    cin>>q;
    while (q--)
    {
        int u,d;
        cin>>u>>d;
        int ans=lower_bound(all(v[d]),en[u])-lower_bound(all(v[d]),st[u]);
        cout<<ans<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define set_precision(ans,l) cout << fixed << setprecision(l)<<ans;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<ll>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<ll>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
long double EPS = 1e-9;

/*struct comp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};*/

ll cel(ll a,ll b){return((a-1)/b+1);}
ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}
ll MIN(ll a,int b){ll ans;(a>=b)?ans=b:ans=a;return ans;}
ll MAX(ll a,int b){ll ans;(a>=b)?ans=a:ans=b;return ans;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll po(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1){ans=(ans*x)%mod;}
        y>>=1;x=(x*x)%mod;
    }
    return ans;
}

int main()
{
    FIO;
    ll n,t,x,y,m,k;
    cin>>n>>k;
    ll ans=0,a,b;
    rep(i,2,2*n+1){
        x=k+i;
        if(x<2||(x>2*n)){continue;}
        a=n-abs(n+1-i);
        b=n-abs(n+1-x);
        //cout<<i<<" "<<x<<" "<<a<<" "<<b<<"\n";
        ans+=(a*b);
    }
    cout<<ans;
    return 0;
}

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

bool ok[4][2000][2000];//migi hidari ue shita
bool light[2200][2200];
bool block[2200][2200];
int main(){//cout<<fixed<<setprecision(20);
  ll h,w,n,m;
  cin>>h>>w>>n>>m;
  rep(i,0,n){
   int a,b;
    cin>>a>>b;
    a--;b--;
    light[a][b]=true;
  }
  rep(i,0,m){
   int c,d;
    cin>>c>>d;
    c--;d--;
    block[c][d]=true;
  }
  rep(i,0,h){
    bool check=false;
    rep(j,0,w){
      if(light[i][j])check=true;
      if(block[i][j])check=false;
      if(check)ok[0][i][j]=true;
    }
  }
  rep(i,0,h){
    bool check=false;
    for(int j=w-1;j>=0;j--){
      if(light[i][j])check=true;
      if(block[i][j])check=false;
      if(check)ok[1][i][j]=true;
    }
  }
  rep(j,0,w){
    bool check=false;
    rep(i,0,h){
      if(light[i][j])check=true;
      if(block[i][j])check=false;
      if(check)ok[2][i][j]=true;
    }
  }
  rep(j,0,w){
    bool check=false;
    for(int i=h-1;i>=0;i--){
      if(light[i][j])check=true;
      if(block[i][j])check=false;
      if(check)ok[3][i][j]=true;
    }
  }
  int ans=0;
  rep(i,0,h){
    rep(j,0,w){
    bool q=0;
    rep(k,0,4){
     if(ok[k][i][j]){
       q=true;
     }
    }
    if(q)ans++;
   }
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define rep(i, n) for (Int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(Int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(Int i=a;i<=Int(b);i++)
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);
//#include <atcoder/all>
//using namespace atcoder;
typedef long long Int;
const long long INF = 1ll << 60;
using namespace std;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  __MAGIC__
  int n;
  cin >> n;
  int day = 0;
  int total = 0;
  while (total < n) {
    day++;
    total += day;
  }
  cout << day << endl;
  return 0;

	//  cout << ans << endl;
  //  cout << (ans ? "Yes" : "No") << endl;

}

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
typedef long long ll;
const double pi = acos(-1.0);
#define memset(a,b) memset(a,b,sizeof(a))
const int mod = (1 ? 1000000007 : 998244353);
const int inf = (1 ? 0x3f3f3f3f : 0x7fffffff);
const int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
const ll INF = (1 ? 0x3f3f3f3f3f3f3f3f : 0x7fffffffffffffff);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll poww(ll a, ll b) { ll s = 1; while (b) { if (b & 1)s = (s * a) % mod; a = (a * a) % mod; b >>= 1; }return s % mod; }
struct quickread {
	template <typename _Tp> inline quickread& operator >> (_Tp& x) {
		x = 0; char ch = 1; int fh = 1;
		while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar();
		if (ch == '-') { fh = -1, ch = getchar(); }
		while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
		x *= fh; return *this;}
}cinn;

const int N = 1e5 + 11;
ll n,m;

void solve()
{
	ll a,b,c,d;
	cin>>a;
	if(a%2==0)cout<<"White"<<endl;
	else cout<<"Black"<<endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    ll T = 1;
    //cin >> T;
    while (T--)solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	int i,all = 1;
	cin >> n;
	while (all < n) all <<= 1;
	all -= 1;
	for (i = 0; i < n; ++i){
		int lc = all&(i<<1),rc = all&(i<<1|1);
		if (lc >= n) lc -= (all+1)>>1;
		if (rc >= n) rc -= (all+1)>>1;
		++lc,++rc;
		cout << lc << ' ' << rc << '\n';
	}
	return 0;
}

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

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

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

  while(t--){
    int n;
    string s1,s2,s3;
    cin>>n>>s1>>s2>>s3;

    rep(i,n) cout<<0;
    rep(i,n) cout<<1;
    cout<<0<<endl;
  }

  return 0;
}


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

int main(){
  int n,first = 0,second = 0,findex = 0,sindex;

  cin >> n;

  vector<string>s(n);
  vector<int>t(n);
  for(int i = 0;i < n;i++){
    cin >> s.at(i) >> t.at(i);

    if(first < t.at(i)){
      second = first;
      first = t.at(i);
      sindex = findex;
      findex = i;
    }else if(second < t.at(i)){
      second = t.at(i);
      sindex = i;
    }
  }

  cout << s.at(sindex) << endl;
}

/*                          AUTHOR
                            (_|_)
                             \_/
_______________________ÃMIT SÃRKER KISHÕR_______________________
----------------------------------------------------------------
_____DEPARTMENT OF CSE, CITY UNIVERSITY, DHAKA, BANGLADESH______
----------------------------------------------------------------
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ci std ::cin
#define co std ::cout
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld%lld",&n,&m)
#define pd(n) printf("%d",n)
#define pdd(n,m) printf("%d%d",n,m)
#define pl(n) printf("%lld",n)
#define pll(n,m) printf("%lld%lld",n,m)
#define p_line printf("\n")
#define line cout<<"\n"
#define cas(n) printf("Case %d: ",n++)
#define task return
#define loop(x,n)  for(int x = 0 ; x < n ; x++)
#define constloop(x,a,n) for(int x = a ; x < n ; x++)
#define revloop(x,a,n)  for(int x = a ; x >= n ; x--)
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define pb push_back
#define mkp make_pair
#define pi acos(-1)
const ll mx=100000;
const ll mod=1e9+7;
/*
ll P[mx+5],cnt=1;
bool nP[mx+5];
void sieve(void)
{
    P[0]=2;
    nP[0]=true;
    nP[1]=true;
    for(ll i=3 ; i<=mx ; i+=2)
    {
        if(nP[i]==true)
            continue;
        for(ll j=i+i ; j<=mx ; j+=i)
            nP[j]=true;
        P[cnt++]=i;
    }
}
*/
/*
ll bigMod(ll a, ll b)
{
    if(b<=0)
    {
        return 1;
    }
    ll value=bigMod(a,b/2);
    value=(value*value)%mod;
    if(b%2==1)
        value=(value*a)%mod;
    return value;
}
*/
/*
struct st
{
    int value;
    int pos;
};
*/
/*
bool cmp(st n,st m)
{
    return n.a>m.a;
}
*/
/*
bool cmp(int n,int m)
{
    return m>n;
}
*/
void solve()
{
    //Code here
    int t=1;
    // ci>>t;
    while(t--)
    {
        int n;
        cin>>n;
        priority_queue<pair<int,string>>pq;
        for(int i=0 ; i<n ; i++)
        {
        	string name;
        	int high;
        	cin>>name>>high;
        	pq.push({high,name});
        }
        pq.pop();
        auto it=pq.top();
        cout<<it.second;
        line;
    }
}
void I_O()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main()
{
    I_O();
    solve();
    //line;
    return 0;
}


#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    lli n;cin>>n;
    vlli sum2(2*n+1,0);
    flli(i,1,n)
    {
    	sum2[i+1]++;
    	if(i+n+1<=2*n)
    		sum2[i+n+1]--;
    }
    flli(i,1,2*n)
    	sum2[i]=sum2[i-1]+sum2[i];
    vlli sum3;
    sum3.pb(0);
    sum3.pb(0);
    sum3.pb(0);
    flli(i,3,n+2)
    {
    	lli temp=((i-2)*(i-1))/2;
    	sum3.pb(temp);
    }
    for(lli i=n-2;i>0;i-=2)
    {
    	lli temp=sum3.back();
    	temp=temp+i;
    	sum3.pb(temp);
    }
    //now just copy everything
    lli idx=sz(sum3)-1;
    if(n%2)idx--;
    while(idx>2)
    {
    	sum3.pb(sum3[idx]);
    	idx--;
    }
    lli szsum3=sz(sum3);
    flli(i,1,szsum3-1)sum3[i]+=sum3[i-1];
    lli k;cin>>k;
    auto findi=lower_bound(all(sum3),k);
    lli sumfind=findi-sum3.begin();
    //find first number
    k=k-sum3[sumfind-1];
    flli(beauty,1,n)
    {
    	if(beauty+2*n<sumfind)continue;
    	if(beauty+2>sumfind)continue;
    	if(sum2[sumfind-beauty]>=k)
    	{
    		//we found the beauty no
    		cout<<beauty<<" ";
    		//now we need to find taste and popularity
    		lli remsum=sumfind-beauty;
    		flli(taste,1,n)
    		{
    			lli newremsum=remsum-taste;
    			if(newremsum>=1 && newremsum<=n && k==1)
    			{
    				cout<<taste<<" "<<newremsum;
    				return 0;
    			}
    			else if(newremsum>=1 && newremsum<=n)
    			{
    				k--;
    			}
    		}
    		assert(false);
    	}
    	else
    	{
    		k-=sum2[sumfind-beauty];
    	}
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;

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

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

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

//グラフ関連
struct Edge {
    int to, rev;
    ll cap;
    Edge(int _to, ll _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (int)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (int)G[from].size() - 1));
}

void solve() {
    ll n, k;
    cin >> n >> k;

    ll num = 0;
    ll pre = 0;
    k--;
    rep(s, 3, n * 3 + 1) {
        //合計
        ll tmp = pre;
        if(s <= 2 * n + 1) {
            ll r = min(s - 1 - 1, n);
            ll l = max(1LL, s - 1 - n);
            tmp += r - l + 1;
        }
        if(s >= n + 2) {
            ll r = min(s - (n + 1) - 1, n);
            ll l = max(1LL, s - (n + 1) - n);
            tmp -= r - l + 1;
        }
        pre = tmp;

        //cout << s << " " << num << en;
        if(num + tmp <= k) {
            num += tmp;
            continue;
        }
        rep(i, 1, n + 1) {
            ll r = min(s - i - 1, n);
            ll l = max(1LL, s - i - n);
            ll nxt = max(0LL,r - l + 1);
            if(num + nxt <= k) {
                //cout<<num<<" "<<nxt<<" "<<k<<en;
                num += nxt;
                continue;
            }
            ll j = k - num + l;
            cout << i << " " << j << " " << s - i - j << en;
            return;
        }
    }
}

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

    // ll t;
    // cin >> t;
    // REP(i, t - 1) {
    //     solve();
    // }

    solve();

    return 0;
}


#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
vector<pair<int,int>> g[205];
int dis[205];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
int main(){
	int i,n,a,b,x,y;
	scanf("%d%d%d%d",&a,&b,&x,&y);
	for(i=1;i<=100;i++){
		g[i].emplace_back(i+100,x);
		g[i+100].emplace_back(i,x);
	}
	for(i=2;i<=100;i++){
		g[i].emplace_back(i-1+100,x);
		g[i+99].emplace_back(i,x);
	}
	for(i=1;i<=99;i++){
		g[i].emplace_back(i+1,y);
		g[i+1].emplace_back(i,y);
	}
	for(i=101;i<=199;i++){
		g[i].emplace_back(i+1,y);
		g[i+1].emplace_back(i,y);
	}
	pq.push({0,a});
	for(i=1;i<=200;i++)
		dis[i]=1000000000;
	dis[a]=0;
	while(pq.size()){
		auto v=pq.top();
		pq.pop();
		for(auto x:g[v.second]){
			if(dis[x.first]>dis[v.second]+x.second){
				dis[x.first]=dis[v.second]+x.second;
				pq.push({dis[x.first],x.first});
			}
		}
	}
	printf("%d\n",dis[100+b]);
}

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int sum=0,nega=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')nega=-1;ch=getchar();}
	while(ch<='9'&&ch>='0')sum=sum*10+ch-'0',ch=getchar();
	return sum*nega;
}
int a,b,x,y,sum;
int main()
{
	a=read(),b=read(),x=read(),y=read();
	sum=abs(b-a);
	if(a>b)cout<<min((sum*2-1)*x,x+(sum-1)*y)<<endl;
	else cout<<min((sum*2+1)*x,sum*y+x)<<endl;
	//cout<<min((sum*2-1)*x,x+)<<endl;
	return 0;
}


//C++ 17
#include "bits/stdc++.h"

#define ull unsigned long long
#define ll signed long long
#define ld long double
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define vt vector
#define vi vector<int>
#define vvi vt<vi>
#define vl vector<ll>
#define vs vector<string>
#define pii pair<int,int>
#define pll pair<ll ,ll>
#define pb push_back
#define sz(x) int((x).size())
#define inf INT_MAX
#define linf LLONG_MAX
#define M(a,b) (((a-1)%b)+1)
#define ys(a) {cout<<((a)?"YES":"NO");return ;}
#define yes(a) {cout<<((a)?"YES":"NO")<<endl;}
#define cdiv(a,b) ((a+b-1)/b)
#define cfind(sr,el) (sr.find(el)!=sr.end())
#define ar array

#define EACH(iterable) for(auto & itr : iterable)
#define FOR_MAIN(i,s,e,u) for(int i = s ; i < e;i+=u)
#define FOR_1(n) FOR_MAIN(i,0,n,1)
#define FOR_2(i,n) FOR_MAIN(i,0,n,1)
#define FOR_3(i,s,e) FOR_MAIN(i,s,e,1)
#define FOR_4(i,s,e,u) FOR_MAIN(i,s,e,u)
#define GET_LOOP(a,b,c,d,e,...) e
#define FOR(...) GET_LOOP(__VA_ARGS__,FOR_4,FOR_3,FOR_2,FOR_1)(__VA_ARGS__)
#define GI_1(x) >>x
#define GI_2(a,b)     GI_1(a)GI_1(b)
#define GI_3(a,b,c)   GI_2(a,b)GI_1(c)
#define GI_4(a,b,c,d) GI_3(a,b,c)GI_1(d)
#define GI(...) int __VA_ARGS__ ;cin GET_LOOP(__VA_ARGS__,GI_4,GI_3,GI_2,GI_1)(__VA_ARGS__)
#define GLL(...) ll __VA_ARGS__ ;cin GET_LOOP(__VA_ARGS__,GI_4,GI_3,GI_2,GI_1)(__VA_ARGS__)
using namespace std;

#ifdef LOCAL
    #define DBG_1(x) <<" | "<<#x<<":"<<setw(4)<<x
    #define DBG_2(a,b)         DBG_1(a)DBG_1(b)
    #define DBG_3(a,b,c)       DBG_2(a,b)DBG_1(c)
    #define DBG_4(a,b,c,d)     DBG_3(a,b,c)DBG_1(d)
    #define DBG_5(a,b,c,d,e)   DBG_4(a,b,c,d)DBG_1(e)
    #define DBG_6(a,b,c,d,e,f) DBG_5(a,b,c,d,e)DBG_1(f)
    #define GET_DBG(a,b,c,d,e,f,g,...) g
    #define dbg(...) cerr<<"\033[00;33m"<<__LINE__<<"\033[01;34m" GET_DBG(__VA_ARGS__,DBG_6,DBG_5,DBG_4,DBG_3,DBG_2,DBG_1)(__VA_ARGS__)<<"\033[00m"<<endl
    template<class T> void dbgarr(T arr[] , int n){ cerr<<arr[0]; FOR(i,1,n)cerr<<" "<<arr[i]; }
#else
    #define dbg(...)
    #define dbgarr(...)
#endif

const int mod = 1'000'000'007;//998'244'353;
const int UL5  = 1'00'001,UL6  = 1'000'001,UL25 = 2'00'001,UL8  = 1'00'000'001;
template<class T1,class T2> inline bool umax(T1 &a,const T2 &b){return (a < b)?a = b,1:0;}
template<class T1,class T2> inline bool emax(T1 &a,const T2 &b){return (a < b)?a = b,1:a==b;}
template<class T1,class T2> inline bool umin(T1 &a,const T2 &b){return (a > b)?a = b,1:0;}
template<class T1,class T2> inline bool emin(T1 &a,const T2 &b){return (a > b)?a = b,1:a==b;}

template<class T> void input(T arr[] , int n){ FOR(n) cin>>arr[i]; }
template<class T> void print(T arr[] , int n){ cout<<arr[0]; FOR(i,1,n)cout<<" "<<arr[i]; }

template<class T1,class  T2> istream& operator >> (istream& in ,pair<T1,T2>& p){ in>>p.first>>p.second; return in; }
template<class T> istream& operator >> (istream& in ,vector<T>& arr){ EACH(arr) in>>itr; return in; }
template<class T1, class T2> ostream& operator << (ostream& out ,pair<T1,T2>& p){ out<<p.first<<" "<<p.second; return out; }
template<class T> ostream& operator << (ostream& out ,deque<T>& arr){ EACH(arr) out<<itr<<" "; return out; }
template<class T> ostream& operator << (ostream& out ,vector<T>& arr){ EACH(arr) out<<itr<<" "; return out; }

int arr[UL25]; int n;
ll k,ans;

void solve(){
    string str;
    cin>>str;
    reverse(all(str));
    EACH(str){
        if(itr=='6' || itr=='9')
            itr^='6'^'9';
        cout<<itr;
    }

}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    if (0) cin>>tc;
    for(int i = 1;i<=tc ;i++){
        #ifdef LOCAL
            cerr<<"\033[01;31mCase #"<<i<<": \n\033[00m";
        #endif
        //cout<<"Case #"<<i<<": ";
        solve();
        cout<<endl;
    }
}
/*
Integer overflow,BS,dp,TP
*/

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long
#define tc(t) int t; cin >> t;while(t--)
#define lp(i, x, y) for(ll i = x; i <= y; i++)
#define lpr(i, x, y) for(ll i = x; i >= y; i--)
#define in1(x) ll x; cin >> x
#define in2(x, y) ll x, y; cin >> x >> y
#define in3(x, y, z) ll x, y, z; cin >> x >> y >> z
#define mem(x, y) memset(x, (y), sizeof(x))
#define ite(it, l) for (auto it = l.begin(); it != l.end(); it++)

const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

int main()
{
    // cin.tie(0); cout.tie(0); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    string a;
    cin >> a;
    int n = a.size();
    lpr(i, n-1, 0)
    {
        if(a[i] == '6')
            cout << "9";
        else if(a[i] == '9')
            cout << "6";
        else
            cout << a[i];
    }
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N+2), B(M+2);
    REP(i, N) cin >> A[i+1];
    REP(i, M) cin >> B[i+1];

    vector<vector<int>> dp(N+2, vector<int>(M+2, 1<<30));
    dp[0][0] = 0;
    for(int i=0; i<=N; i++){
        for(int j=0; j<=M; j++){
            dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1);
            dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1);
            int tmp = (A[i+1] == B[j+1]) ? 0 : 1;
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + tmp);
        }
    }
    cout << dp[N][M] << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define deb(k) cerr << #k << ": " << k << "\n";
#define size(a) (int)a.size()
#define fastcin cin.tie(0)->sync_with_stdio(0);
#define st first
#define nd second
#define pb push_back
#define mk make_pair
#define int long long
typedef long double ldbl;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vector<int> vint;
#define MAXN 300100
#define MAXLG 20
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int f(char c){
	if('A' <= c && c <= 'F') return 10 + c - 'A';
	return c - '0';
}

int dp[200100][18];
bool w[16];

void solve(){
	string s;
	int k;
	cin>>s>>k;
	int n = size(s);
	int cnt = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<=16;j++){
			dp[i+1][j] += j * dp[i][j];
			dp[i+1][j] %= mod;

			dp[i+1][j+1] += (16 - j)*dp[i][j];
			dp[i+1][j+1] %= mod;
		}
		if(i){
			dp[i+1][1] += 15;
			dp[i+1][1] %= mod;
		}

		for(int j=0;j<f(s[i]);j++){
			if( i == 0 && j == 0 ) continue;

			if(w[j]){
				dp[i+1][cnt] += 1;
				dp[i+1][cnt] %= mod;
			}
			else{
				dp[i+1][cnt+1] += 1;
				dp[i+1][cnt+1] %= mod;
			}
		}

		if(!w[f(s[i])]){
			w[f(s[i])] = 1;
			cnt++;
		}
	}

	if(cnt == k){
		dp[n][k] += 1;
		dp[n][k] %= mod;
	}
	cout<<dp[n][k]<<"\n";

	// Have you read the problem again?
	// Maybe you understood the wrong problem
}

int32_t main(){
	fastcin;
	int t_ = 1;
	//cin>>t_;
	while(t_--)
		solve();
	return 0;
}


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

#define fo(i, x, y) for (int i = (x); i <= (y); ++i)
#define fd(i, x, y) for (int i = (x); i >= (y); --i)

const int maxn = 2e5 + 5;

struct edge{int to, w; edge *nxt;}*arc1[maxn], *arc2[maxn], pool[maxn << 2], *pt = pool;
int n, m;
int ans[maxn];
bool vis[maxn];

int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}

void addedge(edge *arc[], int u, int v, int w)
{
	*pt = (edge){v, w, arc[u]};
	arc[u] = pt++;
}

void gettr(int x)
{
	vis[x] = true;
	for (edge *e = arc1[x]; e; e = e->nxt)
		if (!vis[e->to])
		{
			addedge(arc2, x, e->to, e->w);
			gettr(e->to);
		}
}

void dfs(int x)
{
	for (edge *e = arc2[x]; e; e = e->nxt)
	{
		if (e->w != ans[x])
			ans[e->to] = e->w;
		else
			ans[e->to] = e->w - 1? e->w - 1 : e->w + 1;
		dfs(e->to);
	}
}

int main()
{
	n = getint(); m = getint();
	fo(i, 1, m)
	{
		int u, v, w;
		u = getint(); v = getint(); w = getint();
		addedge(arc1, u, v, w);
		addedge(arc1, v, u, w);
	}
	gettr(1);
	ans[1] = 1;
	dfs(1);
	fo(i, 1, n) printf("%d\n", ans[i]);
	return 0;
}

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

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long
#define mod 1000000007

using namespace std;

ll int kfj=0;
long long int sech(vector<ll int>& A,vector<vector<ll int> >& root,vector<bool>& bo,ll int n, ll int min, ll int sa){
	ll int ans;
	ll int kari;
        ans=A[n]-min;
	if(ans<sa){
	      ans=sa;
	}
	if(min>A[n]){
		min=A[n];
	}
	for(ll int i:root[n]){
		kari=sech(A,root,bo,i-1,min,ans);
		bo[i-1]=true;
		ans=std::max(kari,ans);

	}
	return ans;
}

int main(){

 ll int N,M;
 cin >> N >> M;
 vector<vector<ll int> > root(N);
 vector<ll int> A(N);
 rep(i,N){
	 cin >> A[i];
 }
 ll int X,Y;
 rep(i,M){
	 cin >> X >> Y;
	 root[X-1].push_back(Y);
 }
vector <ll int> dp(N,100000000000000);
for(ll int i=0;i<N;i++){
	for(ll int j:root[i]){
		dp[j-1]=min({A[i],dp[i],dp[j-1]});
	}
}

ll int ans=-1000000000000000;
rep(i,N){
	ans=max(ans,A[i]-dp[i]);
//	cout << dp[i] << " " ;
}

 cout << ans;

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,m;
  	int vdnmkhcmkxmh;
    cin>>n>>m;
    vector<pair<int,int>>a(m);
    for(int i=0;i<m;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    int k;
    cin>>k;
    vector<pair<int,int>>b(k);
    for(int j=0;j<k;j++)
    {
        cin>>b[j].first>>b[j].second;
    }
    ll l=0;
    ll tot=1<<k;
    for(ll mask=0;mask<tot;mask++)
    {
        vector<int>v(n+1);
        ll ans=0;
        for(int i=0;i<k;i++)
        {
            if(mask & (1<<i))
                v[b[i].second]=1;
            else
                v[b[i].first]=1;
        }
        for(int i=0;i<m;i++)
        {
            if(v[a[i].first] && v[a[i].second])
                ans++;
        }
        l=max(l,ans);
    }
    cout<<l<<endl;
    return 0;
}

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
    string sep = " ";
    if(v.size()) os << v[0];
    for(int i=1; i<v.size(); i++) os << sep << v[i];
    return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
    for(int i=0; i<v.size(); i++) is >> v[i];
    return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
    cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int n;
    cin >> n;
    vector<ll> a(n);
    vector<int> t(n);
    for(int i=0; i<n; i++) cin >> a[i] >> t[i];

    int q;
    cin >> q;
    vector<ll> x(q);
    cin >> x;

    ll xl = -1e18, xr = 1e18;
    ll yl = -1e18, yr = 1e18;
    ll b = 0;

    for(int i=0; i<n; i++){
        if(t[i]==1){
            yl += a[i];
            yr += a[i];
            b += a[i];
        } else if(t[i]==2){
            if(yr<=a[i]){
                xl = xr = 1e18;
                yl = yr = b = a[i];
            } else if(yl<=a[i]){
                yl = a[i];
                xl = a[i]-b;
            }
        } else if(t[i]==3){
            if(a[i]<=yl){
                xl = xr = -1e18;
                yl = yr = b = a[i];
            } else if(a[i]<=yr){
                yr = a[i];
                xr = a[i]-b;
            }
        }
    }

    for(int i=0; i<q; i++){
        if(x[i]<=xl){
            cout << yl << endl;
        } else if(x[i]<=xr){
            cout << x[i]+b << endl;
        } else {
            cout << yr << endl;
        }
    }

    return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}

int MOD;
struct ModInt {
    long long v;
    ModInt(long long _v = 0) {v = (-MOD < _v && _v < MOD) ? _v : _v % MOD; if (v < 0) v += MOD;}
    ModInt& operator += (const ModInt &other) {v += other.v; if (v >= MOD) v -= MOD; return *this;}
    ModInt& operator -= (const ModInt &other) {v -= other.v; if (v < 0) v += MOD; return *this;}
    ModInt& operator *= (const ModInt &other) {v = v * other.v % MOD; return *this;}
    ModInt& operator /= (const ModInt &other) {return *this *= inverse(other);}
    bool operator == (const ModInt &other) const {return v == other.v;}
    bool operator != (const ModInt &other) const {return v != other.v;}
    friend ModInt operator + (ModInt a, const ModInt &b) {return a += b;}
    friend ModInt operator - (ModInt a, const ModInt &b) {return a -= b;}
    friend ModInt operator * (ModInt a, const ModInt &b) {return a *= b;}
    friend ModInt operator / (ModInt a, const ModInt &b) {return a /= b;}
    friend ModInt operator - (const ModInt &a) {return 0 - a;}
    friend ModInt power(ModInt a, long long b) {ModInt ret(1); while (b > 0) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
    friend ModInt inverse(ModInt a) {return power(a, MOD - 2);}
    friend istream& operator >> (istream &is, ModInt &m) {is >> m.v; m.v = (-MOD < m.v && m.v < MOD) ? m.v : m.v % MOD; if (m.v < 0) m.v += MOD; return is;}
    friend ostream& operator << (ostream &os, const ModInt &m) {return os << m.v;}
};

ModInt dp[105][1000005];

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

    int n, k;
    cin >> n >> k >> MOD;

    dp[0][0] = 1;
    int sum = n * (n + 1) / 2 * k;
    for (int i=1; i<=n; i++)
        for (int s=0; s<i; s++) {
            ModInt cur = 0;
            for (int j=s; j<=sum; j+=i) {
                cur += dp[i-1][j];
                if (j - i * (k + 1) >= 0)
                    cur -= dp[i-1][j-i*(k+1)];
                dp[i][j] = cur;
            }
        }

    for (int x=1; x<=n; x++) {
        ModInt ret = 0;
        for (int j=0; j<=sum; j++)
            ret += dp[x-1][j] * dp[n-x][j] * (k + 1);
        cout << ret - 1 << "\n";
    }

    return 0;
}

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

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

const int MAX = 44;

int N, T;
int A[MAX];

int solve() {
    int N1 = N/2, N2 = N-N1;
    vi t1, t2;
    REP (s, 1<<N1) {
        ll time = 0;
        REP (i, N1) if ((s >> i) & 1) time += A[i];
        if (time <= T) t1.push_back(time);
    }

    REP (s, 1<<N2) {
        ll time = 0;
        REP (i, N2) if ((s >> i) & 1) time += A[i+N1];
        if (time <= T) t2.push_back(time);
    }

    UNIQ(t1);
    UNIQ(t2);

    ll ret = 0;

    int j = t2.size()-1;
    FORE(t, t1) {
        while (j > 0 && t + t2[j] > T) j--;
        CHMAX(ret, t + t2[j]);
    }

    return ret;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N >> T;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}


/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

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

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

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 61;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll conbinationMemo[61][31];

void cmemoInit(){
    rep(i, 61){
        rep(j, 31){
            conbinationMemo[i][j] = -1;
        }
    }
}

ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll n;
vector<ll> t;
ll dp[110][100100];
int main(void){
    cin >> n;
    t.resize(n);
    rep(i, n) cin >> t[i];

    rep(i, 110){
        rep(j, 100100){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    rep(i, n){
        rep(j, 100100){
            if(j + t[i] < 100100) dp[i + 1][j + t[i]] = min(dp[i + 1][j + t[i]], dp[i][j]);
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + t[i]);
        }
    }

    ll ans = INF;
    rep(i, 100100){
        ans = min(ans, max((ll)i, dp[n][i]));
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    string st;
    cin>>st;
    REP(i,st.size()){
        if(st[i]=='.'){
            break;
        }
        cout<<st[i];
    }
    cout<<endl;
    return 0;
}