//@sakshjha
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld   long double
#define JALDI ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define pi 3.14159265358979

const int mod = 1e9 +7;
const int N = 1e6 +5 ;
int a[1005],b[1005];
int dp[1005][1005];
int solve(int x, int y)
{
    if(x<0)
        return y+1;
    if(y<0)
        return x+1;
    if(dp[x][y]==-1)
    {
        dp[x][y]=min(solve(x-1,y),solve(x,y-1))+1;
        int tmp=0;
        if(a[x]!=b[y])
            tmp=1;
        dp[x][y]=min(dp[x][y],solve(x-1,y-1)+tmp);
    }
    return dp[x][y];

}
int32_t main()
{
    JALDI
    int i,j,tc=1;
    //cin>>tc;
    while(tc--)
    {
        int n,m; cin>>n>>m;
        for(i=0; i<n; i++)
            cin>>a[i];
        for(i=0; i<m; i++)
            cin>>b[i];
        memset(dp,-1,sizeof(dp));
        cout<<solve(n-1,m-1);
    }
    return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

char myHeap[200 * 1024 * 1024];
int sz = 0;
void assert_tle(bool q) { while (!q); }
void* operator new  ( std::size_t count ) {
    sz += count;
    assert_tle(sz <= 200 * 1024 * 1024);
    return myHeap + sz - count;
}

void operator delete (void *ptr) { }

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

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

    int ar[n],br[m];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }

    for(int i=0;i<m;i++)
    {
        cin>>br[i];
    }

    int memo[n+1][m+1]={0};

    for(int i=1;i<=n;i++)
    {
        memo[i][0]=i;
    }
    for(int j=1;j<=m;j++)
    {
        memo[0][j]=j;
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int mn=1+min(memo[i-1][j],memo[i][j-1]);
            memo[i][j]=mn;
            if(ar[i-1]==br[j-1])
            {
                memo[i][j]=min(memo[i][j],memo[i-1][j-1]);
            }
            else
            {
                memo[i][j]=min(memo[i][j],1+memo[i-1][j-1]);
            }

        }
    }

    cout<<memo[n][m];
}

int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}


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

#define fi first
#define se second
#define rng(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define per(i, b) gnr(i, 0, b)
#define all(obj) begin(obj), end(obj)
#define allr(obj) rbegin(obj), rend(obj)
#define cinv(a) rep(i, (int)a.size()) cin >> a[i]
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<Pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;

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

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const int MOD =	1e9 + 7;
const int INF = 1e9 + 9;
const ll LINF = 1e18;
const long double eps = 1e-10;
const char nl = '\n';

ll power(ll a, ll b) { return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; }

ll nCk(int n, int k)
{
	ll x = 1, y = 1;
	for (int i = 1; i <= k; ++i)
	{
		x = x * (n - i + 1) % MOD;
		y = y * i % MOD;
	}
	return x * power(y, MOD - 2) % MOD;
}

