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

// #pragma GCC target ("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("fpmath=387") //extra precision

#define debug_input cout<<"input"<<endl;freopen("input.txt","r",stdin);
#define debug_output cout<<"output"<<endl;freopen("output.txt","w",stdout);
#define debug_io debug_input;debug_output;

//start debugger
#define tpc template<class c
#define ckt(x) tpc> typename enable_if<sizeof ptb<c>(0) x 1, debug&>::type
#define rpt return *this
#define dop debug& operator <<
tpc> struct rge { c b, e; };
tpc> rge<c> range(c x, c y) { return rge<c>{x, y}; }
tpc> auto ptb(c* x) -> decltype(cerr << *x, 0);
tpc> char ptb(...);
struct debug {
#ifdef LOCAL
// ~debug() {cerr << "\u001b[0m\n";}
// debug() {cerr << "\u001b[33m";}
ckt(!=) operator <<(c x) { cerr << boolalpha << x; rpt; }
ckt(==) operator <<(c x) { rpt << range(x.begin(), x.end()); }
tpc, class b> dop(pair<c,b> x) { rpt << "(" << x.first << ", " << x.second << ")"; }
tpc> dop(rge<c> r) { *this << "{";
for(auto it = r.b; it != r.e; ++it) *this << ", "+2*(it==r.b) << *it; rpt << "}";}
#else
tpc> dop(const c&) {rpt;}
#endif
};
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end debugger

typedef double db;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

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

#define F first
#define S second
#define endl '\n'
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<(int)b;i++)
#define FORN(i,a,b) for(int i=a;i<=(int)b;i++)
#define FORB(i,a,b) for(int i=a;i>=(int)b;i--)
#define REP(i,x) FOR(i,0,x)
#define MEM(arr, x) memset(arr, (x), sizeof(arr))

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<str> vs;
typedef vector<pi> vii;
typedef vector<pl> vll;

// const int MOD = 1e9+7;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