struct UF
{
	vi d;
	UF(int n) : d(n, -1) {}
	int root(int x)
	{
		if (d[x] < 0)
			return x;
		return d[x] = root(d[x]);
	}
	bool unite(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (d[x] > d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -d[root(x)]; }
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(20);
	int n, m; cin >> n >> m;
	map<int, vi> mp;
	rep(i, m)
	{
		int x, y; cin >> x >> y;
		mp[x].pb(y);
	}
	set<int> s{n};
	for (auto p : mp)
	{
		vi add;
		for (auto y : p.se)
			if (s.count(y-1) || s.count(y+1))
				add.pb(y);
		for (auto y : p.se) s.erase(y);
		for (auto y : add) s.insert(y);
	}
	cout << sz(s) << nl;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef	long long ll;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;

int main() {
	fio;
	int n, m;
	cin >> n >> m;
	map<int, vi> a;
	for (int i = 0;i < m;i++) {
		int x, y;
		cin >> x >> y;
		a[x].pb(y);
	}
	set<int> s;
	s.insert(n);
	for (auto &p : a) {
		vi &b = p.se;
		vi rem, add;
		for (auto &x : b)
			if (s.count(x))
				rem.pb(x);
		for (auto &x : b)
			if (s.count(x - 1) || s.count(x + 1))
				add.pb(x);
		for (auto &x : rem)
			s.erase(x);
		for (auto &x : add)
			s.insert(x);
	}
	cout << s.size() << '\n';
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
    int res = a % MOD;
    if(res < 0) {
        return res + MOD;
    }
    return res;
}
int mul_mod(int a, int b)
{
    ll res = ((ll)a * (ll)b) % MOD;
    return mod((int)res);
}
int pow_mod(int a, int b)
{
    ll res = 1;
    while (b > 0) {
        if(b & 1) {
            res = res * (ll)a % (ll)MOD;
        }
        a = mul_mod(a, a);
        b >>= 1;
    }
    return (int)res;
}
int inv_mod(int a)
{
    return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
    return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 3000001;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < FAC_MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll com_mod(int a, int b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t; cin >> t;
    ll inv2 = inv_mod(2);
    rep (_, t) {
        ll n, a, b, p;
        cin >> n >> a >> b;
        if (a + b > n) {
            cout << "0\n";
            continue;
        }
        p = n - a - b + 2;
        ll x = mul_mod(inv2, mul_mod(p, p - 1)), y = mul_mod(n - a + 1, n - b + 1);
        eprintf("%lld %lld %lld\n", p, x, y);
        cout << mod(mul_mod(4, mul_mod(x, y) - mul_mod(x, x))) << "\n";
    }
    /***************************************************/
    /* Use "submit code (with ACL v1)" when using ACL! */
    /***************************************************/
    return 0;
}

#include<iostream>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define int long long
using namespace std;
int c[502][502],a[502],b[502];
signed main(){
    ios::sync_with_stdio(false);
    int n; cin>>n;
    rep(i,1,n)rep(j,1,n)cin>>c[i][j];
    bool flag=true;
    rep(i,1,n){rep(j,2,n){
        if(i==1)a[j]=c[i][j]-c[i][j-1];
        else if(a[j]!=c[i][j]-c[i][j-1]){flag=false;break;}
    }if(!flag)break;}
    if(!flag){cout<<"No\n";return 0;}
    rep(j,1,n){rep(i,2,n){
        if(j==1)b[i]=c[i][j]-c[i-1][j];
        else if(b[i]!=c[i][j]-c[i-1][j]){flag=false;break;}
    }if(!flag)break;}
    if(!flag){cout<<"No\n";return 0;}
    int mna=0,mnb=0;
    rep(i,1,n){
        a[i]+=a[i-1],b[i]+=b[i-1];
        mna=min(mna,a[i]),mnb=min(mnb,b[i]);
    }
    //cout<<mna<<" "<<mnb<<endl;
    if(c[1][1]+mna+mnb<0){cout<<"No\n";return 0;}
    int ada=-mna,adb=c[1][1]-ada;
    cout<<"Yes\n";
    rep(i,1,n)cout<<b[i]+adb<<" ";
    cout<<endl;
    rep(i,1,n)cout<<a[i]+ada<<" ";
    cout<<endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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 S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll X[200010], C[200010];
std::vector<ll> vs[200010];
std::map<ll, ll> dp[2];

void chminMp( std::map<ll, ll> &mp, ll idx, ll x ) {
  if( !mp.count(idx) )
    mp[idx] = x;
  else
    mp[idx] = std::min( mp[idx], x );

  return;
}

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

  rep( i, N ) {
    std::cin >> X[i] >> C[i];
    --C[i];

    vs[C[i]].emplace_back(X[i]);
  }

  rep( i, N )
    std::sort(all(vs[i]));

  ll x = 0;

  dp[0][0] = 0;

  ll p = 0;

  auto prv = dp[0], nxt = dp[1];

  rep( i, N ) {
    if( vs[i].empty() )
      continue;

    nxt.clear();

    itr( it, prv ) {
      ll x = it->first;

      ll idx = std::lower_bound(all(vs[i]), x)-vs[i].begin();

      if( idx && vs[i].size()-idx ) {
        ll d1 = llabs(vs[i][0]-x);
        ll d2 = llabs(vs[i][vs[i].size()-1]-x);

        chminMp(nxt, vs[i][vs[i].size()-1], prv[x]+d1*2+d2);
        chminMp(nxt, vs[i][0], prv[x]+d1+d2*2);
      } else if( idx ) {
        ll d1 = llabs(vs[i][0]-x);

        chminMp(nxt, vs[i][0], prv[x]+d1);
      } else if( vs[i].size()-idx ) {
        ll d2 = llabs(vs[i][vs[i].size()-1]-x);

        chminMp(nxt, vs[i][vs[i].size()-1], prv[x]+d2);
      }
    }

    std::swap(prv, nxt);
  }

  ll ans = INF;

  itr( it, prv ) {
    chmin( ans, it->second+llabs(it->first) );
  }

  std::cout << ans << endl;

  return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h> // __builtin_popcount(int x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(x) int(x.size())
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 <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n; cin >> n;
    V<P> a(n); // {l, r}
    const ll INF = 1e18;
    rep(i, n) a[i] = mp(INF, -INF);
    rep(i, n) {
        ll x, c; cin >> x >> c; c--;
        chmin(a[c].first, x), chmax(a[c].second, x);
    }

    V<ll> dp(2, 0); // 0:左 1:右
    ll l = 0, r = 0;
    rep(i, n) {
        if (a[i].first == INF) continue;
        V<ll> ndp(2);
        ll nl = a[i].first, nr = a[i].second;
        // l->nr->nl or r->nr->nl
        ndp[0] = min(dp[0] + abs(l-nr) + abs(nr-nl), dp[1] + abs(r-nr) + abs(nr-nl));
        // l->nl->nr or r->nl->nr
        ndp[1] = min(dp[0] + abs(l-nl) + abs(nl-nr), dp[1] + abs(r-nl) + abs(nl-nr));
        l = nl, r = nr;
        swap(dp, ndp);
    }
    ll ans = min(dp[0] + abs(l), dp[1] + abs(r));
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    if(n == 1){
        if(s == "0"){
            cout << 10000000000LL << endl;
        }else{
            cout << 20000000000LL << endl;
        }
        return 0;
    }
    if(n == 2){
        if(s == "11") cout << 10000000000LL << endl;
        else if(s == "10") cout << 10000000000LL << endl;
        else if(s == "01") cout << 9999999999LL << endl;
        else cout << 0 << endl;

        return 0;
    }
    int cas;
    if(s[0] == '0') cas = 0;
    else if(s[1] == '0') cas = 1;
    else cas = 2;

    if(cas == 0){
        s = s.substr(1, n - 1);
        n--;
        string t = "110";
        bool ok = true;
        for(int i=0;i<n;i++){
            if(s[i] != t[i%3]) ok = false;
        }
        n = (n + 2) / 3;
        cout << (ok ? 10000000000LL - n : 0) << endl;
        return 0;
    }else if(cas == 1){
        s = s.substr(2, n - 2);
        n -= 2;
        string t = "110";
        bool ok = true;
        for(int i=0;i<n;i++){
            if(s[i] != t[i%3]) ok = false;
        }
        n = (n + 2) / 3;
        cout << (ok ? 10000000000LL - n : 0) << endl;
        return 0;
    }else{
        if(s[2] == '1'){
            cout << 0 << endl;
            return 0;
        }
        s = s.substr(3, n - 3);
        n -= 3;
        string t = "110";
        bool ok = true;
        for(int i=0;i<n;i++){
            if(s[i] != t[i%3]) ok = false;
        }
        n = (n + 2) / 3;
        cout << (ok ? 10000000000LL - n : 0) << endl;
    }
    return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

char myHeap[200 * 1024 * 1024];
int sz = 0;
void assert_tle(bool q) { while (!q); }
void* operator new  ( std::size_t count ) {
    sz += count;
    assert_tle(sz <= 200 * 1024 * 1024);
    return myHeap + sz - count;
}

void operator delete (void *ptr) { }

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

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

    string s="110";

    int i=0;
    bool started=false;

    string comp;

    while(comp.length()<=n+5)
    {
        comp.pb('1');
        comp.pb('1');
        comp.pb('0');
    }
    int lim=pow(10ll,10);
    lim*=3;
    lim--;
    int endpt=lim+3;
    // if(str=="0")
    // {
    //     cout<<pow(10ll,10);
    //     return;
    // }
    if(str=="1")
    {

        int ret=2*pow(10ll,10);
        cout<<ret;
        return;
    }
    if(comp.substr(0,n)==str)
    {
        endpt=n-1;
    }
    if(comp.substr(1,n)==str)
    {
        endpt=n;
    }
    if(comp.substr(2,n)==str)
    {
        endpt=n+1;
    }
    int ans=1;
    ans=(lim-endpt)/3;
    ans++;
    cout<<ans;

}

int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>
//#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;
//typedef boost::multiprecision::cpp_int ll;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main() {
#ifdef DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N, P;
    cin >> N >> P;
    mint ans = P - 1;
    mint m = P - 2;
    m = m.pow(N-1);
    ans = ans * m;
    cout << ans.x << endl;
    return 0;
}

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

int main()
{
    long S,P;
    cin >> S >> P;
    for(long i=1; i<S;i++){
        if(i*(S-i) == P){
            cout << "Yes" << endl;
            //cout << i << S << P << endl;
            return 0;
        }
        else if (i*(S-i) > P){
            cout << "No" << endl;
            //cout << i << S << P << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define tp top()
#define fr front()
#define vi vector<int>
#define sz size()
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define mem(a,  b) memset(a,  (b),  sizeof(a))
#define clr(a) memset(a,  0,  sizeof(a))
#define sqr(x) ( (x) * (x) )
#define all(v) v.begin(),  v.end()

typedef pair<int, int> pii;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;

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

ll a[55];
int n;

map<pair<int,ll>, ll> memo;

ll rek(int x, ll j){
	if (memo.find({x,j}) != memo.end()) return memo[{x,j}];
	ll cnt = 0;
	if (j % a[x]==0){
		cnt = 1;
	} else {
		ll y = j / a[x];
		if (x == n-1 || y * a[x] < a[x+1]) cnt += rek(x-1, abs(y * a[x] - j));
		if (x == n-1 || (y+1) * a[x] < a[x+1]) cnt += rek(x-1, abs((y+1) * a[x] - j));
	}
	return memo[{x,j}] = cnt;
}

void solve(){
	ll x; cin>>n>>x;
	rep(i,0,n) cin>>a[i];
	cout<<rek(n-1,x)<<"\n";
}

int main()
{
	base();
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;

void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
    cin >> head;
    INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
    cout << head << endl;
    OUTX(forward<Tail>(tail)...);
}
void OUTX2(){cout << endl;}
template<typename Head, typename... Tail>
void OUTX2(Head&& head, Tail&&... tail)
{
    cout << head << ' ';
    OUTX2(forward<Tail>(tail)...);
}

#define ADD emplace_back
#define MP make_pair
#define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1)

//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)

// 公式解説

ll N;
vll ballcnt; // 色ごとのボールの数
vll lpos; // 色ごとにボールの左端(最小)の位置を記録した配列
vll rpos; // 色ごとにボールの右端(最大)の位置を記録した配列

vvpll dp; // 色cまで回収した時点でのコスト(.first)と位置(.second)
pll f(ll c, ll lr)
{
    if(c < 0) return MP(0, 0);
    else if(dp[c][lr].first >= 0) return dp[c][lr];
    else if(ballcnt[c] == 0) return f(c - 1, lr);
    else
    {
        auto f2 = [](pll &pre, ll &pass, ll &goal)
        {
            return MP(pre.first + abs(pass - pre.second) + abs(goal - pass), goal);
        };
        pll prel = f(c - 1, 0);
        pll prer = f(c - 1, 1);
        pll can1, can2;
        if(lr == 0)
        {
            can1 = f2(prel, rpos[c], lpos[c]);
            can2 = f2(prer, rpos[c], lpos[c]);
        }
        else
        {
            can1 = f2(prel, lpos[c], rpos[c]);
            can2 = f2(prer, lpos[c], rpos[c]);
        }
        pll &result = (can1.first < can2.first ? can1 : can2);
        dp[c][lr] = result;
        return result;
    }
}

int main()
{
    INX(N);
    ballcnt.resize(N, 0);
    lpos.resize(N, __LONG_LONG_MAX__);
    rpos.resize(N, __LONG_LONG_MIN__);
    dp.resize(N, vpll(2, MP(-1, -1)));

    for (ll i = 0; i < N; i++)
    {
        ll X, C;
        INX(X, C);
        C--;
        lpos[C] = min(lpos[C], X);
        rpos[C] = max(rpos[C], X);
        ballcnt[C]++;
    }

    pll can1 = f(N - 1, 0);
    pll can2 = f(N - 1, 1);
    ll can1c = can1.first + abs(can1.second);
    ll can2c = can2.first + abs(can2.second);
    OUTX(min(can1c, can2c));

    return 0;
}


#include <bits/stdc++.h>

#include <random>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3,unroll-loops")
using ll = long long;
using ull = unsigned long long;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) for (int(i) = 0; (i) < int(n); (i)++)
#define repi(i, a, b) for (int(i) = (a); (i) < int(b); (i)++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int dy[4] = {-1, 0, 1, 0};
constexpr int dx[4] = {0, -1, 0, 1};
constexpr ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;

template <unsigned int Mod>
struct mint {
    unsigned int x;
    mint(long long x = 0) : x((x % Mod + Mod) % Mod) {}

    mint operator-() const { return mint(0) - *this; }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += Mod - a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        x = (unsigned long long)x * (unsigned long long)a.x % Mod;
        return *this;
    }

    mint operator^(long long t) const {
        mint ret(1);
        mint a = *this;
        while (t) {
            if (t & 1) {
                ret *= a;
            }
            a *= a;
            t >>= 1;
        }
        return ret;
    }
    mint inv() const { return *this ^ (Mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }

    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }

    friend istream& operator>>(istream& is, mint& a) { return is >> a.x; }
    friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
};

int H, W, K;
string S[5000];
mint<MOD> dp[5001][5001];
int sumX[5001][5001], sumY[5001][5001];
mint<MOD> prod[5001];

signed main() {
    cin >> H >> W >> K;
    rep(i, H) S[i] = string(W, '?');
    rep(i, K) {
        int h, w;
        char c;
        cin >> h >> w >> c;
        S[h - 1][w - 1] = c;
    }

    rep(i, H) {
        rep(j, W) {
            sumY[j][i + 1] = sumY[j][i] + (S[i][j] == '?');
            sumX[i][j + 1] = sumX[i][j] + (S[i][j] == '?');
        }
    }
    prod[0] = 1;
    rep(i, 1, 5001) prod[i] = prod[i - 1] * 3;

    dp[0][0] = 1;
    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '?') {
                dp[i + 1][j] += dp[i][j] * prod[sumX[i + 1][j]] * 2;
                dp[i][j + 1] += dp[i][j] * prod[sumY[j + 1][i]] * 2;
            }
            if (S[i][j] == 'R') {
                dp[i][j + 1] += dp[i][j] * prod[sumY[j + 1][i]];
            }
            if (S[i][j] == 'D') {
                dp[i + 1][j] += dp[i][j] * prod[sumX[i + 1][j]];
            }
            if (S[i][j] == 'X') {
                dp[i + 1][j] += dp[i][j] * prod[sumX[i + 1][j]];
                dp[i][j + 1] += dp[i][j] * prod[sumY[j + 1][i]];
            }
            // cout << dp[i][j] << " ";
        }
        // cout << endl;
    }
    cout << dp[H - 1][W - 1] * (S[H - 1][W - 1] == '?' ? 3 : 1) << endl;
}

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 5010
using namespace std;
ll ksm(ll x,ll y)
{
	if(y==0)
	{
		return 1;
	}
	ll ret=ksm(x,y>>1);
	ret=(ret*ret)%mod;
	if(y&1)
	{
		ret=(ret*x)%mod;
	}
	return ret;
}
ll n,m,k,dp[N][N],sum[N][N],pw3[2],inv[5],ans=0;
char grid[N][N];
ll dfs(ll x,ll y)
{
	if(x==n-1&&y==m-1)
	{
		return dp[x][y]=pw3[0];
	}
	if(x>=n||y>=m)
	{
		return dp[x][y]=0;
	}
	if(dp[x][y]!=-1)
	{
		return dp[x][y];
	}
	dp[x][y]=0;
	if(grid[x][y]=='D')
	{
		return dp[x][y]=dfs(x+1,y);
	}
	if(grid[x][y]=='R')
	{
		return dp[x][y]=dfs(x,y+1);
	}
	if(grid[x][y]=='X')
	{
		return dp[x][y]=(dfs(x,y+1)+dfs(x+1,y))%mod;
	}
	return dp[x][y]=(2*(dfs(x,y+1)+dfs(x+1,y))*inv[1])%mod;
}
int main(){
	ll i,j,x,y;
	char c;
	scanf("%lld%lld%lld",&n,&m,&k);
	pw3[0]=ksm(3,n*m-k);
	inv[1]=ksm(3,mod-2);
	for(i=0;i<k;i++)
	{
		scanf("%lld%lld %c",&x,&y,&c);
		x--;
		y--;
		grid[x][y]=c;
	}
	memset(dp,-1,sizeof(dp));
	for(i=n-1;i>=0;i--)
	{
		for(j=m-1;j>=0;j--)
		{
			sum[i][j]=(sum[i+1][j]+sum[i][j+1]-sum[i+1][j+1]+(grid[i][j]!='D'&&grid[i][j]!='R'&&grid[i][j]!='X'));
		}
	}
	dfs(0,0);
	printf("%lld\n",dp[0][0]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a, b;
    cin>>a>>b;
    if(a=='Y')  {b=b-32; cout << b << endl;}
    else        cout << b << endl;
    return 0;
}

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

int main()
{
    int a,b;
    cin>>a>>b;
    int k=(2*a)+100;
    cout<<k-b<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define MOD2 1000000009
#define endl "\n"
#define pii pair <int, int>
#define pll pair <ll, ll>
#define F first
#define S second

map<ll, ll> dp, vis;
ll ans = 1e18;
ll solve(ll x, ll y) {

    if(vis[y]) {
        return dp[y];
    }
    vis[y] = 1;
    dp[y] = 1e18;
    dp[y] = min(dp[y], abs(x - y));
    if(x == y)
        return dp[y];
    if(y % 2 == 0)
        return dp[y] = min(dp[y], 1 + solve(x, y / 2));

    return dp[y] = min(dp[y], 1 + min(solve(x, y - 1), solve(x, y + 1)));

    return dp[y];
}

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

   /* int t;
    cin >> t;
    while(t--) {

    }*/
    ll x, y;
    cin >> x >> y;
    cout << solve(x, y);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll mod=1000000007;
// ll MOD=998244353;
const ll MOD=998244353;

void Add(int &a, int b) {
  a += b;
  while (a >= MOD) a -= MOD;
  while (a < 0) a += MOD;
}

void Mul(int &a, int b) {
  a = 1LL * a * b % MOD;
}

int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}

int main() {
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    // vector<vector<ll>> b(n,vector<ll>(k+1,1));
    vector<ll> b(n,1);
    vector<ll> e(k+5,0);
    rep(i,k+1) e[i]=Pow(i,MOD-2);
    vector<ll> c(k+1,0);
    rep(i,n){
      rep(j,k+1){
        (c[j]+=b[i])%=MOD;
        b[i]=(b[i]*a[i]%MOD*e[j+1])%MOD;
      }
    }
    // rep(i,n){
    //   rep(j,k+1) (c[j]+=b[i][j])%=MOD;
    // }
    vector<ll> ans(k+1);
    ans[1]=1;
    rep(i,k){
      ans[i+2]=(ans[i+1]*(i+2))%MOD;
    }
    vector<ll> o(k,0);
    rep(i,k){
      rep(j,k+1){
        if (i+1-j<0) break;
        (o[i]+=c[j]*c[i+1-j]%MOD)%=MOD;
      }
    }
    vector<ll> p(k+2,0);
    ll cc;
    rep(i,n){
      cc=a[i]*2;
      rep(j,k) {
        (p[j]+=cc)%=MOD;
        (cc*=a[i]*2)%=MOD;
      }
    }
    rep(i,k) cout << ((ans[i+1]*o[i]%MOD+MOD-p[i])%MOD)*Pow(2,MOD-2)%MOD << endl;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef vector<vector<bool> > vvb;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

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

ll modpow(ll x, ll y) {
    if(y == 1) {
        return x;
    }
    ll ans;
    if(y % 2 == 1) {
        ll r = modpow(x,(y-1)/2);
        ans = r * r % MOD;
        ans = ans * x % MOD;
    }
    else {
        ll r = modpow(x,y/2);
        ans = r * r % MOD;
    }
    return ans;
}

ll modncr(ll N, ll K) {
    ll res = 1;
    ll p=1;
    for (ll n = 0; n < K; ++n) {
      res = (res*(N - n))%MOD;
      p = (p*(n + 1))%MOD;
    }
    return (res*modpow(p,MOD-2))%MOD;
}

signed main() {
    ll n;
    cin >> n;
    ll r = 1;
    vll flg(31, 0);
    for (ll i = n; i >= 2; i--) {
        r = lcm (r, i);
    }

    mes(r+1);

}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define int long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 100005
int f[N],g[N],n;
vector<int> ans;
int now,x,y;
void push(int v)
{
	if(v==1) x++;
	else if(v==2) y++;
	else if(v==3) x+=y;
	else y+=x;
	ans.pb(v);
}
signed main()
{
	cin>>n;
	f[0]=f[1]=1;
	for(int i=2;i<=100;i++) f[i]=f[i-1]+f[i-2];
	int maxn=-1;
	for(int i=87;i>=1;i--)
	{
		while(n>=f[i])
		{
			if(maxn==-1) maxn=i;
			n-=f[i],g[maxn-i]++;
		}
	}
	now=maxn&1;
	for(int i=0;i<=maxn;i++)
	{
		while(g[i]) push(now+1),g[i]--;
		push(now+3),now^=1;
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<(int)ans.size();i++) printf("%lld\n",ans[i]);
	return 0;
}


//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#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;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;

int fix(int v)
{
	while(v>n)
		v-=n;
	return v;
}

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		int a=2*i;
		int b=2*i+1;
		a=fix(a);
		b=fix(b);
		printf("%d %d\n", a, b);
	}
	return 0;
}


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

#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())

using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
using P = pair<ll, ll>;

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

const ll MOD = 998244353;
const ll INF = 1e9;

//BIT
template <typename T>
struct BIT{
    int n;  //配列の要素数
    vector<T> bit;  //データの格納先
    BIT(int n_) : n(n_ + 1), bit(n, 0){}

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

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

    //sum(a_i) >= w となるような最小のxを求める
    int lower_bound(T w) { // a_1 + a_2 + ... + a_x >= w となるような最小の x を求める(ただし a_i >= 0)
    if (w <= 0) return 0;
    else {
        int x = 0, r = 1;
        while (r < n) r = r << 1;
            for (int len = r; len > 0; len = len >> 1) { // 長さlenは1段下るごとに半分に
                if (x + len < n && bit[x + len] < w) { // 採用するとき
                    w -= bit[x + len];
                    x += len;
                }
            }
            return x + 1;
        }
    }

    T num(int i){
        T res = sum(i);
        if(i != 1)res -= sum(i - 1);
        return res;
    }
};
vector<vector<int>> G;
vector<int> eul, dep;
void dfs(int v, int p){
    eul.pb(v);
    for(auto nv : G[v]){
        if(nv == p)continue;
        dep[nv] = dep[v] + 1;
        dfs(nv, v);
    }
    eul.pb(v);
}
int main(){
    int n;
    cin >> n;
    G.resize(n);
    dep.resize(n);
    vector<int> p(n - 1);
    rep(i, n - 1)cin >> p[i];
    rep(i, n - 1){
        p[i]--;
        G[i + 1].pb(p[i]);
        G[p[i]].pb(i + 1);
    }
    int q;
    cin >> q;
    vector<int> U(q), D(q);
    rep(i, q)cin >> U[i] >> D[i];
    //Dごとに管理する
    vector<vector<P>> qry(n + 1);
    rep(i, q){
        U[i]--;
        qry[D[i]].pb(P(U[i], i));
    }
    dfs(0, -1);
    //dep[v] -> v
    vector<vector<int>> rdep(n + 1);
    rep(i, n){
        rdep[dep[i]].pb(i);
    }
    //vを根とする部分木に対応する区間を持つ
    vector<int> L(n, -1), R(n);
    rep(i, sz(eul)){
        if(L[eul[i]] == -1)L[eul[i]] = i;
        R[eul[i]] = i;
    }
    BIT<int> bit(sz(eul));
    vector<int> res(q);
    REP(i, 0, n){
        //bitに深さiの点を加える
        for(auto v : rdep[i]){
            bit.add(L[v] + 1, 1);
        }
        //クエリ処理
        for(auto qi : qry[i]){
            auto [ui, id] = qi;
            res[id] = bit.sum(R[ui] + 1);
            if(L[ui] > 0)res[id] -= bit.sum(L[ui]);
        }
        //足した分引く
        for(auto v : rdep[i]){
            bit.add(L[v] + 1, -1);
        }
    }
    for(auto ri : res)cout << ri << endl;
}