ll MOD;
ll bin_pow(ll x,ll y){
    if(y == 0)  return 1;
    ll temp = bin_pow(x,y/2)%MOD;
    if(y&1) return (((temp*temp)%MOD)*x)%MOD;
    return (temp*temp)%MOD;
}
void solve(){
    ll n, m;
    cin>>n>>m;
    MOD = m * m;
    n = bin_pow(10, n);
    cout<<n/m<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    // cout.tie(nullptr);

    #ifdef LOCAL
        // system("cls");
        // debug_input;
        // debug_output;
        // debug_io;
    #endif

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

#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

void solve(long long N, std::vector<long long> a){
  ll ans=a[0];
  REP(N){
    ans=gcd(ans,a[i]);
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


#include <bits/stdc++.h>        //12.25 , -7,
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#include <fstream>
#define int unsigned long long int
#define mod 1000000007
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n"
#define watch2(x,y) cout<<(#x)<<" is "<<(x)<<" and "<<(#y)<< " is " <<(y)<<"\n"
int powerr(int m,int n){if(m==0 || n==1)return m;if(n==0)return 1;int ans = 1;if(n&1)ans = m*powerr(m,n-1);else {ans = powerr(m,n/2);ans = ans * ans;}return ans%mod;}
int gcdd(int a,int b){if(b==0)return a;   return gcdd(b,a%b);}
int lcmm(int a,int b){return (a*b)/gcdd(a,b);}

bool comparee(pair<int,int> &a,pair<int,int> &b){
    return a.first < b.first;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<pair<int,int>> v;
    for(int i=0;i<n;++i){
        int a,b;cin>>a>>b;
        v.push_back({a,b});
    }
    sort(v.begin(),v.end(),comparee);
    int summ = k;
    int pos = 0;
    for(int i=0;i<n;++i){
        if(v[i].first-pos<=summ){
            summ = summ - (v[i].first - pos);
            summ = summ + v[i].second;
            pos = v[i].first;
        }
        else {
            pos = pos + summ;
            summ = 0;
            break;
        }
    }
    pos = pos + summ;
    cout<<pos;
    return 0;
}

//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
    return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////

int32_t main() {
    boost; IO();

    int N,K; cin>>N>>K;
    vpi vec={{0,K}};
    FOR(i,0,N){
        int a,b; cin>>a>>b;
        vec.eb(a,b);
    }
    sort(all(vec));

    int ans=0,r=0;
    FOR(i,0,sz(vec)){
        r+=vec[i].se;

        if(i==sz(vec)-1) ans+=r;
        else{
            int d=vec[i+1].fi-vec[i].fi;
            if(d<=r){
                ans+=d;
                r-=d;
            }
            else{
                ans+=r;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}
//Change your approach


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

#define MAX_V 200005

ll A[MAX_V], X[MAX_V], Y[MAX_V];
ll buy[MAX_V];
ll ans = -3e9;
int V;
#define SZ(x) ((int)((x).size()))
vector<int> G[MAX_V];
bool used[MAX_V];
void add_edge(int from, int to){
    G[from].push_back(to);
}

int main() {
    ll N, M;
    cin >> N >> M;
    V = N;
    rep(i, N)cin >> A[i];
    rep(i, M){
        cin >> X[i] >> Y[i];
        X[i]--;
        Y[i]--;
        add_edge(X[i], Y[i]);
    }
    rep(i, MAX_V)buy[i] = 3e9;

    //mmax[0] = A[0];
    rep(v, N){
        //cout << v << " " << buy[v] << " " << A[v] << endl;

        chmax(ans, A[v] - buy[v]);
        rep(i, SZ(G[v])){
            ll j = G[v][i];
            chmin(buy[j], buy[v]);
            chmin(buy[j], A[v]);
        }
    }
    cout << ans;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define N 2114514
const ll mod = 998244353;
const ll inf = 1000000000000000000;

P a[N];
ll num[N];
bool used[N];
int main() {
    ll n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        ll x;
        cin >> x;
        num[i] = x;
        a[i] = {x, i};
    }
    vector<vector<ll>> v(n + 1);
    for (int i = 0; i < m; i++) {
        ll x, y;
        cin >> x >> y;
        v[x].push_back(y);
    }
    sort(a + 1, a + n + 1);
    queue<ll> que;
    ll ans = -inf;
    for (int i = 1; i <= n; i++) {
        que.push(a[i].second);
        ll ma = -inf;
        while (!que.empty()) {
            ll p = que.front();
            que.pop();
            for (ll x : v[p]) {
                if (used[x]) continue;
                used[x] = 1;
                ma = max(ma, num[x] - a[i].first);
                que.push(x);
            }
        }
        ans = max(ans, ma);
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define vec vector<int>
#define vecp vector<pair<int,int>>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fr first
#define sc second
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define fr2(i,a,b) for(int i=a;i>=b;i--)
#define fr3(i,a,b) for(int i=a;i<=b;i++)
#define umap unordered_map<int,int,custom_hash>
#define omap map<int,int>
#define uset unordered_set<int,custom_hash>
#define oset set<int>
#define pr pair<int,int>
#define mod 1000000007
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ppb pop_back

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

void solve()
{
  int n,m;
  cin>>n>>m;
  map<int,int> map1;
  fr1(i,0,n)
  {
    int x;
    cin>>x;
    map1[x]++;
  }
  fr1(i,0,m)
  {
    int x;
    cin>>x;
    map1[x]++;
  }
  for(auto i:map1)if(i.sc==1)cout<<i.fr<<" ";
  cout<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    fr3(i,1,t){
      //cout<<"Case: "<<t<<;
        solve();
    }
   return 0;
}

#include <bits/stdc++.h>
#define F first
#define S second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define RFOR(i, a, b) for(int i = a; i >= b; i--)
#define all(v) ((v).begin()), ((v).end())
#define endl '\n'

using namespace std;
using ll     = long long;
using ull    = unsigned long long;
using Graph  = vector<vector<int>>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vll    = vector<ll, ll>;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using BigInt = __int128;

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

  string s;
  cin >> s;

  if(s.size() == 1){
    cout << (stoi(s) % 8 ? "No" : "Yes");
    return 0;
  }

  if(s.size() == 2){
    if(stoi(s) % 8 == 0)
      return cout << "Yes", 0;
    swap(s[0], s[1]);
    if(stoi(s) % 8 == 0)
      return cout << "Yes", 0;
    return cout << "No", 0;
  }

  map<int, int> lookup;

  for (const auto& c : s)
    lookup[c-'0']++;

  for (int i = 100; i < 1000; i++) {
    if (i % 8) continue;
    int t = i;
    vi digits;
    while (t) digits.push_back(t%10), t/=10;

    bool ok = true;
    for (const auto& d : digits) {
      if (lookup[d] <= 0) ok = false;
      lookup[d]--;
    }

    if(ok) return cout << "Yes", 0;

    for (const auto& d : digits)
      lookup[d]++;
  }
  cout << "No";
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define endl '\n'

// n acho que eu seja bom, mas eu ja fui pior

using namespace std;

const int MAX = 1e5+7;
const int INF = 1e9+7;
const ll LLINF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1000000007;
const ld EPS = 1e-8;
const ld PI = acos(-1);

ll solve(ll n) {
    return (n*(n+1)) / 2;
}

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

    ll n; cin >> n;
    for (ll it = 1; it <= 1e9; it++) {
        if (solve(it) >= n) {
            cout << it << endl;
            return 0;
        }
    }

    return 0;
}

///

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fodec(i,a,b) for(int i=a;i>b;i--)
#define sz(v) int(v.size())
#define len(s) s.length()
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vvll vector<vector<ll>>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define piii pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define bit_cnt(x) __builtin_popcount(x)
#define fastio ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fileio freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define inf 1e9
#define cerr if(false)cerr
const int MOD = 1e9+7;

void solve(){

}

int main(){
    int n; cin>>n;
    int d=1;
    int tot=0;
    while(tot<n){
        tot+=d;
        d++;
    }
    cout<<d-1;
}


#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
using namespace std;
// タイプ定義
typedef long long llong;
// マクロ
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(llong i=llong(a);i<llong(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int A[3];

int main()
{
    cin >> A [0] >> A[1] >> A[2];
    std::vector<int> v;
    v.push_back(A[0]);
    v.push_back(A[1]);
    v.push_back(A[2]);

    std::sort(v.begin(), v.end());
    //cout << v[0] << v[1] << v[2];
    if((v[1]-v[0]) == (v[2]-v[1])) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

// In the name of God...
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 3000;
int a[N], t;
bool mark[N];
ll GCD(int n, int m){
	if(n == 0) return m;
	if(m == 0) return n;
	if(n > m) return GCD(n % m, m);
	return GCD(n, m % n);
}
///////////////////////////////
int main(){
	ios_base:: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	if(n * n + m * m >= k * k) cout << "No\n";
	else cout << "Yes\n";
	return false;
}


#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl

using namespace std;
using ll = long long;
using ld = long double;
ll MOD = 1000000007;
const ll root = 3;
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 200001;
vector<int> adj[mxN];
int dp[mxN];
int sz[mxN];
bool done[mxN];
int n;
void dfs(int u) {
    sz[u] = 1;
    vector<ttgl> t, o;
    vector<int> rst;
    int numod = 0;
    for(int v: adj[u]) {
        dfs(v);
        if(sz[v]&1){
            t.senpai({2*dp[v] - sz[v], v});
            numod++;
        }else {
            rst.senpai(v);
        }
        sz[u]+=sz[v];
    }
    sort(t.begin(), t.end());
    owo(_, 0, numod) {
        if(_&1) {
            //while(done[t[tid].second])tid--;
            dp[u] += sz[t[_].second] - dp[t[_].second];
        }else {//aoki choose a dp[0]
            //while(done[t[tid].second])tid++;
            dp[u]+=dp[t[_].second];
        }
    }
    for(int k: rst) {
        if(dp[k] < sz[k] - dp[k]) {
            dp[u]+=dp[k];
        }else{
            if(numod%2==0) dp[u]+=dp[k];
            else dp[u]+=sz[k]-dp[k];
        }
    }
    dp[u]++;
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    int a;
    owo(i, 1, n) {
        cin>>a;
        a--;
        adj[a].senpai(i);
    }
    dfs(0);
    cout<<dp[0]<<"\n";
    return 0;
}

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

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

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

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

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

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

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

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


////////////////////////////////////
///        ∧__∧                 ///
///　    （ '・ω・） < Let's        ///
///　    （ つ旦と）  Go AC        ///
///      と__)___）               ///
////////////////////////////////////
///      Coded In Sublime Text   ///
////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin >> in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout << out[i] << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(a, b) - min(c, d) << endl;
}

#include<bits/stdc++.h>
using namespace std;
int a[3];
int n1,n2,n;
int main(){
	int t,i,m,j,k;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]==a[1])
    {
    	cout<<a[2]<<endl;
	}
	else if(a[1]==a[2])
	{
	     cout<<a[0]<<endl;
	}
	else
	{
		cout<<0<<endl;
	}
}


#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define PRECISION cout << fixed << setprecision(20);

using namespace std;

template<class Fun>
class y_combinator_result {
    Fun fun_;
public:
    template<class T>
    explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

    template<class ...Args>
    decltype(auto) operator()(Args &&...args) {
        return fun_(std::ref(*this), std::forward<Args>(args)...);
    }
};

template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
    return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

void solve() {
    int n;
    cin >> n;
    vector<array<int, 5>> arr(n);
    vector<int> store;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 5; j++) {
            cin >> arr[i][j];
            store.push_back(arr[i][j]);
        }
    }

    sort(store.begin(), store.end(), greater<>());

    int low = 0, high = 1e9 + 6;

    auto check = [&](int x) -> bool {
        vector<int> mask(5, -1);
        auto get = y_combinator([&](auto get, int pos) -> bool {
            if (pos == 5) {
                vector<vector<int>> all(3);
                for (int i = 0; i < 5; i++) {
                    all[mask[i]].push_back(i);
                }
                for (int who = 0; who < 3; who++) {
                    if (all[who].size()) {
                        int done = 0;
                        for (int i = 0; i < n; i++) {
                            int ok = 1;
                            for (int j: all[who]) {
                                if (arr[i][j] < x) {
                                    ok = 0; break;
                                }
                            }
                            if (ok) {
                                done = 1;
                                break;
                            }
                        }
                        if (!done) {
                            return false;
                        }
                    }
                }
                return true;
            }

            for (int i = 0; i <= 2; i++) {
                mask[pos] = i;
                if (get(pos + 1)) {
                    return true;
                }
            }
            return false;
        });

        return get(0);
    };

    while (low + 1 < high) {
        int mid = (low + high) / 2;
        if (check(mid)) {
            low = mid;
        } else {
            high = mid;
        }
    };

    cout << low << "\n";
}

int main() {
    FASTIO;
    PRECISION;

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

    for (int i = 1; i <= t; i++) {
        solve();
    }
}

#include <bits/stdc++.h>

using namespace std ;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;

const ll mod = 1e9 + 7 ;

int main(){
    ll n ;
    cin >> n ;
    ll ans = 0 ;
    map<ll,ll> P ;
    rep(i,n){
        ll p ;
        cin >> p ;
        P[p]++ ;
        if( p == ans ){
            for(ll j = ans ; ans < 200003 ; j++ ){
                if(P[j] != 0 ) continue ;
                else{
                    cout << j << endl;
                    ans = j ;
                    break ;
                }
            }
        }
        else{
            cout << ans << endl ;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
const int p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int n,x[55];
long long ans=1e18;

void dfs(int i,long long j) {
	if (i==15) {
		for (int i=1; i<=n; ++i)
			if (__gcd((long long)x[i],j)==1) return;
		ans=min(ans,j); return;
	}
	dfs(i+1,j);
	dfs(i+1,j*p[i]);
}

int main() {
	cin>>n;
	for (int i=1; i<=n; ++i) cin>>x[i];
	dfs(0,1);
	cout<<ans;
}

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

typedef long long ll;
#define int ll
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb emplace_back
#define pii pair<int , int>
#define F first
#define S second
const int mod = 1000000007;
const int MAXX = 1e5 + 5;

int t , n;
int x[MAXX];

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

signed main()
{
    _FastIO;
    cin >> n;
    int a[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
    vector<int> v;
    for(int i = 1; i < (1 << 15); i++){
        int k = 1;
        for(int j = 0; j < 15; j++){
            if(i & (1 << j)){
               k *= a[j];
            }
        }
        v.pb(k);
    }
    sort(v.begin() , v.end());
    map<int , bool> m;
    int ans = 1;
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < v.size(); i++){
        bool f = true;
        for(int j = 0; j < n; j++){
            if(gcd(v[i] , x[j]) == 1)
                f = false;
        }
        if(f){
            cout << v[i] << endl;
            return 0;
        }
    }
    return 0;
}


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

int main()
{
    double N;
    cin >> N;
    double a;
    int ans;

    a = 1.08 * N;
    ans = a;

    if(ans < 206) {
        cout << "Yay!" << endl;
    }
    else if(ans == 206) {
        cout << "so-so" << endl;
    }
    else {
        cout << ":(" << endl;
    }

    //system("pause");
    return 0;
}

// Ref :

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

#define      tab                   "\t"
#define      endl                  "\n"
#define      pb                    emplace_back
#define      sz(x)                 int((x).size())
#define      gc                    getchar_unlocked
#define      gcd(x,y)              __gcd(x,y)
#define      all(a)                a.begin(), a.end()                           // usage in stl functions for traversing the container
#define      rep(i,a,b)            for(int i = a; i < b; i++)                   // @00G_aurkS00 @00G_aurkS00
#define      rrep(i,a,b)           for(int i = a; i >= b; i--)
#define      in(a,b)               ( (b).find(a) != (b).end() )                 // returns true(1) if element is present otherwise false(0)

#define      EPS                   1e-9
#define      INF                   (int)1e9
#define      MOD                   1000000007

#define      countLZ(x)            __builtin_clz(x)                             // returns the count of leading zeros in binary of a data upto first set(1) bit
#define      countTZ(x)            __builtin_ctz(x)                             // returns the count of trailing zeros in binary of a data from last set(1) bit
#define      checkbit(n,b)         ( (n >> b) & 1 )                             // @00G_aurkS00 @00G_aurkS00
#define      parityCheck(x)        __builtin_parity(x)                          // returns 1(true) if odd number of set bits present in int, long data
#define      setbitCount(x)        __builtin_popcount(x)                        // returns the number of one’s(set bits) in binary of an int, long data
#define      PI                    3.1415926535897932384626433832795

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

inline void boostIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input_6.txt","r",stdin);
        freopen("output_6.txt","w",stdout);
    #endif
}
/*=========================================================== End_Of_Header ===========================================================*/

int main(){
    //boostIO();
    ll tc = 1;
    //cin >> tc;

    while(tc--){
        ll n;
        cin >> n;
        ll ans = n*1.08;
        //cout << n*1.08 << endl;
        if ( ans > 206 ) cout << ":(" << endl;
        else if ( ans < 206 ) cout << "Yay!" << endl;
        else cout << "so-so" << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    std::ios::sync_with_stdio(false) , cin.tie(0) ;
    int n ;
    cin >> n ;
    vector<array<int , 2>> v(n) ;
    for(int i = 0 ; i < n ; i ++)  v[i][0] = i * 2 % n , v[i][1] = (i * 2 + 1) % n ;
    for(int i = 0 ; i < n ; i ++)  cout << v[i][0] + 1 << ' ' << v[i][1] + 1 << '\n' ;
    return 0 ;
}

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
template<class T>T ABS(T x) {return x<0?-x:x;}
//int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;}
//char __buf[1<<20],*__p1,*__p2;
//#define getchar() (__p1==__p2?(__p2=__buf+fread(__p1=__buf,1,1<<20,stdin),__p1==__p2?EOF:*__p1++):*__p1++)
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<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
const int maxn = 4e5+10;
//const int mod = ;
//struct Edge{int to,next;}a[maxn];int h[maxn],cnt;
//void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;}
//vector<int>G[maxn];
//void add(int x,int y) {G[x].push_back(y),G[y].push_back(x);}
int a[maxn],ans,n;
signed main() {
	n=read();
	for(int i=1;i<=n<<1;i++) a[i]=read();
	for(int i=1;i<=n<<1;i++) ans+=a[i];
	priority_queue<int,vector<int>,greater<int> >Q;
	for(int i=1;i<=n;i++) Q.push(a[n-i+1]),Q.push(a[n+i]),ans-=Q.top(),Q.pop();
	cout<<ans<<'\n';
	return 0;
}


#pragma GCC optimize("Ofast")
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Po = pair<double, double>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=ll(a);i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define PB push_back
#define MP make_pair
#define SZ(x) ll(x.size())
#define ALL(x) x.begin(),x.end()
#define NIL -1
#define INF pow(2,31)-1
#define MOD 1000000007
#define PI 3.14159265358979323846
#define endl "\n"
#define EPS 1e-9

template <class T, class U>
bool chmin(T& t, const U& u) {
	if (t > u) {
		t = u;
		return true;
	}
	else return false;
}
template <class T, class U>
bool chmax(T& t, const U& u) {
	if (t < u) {
		t = u;
		return true;
	}
	else return false;
}

ll powmod(ll x, ll n, ll mod) {
	ll s = 1;
	REP(i, n) {
		s = s * x % mod;
	}
	if (s < 0)s += mod;
	return s;
}

signed main() {
	ll n, m;
	cin >> n >> m;
	n++;
	ll c = 0;
	V<ll> w, h;
	REP(i, m) {
		ll a;
		cin >> a;
		w.push_back(a);
	}
	sort(ALL(w));
	REP(i, m) {
		if (w[i] - c >= 2) {
			h.push_back(w[i] - c-1);
		}
		c = w[i];
	}
	if (n - c >= 2)h.push_back(n - c-1);
	sort(ALL(h));
	if (SZ(h) == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll x = 1;
	FOR(i, 1, SZ(h) - 1) {
		if (h[i] % h[0] == 0)x += h[i] / h[0];
		else x += h[i] / h[0] + 1;
	}
	cout << x << endl;
}

#include <bits/stdc++.h>

using namespace std;

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

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

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

    cout << (a + b) / 2 << ' ' << (a - b) / 2;
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}


#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  2e3+5;
const ll   mod   =  998244353;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   LEVEL =  log2(N)+1;

ll n, m, t, a[N], b[N], dp[N][N];

ll mem(int i, int j){
	if(i == n + 1) return m - j + 1;
	if(j == m + 1) return n - i + 1;
	if(dp[i][j] != -1) return dp[i][j];
	dp[i][j] = INFi;
	if(a[i] != b[j])
		dp[i][j] = min(dp[i][j], mem(i + 1, j + 1) + 1);
	else
		dp[i][j] = min(dp[i][j], mem(i + 1, j + 1));
	dp[i][j] = min(dp[i][j], mem(i, j + 1) + 1);
	dp[i][j] = min(dp[i][j], mem(i + 1, j) + 1);
	return dp[i][j];

}

void solve(){
	mset(dp, -1);
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= m; i++) cin >> b[i];
	deb1(mem(1, 1))
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

#include<bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
int n,m;
int dp[2000][2000];
int a[2000],b[2000];
signed main(){
	memset(dp,10,sizeof(dp));
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=m;i++)cin>>b[i];
	dp[0][0]=0;
	for(int i=1;i<=n;i++)dp[i][0]=i;
	for(int i=1;i<=m;i++)dp[0][i]=i;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			int x=1;
			if(a[i]==b[j]){
				x=0;
			}
			dp[i][j]=min(dp[i-1][j]+1,min(dp[i][j-1]+1,dp[i-1][j-1]+x));
		}
	}
	cout<<dp[n][m]<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define repr(i,n) for (int i = (n)-1; i >= 0; --i)
#define rep1r(i,n) for (int i = (n); i > 0; --i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;

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

struct Solver{

    ll mindiff(vec(ll) a, vec(ll) b){
        ll res = llINF;

        ll idx=0;
        for(ll ai:a){
            while(idx<b.size()){
                ll bi = b[idx];
                chmin(res, abs(ai-bi));
                if(ai<=bi) break;
                idx++;
            }
        }
        return res;
    }

    void solve(){
        ll N;
        cin >> N;
        vec(ll) R,G,B;
        rep(i,2*N){
            ll ai;
            char ci;
            cin >>ai >> ci;
            if(ci=='R') R.push_back(ai);
            if(ci=='G') G.push_back(ai);
            if(ci=='B') B.push_back(ai);
        }

        if(R.size()%2==0 && G.size()%2==0 && B.size()%2==0){
            cout << 0 << endl;
            return;
        }

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

        ll ans = llINF;
        if(R.size()%2==0){
            ans = mindiff(R,G)+mindiff(R,B);
            chmin(ans, mindiff(G,B));
        }else if(G.size()%2==0){
            ans = mindiff(R,G)+mindiff(G,B);
            chmin(ans, mindiff(R,B));
        }else{
            ans = mindiff(R,B)+mindiff(G,B);
            chmin(ans, mindiff(G,R));
        }
        cout << ans << endl;
    }
};

int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}

#include<bits/stdc++.h>
#define FORz(i,t,n) for(int i=t;i<=n;i++)
#define FORf(i,n,t) for(int i=n;i>=t;i--)
#define SCC(x) scanf("%d",&x)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
using namespace std;
const int N=2e5+5;
const ll MOD=1e9+7;
// inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
//ll pow1(ll a,ll b){ll r=1;while(b){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll pow2(ll a,ll b,ll mod){ll r=1;while(b){if(b&1)r=r*a%mod;a=a*a%mod;b>>=1;}return r%mod;}
//ll gcd(ll a,ll b){ll m=a%b;while(m){a=b;b=m;m=a%b;}return b;}
void exgcd(ll a, ll b, ll &d, ll &x, ll &y){if(!b) { d = a; x = 1; y = 0;}else { exgcd(b, a % b, d, y, x); y -= x * (a / b); }}
ll inv(ll a){ll d, x, y;exgcd(a, MOD, d, x, y);return d == 1 ? (x + MOD) % MOD : -1;}struct node{ll mat[105][105];};node mul(node x,node y,int n,ll mod){node tmp;for(int i=0;i<n;i++)for(int j=0;j<n;j++){tmp.mat[i][j]=0;for(int k=0;k<n;k++)tmp.mat[i][j]+=(x.mat[i][k]*y.mat[k][j])%mod;tmp.mat[i][j]%=mod;}return tmp;}
// node matpow(node x,node y,ll num,int n,ll mod){while(num){if(num&1){y=mul(x,y,n,mod);}x=mul(x,x,n,mod);num=num>>1;}return y;}
//for(ll i=2;i<N-1;i++){if(!a[i]) b[++cnt]=i;for(ll j=1;j<=cnt&&i*b[j]<N;j++){a[i*b[j]]=1;if(i%b[j]==0) break;}}
//int find(int x){return a[x]==x?x:a[x]=find(a[x]);}
//void merge(int x,int y){a[find(y)]=a[find(x)];}
int n;
struct ty{
    ll a;
    char c;
    bool operator <(ty kk){
        return a<kk.a;
    }
}x[N];
char a[3];
int sum[500];
int w[500];
map<int,ll>mp;
int main()
{
    cin>>n;
    FORz(i,1,n<<1) cin>>x[i].a>>x[i].c,sum[x[i].c]++;
    int p=-1;
    if(sum['R']&1) a[++p]='R';else a[2]='R';
    if(sum['G']&1) a[++p]='G';else a[2]='G';
    if(sum['B']&1) a[++p]='B';else a[2]='B';
    if(!a[0]){
        cout<<0;
        return 0;
    }
    sort(x+1,x+(n<<1)+1);
    mp['R'+'B']=1e16,mp['R'+'G']=1e16,mp['B'+'G']=1e16;

    FORz(i,1,n<<1){
        w[x[i].c]=i;
        if(w['R']) mp['R'+x[i].c]=min(x[i].a-x[w['R']].a,mp['R'+x[i].c]);
        if(w['G']) mp['G'+x[i].c]=min(x[i].a-x[w['G']].a,mp['G'+x[i].c]);
        if(w['B']) mp['B'+x[i].c]=min(x[i].a-x[w['B']].a,mp['B'+x[i].c]);
    }
    cout<<min(mp[a[0]+a[1]],mp[a[0]+a[2]]+mp[a[1]+a[2]]);
}


#include <iostream>
#include <vector>
#include <map>

using namespace std;
map<int,vector<int>> mp;
bool dp[400010];
int main(){
    int i,n,m; cin >> n >> m;
    for(i=0;i<m;i++){
        int x,y; cin >> x >> y;
        mp[x].push_back(y);
    }
    for(i=0;i<=2*m;i++) dp[i] = false;
    dp[m] = true;
    map<int,bool> mp1;
    for(auto x:mp){
        vector<int> v = x.second;
        for(int y:v){
            if(y<n - m || y>n + m) continue;
            y -= n - m;
            //cout << x.first << " " << y << endl;
            if(y - 1>=0 && dp[y - 1]) mp1[y] = true;
            else if(y + 1<=2*m && dp[y + 1]) mp1[y] = true;
            else mp1[y] = false;
        }
        for(int y:v){
            if(y<n - m || y>n + m) continue;
            y -= n - m;
            //cout << x.first << " " << y << " " << mp1[y] << endl;
            if(mp1[y]) dp[y] = true;
            else dp[y] = false;
        }
        /*for(i=0;i<=2*m;i++) cout << dp[i];
        cout << endl;*/
    }
    int cnt = 0;
    /*for(i=0;i<=2*m;i++){
        cout << dp[i] << " ";
    }
    cout << endl;*/
    for(i=0;i<=2*m;i++) cnt += dp[i];
    cout << cnt << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

signed main(){
    int N,M;cin>>N>>M;

    map<int,vector<int>> v;
    rep(i,M){
        int h,w;cin>>h>>w;
        v[h].push_back(w);
    }

    set<int> st;
    st.insert(N);

    for(auto &p:v){
        vector<int> nxt,ers;
        for(auto &j:p.second){
            if(st.count(j)){
                if(!st.count(j-1) and !st.count(j+1)) ers.push_back(j);
            }else{
                if(st.count(j-1) or st.count(j+1)) nxt.push_back(j);
            }
        }
        for(auto &j:ers) st.erase(j);
        for(auto &j:nxt) st.insert(j);
    }
    cout<<st.size()<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FOR(i,x,n) for(int i=x;i<(n);i++)

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vll = vector<ll>;
using vvll = vector<vll>;
using Graph = vector<vector<int>>;

ll MOD = 998244353;
int main()
{
  ll N,sum=0;
  ll ans = 0;
  cin>>N;
  vll A(N);
  rep(i,N)
  {
    cin >> A[i];
    A[i] %= MOD;
  }
  sort(all(A));
  if(N==1)
    {
      ans = A[0] * A[0];
      ans %= MOD;
      cout << ans << endl;
      return 0;
    }
  if(N==2)
  {
    ans += A[0] * A[1];
    ans %= MOD;
    ans += A[0] * A[0];
    ans %=MOD;
    ans += A[1] * A[1];
    ans %= MOD;
    cout << ans << endl;
    return 0;
  }
  else
  {
      ll temp = 2;
      FOR(i, 2, N)
      {
        sum += temp * A[i];
        sum %= MOD;
        temp *= 2;
        temp %= MOD;
  }
  ll kasanari = 0;
  rep(i,N-1)
  {
    kasanari += A[i] * A[i];
    kasanari %= MOD;
    kasanari += A[i] * A[i + 1];
    kasanari %= MOD;
  }
  kasanari += A[N - 1] * A[N - 1];
  kasanari %= MOD;
  rep(i,N-2)
  {
    ans += A[i] * sum;
    ans %= MOD;
    if (sum %2)
    {
      sum += MOD;
    }
    sum /= 2;
    if (sum < A[i + 2])
      sum += MOD;
    sum -= A[i + 2];
    sum %= MOD;
  }
  ans += kasanari;
  ans %= MOD;
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure
// using namespace __gnu_pbds;              //Policy Based Data Structure
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; //Policy Based Data Structure
// #define gc              getchar_unlocked
// #define pqb             priority_queue<int>
// #define pqs             priority_queue<int, vi, greater<int> >
// #define mk(arr,n,type)  type *arr = new type[n]
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int             long long
#define endl            '\n'
#define w(t)            int t; cin>>t; while(t--)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x,y)       cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define all(x)          x.begin(), x.end()
#define clr(x)          memset(x, 0, sizeof(x))
#define sortall(x)      sort(all(x))
#define tr(it,a)        for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define PI              3.1415926535897932384626
#define inf             1e18
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());  //Random Shuffler
typedef pair<int, int>   pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
typedef map<int, int>    mii;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
// const int N = 3e5, M = N;
// vi g[N];
//=======================
//and==1 OR==2

void sol()
{
	int i, n;
	cin >> n;
	int a[n];
	fo(i, n)
	{
		string s;
		cin >> s;
		if (s == "AND")
			a[i] = 1;
		else
			a[i] = 2;
	}
	int tr = 0, fl = 0;
	if (a[0] == 1)
	{
		tr = 1;
		fl = 3;
	}
	else
	{
		tr = 3;
		fl = 1;
	}
	Fo(i, 1, n) {
		if (a[i] == 1) {
			tr *= 1;
			fl = (fl * 2 ) + tr;
		}
		else {
			tr = (tr * 2);
			tr += fl;
		}
	}
	cout << tr;
}

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

	sol();

	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = (result * base) % mod;
		base = (base * base) % mod;
		exp >>= 1;
	}
	return result;
}

// void ipgraph(int n, int m){
//     int i, u, v;
//     while(m--){
//         cin>>u>>v;
//         g[u-1].pb(v-1);
//         g[v-1].pb(u-1);
//     }
// }
//
// void dfs(int u, int par){
//     for(int v:g[u]){
//         if (v == par) continue;
//         dfs(v, u);
//     }
// }


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using db = double;
using vi = vector<int>;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout << #x <<"	"<< x <<endl
const int inf = 0x3f3f3f3f;
const db eps = 1e-8;
const int mod = 1e9+7;
ll qpow(ll a, ll b){
    ll ret = 1;
    while(b){
        if(b&1)ret = ret*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ret;
}
const int maxn = 1<<10;
int n;
int a[maxn], b[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
	cin >> n;
	for(int i=1; i<=n; ++i){
		a[i] = (2*i)%n+1;
		b[i] = (2*i+1)%n+1;
	}
	for(int i=1; i<=n; ++i)cout << a[i] <<" " << b[i] <<"\n";
    return 0;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<int32> p(n);
  REP(i,n)cin >> p[i],--p[i];
  queue<int32> que;
  vector<bool> used(n,false);
  REP(i,n-1){
    if(i < p[i] && p[i+1] < i+1)que.emplace(i);
  }
  vector<int32> ans;
  while(que.size()){
    int32 i = que.front();que.pop();
    if(!(i < p[i] && p[i+1] < i+1))continue;
    if(used[i]){
      ANS(-1);
      return 0;
    }
    ans.emplace_back(i);
    used[i] = true;
    swap(p[i],p[i+1]);
    if(i-1 >= 0 && i-1 < p[i-1] && p[i] < i)que.emplace(i-1);
    if(i+2 < n && i+1 < p[i+1] && p[i+2] < i+2)que.emplace(i+1);
  }
  REP(i,n){
    if(p[i] != i){
      ANS(-1);
      return 0;
    }
  }
  if(ans.size() != n-1){
    ANS(-1);
    return 0;
  }
  REP(i,n-1)ANS(ans[i]+1);
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
const int N =2000005;
int cnt[20];
bool check(int x) {
	int key[10]={};
	while(x) {
		key[x%10]++;
		x/=10;
	}
	for(int i=0;i<10;++i) {
		if(key[i]>cnt[i])
		return false;
	}
	return true;
}
int main()
{
	char ch[N];
	scanf("%s",ch);
	getchar();
	int len=strlen(ch);
	for(int i=0;i<len;++i) {
		cnt[ch[i]-'0']++;
	}
	if (len==1) {
		if(ch[0]=='8')
		puts("Yes");
		else
		puts("No");
	}
	else if (len==2) {
		int a=(ch[0]-'0')*10+ch[1]-'0';
		int b=(ch[1]-'0')*10+ch[0]-'0';
		if(a%8==0||b%8==0)
		puts("Yes");
		else
		puts("No");
	}
	else {
		for(int i=104;i<1000;i+=8) {
			if (check(i)) {
				puts("Yes");
				return 0;
			}
		}
		puts("No");
	}

	return 0;
}

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <unordered_set>

using namespace std;

class InputReader {
public:
    InputReader() {}
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
    inline InputReader &operator >>(long long &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

const int MAXN = 200000;

int a[1 + MAXN], b[1 + MAXN], p[1 + MAXN];

bool compare(const int &i, const int &j) {
    return a[i] > a[j];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //ifstream cin("input.txt");
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    vector<int> bad;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        if (p[i] != i) {
            if (b[p[i]] >= a[i]) {
                cout << "-1\n";
                return 0;
            }
            bad.push_back(i);
        }
    }
    sort(bad.begin(), bad.end(), compare);
    vector<pair<int, int> > op;
    for (auto x : bad) {
        while (p[x] != x) {
            int y = p[x];
            op.push_back(make_pair(x, y));
            swap(p[x], p[y]);
        }
    }
    for (int i = 1; i <= n; i++) {
        assert(p[i] == i);
    }
    cout << op.size() << "\n";
    for (auto it : op) {
        cout << it.first << " " << it.second << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e2 + 7;
char dp[MAX_N][MAX_N];
char s[MAX_N];
int n, k;

int f_pow(int base, int b, int mod) {
	int res = 1;
	while (b) {
		if (b & 1) res = res * base % mod;
		base = base * base % mod;
		b >>= 1;
	}
	return res;
}

char ans(char a, char b) {
	if (a == 'P') {
		if (b == 'R') return 'P';
		if (b == 'S') return 'S';
		return 'P';
	} else if (a == 'R') {
		if (b == 'S') return 'R';
		if (b == 'P') return 'P';
		return 'R';
	} else {
		if (b == 'P') return 'S';
		if (b == 'R') return 'R';
		return 'S';
	}
}

int main() {
	scanf("%d%d", &n, &k);
	scanf("%s", s);
	for (int i = 0; i < n; ++i) dp[i][0] = s[i];
	for (int j = 1; j <= k; ++j) {
		for (int i = 0; i < n; ++i) {
			char a = dp[i][j - 1], b = dp[(i + f_pow(2, j - 1, n)) % n][j - 1];
			dp[i][j] = ans(a, b);
		}
	}
	printf("%c\n", dp[0][k]);
	return 0;
}

#include <bits/stdc++.h>
#define endl '\n'
#define sz(X) X.size()
#define IO cin.tie(0), ios_base::sync_with_stdio(0);
#define FOR(N) for(int i=0;i<N;++i)
#define FORf(X,V,N) for(int X=V;X<N;++X)
#define FORi(X,V,N,S) for(int X=V;(S>0?X<N:X>=N);X+=S)
#define EACH(X, V) for(auto& X : V)
#define For(X, V, N) for(int X = V, Len = N, X < V; ++X)
#define All(X) X.begin(), X.end()
#define ar array
using ll = long long;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T, class C>
using Pset = tree<T, null_type, C, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class P> inline bool umax(T& x, P y) {
	bool big; x = (big = x>y) ? x : y; return !big;
}
template<class T, class P> inline bool umin(T& x, P y) {
	bool big; x = (big = x<y) ? x : y; return !big;
}
template<class T> istream& operator>>(istream& is, vector<T>& vt) {
	for(auto& i : vt)
		is >> i;
	return is;
}
template<class T, unsigned int N> istream& operator>>(istream& is, array<T, N>& ary) {
	for(auto& i : ary)
		is >> i;
	return is;
}
template<class T1, class T2> istream& operator>>(istream& is, pair<T1, T2>& pr) {
	is >> pr.first >> pr.second;
	return is;
}
template<class T> void read(T& x) {
	cin >> x;
	cin.get();
}
template<class T, class ... P> void read(T& x, P& ... t) {
	cin >> x;
	read(t...);
}
template<class T> void readl(T& x) { // readline
	getline(cin, x);
}
template<class T, class ... P> void readl(T& x, P& ... t) {
	getline(cin, x);
	readl(t...);
}

template<class T> void write(T x) {
	cout << x;
}
template<class T, class ... P> void write(T x, P ... t) {
	cout << x;
	write(t...);
}
void print() { cout << '\n'; }
template<class T> void print(T x) {
	cout << x << '\n';
}
template<class T, class ... P> void print(T x, P ... t) {
	cout << x << ' ';
	print(t...);
}

#define fastIO

void solve() {
	string n;
	int k;
	read(n, k);
	while(k--) {
		if(sz(n) < 3)
			n += "200";
		else if(n.substr(sz(n)-2, 2) == "00" && ((n[sz(n)-3]-'0')&1) == 0) {
			int f = 0;
			FOR(2)
				n.pop_back();
			EACH(s, n) {
				int i = s-'0'+f*10;
				s = i/2+'0';
				f = i&1;
			}
		} else {
			n += "200";
		}
	}
	int id = 0;
	while(n[id] == '0')
		++id;
	print(n.substr(id, sz(n)-id));
}

int main() {
#ifdef fastIO
	IO;
#endif
	//int t;
	//cin >> t;
	//while(t--)
		solve();
}


#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N, M; cin >> N >> M;
  map<i64, vector<i64>> PC; //
  unordered_set<i64> reachable;
  REP(0, M, i) {
    i64 X, Y; RI(X); RI(Y);
    PC[X].pb(Y);
  }

  reachable.insert(N);
  for(auto &pc: PC) {
    if(pc.first == 0) {
      continue;
    }

    vi &xs = pc.second;
    vi add, remove;

    for(auto &x: xs) {
      if(IN(reachable, x)) {
        remove.pb(x);
      }
      if(IN(reachable, x-1) || IN(reachable, x+1)) {
        add.pb(x);
      }
    }

    for(auto &r: remove) {
      auto it = reachable.find(r);
      reachable.erase(it);
    }
    for(auto &a: add) {
      reachable.insert(a);
    }

#if 0
    cerr << pc.first << endl;
    for(auto &r: reachable) {
      cerr << r << " ";
    }
    cerr << endl;
#endif
  }

  WI(sz(reachable));

  return 0;
}

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
vector<pair<int, int>> a[2*N];
vector<int> b[2*N];
int n, m;
int ans = 0;
bool vis[2*N];
void dfs(int x){
	// cout<<x<<endl;
	if(vis[x])return;
	vis[x]=1;
	if(x>m)++ans;
	for(auto it:b[x])dfs(it);
}
map<int, int> mp;
int main(){
	scanf("%d%d",&n,&m);
	int x, y;
	int cnt = 1;
	for(int i=1; i<=m; ++i){
		scanf("%d%d",&x,&y);
		if(mp.count(y)==0)
			mp[y]=cnt++;
		a[mp[y]].push_back(mk(x,i));
	}
	if(mp.count(n)==0)mp[n]=cnt++;
	a[mp[n]].push_back(mk(0,0));
	cnt = m+1;
	for(auto ii:mp){
		int i=ii.sc;
		if(a[i].size()==0)continue;
		a[i].push_back(mk(2*n+1, cnt++));
		sort(a[i].begin(), a[i].end());
	}
	for(auto ii:mp){
		int i=ii.sc;
		if(a[i].size()==0)continue;
		int p1=0, p2=0, k1 = mp[ii.fs+1], k2 = mp[ii.fs-1];
		for(int j=0; j+1<a[i].size(); ++j){
			auto it=a[i][j];
			for(p1;p1+1<a[k1].size();++p1){
				// cout<<ii.fs<<" "<<it.fs<<" "<<a[k1][p1].fs<<endl;
				if(a[k1][p1].fs>it.fs && a[k1][p1].fs<=a[i][j+1].fs)
					b[it.sc].push_back(a[k1][p1].sc);
				if(a[k1][p1].fs>a[i][j+1].fs)
					break;
			}
			for(p2;p2+1<a[k2].size();++p2){
				// cout<<ii.fs<<" "<<it.fs<<" %"<<a[k1][p1].fs<<endl;
				if(a[k2][p2].fs>it.fs && a[k2][p2].fs<=a[i][j+1].fs)
					b[it.sc].push_back(a[k2][p2].sc);
				if(a[k2][p2].fs>a[i][j+1].fs)
					break;
			}
		}
		int j=a[i].size();
		b[a[i][j-2].sc].push_back(a[i][j-1].sc);
	}
	ans = 0;
	dfs(0);
	cout<<ans<<endl;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <set>
#include <iostream>
#include <fstream>
#include <chrono>

using namespace std;

const int MOD = 998244353;

int calcPow(int a, int b) {
    if (a == 0)
        return 0;
    if (b == 0)
        return 1;
    if (b == 1)
        return a % MOD;
    int64_t ans = calcPow(a, b / 2);
    ans = (ans * ans) % MOD;
    if (b % 2 == 1)
        ans = (ans * a) % MOD;
    return ans;
}

void solve(int test, istream &in) {
    int n, m, k;
    in >> n >> m >> k;
    vector<int> powM(k + 1), powN(k + 1);
    for (int i = 0; i <= k; i++) {
        powM[i] = calcPow(i, m);
        powN[i] = calcPow(i, n);
    }
    int64_t answer = 0;
    for (int c = 1; c <= k; c++) {
        int64_t cur1 = (powN[c] - powN[c - 1]) % MOD;
        int64_t cur2 = powM[k - c + 1];
        if (n == 1 || m == 1)
            cur2 = (cur2 - powM[k - c]) % MOD;
        answer = (answer + cur1 * cur2) % MOD;
    }
    if (answer < 0)
        answer += MOD;
    printf("%lld\n", answer);
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
    ifstream f("in.txt");
    auto start = std::chrono::steady_clock::now();
#else
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }
#ifdef VLAD_LOCAL
    auto end = std::chrono::steady_clock::now();
    double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
    printf("%.3lf\n", seconds);
#endif
    return 0;
}

//#pragma GCC optimize(3)
#include <bits/stdc++.h>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
#include<iostream>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const ll INF= 1e18+7;
const ll maxn = 2e6+700;
const int M = 2e5+700;
const ll mod= 998244353;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a){char c=getchar();T x=0,f=1;while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}a=f*x;}
ll n,m;
ll a[maxn];
int dp[25][5005];
int s[5005][5005];
ll cal(ll x,ll y){
    if(y == 0 || x == y) return s[x][y] = 1;
    if(y == 1) return s[x][y] = x%mod;
    if(~s[x][y]) return s[x][y];
    return s[x][y] = (cal(x-1,y) + cal(x-1,y-1))%mod;
}
int main(){
  memset(s,-1,sizeof(s));
  read(n);read(m);
  dp[0][0] = 1;
  for(int i=1;i<=20;i++){
    if((1<<(i-1))>m){
      printf("%d\n",dp[i-1][m]);
      return 0;
    }
    for(int k=0;k<=n;k+=2){
      ll tmp = k*(1<<(i-1));
      if(tmp>m) break;
      for(ll j=tmp;j<=m;j++){
        dp[i][j] = (dp[i][j]+dp[i-1][j-tmp]*cal(n,k))%mod;
      }
    }
  }
  return 0;
}
/***
6

1 1 2 2 2 2
***/


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int num;
	scanf("%lld",&num);
	string str1,str2;
	cin>>str1>>str2;
	int cur=0,ans=0;
	vector<int>v;
	for(int i=0;i<num;i++)
	{
		if(str1[i]=='1')
		v.push_back(i);
	}
	for(int i=0;i<num;i++)
	{
		if(str1[i]==str2[i]) continue;
		while(cur<v.size()&&v[cur]<=i) cur++;
		if(cur>=v.size())
		{
			printf("-1");
			return 0;
		}
		ans+=v[cur]-i;
		str1[v[cur]]='0';
		cur++;
	}
	cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define i64 int64_t
#define u64 uint64_t
const i64 inf = 1e17;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
#define endl "\n"
#define all(a) a.begin(),a.end()
#define overload(_1,_2,_3,_4,name,...) name
#define _rep1(n) for(int i = 0; i < (n); i++)
#define _rep2(i,n) for(int i = 0; i < (n); i++)
#define _rep3(i,a,b) for(int i = (a); i < (b); i++)
#define _rep4(i,a,b,c) for(int i = (a); i < (b); i += (c))
#define rep(...) overload(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep2(i,n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define _rrep4(i,a,b,c) for(int i = (b) - 1; i >= (a); i -= (c))
#define rrep(...) overload(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define ForEach(a,b) for_each(a.begin(),a.end(),b)
#define NextAfter(x) x = nextafter(x, INFINITY)
template <class T> bool chmin(T& a, T b){ if(a > b){ a = b; return 1; } return 0; }
template <class T> bool chmax(T& a, T b){ if(a < b){ a = b; return 1; } return 0; }
struct Edge { int to; i64 cost; Edge(int to, i64 cost) : to(to), cost(cost) {} };
using Graph = vector<vector<Edge>>;

bool check(string &x, i64 n, i64 m) {
  i64 val = 0;
  rep(x.size()) {
    if (val > (m-(x.at(i)-'0')+n-1)/n) {
      val = m+1;
      break;
    }
    val = val * n + (x.at(i) - '0');
  }
  return val <= m;
}

void Main() {
  string x;
  i64 m;
  cin >> x >> m;
  if (x.size() == 1) {
		if (stoi(x) <= m)
			cout << 1 << endl;
		else
			cout << 0 << endl;
		return;
	}
  i64 lb_init = *max_element(all(x)) - '0';
  i64 lb = lb_init, ub = m+1;
  while (ub - lb > 1) {
    i64 mid = (lb + ub)/2;
    if (check(x, mid, m))
      lb = mid;
    else
      ub = mid;
  }
  cout << lb - lb_init << endl;
}

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


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll mod = 1e9 + 7;
const ll linf = 1LL << 62;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
ll V[400010];
ll sum;
int main() {
    cin >> N;
    for (int i = 0; i < 2 * N; i++) {
        cin >> V[i];
        sum += V[i];
    }
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    ll ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        pq.push(V[i]);
        pq.push(V[2 * N - i - 1]);
        ans += pq.top();
        pq.pop();
    }
    cout << sum - ans << endl;
}

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

long long sisu(long long n, long long k) {
	long long a = 1;
	for (long long i = 0; i < k; i++) {
		a *= n;
	}
	return a;
}

int main() {

	int N;
	cin >> N;

	long long max1=-1, max2=-1, b1,b2;

	vector<long long> A(sisu(2, N-1));
	vector<long long> B(sisu(2, N-1));
	vector<pair<long long, long long>> S;
	for (int i = 0; i < sisu(2, N); i++) {
		long long k;
		cin >> k;
		if (i >= sisu(2, N - 1)) {
			B.at(i - sisu(2, N - 1)) = k;
			if (max2 < k) {
				max2 = k;
				b2 = i + 1;
			}
		}
		else {
			A.at(i) = k;
			if (max1 < k) {
				max1 = k;
				b1 = i + 1;
			}
		}
		S.push_back(make_pair(k, i));
	}
	sort(S.begin(), S.end());

	if (S.at(sisu(2, N) - 1).second >= sisu(2, N - 1)){
		cout << b1;
	}
	else {
		cout << b2;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(ll i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define coy cout<<"Yes"<<endl
#define con cout<<"No"<<endl
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF (ll)1e18+10
using ll = long long;

using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
using PIP = pair<int, P>;
using Ps = pair<int, string>;

using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
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; }

//const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll MAX = 100;
template <typename T>
T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error
//////////////////////////////////////

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

    vvi a(r, vi(c - 1)), b(r - 1, vi(c));

    rep(i, r)rep(j, c - 1)cin >> a[i][j];
    rep(i, r - 1)rep(j, c)cin >> b[i][j];

    vvi dist(r, vi(c, INF));
    --r, --c;

    priority_queue<PIP, vector<PIP>, greater<PIP>> q;

    dist[0][0] = 0;
    q.push(PIP(0, P(0, 0)));

    auto ok = [&](int x, int y) {
        return x >= 0 & x <= r && y >= 0 && y <= c;
    };
    while (q.size()) {
        PIP t = q.top(); q.pop();
        P now = t.second;
        int d = t.first;

        if (d > dist[now.fs][now.sc])continue;

        {
            int nx = now.fs, ny = now.sc + 1;
            if (ok(nx, ny)) {
                int nd = dist[now.fs][now.sc] + a[now.fs][now.sc];
                if (chmin(dist[nx][ny], nd))q.push(PIP(dist[nx][ny], P(nx, ny)));
            }
        }

        {
            int nx = now.fs, ny = now.sc - 1;
            if (ok(nx, ny)) {
                int nd = dist[now.fs][now.sc] + a[nx][ny];
                if (chmin(dist[nx][ny], nd))q.push(PIP(dist[nx][ny], P(nx, ny)));
            }
        }
        {
            int nx = now.fs + 1, ny = now.sc;
            if (ok(nx, ny)) {
                int nd = dist[now.fs][now.sc] + b[now.fs][now.sc];
                if (chmin(dist[nx][ny], nd))q.push(PIP(dist[nx][ny], P(nx, ny)));
            }
        }

        rep(i, now.fs) {
            int nx = now.fs - i - 1, ny = now.sc;
            if (ok(nx, ny)) {
                int nd = dist[now.fs][now.sc] + i + 2;
                if (chmin(dist[nx][ny], nd))q.push(PIP(dist[nx][ny], P(nx, ny)));
            }
        }
    }

    cout << dist[r][c] << endl;
    return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    REP(i, H) {
        cin >> S[i];
    }

    int edge = 0;

    REP(i, H - 1) {
        REP(j, W - 1) {
            int white = 0;
            FOR(k, i, i + 2) {
                FOR(l, j, j + 2) {
                    if(S[k][l] == '.') {
                        white++;
                    }
                }
            }
            if(white == 1 || white == 3) {
                edge++;
            }
        }
    }
    cout << edge << endl;
    return 0;
}


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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;
  std::unordered_map<int, int> mx;
  std::unordered_map<int, int> mn;

  rep(i, N)
  {
    int x, c;
    cin >> x >> c;

    if (mx.find(c) != mx.end())
    {
      mx[c] = std::max(mx[c], x);
      mn[c] = std::min(mn[c], x);
    }
    else
    {
      mx[c] = x;
      mn[c] = x;
    }
  }

  long long time1 = 0;
  long long time2 = 0;
  int pos1 = 0;
  int pos2 = 0;
  for (int i = 1; i <= N; i++)
  {
    if (mx.find(i) != mx.end())
    {
      long long diff = std::abs(mx[i] - mn[i]);
      long long tmp1 = time1;
      long long tmp2 = time2;
      // from pos1, mx -> mn
      tmp1 += std::abs(pos1 - mx[i]) + diff;

      // from pos2, mx -> mn
      tmp2 += std::abs(pos2 - mx[i]) + diff;

      long long tmp3 = time1;
      long long tmp4 = time2;
      // from pos1, mn -> mx
      tmp3 += std::abs(pos1 - mn[i]) + diff;

      // from pos2, mn -> mx
      tmp4 += std::abs(pos2 - mn[i]) + diff;

      time1 = std::min(tmp1, tmp2);
      time2 = std::min(tmp3, tmp4);

      pos1 = mn[i];
      pos2 = mx[i];
    }
  }

  time1 += std::abs(pos1);
  time2 += std::abs(pos2);

  cout << std::min(time1, time2) << endl;

  return 0;
}

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

bool onBoard(int y, int x) {
    if (y >= 0 && y < H && x >= 0 && x < W) {
        return true;
    }
    return false;
}

int main() {
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) {
        cin >> S[i];
    }
    vector<set<P>> sets(26);

    P start, goal;

    rep(i, H) rep(j, W) {
        int t = S[i][j] - 'a';
        if (t >= 0 && t < 26) {
            // cerr << "i=" << i << " j=" << j << "S[i][j] =" << S[i][j] << endl;
            sets[t].insert(P(i, j));
        }
        if (S[i][j] == 'S') {
            start = P(i, j);
        }
        if (S[i][j] == 'G') {
            goal = P(i, j);
            S[i][j] = '.';
        }
    }
    rep(i, H) rep(j, W) {
        d[i][j] = -1;
    }

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

    queue<P> q;
    q.push(start);
    d[start.first][start.second] = 0;
    while (!q.empty()) {
        P p = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if (onBoard(ny, nx) && S[ny][nx] != '#' && d[ny][nx] == -1) {
                d[ny][nx] = d[p.first][p.second] + 1;
                q.push(P(ny, nx));
            }
        }
        int t = S[p.first][p.second] - 'a';
        if (t >= 0 && t < 26) {
            for (auto itr = sets[t].begin(); itr != sets[t].end(); ++itr) {
                int ny = itr->first, nx = itr->second;
                if (d[ny][nx] == -1) {
                    d[ny][nx] = d[p.first][p.second] + 1;
                    q.push(P(ny, nx));
                }
            }
            sets[t].clear();
        }
    }

    cout << d[goal.first][goal.second] << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int kN = 2e5 + 10;

int main() {
  int n; scanf("%d", &n);
  vector<long long> v[3];
  auto ID = [&](char c) {
    if(c == 'R') return 0;
    else if(c == 'G') return 1;
    return 2;
  };
  for(int i = 0; i < 2 * n; i++) {
    long long x; char c[2];
    scanf("%lld%s", &x, c);
    v[ID(c[0])].push_back(x);
  }

  for(int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end());

  bool flag = 1;
  for(int i = 0; i < 3; i++) flag &= (int(v[i].size()) % 2 == 0);
  if(flag) return puts("0"), 0;

  long long ans = 1e17;
  for(int i = 0; i < 3; i++) if(int(v[i].size()) % 2 == 0) {
    int j1 = (i + 1) % 3, j2 = (i + 2) % 3;
    for(int k = 0, r = 0; k < int(v[j1].size()); k++) {
      while(r < int(v[j2].size()) && v[j2][r] < v[j1][k]) r++;
      if(r < int(v[j2].size())) ans = min(ans, v[j2][r] - v[j1][k]);
    }
    for(int k = 0, r = 0; k < int(v[j2].size()); k++) {
      while(r < int(v[j1].size()) && v[j1][r] < v[j2][k]) r++;
      if(r < int(v[j1].size())) ans = min(ans, v[j1][r] - v[j2][k]);
    }

    long long mn1 = 1e17;
    for(auto x : v[j1]) {
      auto it = lower_bound(v[i].begin(), v[i].end(), x);
      if(it != v[i].end()) mn1 = min(mn1, *it - x);
      if(it != v[i].begin()) mn1 = min(mn1, x - *prev(it));
    }
    long long mn2 = 1e17;
    for(auto x : v[j2]) {
      auto it = lower_bound(v[i].begin(), v[i].end(), x);
      if(it != v[i].end()) mn2 = min(mn2, *it - x);
      if(it != v[i].begin()) mn2 = min(mn2, x - *prev(it));
    }

    ans = min(ans, mn1 + mn2);
    printf("%lld\n", ans);
    return 0;
  }

  return 0;
}

#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> T[20];

int query(int h, int k, int i, int j)
{
	int m = (k << h) + (1 << (h - 1));
	if(i == (k << h) && j == ((k + 1) << h) - 1) return T[h][k];
	if(j < m) return query(h - 1, k << 1, i, j);
	if(i >= m) return query(h - 1, k << 1 | 1, i, j);
	return query(h - 1, k << 1, i, m - 1) ^ query(h - 1, k << 1 | 1, m, j);
}

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	int d = ceil(log2(n));
	for(int i = 0; i <= d; i++)
	{
		T[i].clear();
		T[i].resize(1 << (d - i), 0);
	}
	for(int i = 0; i < n; i++)
		scanf("%I64d", &T[0][i]);
	for(int i = 1; i <= d; i++)
		for(int j = 0; j < (int)T[i].size(); j++)
			T[i][j] = T[i - 1][j << 1] ^ T[i - 1][j << 1 | 1];
	for (int i = 0; i < q; i++) {
		int t, x, y;
		scanf("%d%d%d", &t, &x, &y);
		if (t == 2) {
			printf("%d\n", query(d, 0, x - 1, y - 1));
		} else {
			int p = x - 1;
			T[0][p] = T[0][p] ^ y;
			p >>= 1;
			for (int j = 1; j <= d; j++) {
				T[j][p] = T[j - 1][p << 1] ^ T[j - 1][p << 1 | 1];
				p >>= 1;
			}
		}
	}
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
 int n;
 cin>>n;
 if(n%2==0)
 cout<<"White"<<endl;
 else if(n%2!=0)
 cout<<"Black"<<endl;
return 0;
}

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

int main(){
    string N;
    cin >> N;
    N = N.substr(0, N.find_last_not_of('0') + 1);

    string s;
    s = N;
    std::reverse(N.begin(), N.end());

    // cout << s << N << endl;

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

}


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define MOD1 998244353
#define ceil(x, y) ((x)%(y))==0? ((x)/(y)) : ((x)/(y)+1)
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int 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 dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in7.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int T=1;
    // cin >> T;
    FOR1(tt, T){
        // cout << "Case #" << tt << ": ";
        int m, h; cin >> m >> h;
        if(h % m == 0) cout << "Yes";
        else cout << "No";

        cout << '\n';
    }
    return 0;
}

//a solutjion from @tanmaymodi
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ff(i,a,b) for(ll i=a;i<=b;i++)
#define bf(i,a,b) for(ll i=a;i>=b;i--)
const ll INF = 1e18;

//_______________necessary functinos____________
//________________DO NOT REMOVE_________________
ll ADD(ll x, ll y) {
	ll res = x + y;
	return (res >= mod ? res - mod : res);
}
ll MUL(ll x, ll y) {
	ll res = x * y;
	return (res >= mod ? res % mod : res);
}
ll SUB(ll x, ll y) {
	ll res = x - y;
	return (res < 0 ? res + mod : res);
}

ll POWER(ll x, ll y) {
	ll res = 1;
	x %= mod;
	while (y) {
		if (y & 1)
			res = MUL(res, x);
		y >>= 1; x = MUL(x, x);
	} return res;
}
ll MOD_INV(ll x) {
	return POWER(x, mod - 2);
}
ll maxofarray(ll a[], ll n) {
	ll max = a[0];
	ff(i, 0, n - 1) {
		if (max < a[i])
			max = a[i];
	}
	return max;
}

string lleger_to_binary_str(ll n) {
	string s = "";
	while (n > 0) {
		if (n % 2 == 0) {
			s += "0";
		}
		else {
			s += "1";
		}
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
//_______________________________________
void solve() {
	ll n;
	cin >> n;
	ll ans = mod;
	vector<ll> x(n), y(n);
	ff(i, 0, n - 1) {
		cin >> x[i] >> y[i];
	}
	ff(i, 0, n - 1) {
		ff(j, 0, n - 1) {
			if (i == j) {
				ans = min(ans, x[i] + y[j]);
			} else {
				ans = min(ans, max(x[i], y[j]));
			}
		}
	}
	cout << ans << endl;
}
//_______________________________________

int main() {
	//________________________________________
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//_______________________________________

	solve();

}


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

using namespace std;

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i,n) for (ll i = 0; i < (ll)(n); i++)
#define fore(x,a) for(auto&(x) : (a))

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

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

const ll INFL = 1e18;
const int INFI = 1e9;
const int MOD = 1e9 + 7;

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<ll> F(N + 1);
  F[0] = 1;
  F[1] = 1;
  for (int i = 2; i <= N; i++){
    F[i] = (F[i - 1] + F[i - 2]) % MOD;
  }
  ll ans = 0;
  ans += F[N] * A[0] % MOD;
  for (int i = 1; i < N; i++){
    ans += F[i] * F[N - i] % MOD * A[i] % MOD;
    ans += F[i - 1] * F[N - i - 1] % MOD * (MOD - A[i]) % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}

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


#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,w;
  cin >> a >> b >> w;
  int m=1e9,M=0;
  for(int n=1;n<=1000000;n++){
    if(a*n<=1000*w && 1000*w<=b*n){
      m=min(m,n);
      M=max(M,n);
    }
  }
  if(M==0)cout << "UNSATISFIABLE";
  else cout << m << ' ' << M;
}

/// In the name of ALLAH
/// I'm THEOVE46
#include<bits/stdc++.h>
using namespace std;

#define gap             " "
#define nn              "\n"
#define pi              2*acos(0.0)
#define db              double
#define ft              float
#define ll              long long int
#define ull             unsigned long long int
#define pf              printf
#define sf              scanf
#define ff              first
#define ss              second
#define sfi(n)          sf("%d",&n)
#define sfi2(n, m)      sf("%d%d",&n,&m)
#define sfl(n)          sf("%lld",&n)
#define sfl2(n, m)      sf("%lld%lld",&n,&m)
#define sff(n)          sf("%f",&n)
#define sfd(n)          sf("%lf",&n)
#define pfi(n)          pf("%d",n)
#define pfl(n)          pf("%lld",n)
#define pff(n)          pf("%f",f)
#define pfd(n)          pf("%lf",f)
#define bfi             cin.ignore()
#define bfs             cin.get()
#define bfc             getchar()
#define gl(s)           getline(cin, s)
#define loop(a,n)       for(i=a; i<n; i++)
#define mloop(i,a,n)    for(i=a; i<n; i++)
#define rloop(i,a,n)    for(i=a; i>=n; i--)
#define tloop(test)     for(ll tl=1; tl<=test; tl++)
#define case1(z)        cout<<"Case "<<z<<": "
#define case2(z)        printf("Case %d: ",z)
#define vi              vector<int>
#define vl              vector<ll>
#define vld(vc,rw)      vector<vector<ll> >vc(rw)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define pis             pair<int,string>
#define psi             pair<string,int>
#define mls             map <ll,string>
#define msl             map <string,ll>
#define mll             map <ll,ll>
#define mp              make_pair
#define pb              push_back
#define itr             vector<int> :: iterator
#define atl(i, v)       for(auto i: v)
#define sz(s)           s.size()
#define sl(s)           s.length()
#define Sort(s)         sort(s.begin(), s.end())
#define SortR(s)        sort(s.rbegin(), s.rend())
#define all(x)          x.begin(),x.end()
#define rall(x)         x.end(), x.begin()
#define MEM(ar,val)     memset(ar, (val), sizeof(ar))
#define IN(A,B,C)       assert(B<=A && A<=C)
#define MOD             1000000007
#define EPS             1e-9
#define Max             1e9
#define Min             -1e9
#define bug1            " **1** "
#define bug2            " ****2**** "
#define artri(b,h)      0.5*b*h
#define artrap(b1,b2,h) (b1+b2)/2*h
#define arcrl(r)        pi*r*r
#define vlsyl(r,h)      pi*r*r*h
#define vlcone(r,h)     pi*r*r*(h/3)
#define vlsph(r)        (4/3)*pi*r*r*r
#define flush           fflush(stdout)
#define pcn(dg,val)     fixed << setprecision(dg) << val
#define ggl             pf("Case #%lld: ", tl)
#define FastIO          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define showsort(n, a)  for(int i=0; i<n; i++) cout << a[i] << gap; cout << endl;

inline string IntToString(ll a) {char x[100]; sprintf(x,"%lld",a); string s=x; return s;}
inline ll StringToInt(string a) {char x[100]; ll res; strcpy(x, a.c_str()); sscanf(x,"%lld",&res); return res;}
///THEOVE46

int main()
{
    FastIO;
    bool bl = true;
    ll a, b, w, mn, mx, x, y, s;
    sf("%lld%lld%lld", &a, &b, &w);
    w*=1000;

    mn = w/b;
    if(w%b!=0)
    {
        x = w%b;
        s = w - (a*mn);
        if(s<a)
        {bl = false;
        //cout << bug1 << endl;
        }
        mn++;
    }

    mx = w/a;
    if(w%a!=0)
    {
        x = w%a;
        s = (b-a)*mx;
        if(s<x)
        {bl = false;
        //cout << bug2 << x << " "  << mx << " " << s << endl;
        }
    }

    if(bl) cout << mn << " " << mx << nn;
    else cout << "UNSATISFIABLE" << endl;
    return 0;
}

///   check for integer overflow, array bounds
///   check for n=1
///   - - - The Ove 46


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

//double dist(double x1, double y1, double x2, double y2){
//	return hypot(x1-x2,y1-y2);
//}

struct point {
    double x,y;
    point() {
        x=y=0.0;
    }
};

bool collinear(point P, point L, point R) { //newly added(luis), cek 3 poin segaris
    return P.x*(L.y-R.y)+L.x*(R.y-P.y)+R.x*(P.y-L.y)==0; // bole gnti “dabs(x)<EPS”
}

point ps[120];
//double x[120], y[120];
void solve(){
	int n; cin>>n;
	rep(i,0,n) cin>>ps[i].x>>ps[i].y;
	bool v=0;
	rep(i,0,n) rep(j,i+1,n) rep(k,0,n){
		if (k==i || k==j)  continue;
		if (collinear(ps[i],ps[j],ps[k])) {
			v = 1;
		}
	}
	if (v) cout<<"Yes\n";
	else cout<<"No\n";
}

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

//Keep calm and carry on..

/*  Problem :
    URL :
*/

#include<bits/stdc++.h>

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

# define fast           ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
# define pb             push_back
# define pi             3.1415926535897932384626
# define mod            1000000007
# define endl          '\n'
# define DEBUG          false
# define F              first
# define S              second
# define loop1(i,a,b)   for(ll i = a; i<b; i++)
# define loop2(i,a,b)   for(ll i = b-1; i>=a; i--)
# pragma GCC optimize "trapv"

void just_solved_it() {

	ld sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	ld ans = (gy*sx + sy*gx)/ (sy + gy);
    cout << fixed << setprecision(12) << ans ;
}

int main() {

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

	fast;
	ll t;	//cin >> t;
	t = 1;

	while (t--) {

		just_solved_it();
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// typedef long long int;
#define int long long
int const MAXN = 2e5 + 10, INF = 0x3f3f3f3f3f3f3f3f;
int T;
int a[5], m[5];

int qmi(int a, int b, int mod) {
    int res = 0;
    while (b > 0) {
        if (b & 1) res = (res + a) % mod;
        a = (a + a) % mod;
        b >>= 1;
    }
    return res;
}

int exgcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int gcd = exgcd(b, a % b, x, y);
    int tp = x;
    x = y;
    y = tp - a / b * y;
    return gcd;
}

// a, m --- 第i个方程表示x ≡ ai(mod mi)，下标从0开始
// n---- 方程个数
int excrt(int ai[], int mi[], int n) {
    int x, y, k;
    int M = mi[0], ans = ai[0];  //第一个方程的解特判
    for (int i = 1; i < n; i++) {
        int a = M, b = mi[i], c = (ai[i] - ans % b + b) % b;  // ax≡c(mod b)
        int gcd = exgcd(a, b, x, y), bg = b / gcd;
        if (c % gcd != 0) return -1;  //判断是否无解，然而这题其实不用
        x = qmi(x, c / gcd, bg);  //把x转化为最小非负整数解
        ans += x * M;             //更新前k个方程组的答案
        M *= bg;
        ans = (ans % M + M) % M;
    }
    return (ans % M + M) % M;
}

signed main() {
    cin >> T;
    while (T--) {
        int x, y, p, q;
        cin >> x >> y >> p >> q;
        int ans = INF;
        for (int i = x; i < x + y; i++) {
            for (int j = p; j < p + q; j++) {
                a[0] = i, m[0] = 2 * (x + y);
                a[1] = j, m[1] = p + q;
                // cout << CRT(a, m, n) << endl;
                // cout << "a[0] " << a[0] << "  " << "m[0] " << m[0] << endl;
                // cout << "a[1] " << a[1] << "  " << "m[1] " << m[1] << endl;
                int t = excrt(a, m, 2);
                // cout << "res: " << t << endl;
                if (t == -1) continue;
                ans = min(ans, t);
            }
        }
        if (!ans || ans == INF)
            cout << "infinity" << endl;
        else
            cout << ans << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define IFOR(i, a, b) for (long long i = (a); i <= (long long)(b); i++)
using namespace std;
using VL = vector<long long>;
using ll = int64_t;
ll mod(ll x,ll m){ll y=x%m;return (y>=0LL)?y:y+m;}
template<class T>bool chmin(T& a, T b){if(a>b){a=b;return true;}else return false;}
ll gcd(ll a,ll b,ll& x,ll& y)
{if(a){ll d=gcd(b%a,a,x,y);y-=(b/a)*x;swap(x,y);if(d<0LL){d=-d;x=-x;y=-y;}return d;}else{x=0;y=1;return b;}}

int main(){
    int T;
    cin>>T;
    string ans = "";
    REP(i,T){
        ll t = LLONG_MAX;
        ll X,Y,P,Q;
        scanf("%lld %lld %lld %lld",&X,&Y,&P,&Q);
        ll a=(X+Y)<<1, b=P+Q;
        ll x, y;
        ll d = gcd(a, -b, x, y);
        ll u = b/d, v = a/d;
        ll stop0=P-X, stop1=P-X+Q-1LL;
        ll wake0=P-X-Y+1LL, wake1=P-X;
        ll from=min(stop0, wake0), to=max(stop1, wake1);
        IFOR(z, from, to){
            if(mod(z,d)!=0LL)continue;
            if(stop0<=z && z<=stop1){
                chmin(t,a*mod(z/d*x,u)+X);
            }else{
                chmin(t, b*mod(z/d*y,v)+P);
            }
        }
        ans += (t==LLONG_MAX ? "infinity" : (to_string(t)))+"\n";
    }

    cout << ans;

    return 0;
}