#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define endl '\n'

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007;
const int dx[] = { 0, 0, -1, 1, 1, -1,  1, -1};
const int dy[] = {-1, 1,  0, 0, 1, -1, -1,  1};

void merge(map<int, int> &from, map<int, int> &to){
  if(from.size() > to.size())
    swap(from, to);
  for(auto &[a, b]: from)
    to[a] += b;
  from.clear();
}
const int MAXN = 200010;
int ans[MAXN];
vector<int> adj[MAXN];
vector<pii> queries[MAXN];

void dfs(int u, int dt, map<int, int> &mp){
  for(int to: adj[u]){
    map<int, int> aux;
    dfs(to, dt + 1, aux);
    merge(aux, mp);
  }
  mp[dt]++;
  for(auto [d, id]: queries[u])
    ans[id] = mp[d];

}

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

  int n;
  cin >> n;
  for(int i=2; i<=n; i++){
    int x;
    cin >> x;
    adj[x].push_back(i);
  }
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    int u, d;
    cin >> u >> d;
    queries[u].emplace_back(d, i);
  }
  map<int, int> mp;
  dfs(1, 0, mp);
  for(int i=0; i<q; i++)
    cout << ans[i] << endl;

  return 0;
}


//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define ERR 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);}

int main(){
    FAST;
    LL i,ans=0,V,T,S,D;
    cin>>V>>T>>S>>D;
    Yn(!(V*T<=D&&V*S>=D));
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//int a[200000];
int main()
{
    int n, m, t, k, s = 0;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int t1=b*a;
    int t2=c*a;
    if(d>=t1&&d<=t2)
    {
        cout<<"No";
    }
    else
    {

        cout<<"Yes";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
std::chrono::high_resolution_clock::time_point start_time = std::chrono::high_resolution_clock::now();
// Defines
#define all(x) (x).begin(),(x).end()
#define sortall(x) sort(x.begin(),x.end())
#define maxin(x) *max_element(x.begin(),x.end())
#define minin(x) *min_element(x.begin(),x.end())
#define lint long long int
#define nl '\n'
#define INF (lint)1e18
#define EPS (long double)1/(INF)
//#define MOD (lint)998244353
#define MOD (lint)(1e9+7)
//Debugs
#ifdef LOCAL
    #define debugvar(x) cout<<#x<<"\t:"<<(x)<<"\n"
    #define debugvec(x) cout<<#x<<"\t:"; for(auto it = (x).begin();it!=(x).end();it++) cout<<*it<<" "; cout<<nl
#else
    #define debugvar(x) 0
    #define debugvec(x) 0
#endif
//Templates
template <typename T> inline T gcd(T a, T b) { a=(a>0?a:-a); b=(b>0?b:-b); while (b != 0) swap(b, a %= b); return a;}
template <typename T> inline T extended_gcd(T a, T& x, T b, T& y){  // returns gcd(a,b) && a*x + b*y = gcd(a,b)
    T l_a = 1, l_b = 0;
    T r_a = 0, r_b = 1;
    T q = a/b, r = a%b;
    while(r>0){
        T temp;
        temp = r_a, r_a = l_a - q*r_a ,l_a = temp;
        temp = r_b, r_b = l_b - q*r_b ,l_b = temp;
        a = b;
        b = r;
        q = a/b;
        r = a%b;
    }
    x = r_a;
    y = r_b;
    return b;
}
template <typename T> inline T MOD_inv (T num){
    lint inv,temp;
    assert(extended_gcd(MOD,temp,num,inv)==1);
    return (inv%MOD+MOD)%MOD;
}
template <typename T> inline T lcm(T a, T b) { if(a*b==0) return (T)0; return ((a/gcd(a,b))*b);}
template <typename T> inline T getpow(T base, T exp){
    if(exp==0) return (T)1;
    T half  = getpow(base,exp/2);
    T ans   = half*half;
    if(exp&1) ans = ans*base;
    return ans;
}
template <typename T> inline T getpowMOD(T base, T exp){
    if(exp==0) return (T)1;
    base    = base%MOD;
    T half  = getpowMOD(base,exp/2);
    T ans   = (half*half)%MOD;
    if(exp&1) ans = (ans*base)%MOD;
    return ans;
}
lint ncrMOD(lint n, lint r){
    if(r>n) return 0;
    r = min(r,n-r);
    lint fact = 1;
    for(lint i=1;i<=r;i++){
        fact=(fact*(n+1-i))%MOD;
        fact=(fact*MOD_inv(i))%MOD;
    }
    return fact;
}
void solve(){
    lint n,m,k;
    cin>>n>>m>>k;
    if(m-n<-k){cout<<0;return;}
    lint ans = ncrMOD(m+n,m)-ncrMOD(m+n,m+k+1);
    ans = (ans+MOD)%MOD;
    cout<<ans;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);lint testnum=1,totalnum=1;
    //cin>>totalnum;
    for(testnum=1;testnum<=totalnum;++testnum){
        //cout<<"Case #"<<testnum<<": ";
        //cout<<ncrMOD(28,14);
        solve();
        cout<<nl;
    }
    bool time = 0;
    //time=true;
    if(time){
        std::chrono::high_resolution_clock::time_point end_time = std::chrono::high_resolution_clock::now();
        std::chrono::duration<double> time_taken = std::chrono::duration_cast<std::chrono::duration<double>>(end_time - start_time);
        cout << "\nTime Taken: " <<setprecision(10)<<time_taken.count() << " s";
    }
return 0;
}
/*
    created on: 27.06.2021

*/

/*
	JAI JAGANNATH!
*/
//@Author : zanj0

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

#define int 			long long int
#define ff              first
#define ss              second
#define pb              push_back
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl       		"\n"
#define timetaken cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n"

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
const int MAX = 3e6 + 5;
int fac[MAX], finv[MAX];
int inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
int COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int add(int a, int b) {
	return ((a % MOD) + (b % MOD)) % MOD;
}
int mul(int a, int b) {
	return ((a % MOD) * (b % MOD)) % MOD;
}
int fastPow(int base, int p) {
	int ret = 1;
	while (p) {
		if (p & 1) ret = mul(ret, base);
		base = mul(base, base);
		p >>= 1;
	}
	return ret;
}
int sub(int a, int b) {
	return (((a % MOD) - (b % MOD)) + MOD) % MOD;
}
void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	COMinit();
	if (n > m + k) {
		cout << 0 << endl;
	} else if (k >= n) {
		cout << COM(n + m, n) << endl;
	} else {
		cout << sub(COM(n + m, n), COM(n + m, n - k - 1)) << endl;
	}

}
int32_t main()
{
	zanj0();
	solve();
	timetaken;
	return 0;
}


//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

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

using namespace std;

//#define pb push_back
//#define mp make_pair
#define fi first
#define se second

typedef long long ll;

//#define rep(_i,iv,n) for(int _i=(int)(iv);_i<(int)(n);++_i)
#define rep0(_i,n) for(int _i=0;_i<(int)(n);++_i)
//#define REP(_i,iv,_l,n) for(int _i=(int)(iv),_l=(int)(n);_i<_l;++_i)
#define REP0(_i,_l,n) for(int _i=0,_l=(int)(n);_i<_l;++_i)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;

typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef vector<ll> vll;
typedef vector<vll > vvll;

#define INF 1<<30

td pair<int, int > pii;
td priority_queue<pii,vector<pii>,greater<pii> > pq;

#define mod7 1000000007

void init(int S, int *tree, int i) {
    if (i >= S) {
        return;
    }
    init(S, tree, i * 2);
    init(S, tree, i * 2 + 1);
    tree[i] = tree[i * 2] ^ tree[i * 2 + 1];
}

void update(int *tree, int i) {
    if (i == 1) {
        return;
    }
    int pi = i / 2;
    tree[pi] = tree[pi * 2] ^ tree[pi * 2 + 1];
    update(tree, pi);
}

int show(int *tree, int l) {
    int ans = tree[l];
    for (int i = l; i != 1; i /= 2) {
        if (i % 2) {
            ans ^= tree[i - 1];
        }
    }
    return ans;
}

int getS(int N) {
    for (int i = 1; ; ++i) {
        if (N <= (1 << i)) {
            return 1 << i;
        }
    }
}

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    int A[N], B[N];
    rep0(i, N) {
        cin>>A[i]>>B[i];
    }

    int tMin = INT32_MAX;
    rep0(i, N) {
        rep0(j, N) {
            int t;
            if (i == j) {
                t = A[i]+B[j];
            } else {
                t = max(A[i], B[j]);
            }
            if (t <tMin) {
                tMin = t;
            }
        }
    }
    cout << tMin <<endl;

    return 0;
}

/*	_____________________
	|Author : canhnam357|
	|___________________|
*/
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef vector <vector <int>> vvi;
typedef vector <vll> vvll;
typedef map<int, int> mi;
typedef map<string, int> ms;
typedef map<char, int> mc;
typedef map <int, bool> mb;
typedef map<ll, ll> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<string, int> ums;
typedef unordered_map<char, int> umc;
typedef unordered_map <int, bool> umb;
typedef unordered_map<ll, ll> umll;
typedef vector <ld> vld;
typedef vector <bool> vb;
typedef pair <int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
int CASE = 1;
const int mxn = 4e3 + 1;
const ll INF = 1e18;
#define FOR(i,N) for(ll i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(ll i = a; i <=b;i++)
#define dFOR(i,N) for(ll i = N - 1; i>=0;i--)
#define edFOR(i,b,a) for(ll i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define UNQ(x)  unique(all(x))
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define lb(v, x) lower_bound(all(v) , x)
#define ub(v , x) upper_bound(all(v) , x)
#define pb push_back
#define PI 3.141592653589793
#define FIX cout << fixed << setprecision(15)
#define g(i , a) get<i>(a)
const ll mod = 1e5;
bool prime(ll n)
{
	if (n <= 1)
		return false;
	eFOR(i, 2, sqrt(n))
		if (!(n % i))
			return false;
	return true;
}
ll __gcd(ll a, ll b)
{
	return !b ? a : __gcd(b, a % b);
}
void solve()
{
	int a, b, x, y;
	cin >> a >> b >> x >> y;
	if (b >= a)
	{
		cout << x + min(2 * x, y) * (b - a);
	}
	else
	{
		int k = a - b;
		cout << min(x + (k - 1) * y, (2 * k - 1) * x);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	while (T--)
	{
		solve();
	}
	return 0;
}


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

const int64_t MOD = 1e9+7;

void experiment(vector<char> V){
  for(int i=0; i<4; i++){
    cout << V[i];
  }
  cout << " ";
  set<string> S;
  S.insert("AB");
  queue<string> Q;
  Q.push("AB");
  for(int i=3; i<=10; i++){
    cout << S.size() << " ";
    S.clear();
    int q = Q.size();
    for(int a=0; a<q; a++){
      string T = Q.front();
      Q.pop();
      for(int i=0; i<T.size()-1; i++){
        string U = "";
        U += T.substr(0,i+1);
        if(T[i] == 'A' && T[i+1] == 'A'){
          U += V[0];
        }
        if(T[i] == 'A' && T[i+1] == 'B'){
          U += V[1];
        }
        if(T[i] == 'B' && T[i+1] == 'A'){
          U += V[2];
        }
        if(T[i] == 'B' && T[i+1] == 'B'){
          U += V[3];
        }
        U += T.substr(i+1);
        S.insert(U);
        Q.push(U);
      }
    }
  }
  cout << endl;
}

int main(){
  int N;
  cin >> N;
  vector<char> vec(4);
  string ans = "";
  for(int i=0; i<4; i++){
    cin >> vec[i];
    ans += vec[i];
  }
  /*for(int bit = 0; bit<(1<<4); bit++){
    bitset<4> X(bit);
    for(int j=0; j<4; j++){
      if(X.test(j)){
        vec[j] = 'B';
      }
      else{
        vec[j] = 'A';
      }
    }
    experiment(vec);
  }*/

  vector<int64_t> calc(N+1,1);

  if(ans == "ABAA" || ans == "BBAA" || ans == "BABA" || ans == "BABB"){
    for(int i=3; i<N; i++){
      calc[i+1] = calc[i]*2;
      calc[i+1] %= MOD;
    }
  }
  else if(ans == "BAAA" || ans == "ABBA" || ans == "BBBA" || ans == "BAAB"){
    for(int i=3; i<N; i++){
      calc[i+1] = calc[i] + calc[i-1];
      calc[i+1] %= MOD;
    }
  }
  cout << calc[N] << endl;
}

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
#define pdd pair<double,double>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
LL mod=1e9+7;
LL f_pow(LL a,LL b){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
void solve(){
    int n;
    scanf("%d",&n);
    char c[2][2];
    for(int i = 0;i<2;i++){
        for(int j =0;j<2;j++){
            scanf(" %c",&c[i][j]);
        }
    }
    if(n<=3){
        printf("1\n");
        return;
    }
    if(c[0][1]=='A'){
        if(c[0][0]=='A')printf("1\n");
        else{
            if(c[1][0]=='B'){
                printf("%d\n",f_pow(2,n-3));
            }
            else{
                int f[1005];
                f[0]=1;
                f[1]=1;
                for(int i=2;i<=n-2;i++){
                    f[i]=(f[i-1]+f[i-2])%mod;
                }
                printf("%lld\n",(f[n-3]+f[n-4])%mod);
            }
        }
    }
    else{
        if(c[1][1]=='B')printf("1\n");
        else{
            if(c[1][0]=='A'){
                printf("%d\n",f_pow(2,n-3));
            }
            else{
                int f[1005];
                f[0]=1;
                f[1]=1;
                for(int i=2;i<=n-2;i++){
                    f[i]=(f[i-1]+f[i-2])%mod;
                }
                printf("%lld\n",(f[n-3]+f[n-4])%mod);
            }
        }
    }
}

int main(){
    int t=1;
   // scanf("%d",&t);
    while(t--){
        solve();
    }
}


#define ll long long int
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#include <bits/stdc++.h>
using namespace std;

void solve()
{
  string s;
  cin >> s;
  string t = "";
  for(int i=0; i<s.size(); i++){
    if(s[i] == '.'){break;}
    else{t += s[i];}
  }
  cout << t << "\n";
}

int main()
{
    fast;
    solve();
    return 0;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

vector <ll> vec ;

int main()
{
    ll n, lim ;
    cin >> n ;
    lim = sqrt(n) ;
    for (int i = 1; i <= lim; i++) {
        if (n % i == 0) {
            if (n / i != i) {
                vec.push_back(i) ;
                vec.push_back(n / i) ;
            }
            else {
                vec.push_back(n / i) ;
            }
        }
    }
    sort(vec.begin(), vec.end()) ;
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << "\n" ;
    }

    return 0 ;
}


#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for(T &x : v) is >> x;
    return is;
}
struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;
/*-------------------------------------------*/

int isp[1000009];

int main() {
    int l, r;
    cin >> l >> r;

    for(int i = 2; i < 1000009; i++)
        if(isp[i] == 0)
            for(int j = i; j < 1000009; j += i) isp[j] = i;

    ll ans = 0;
    FOR(i, 2, r + 1) {
        int g = i;
        int mn = l / g;
        if(l % g != 0) mn++;
        if(mn * g > r) continue;
        int mx = r / g;
        vector<int> ps;
        bool flag = true;
        while(g != 1) {
            if(!ps.empty() && ps.back() == isp[g]) flag = false;
            ps.push_back(isp[g]);
            g /= isp[g];
        }
        if(flag)
            ans += (ps.size() % 2 ? 1LL : -1LL) * (mx - mn + 1) * (mx - mn + 1);
        if(mn == 1) ans -= 2 * mx - 1;
        // cout << g << " " << ans << " " << mn << " " << mx << endl;
    }

    cout << ans << endl;
}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ull unsigned ll
#define ld long double
#define mod 1000000007
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define dpll deque<pll>
#define mapll map<ll,ll>
#define umapll unordered_map<ll,ll,custom_hash>
#define nl "\n"
#define all(v) v.begin(),v.end()
#define fr for(ll i=0;i<n;i++)
#define frr for(ll i=1;i<=n;i++)
#define ms(a,x) memset(a,x,sizeof(a))
//#define fr(aa,bb) for(ll i=aa;i<=bb;i++)
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace __gnu_pbds;
vector<pair<ll,ll>>v[100005];
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
//template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
//template<class T>using uset=unordered_set<T,custom_hash>;
ll dmod(ll x){
    return ((x+mod)%mod);
}
ll modular_power(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1)ans=dmod(ans*x);
        y/=2;
        x=dmod(x*x);
    }
    return ans;
}
ll inv(ll x){
    return modular_power(dmod(x),mod-2);
}

int main()
{
    //clock_t clk = clock();
    fio
    //cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n,var;cin>>n;string s;
        vector<ll>v;
        unordered_map<ll,string,custom_hash>mp;
        fr
        {
            cin>>s>>var;
            mp[var]=s;
            v.pb(var);
        }
        sort(v.begin(),v.end());
        cout<<mp[v[v.size()-2]];
    }
    return 0;
}


#include<bits/stdc++.h>
#define for0(n) for(lli i=0;i<n;i++)
#define in(x) lli x; cin>>x
using namespace std;
typedef long long int lli;
void buildTree(lli s,lli e,lli *arr, vector<lli> &tree,lli ind){
    // base
    if(s==e){
        // at the leaf node
        tree[ind] = arr[s];
        return;
    }
    // recurse
    lli mid = (s+e)/2;
    buildTree(s,mid,arr,tree,2*ind);
    buildTree(mid+1,e,arr,tree,2*ind+1);
    tree[ind] = (tree[2*ind] ^ tree[2*ind+1]);
    return;
}
lli queryTree(lli l,lli r ,lli s,lli e,vector<lli> &tree,lli ind){
    //base
    if(s > r || e < l)
        return 0; // as x xor 0 is just x
    if(s>=l && e<=r){
        return tree[ind];
    }
    // recurse
    lli mid = (s+e)/2;
    lli left = queryTree(l,r,s,mid,tree,2*ind);
    lli right = queryTree(l,r,mid+1,e,tree,2*ind+1);
    return (left^right);
}
// let's just not take lazy and try it

void updateTree(lli s,lli e,lli i,lli val, vector<lli> &tree,lli ind){
    //base
    // function signature ->
    // val : it is the value with which
    // you wanna replace a[i].
    if(s == e && i==s){
        tree[ind] = val;
        return;
    }
    if(i < s || i > e)
        return;
    //reurse
    lli mid = (s+e)/2;
    updateTree(s,mid,i,val,tree,2*ind);
    updateTree(mid+1,e,i,val,tree,2*ind+1);
    tree[ind] = tree[2*ind] ^ tree[2*ind+1];
    return;
}
int main(){
    ios::sync_with_stdio(0);
    in(n);
    in(q);
    lli t,x,y;
    lli arr[n];
    for0(n)
        cin>>arr[i];
    vector<lli> tree(4*300005);
    buildTree(0,n-1,arr,tree,1LL);
    while(q--){
        cin>>t>>x>>y;
        if(t==1){
            updateTree(0,n-1,x-1,(arr[x-1] ^ y),tree,1LL);
            arr[x-1] ^= y;
        }
        else{
            cout<<queryTree(x-1,y-1,0,n-1,tree,1LL)<<endl;
        }
    }
    return 0;
}

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

#define LL long long
#define int long long

namespace IO {
	const int N = 2e6;
	char buf[N], *p1 = buf, *p2 = buf;
	inline char gc() {
		if(p1 == p2) p2 = (p1 = buf) + fread(buf, 1, N, stdin);
		return p1 == p2 ? EOF : *(p1 ++);
	}
	template <typename T>
	inline void read(T &x) {
		x = 0; bool f = 0; char a = gc();
		for(; ! isdigit(a); a = gc()) if(a == '-') f = 1;
		for(; isdigit(a); a = gc()) x = x * 10 + (a ^ 48);
		if(f) x = -x;
	}
	inline int read() { int x; read(x); return x; }
	inline LL readll() { LL x; read(x); return x; }
	inline char readchar() {
		char a = gc();
		while(a == ' ' || a == '\n') a = gc(); return a;
	}
	inline int reads(char *s) {
		char *O = s, a = gc();
		while(! isalpha(a) && ! isdigit(a)) a = gc();
		while(isalpha(a) || isdigit(a)) *O = a, O ++, a = gc();
		return O - s;
	}
	inline void outs(int len, char *s, char ch = '\n') {
		char *O = s;
		while(len --) putchar(*O), O ++; putchar(ch);
	}
	char Of[105], *O1 = Of, *O2 = Of;
	template <typename T>
	inline void print(T n, char ch = '\n') {
		if(n < 0) putchar('-'), n = -n;
		if(n == 0) putchar('0');
		while(n) *(O1 ++) = (n % 10) ^ 48, n /= 10;
		while(O1 != O2) putchar(*(-- O1));
		putchar(ch);
	}
}

using IO :: read;
using IO :: print;
using IO :: reads;
using IO :: outs;
using IO :: readchar;

const int N = 2e5 + 10;

int A, B, C;

vector<int> find(int x, int p) {
	x %= p;
	map<int, int> mp;
	vector<int> res;
	int t = 1;
	while(1) {
		t = (LL) t * x % p;
		if(mp[t]) return res;
		res.push_back(t);
		mp[t] = 1;
	}
}

int power(int x, int k, int P) {
	int res = 1;
	while(k) {
		if(k & 1) res = (LL) res * x % P;
		x = (LL) x * x % P; k >>= 1;
	} return res;
}

signed main() {
	#ifdef IN
	freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	#endif
	A = read(); B = read(); C = read();
	vector<int> p1 = find(A, 10);
	B = power(B, C, p1.size());
	B --;
	if(B < 0) B += p1.size();
	print(p1[B]);
	/*vector<int> p2 = find(B, p1.size());

	C %= p2.size();
	C --;
	if(C < 0) C += p2.size();

	int v = p2[C];
	v %= p1.size();

	v --;
	if(v < 0) v += p1.size();
	v = p1[v];
	print(v % 10);*/

	return 0;
}


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

int main() {
	double Sx, Sy, Gx, Gy;
	cin >> Sx >> Sy >> Gx >> Gy;
	cout << fixed << setprecision(7) << Sx + Sy * (Gx - Sx) / (Gy + Sy) << endl;
}

/*
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

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

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;
char aa , ab , ba , bb;

ll F[maxn];

ll f(int x){
	if(x <= 1)return(F[x] = 1);
	if(F[x])return(F[x]);
	return( F[x] = (f(x - 1) + f(x - 2))%mod );
}

int32_t main(){
    migmig;
	cin >> n >> aa >> ab >> ba >> bb;
	if(n <= 3)dokme(1);
	if(aa == ab && ab == ba && ba == bb)dokme(1);
	if(ab == 'B'){
		if(bb == 'B')dokme(1);
		if(ba == 'A')dokme(pw(2 , n - 3));
		dokme(f(n - 2));
	}
	if(aa == 'A')dokme(1);
	if(ba == 'B')dokme(pw(2 , n - 3));
	dokme((f(n - 2)));

    return(0);
}


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

const ll INF = 10e16;

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(m), b(m);
    vector<char> c(m);
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
    }

    vector<vector<vector<P>>> G(n, vector<vector<P>>(n));
    rep(i, m) rep(j, m) {
        if (i == j) continue;
        if (c[i] != c[j]) continue;
        G[a[i]][a[j]].push_back({b[i], b[j]});
        G[b[i]][b[j]].push_back({a[i], a[j]});
        G[a[i]][b[j]].push_back({b[i], a[j]});
        G[b[i]][a[j]].push_back({a[i], b[j]});
    }

    vector<vector<ll>> dist(n, vector<ll>(n, INF));
    queue<P> que;

    dist[0][n - 1] = 0;
    que.push({0, n - 1});

    while (!que.empty()) {
        P p = que.front();
        que.pop();

        for (P np : G[p.first][p.second]) {
            if (dist[np.first][np.second] != INF) continue;
            dist[np.first][np.second] = dist[p.first][p.second] + 1;
            que.push(np);
        }
    }

    ll ans = INF;
    rep(i, n) ans = min(ans, dist[i][i] * 2);
    rep(i, m) {
        ans = min(ans, dist[a[i]][b[i]] * 2 + 1);
        ans = min(ans, dist[b[i]][a[i]] * 2 + 1);
    }

    if (ans == INF) ans = -1;
    cout << ans << endl;
}

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1e18 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll extGCD(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x = 1 ;
        y = 0 ;
        return a ;
    }
    ll d = extGCD(b,a%b,y,x) ;
    y -= a/b*x ;
    return d ;
}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T &b){if(a<b) a = b ;}
template<class T> void chmin(T &a,T &b){if(a>b) a = b ;}

int main(){
    int n,m ;
    cin >> n >> m ;
    VV<pair<int,char>> g(n) ;
    VV<V<ll>> edge(n,VV<ll>(26)) ;
    for(int i=0;i<m;i++){
        int a,b ;
        char c ;
        cin >> a >> b >> c ;
        a-- ; b-- ;
        g[a].emplace_back(b,c) ;
        g[b].emplace_back(a,c) ;
        edge[a][c-'a'].push_back(b) ;
        edge[b][c-'a'].push_back(a) ;
    }
    VV<ll> dp(n,V<ll>(n,INF)) ;
    dp[0][n-1] = 0 ;
    queue<pair<int,int>> q ;
    q.emplace(0,n-1) ;
    while(!q.empty()){
        int start = q.front().first ;
        int goal = q.front().second ;
        q.pop() ;
        for(auto p:g[start]){
            int nx = p.first ;
            char c = p.second;
            for(auto &nx2:edge[goal][c-'a']){
                if(dp[nx][nx2]!=INF) continue ;
                dp[nx][nx2] = dp[start][goal]+2 ;
                q.emplace(nx,nx2) ;
            }
        }
    }
    ll ans = INF ;
    for(int i=0;i<n;i++) ans = min(ans,dp[i][i]) ;
    for(int i=0;i<n;i++) for(auto &p:g[i]) ans = min(ans,dp[i][p.first]+1) ;
    if(ans==INF) ans = -1 ;
    cout << ans << endl ;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define int long long
#define ld long double
#define f(i,x,n) for(int i=x;i<n;i++)
using namespace std;
const int mod=1e9+7;
const int inf=1e18;
int n,x[20],y[20],z[20];
int dp[200000][20];
int dfs(int mask,int pos) {
	int &an=dp[mask][pos];
	// cout<<mask<<endl;
	if(an!=-1)
		return an;
	if(mask==((1ll<<n)-1)) {
		return abs(x[0]-x[pos])+abs(y[0]-y[pos])+max(0ll,z[0]-z[pos]);
	}
	an=inf;
	f(i,0,n) {
		if((mask&(1ll<<i)) ==0 ) {
		// cout<<i<<endl;
			an=min(an,abs(x[pos]-x[i])+abs(y[pos]-y[i])+max(0ll,z[i]-z[pos])+dfs(mask|(1ll<<i),i) );
		}
	}
	return an;
}
void solve() {
	f(i,0,200000)
		f(j,0,18)
			dp[i][j]=-1;
	cin>>n;
	f(i,0,n) {
		cin>>x[i]>>y[i]>>z[i];
	}
	cout<<dfs(1,0)<<'\n';
}

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

#include<bits/stdc++.h>
#define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf (int)(1e18)
#define md (int)(998244353)
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;

const int M = 3e5 + 10;

int ex(int a,int b=md-2){
	int ans=1;
	while(b) {
		if(b&1) ans=(ans*a)%md;
		a=(a*a)%md,b/=2;
	}
	return ans;
}
inline int add(int a,int b){
	a+=b;
	if(a>=md) a-=md;
	return a;
}
inline int sub(int a,int b){
	a-=b;
	if(a<0) a+=md;
	return a;
}
inline int mul(int a,int b){
	return (a*b)%md;
}

int f[M],iv[M];
int C(int n,int r){
	if(n<r) return 0;
	return mul(f[n],mul(iv[r],iv[n-r]));
}

void init(){
	f[0]=1;
	for(int i=1;i<M;++i) {
		f[i]=mul(i,f[i-1]);
	}
	iv[M-1]=ex(f[M-1]);
	for(int i=M-2;i>=0;--i) {
		iv[i]=mul(i+1,iv[i+1]);
	}
}

int spf[M];

int get(int n,int x) {
	int ans=1;
	while(x>1) {
		int p=spf[x],cnt=0;
		while(x%p==0) x/=p,++cnt;
		ans=mul(ans,C(cnt+n-1,n-1));
	}
	return ans;
}

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

   	init();

   	spf[1]=1;
   	rep(i,2,M) if(!spf[i])
   	for(int j=i;j<M;j+=i) if(!spf[j]) spf[j]=i;

   	int n,m;
   	cin>>n>>m;
   	int ans=0;
   	rep(i,1,m+1) ans=add(ans,get(n,i));
   	cout<<ans;

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<vector<int>> cnt(200, vector<int>(0));
    for(int i = 0; i < N; i++) cin >> A[i];
    int tg = min(N, 8);
    for(int i = 0; i < (1 << tg); i++) {
        int sum = 0;
        vector<int> s;
        for(int j = 0; j < tg; j++) {
            if(i & (1 << j)) {
                s.push_back(j + 1);
                sum = (sum + A[j]) % 200;
            }
        }
        if(cnt[sum].size() != 0) {
            cout << "Yes" << endl;
            cout << s.size();
            for(auto e : s) cout << " " << e;
            cout << endl;
            cout << cnt[sum].size() << " ";
            for(auto e : cnt[sum]) cout << e << " ";
            cout << endl;
            return 0;
        } else {
            cnt[sum] = s;
        }
    }
  	cout << "No" << endl;
    return 0;
}

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

//#define ACL
#ifdef ACL
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#if __has_include("acl-all.h")
#include "acl-all.h" //on Wandbox
using namespace atcoder;
#endif
#endif //#ifdef ACL

typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef vector<vector<bool> > vvb;
typedef pair<ll, ll> pll;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = 1; i <= int(n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = int(n)-1; i >= 0; --i)

#define MES(a) MES2 a
#define MES2(a0,a1,a2,a3,a4,x,...) x
#define mes_1(x1) cout<<x1<<endl
#define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl
#define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl
#define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl
#define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl
#define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__)

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define Ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())

int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll fact_mod(ll n, ll mod) {
    ll f = 1; for (ll i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}

ll modpow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = modpow((x * x) % mod, n / 2 , mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}

ll modncr(ll n, ll r, ll mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    ll a = 1;
    rep(i, r) a = a * ((n-i) % mod) % mod;
    ll b = modpow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}

signed main() {
	ll n;
	cin >> n;
	ll nn = (ll)sqrt(n)+1;
	ll w = 10000 / nn;
	ll cnt = 0;
	rep(i, nn) {
		rep(j, nn) {
			mes(j*w, i*w, (j+1)*w-1, (i+1)*w-1);
			cnt++;
			if (cnt == n) {
				re0;
			}
		}

	}

}


/* Author: rrrr_wys
 **/

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
typedef double db;
typedef long long ll;
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int N = 200100;
const int P = 1e9 + 7;

ll n, f[1223][1222];
int nn[222], vis[N];
vector<int> op;
void op1() { op.pb(1); }
void op2() { op.pb(2); }
void op3() { op.pb(3); }
void op4() { op.pb(4); }
vector<vector<int>> ops;

int mn = 200;
vector<pii> vv, v;
void dfs(ll n, int num, int I) {
  if (n == 0) {
    if (mn > num) {
      mn = num;
      v = vv;
    }
    return;
  }
  if (num > mn)
    return;
  rep(k, 1, 1) {
    per(i, min(nn[k], I), 2) {
      if (f[k][i] <= n) {
        vv.pb({k, i});
        dfs(n - f[k][i], num + k, i);
        vv.pop_back();
        break;
      }
    }
  }
}
signed main() {
  cin >> n;
  ll tn = n;

  rep(k, 1, 130) {
    f[k][1] = 0;
    f[k][2] = k;
    for (int i = 3;; ++i) {
      f[k][i] = f[k][i - 1] + f[k][i - 2];
      if (f[k][i] >= n) {
        nn[k] = i;
        break;
      }
    }
  }

  // rep(k, 1, 130) {
  //  per(i, nn[k], 2) if (f[k][i] <= n) {
  //    vv.pb({k, i});
  //    dfs(n - f[k][i], k + i - 2, i);
  //    vv.pop_back();
  //  }
  //}
  // cout << mn << "\n";
  // for (auto vx : v) {
  //  cout << vx.fi << "," << vx.se << "\n";
  //}

  int ff = 0;
  per(i, nn[1], 2) if (f[1][i] <= n) {
    if (!ff) {
      ff = 1;
      if (i & 1) {
        op2();
        rep(k, 3, i) {
          if (k & 1)
            op3();
          else
            op4();
        }
      } else {
        op1();
        rep(k, 3, i) {
          if (k & 1)
            op4();
          else
            op3();
        }
      }
    } else {
      int pp = op.size() - i + 1;
      if (i & 1)
        vis[pp] = 2;
      else
        vis[pp] = 1;
    }
    n -= f[1][i];
  }
  vector<int> ans;
  rep(i, 0, (int)op.size() - 1) {
    ans.pb(op[i]);
    if (vis[i])
      ans.pb(vis[i]);
  }
  assert(ans.size() <= 130);
  ll x = 0, y = 0;
  cout << ans.size() << "\n";
  for (int w : ans) {
    cout << w << "\n";
    switch (w) {
    case 1:
      x++;
      break;
    case 2:
      y++;
      break;
    case 3:
      x += y;
      break;
    case 4:
      y += x;
      break;
    }
  }
  assert(x == tn);
}

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

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
        return false;
    }
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

int n;
int ans;

signed main(){
    n=read();

    for(int i=1;i*i<=n;i++){
        if(n%i==0&&i*i!=n){
            int j=n/i;
            if(i%2==1) ans++;
            if(j%2==1) ans++;
        }
        else if(i*i==n){
            if(i%2==1) ans++;
        }
    }

    n*=2;

    for(int i=1;i*i<=n;i++){
        if(n%i==0&&i*i!=n){
            int j=n/i;
            if(i%2==0&&j%2==1) ans++;
            if(j%2==0&&i%2==1) ans++;
        }
        else if(i*i==n){
            continue;
        }
    }

    writeln(ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define mod 998244353
#define pll pair<ll, ll>
#define f first
#define se second
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pb push_back
#define rb pop_back
#define prdb(x) cout << fixed << setprecision(10) << x;
#define speed1 ios_base ::sync_with_stdio(false);
#define speed2 cin.tie(NULL);
#define endl "\n"
/************
 * fill the array with desired value
    fill(all(vec), 1);

 *fills the dsu parent array consecutively starting from desired value
    iota(all(parent), 0);

 * sort the vector and then make all elements unique
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());

************/
ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    ll z = power(x, y / 2);
    z = z * z;
    if (y & 1)
        return (z * x);
    return z;
}
ll solve(vector<ll> &v, ll ind)
{
    if (ind == -1)
        return 1;

    if (v[ind])
        return solve(v, ind - 1);
    return solve(v, ind - 1) + power(2, ind + 1);
}

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

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n, i, j, k;
        cin >> n;
        vector<ll> v(n);

        for (i = 0; i < n; i++)
        {
            string s;
            cin >> s;
            if (s == "AND")
                v[i] = 1;
            else
                v[i] = 0;
        }

        cout << solve(v, n - 1) << endl;
    }
}

#include <bits/stdc++.h>

using namespace std;

#define closeSync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 400005;
const int INF = 0x3f3f3f3f;

char s[MAXN];
inline void solve()
{
    int n;
    cin >> n;
    string str;   cin >> str;
    str = " " + str;
    for (int i=1;i<=(n<<1);i++)
        s[i] = str[i];

    int q;
    cin >> q;
    bool sp = false;
    while (q--)
    {
        int t,a,b;
        cin >> t >> a >> b;
        if (a > b) swap(a,b);
        if (t == 1)
        {
            // || ()
            if (sp)
            {
                if ((a <= n && b <=n) )
                {
                    swap(s[n+a],s[n+b]);
                }
                else if (a>n && b>n)
                {
                    swap(s[a-n],s[b-n]);
                }
                else
                {
                    swap(s[n+a],s[b-n]);
                }
            }
            else
                swap(s[a],s[b]);
        }
        else
            sp = !sp;
    }
    if (!sp)
    {
        for (int i=1;i<=(n<<1);i++)
        {
            cout << s[i];
        }
        cout << endl;
    }
    else
    {
        for (int i=n+1;i<=(n<<1);i++)
            cout << s[i];
        for (int i=1;i<=n;i++)
            cout << s[i];
        cout << endl;
    }

    return ;
}

int main()
{closeSync;
    // int T;
    // cin >> T;
    // while (T--)
        solve();
    return 0;
}

/*
3 4 4
GPLT
PATA
OMSA
*/


#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  vector<int> data(N);
  vector<long long> r(200, 0);

  for (int i = 0; i < N; ++i) {
    cin >> data.at(i);
    r[data.at(i) % 200]++;
  }

  long long ans = 0;
  //for (auto n : r) {
  //  cout << n.first <<"," << n.second << endl;
  //}
  for (int i = 0; i < 200; ++i) {
    ans += (r[i] * (r[i] - 1) / 2);
  }

  cout << ans << endl;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

#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 {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

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

void solve() {
    ll n;
    cin >> n;
    vec<ll> a(n), b(n);
    REP(i, n) {
        cin >> a[i];
    }
    REP(i, n) {
        cin >> b[i];
    }

    vec<ll> odds, evens;
    ll tmp = 0;
    REP(i, n) {
        tmp += a[i];
        if(i % 2)
            odds.push_back(b[i] - a[i]);
        else
            evens.push_back(b[i] - a[i]);
    }
    sort(all(odds), greater<ll>());
    sort(all(evens), greater<ll>());

    ll ans = tmp;
    REP(i, n / 2) {
        tmp += odds[i] + evens[i];
        chmax(ans, tmp);
    }
    cout << ans << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int NN = 2e5 + 5;
const int mo = 1e9 + 7;
const ld eps = 1e-9;
ll n;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    ll x = n % 100;
    x = 100 - x;
    cout << x << "\n";
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <numeric>
using namespace std;
using ll = long long;
//ループ
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
//コンテナ
#define all(x) (x).begin(),(x).end()
//関数
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; }

//-----global variable------------

//-----function definition--------

//-----main-----------------------
int main() {
    //----code here------------
    int X;
    cin >> X;

    cout << ( 100 - ( X % 100 ) ) << endl;

    //----return---------------
    return 0;
}


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

#define IOS         ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll            long long
#define t()           int t;cin>>t;while(t--)
#define lt()          long long int t;cin>>t;while(t--)
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define all(x)              begin(x),end(x)
#define  nik(i,k,n)    for ( long long int i = k; i < (n); ++i)

void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
ll gcd(ll A , ll B)
{
  if(B == 0)return A;
  return gcd(B , A%B);
}
ll fact(ll n){
   ll ans = 1;
   for(ll i=1;i<=n;i++){
      ans*=i%mod;
   }
   return ans%mod;
}

bool checkperfectsquare(int n)
{
    if (ceil((double)sqrt(n)) == floor((double)sqrt(n))) {
        return true;
    }
    return false;
}

bool isPowerOfTwo(ll n)
{
    if (n == 0)
        return 0;
    while (n != 1)
    {
        if (n%2 != 0)
            return 0;
        n = n/2;
    }
    return 1;
}

void fast()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}

char s[500005];

void solve()
{
    int n;
    cin >> n;
    vector<pair<int, string > > v;
    vector<int> t;
    while(n--){
        string s;
        int h;
        cin >> s >> h;
        t.pb(h);
        v.push_back({h , s});
    }
    sort(t.rbegin() , t.rend());

    int x  = t[1];

    for(auto p : v){
        if(p.first == x){
            cout << p.second << endl;

        }
    }

}
int32_t main()
{
   IOS;
   //lt(){
      solve();
   //}
   return 0;
}

#include<cstdio>
#include<algorithm>
using namespace std;
int Read()
{
    int Output=0;
    char Input=getchar();
    while(Input<'0'||Input>'9')
    Input=getchar();
    while(Input>='0'&&Input<='9')
    {
        Output=Output*10+Input-'0';
        Input=getchar();
    }
    return Output;
}
int N;
char Name[1001][16];
int T[1001];
int Max,Sec;
int main()
{
	N=Read();
	for(int i=1;i<=N;++i)
	{
		scanf("%s",Name[i]);
		T[i]=Read();
		if(T[i]>T[Max])
		{
			Sec=Max;
			Max=i;
		}
		else if(T[i]>T[Sec])
		Sec=i;
	}
	printf("%s",Name[Sec]);
}