#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}

/*!* [binsearch] *!*/
/*+* 二分探索 *+*/
// judge を満たすような(l,r]内の下限を求める
// l:[X] 定義域の下限
// r:[X] 定義域の上限
// judge:[F = X -> bool] 値 X を評価する関数
// lower:[bool] false にすると代わりに[l,r)内の上限を求める
// eps:[X] 終了距離

template <typename X, typename F>
X BinSearch(X l, X r, F judge, bool lower = true, X eps = 1) {
    while (r - l > eps) {
        X m = (r + l) / 2;
        if (judge(m) == lower) {
            r = m;
        } else {
            l = m;
        }
    }
    return lower ? r : l;
}

struct Data {
    i64 b, l, u;
    bool operator<(const Data &x) const {
        return make_tuple(b, l, u) < make_tuple(x.b, x.l, x.u);
    }
};

int main() {
    const i64 INF = 1e14;
    i64 N, X;
    cin >> N >> X;
    vector<pair<i64, Data>> data(N);
    i64 S_N = 0;

    for(int i = 0; i < N; i++) {
        i64 b, l, u;
        cin >> b >> l >> u;
        data[i] = {u * (X - b) + l * b, {b, l, u}};
        S_N += l * b;
    }

    // O(N log N)
    sort(REV_WHOLE(data));

    vector<i64> S(N);
    for(int i = 0; i < N; i++) {
        S[i] = data[i].first + (i ? S[i - 1] : 0);
    }

    // O(N log NX)
    i64 ans = BinSearch<i64>(-1, N * X, [&](i64 A) -> bool {
        // O(N)
        // (sum of a_i) <= A ?

        i64 m = A / X;
        i64 r = A - m * X;
        for(int j = 0; j < N; j++) {
            i64 e = 0;
            i64 x;
            Data d;
            tie(x, d) = data[j];
            e += max(d.l * (r - d.b), d.u * (r - d.b)) + d.l * d.b;
            if(m > 0) {
                e += j < m ? S[m] - x : S[m - 1];
            }
            e -= S_N;
            if(e >= 0) return true;
        }
        return false;
    });
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  tuple<long long, long long, char> XYU[N];
  tuple<long long, long long, char> YXU[N];
  tuple<long long, long long, char> XYU_45[N];
  tuple<long long, long long, char> YXU_45[N];
  for (int i = 0; i < N; i++) {
    int x, y;
    char u;
    cin >> x >> y >> u;
    XYU[i] = make_tuple(x, y, u);
    YXU[i] = make_tuple(y, x, u);
    XYU_45[i] = make_tuple(x - y, x + y, u);
    YXU_45[i] = make_tuple(x + y, x - y, u);
  }
  long long ans = INT_MAX;
  sort(XYU, XYU + N);
  sort(YXU, YXU + N);
  sort(XYU_45, XYU_45 + N);
  sort(YXU_45, YXU_45 + N);
  for (int i = 0; i < N; i++) {
    if (get<2>(XYU[i]) != 'U') continue;
    int j = i + 1;
    while (j < N && get<0>(XYU[i]) == get<0>(XYU[j])) {
      if (get<2>(XYU[j]) == 'U') i = j;
      if (get<2>(XYU[j]) == 'D') {
        ans = min(ans, 5 * (get<1>(XYU[j]) - get<1>(XYU[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(YXU[i]) != 'R') continue;
    int j = i + 1;
    while (j < N && get<0>(YXU[i]) == get<0>(YXU[j])) {
      if (get<2>(YXU[j]) == 'R') i = j;
      if (get<2>(YXU[j]) == 'L') {
        ans = min(ans, 5 * (get<1>(YXU[j]) - get<1>(YXU[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(XYU_45[i]) != 'R') continue;
    int j = i + 1;
    while (j < N && get<0>(XYU_45[i]) == get<0>(XYU_45[j])) {
      if (get<2>(XYU_45[j]) == 'R') i = j;
      if (get<2>(XYU_45[j]) == 'D') {
        ans = min(ans, 5 * (get<1>(XYU_45[j]) - get<1>(XYU_45[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(XYU_45[i]) != 'U') continue;
    int j = i + 1;
    while (j < N && get<0>(XYU_45[i]) == get<0>(XYU_45[j])) {
      if (get<2>(XYU_45[j]) == 'U') i = j;
      if (get<2>(XYU_45[j]) == 'L') {
        ans = min(ans, 5 * (get<1>(XYU_45[j]) - get<1>(XYU_45[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(YXU_45[i]) != 'R') continue;
    int j = i + 1;
    while (j < N && get<0>(YXU_45[i]) == get<0>(YXU_45[j])) {
      if (get<2>(YXU_45[j]) == 'R') i = j;
      if (get<2>(YXU_45[j]) == 'U') {
        ans = min(ans, 5 * (get<1>(YXU_45[j]) - get<1>(YXU_45[i])));
      }
      j++;
    }
    i = j - 1;
  }

  for (int i = 0; i < N; i++) {
    if (get<2>(YXU_45[i]) != 'D') continue;
    int j = i + 1;
    while (j < N && get<0>(YXU_45[i]) == get<0>(YXU_45[j])) {
      if (get<2>(YXU_45[j]) == 'D') i = j;
      if (get<2>(YXU_45[j]) == 'L') {
        ans = min(ans, 5 * (get<1>(YXU_45[j]) - get<1>(YXU_45[i])));
      }
      j++;
    }
    i = j - 1;
  }

  if (ans == INT_MAX) {
    cout << "SAFE" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


//E869120さんのコード
#include <bits/stdc++.h>
using namespace std;

long long N; string S;

int main() {
	cin >> N;
	if (N == 0) { cout << "0" << endl; return 0; }
	while (N != 0) {
		if (N % 2 == 1 || N % 2 == -1) { N--; S += "1"; }
		else { S += "0"; }
		N /= -2;
	}
	reverse(S.begin(), S.end());
	cout << S << endl;
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  bool ans=true;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(isupper(s[i])) cnt++;
  }
  if(cnt!=2) ans=false;
  cnt=0;
  if(s[0]!='A') ans=false;
  for(int i=2;i<s.size()-1;i++){
    if(s[i]=='C') cnt++;
  }
  if(cnt!=1) ans=false;
  if(ans) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int ans, n, m1, m2, m3, m4;
int a[N];
int cnt0[N];
int cnt1[N];

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

    for (int i = 0; i < n; i += 2) {
        int m = a[i];
        ++cnt0[m];
        if (m == m1) continue;
        if (cnt0[m] > cnt0[m1]) {
            m2 = m1;
            m1 = m;
        } else if (cnt0[m] > cnt0[m2]) {
            m2 = m;
        }
    }
    for (int i = 1; i < n; i += 2) {
        int m = a[i];
        ++cnt1[m];
        if (m == m3) continue;
        if (cnt1[m] > cnt1[m3]) {
            m4 = m3;
            m3 = m;
        } else if (cnt1[m] > cnt1[m4]) {
            m4 = m;
        }
    }
    if (m2 == m1) m2 = 0;
    if (m4 == m3) m4 = 0;
    if (m1 != m3) {
        ans = n - cnt0[m1] - cnt1[m3];
    } else {
        ans = min(n - cnt0[m1] - cnt1[m4],
                  n - cnt0[m2] - cnt1[m3]);
    }
    cout << ans << endl;
    return 0;
}

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

int a[3][100000];
int x[100000];
int inv[100000];
int BIT[100001];

void init(){
	for(int i=1;i<=100000;i++)
		BIT[i]=0;
}

void add(int x){
	for(;x<=100000;x+=x&-x)
		BIT[x]++;
}

int query(int x){
	int res=0;
	for(;x>0;x-=x&-x)
		res+=BIT[x];
	return res;
}

void fail(){
	cout<<"No"<<endl;
	exit(0);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<3;i++)
		for(int j=0;j<n;j++)
			cin>>a[i][j];
	vector<pair<int,int> > v0,v1;
	long long int cnt0=0,cnt1=0,inv0=0,inv1=0;
	for(int i=0;i<n;i++){
		if(abs(a[0][i]-a[1][i])!=1||abs(a[1][i]-a[2][i])!=1)
			fail();
		x[i]=a[1][i]/3;
		if((x[i]&1)^(i&1))
			fail();
		inv[i]=a[0][i]>a[1][i];
		if(i&1)
			v1.emplace_back(x[i],i),inv1+=inv[i];
		else
			v0.emplace_back(x[i],i),inv0+=inv[i];
	}
	sort(v1.begin(),v1.end(),greater<pair<int,int> >());
	sort(v0.begin(),v0.end(),greater<pair<int,int> >());
	for(auto it:v0){
		cnt0+=query(it.second+1);
		add(it.second+1);
	}
	init();
	for(auto it:v1){
		cnt1+=query(it.second+1);
		add(it.second+1);
	}
	if((inv1+cnt0)&1)
		fail();
	if((inv0+cnt1)&1)
		fail();
	cout<<"Yes"<<endl;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    string s; cin >> s;
    if(s[0] == 'W'){
        cout << 0 << endl;
        return 0;
    }

    vi a(2*n);
    a[0] = 0;
    REP(i,1,2*n){
        if(s[i] != s[i-1]){
            a[i] = a[i-1];
        }else{
            a[i] = a[i-1] ^ 1;
        }
    }
    ll cnt = 0;
    ll ans = 1;
    rep(i,2*n){
        if(a[i] == 1){
            ans *= cnt;
            ans %= mod;
            cnt--;
        }else{
            cnt++;
        }
        if(cnt < 0){
            cout << 0 << endl;
            return 0;
        }
    }
    if(cnt != 0){
        cout << 0 << endl;
    }else{
        rep(i,n){
            ans *= i+1;
            ans %= mod;
        }
        cout << ans << endl;
    }
    return 0;
}

//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_c
//左端、右端を選んで操作、という操作は
//まず左端のみに注目し、次に右端のみに注目していく
//また最左端にまとめるなんて考え方も
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;

#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

int N;
string S;

LL ans = 1;

void solve(){
	int cur = 0;
	for(int i=0;i<2*N;i++){
		if(S[i]=='B'){
			if(cur%2==1){
				ans = ans*cur%mod;
				cur--;
			}else{
				cur++;
			}
		}
		if(S[i]=='W'){
			if(cur%2==1){
				cur++;
			}else{
				ans = ans*cur%mod;
				cur--;
			}
		}
	}
	if(cur>0) ans = 0;
	for(int i=0;i<N;i++) ans = ans*(i+1)%mod;
}

int main(){
	cin >> N;
	cin >> S;

	solve();

	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main(){FIN
    vll a(3); REP(i,3) cin>>a[i];
    ll k;cin>>k;
    VSORTR(a);
    a[0] *= power(2,k);
    cout<<a[0]+a[1]+a[2]<<endl;

    return 0;
}

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

int main() {
    int a, b, c, k, tem, ans;

    cin >> a >> b >> c >> k;
    ans = a + b + c - max({a, b, c});

    tem = max({a, b, c});
    for ( int i = 0; i < k; i++ ) {
        tem *= 2;
    }
    cout << ans + tem << endl;

    return (0);
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

bool fc(vector<int> &a, int m, int v, int p, int mid){
  int n = a.size();
  if(mid < p) return true;
  vector<int> tr;
  rep(i, n){
    if(i == mid) continue;
    tr.push_back(a.at(i));
  }

  ll top = a.at(mid) + m;
  if(top < tr.at(p-1)) return false;
  ll ex = (ll)(v-1)*m;
  rep(i, n-1){
    if(i < p-1) ex -= m;
    else ex -= min((ll)m, top - tr.at(i));
  }
  return ex <= 0;
}

int main(){
  int n, m;
  cin >> n >> m;
  int v, p;
  cin >> v >> p;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  sort(ALL(a), greater<int>());
  int ng = n, ok = 0;
  while(ng - ok > 1){
    int mid = (ok + ng)/2;
    if(fc(a, m, v, p, mid) == true) ok = mid;
    else ng = mid;
  }
  int ans = ok+1;
  cout << ans << endl;
  return 0;
}

#include<cstdio>
#include<algorithm>
#define RI register int
#define CI const int&
using namespace std;
const int N=100005;
int n,a[N],m,v,p; long long sum[N];
inline bool cmp(CI x,CI y)
{
	return x>y;
}
int main()
{
	RI i; for (scanf("%d%d%d%d",&n,&m,&v,&p),i=1;i<=n;++i) scanf("%d",&a[i]);
	for (sort(a+1,a+n+1,cmp),i=1;i<=n;++i) sum[i]=sum[i-1]+a[i];
	for (i=p+1;i<=n;++i)
	{
		int dlt=max(0,v-(p+n-i)); long long tot=sum[i-1]-sum[p-1];
		if (a[i]+m<a[p]||1LL*(i-p)*(a[i]+m)+1-tot<=1LL*dlt*m) return printf("%d",i-1),0;
	}
	return printf("%d",n),0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

//#define N 2000

template<size_t N>
const bitset<N> operator+(const bitset<N>& lhs, const bitset<N>& rhs)
{
    bitset<N> a(lhs), b(rhs), ret(lhs ^ rhs);

    for (b = (a & b) << 1, a = ret; b.any(); b = (a & b) << 1, a = ret) ret ^= b;

    return ret;
}

template<size_t N>
int edit_distance_bitset(const string& str1, const string& str2)
{
    char s1[N] = { ' ' };
    char s2[N] = { ' ' };
    char *p1, *p2;

    if (str1.size() >= str2.size()) { p1 = s1;  p2 = s2; }
    else { p1 = s2;  p2 = s1; }
    copy(str1.begin(), str1.end(), p1 + 1);
    copy(str2.begin(), str2.end(), p2 + 1);
    int m = strlen(s1);
    int n = strlen(s2);

    const bitset<N> ONE(1);
    bitset<N> Peq[256];
    bitset<N> Pv, Mv, Eq, Xv, Xh, Ph, Mh;
    int Score = m;

    for (int i = 0; i < m; i++) {
        Peq[s1[i]] |= ONE << i;
        Pv |= (ONE << i);
    }
    for (int j = 0; j < n; j++) {
        Eq = Peq[s2[j]];
        Xv = Eq | Mv;
        Xh = (((Eq & Pv) + Pv) ^ Pv) | Eq;
        Ph = Mv | ~(Xh | Pv);
        Mh = Pv & Xh;
        if ((Ph & (ONE << (m - 1))).any()) Score++;
        else if ((Mh & (ONE << (m - 1))).any()) Score--;
        Ph = Ph << 1 | ONE;
        Pv = (Mh << 1) | ~(Xv | Ph);
        Mv = Ph & Xv;
    }

    return Score;
}

int main(){
	string a,b;
  cin>>a>>b;
  cout<<edit_distance_bitset<2000>(a,b)<<endl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,s, t) for(int i = s; i < t; i++)
#define ALL(a)  a.begin(), a.end()
#define SZ(x) (int)x.size()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define SORT(a) sort(ALL(a))
using VI = vector<int>;
using LL = long long;
using VVL = vector<vector<LL>>;
using VL = vector<LL>;

const LL LINF = 1e18;

int editDistance(string& s, string& t) {
	VVL dp(1010, VL(1010, 0));

	FOR(i, 0, 1010) {
		dp[i][0] = i;
		dp[0][i] = i;
	}
	FOR(i, 0, SZ(s)) {
		FOR(j, 0, SZ(t)) {
			int cost = (s[i] == t[j]) ? 0 : 1;
			dp[i + 1][j + 1] = min(dp[i][j] + cost, min(dp[i + 1][j] + 1, dp[i][j + 1] + 1));
		}
	}
	return dp[s.size()][t.size()];
}

signed main() {
	string s, t;
	cin >> s >> t;
	cout << editDistance(s, t) << endl;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int N, Q;
int main() {
	scanf("%d%d", &N, &Q);
	vector<int> tp(Q), s(Q), t(Q), x(Q);
	for (int i = 0; i < Q; i++) {
		scanf("%d%d", &tp[i], &s[i]);
		if (tp[i] == 0) scanf("%d%d", &t[i], &x[i]), t[i]++;
	}
	vector<int> d(N, 2147483647);
	int B = sqrt(Q);
	for (int i = 0; i < B; i++) {
		int l = 1LL * i * Q / B, r = 1LL * (i + 1) * Q / B;
		for (int j = l; j < r; j++) {
			if (tp[j] == 1) {
				bool flag = false;
				for (int k = j - 1; k >= l; k--) {
					if (tp[k] == 0 && s[k] <= s[j] && s[j] < t[k]) {
						printf("%d\n", x[k]); flag = true;
						break;
					}
				}
				if (!flag) printf("%d\n", d[s[j]]);
			}
		}
		vector<int> cp = { 0, N };
		for (int j = l; j < r; j++) {
			if (tp[j] == 0) {
				cp.push_back(s[j]);
				cp.push_back(t[j]);
			}
		}
		sort(cp.begin(), cp.end());
		cp.erase(unique(cp.begin(), cp.end()), cp.end());
		vector<int> f(cp.size() - 1, -1);
		for (int j = l; j < r; j++) {
			if (tp[j] == 0) {
				int pl = lower_bound(cp.begin(), cp.end(), s[j]) - cp.begin();
				int pr = lower_bound(cp.begin(), cp.end(), t[j]) - cp.begin();
				for (int k = pl; k < pr; k++) f[k] = x[j];
			}
		}
		for (int j = 0; j < cp.size() - 1; j++) {
			if (f[j] != -1) {
				for (int k = cp[j]; k < cp[j + 1]; k++) d[k] = f[j];
			}
		}
	}
	return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int n,k;
    cin>>n>>k;
    cout<<n-k+1<<endl;

}

#include <bits/stdc++.h>

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

int n, k;

int main() {
	read(n), read(k);
	print(n - k + 1);
}


#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAX 32

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int n, m;

bool exist[MAX][MAX];

int main(void) {
    while (cin >> n) {
        if (n == 0) break;
        for (int i = 0; i <= 20; i++) {
            for (int j = 0; j <= 20; j++) {
                exist[i][j] = false;
            }
        }
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            exist[y][x] = true;
        }
        int nowx = 10;
        int nowy = 10;
        cin >> m;
        for (int i = 0; i < m; i++) {
            //printf("now pos (%d %d)\n", nowx, nowy);
            char d;
            int l;
            cin >> d >> l;
            if (exist[nowy][nowx]) exist[nowy][nowx] = false;
            if (d == 'N') {
                for (int j = 0; j < l; j++) {
                    nowy++;
                    if (exist[nowy][nowx]) exist[nowy][nowx] = false;
                }
            }
            if (d == 'S') {
                for (int j = 0; j < l; j++) {
                    nowy--;
                    if (exist[nowy][nowx]) exist[nowy][nowx] = false;
                }
            }
            if (d == 'E') {
                for (int j = 0; j < l; j++) {
                    nowx++;
                    if (exist[nowy][nowx]) exist[nowy][nowx] = false;
                }
            }
            if (d == 'W') {
                for (int j = 0; j < l; j++) {
                    nowx--;
                    if (exist[nowy][nowx]) exist[nowy][nowx] = false;
                }
            }
        }
        if (exist[nowy][nowx]) exist[nowy][nowx] = false;
        bool ok = true;
        for (int y = 0; y <= 20; y++) {
            for (int x = 0; x <= 20; x++) {
                if (exist[y][x]) {
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

map<char, int> news = {{'N', 0}, {'E', 1}, {'S', 2}, {'W', 3}};
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int main() {
    int N, M, I, x, y;
    char d;
    hset<int> st;
    while (cin >> N) {
        st.clear();
        if (N == 0) break;
        for (int i = 0; i < N; i++) {
            cin >> x >> y;
            st.insert(y*21 + x);
        }

        cin >> M;
        x = 10; y = 10;
        for (int i = 0; i < M; i++) {
            cin >> d >> I;
            for (int j = 0; j < I; j++) {
                x += dx[news[d]];
                y += dy[news[d]];
                st.erase(y*21 + x);
            }
        }
        if (st.empty()) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

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

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n;
  while(n = getInt()){
    REP(i,n){
      int pm = getInt();
      int pe = getInt();
      int pj = getInt();

      int sum = pm + pe + pj;

      if((pm == 100 || pe == 100 || pj == 100) ||
	 (pm + pe >= 180) || (sum >= 240)){
	puts("A");
      }else if((sum >= 210) ||
	       (sum >= 150 && (pm >= 80 || pe >= 80))){
	puts("B");
      }else{
	puts("C");
      }
    }
  }
  return 0;
}

#include <cstdio>
using namespace std;

typedef long long LL;
const int N = 55;
int n; LL K, a[N];

template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + (LL)ch-'0', ch = getchar();
	x *= f;
}

inline void work() {
	in(K), n = 50; LL tmp = K / n;
	for (int i = 1; i <= n; ++i) a[i] = n - 1;
	for (int i = 1; i <= n; ++i) a[i] += tmp;
	for (int i = 1; i <= K % n; ++i) {
		a[i] += n;
		for (int j = 1; j <= n; ++j) if (i != j) --a[j];
	}
	int lim = K % n;
	printf("%d\n", n);
	for (int i = 1; i < n; ++i) printf("%lld ", a[i]);
	printf("%lld\n", a[n]);
}

int main() {work(); return 0;}


#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int D;
    long long G;
    int p[10];
    long long c[10];
    long long sum[10];
    long long ans = 10000000;

    cin >> D >> G;
    for (int i = 0;i < D;i++){
        cin >> p[i] >> c[i];
        sum[i] = 100*(i+1)*p[i] + c[i];
    }

    for (int i = 0;i < (1<<D);i++){
        long long res = 0;
        long long pre = 0;
        for (int j = 0;j < D;j++){
            if ((i>>j)%2){
                res += sum[j];
                pre += p[j];
            }
        }
        if (res < G){
            for (int j = D-1;j >= 0;j--){
                if ((i>>j)%2==0){
                    for (int k = 0;k < p[j]-1;k++){
                        res += 100*(j+1);
                        pre++;
                        if (res >= G){
                            goto EXIT;
                        }
                    }
                }
            }
        }
        EXIT:
        if(res >= G){
            ans = min(ans,pre);
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  string S;
  cin >> S;
  string S1 = S.substr(0, N);
  string S2 = S.substr(N, N);
  lint ans = 0;
  REP(k, 1<<N) {
    string a = "";
    string b = "";
    REP(i, N) {
      if((k>>i&1) == 1) {
        a = S1[i] + a;
      } else {
        b = S1[i] + b;
      }
    }
    vector<vector<lint>> dp(N+1, vector<lint>(a.size()+1));
    dp[0][0] = 1;
    REP(i, N) {
      REP(j, a.size()+1) {
        if(j != a.size() && S2[i] == a[j]) {
          dp[i+1][j+1] += dp[i][j];
        }
        if(S2[i] == b[i-j]) {
          dp[i+1][j] += dp[i][j];
        }
      }
    }
    ans += dp[N][a.size()];
  }
  cout << ans << endl;
}


/* FUCK U*/
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
using namespace std;
void solve(){
    int n,k,count;

    cin>>n>>k;
    for(int i=n;i<=k;++i){
       string str=to_string(i);
        if(str.at(0)==str.at(4) && str.at(1)== str.at(3))
            count++;
    }
    cout<<count<<endl;

}
int main(){

   ios::sync_with_stdio(false);
  cin.tie(0);
     solve();
}


#include <iostream>

int triple(int n) {
  return n * n * n;
}

int main() {
  int input;
  std::cin >>input;
  std::cout << triple(input) << std::endl;
  return 0;
}

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

vector<ll> enum_divisors(ll N){
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i){
        if (N % i == 0){
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int digit(ll a){
    int res = 0;
    while(a > 0){
        a /= 10;
        res++;
    }
    return res;
}

int f(ll a, ll b){
    return max(digit(a),digit(b));
}

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

    vector<ll> divisors = enum_divisors(N);

    int ans = 100000000;
    for(auto divisor : divisors){
        ll a = divisor;
        ll b = N/divisor;
        ans = min(ans, f(a,b));
    }

    cout << ans << endl;

}


#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int base[3] = {0, 0, 0};

void Hit()
{
	if (base[2] == 1)
	{
		base[2] = 0;
	}
	if (base[1] == 1)
	{
		base[2] = 1;
	}
	if (base[0] == 1)
	{
		base[1] = 1;
	}
	else if (base[0] == 0)
	{
		base[0] = 1;
	}

}

void Homerun()
{
	for (int i = 0; i < 3; i++)
	{
		base[i] = 0;
	}

}

int main()
{
	int out = 0;
    int score = 0;
	int n;
	string s;
    vector <string> event;
	int eventnum = 0;

	cin >> n;
	int a = 0;
	for (int i = 0; i < 3 * n; i++)
	{
		while (true)
		{
			cin >> s;
			event.push_back(s);
			if (event.at(a) == "OUT")
			{
				a += 1;
				eventnum += 1;
				break;
			}
			else
			{
				a += 1;
				eventnum += 1;
			}

		}
	}

	for (int i = 0; i < eventnum; i++)
	{
		if (event.at(i) == "HIT")
		{
			if (base[2] == 1)
			{
				score += 1;
			}
			Hit();
		}
		else if (event.at(i) == "HOMERUN")
		{
			score += base[0] + base[1] + base[2] + 1;
			Homerun();
		}
		else
		{
			out += 1;
			if (out == 3)
			{
				cout << score << endl;
				for (int i = 0; i < 3; i++)
				{
					base[i] = 0;
				}
				score = 0;
				out = 0;
			}
		}
	}

	return 0;
}

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

template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n;
string s;
int cache[1000004][3];
int dp(int pos,int carr)
{
    if(pos==n)
        return carr;
    int &ans=cache[pos][carr];
    if(ans!=-1)
        return ans;
    ans=1e18;
    for(int i=0;i<10;i++)
    {
        int dig1=i;
        int dig2=(i+carr+s[pos]-'0')%10;
        ans=min(ans,dig1+dig2+dp(pos+1,(i+carr+s[pos]-'0')/10));
    }
    return ans;
}
int32_t main()
{
    cin>>s;
    reverse(s.begin(),s.end());
    n=s.length();
    memset(cache,-1,sizeof(cache));
    print(dp(0,0));
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=100010,mod=998244353;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,m,lim,wsum,e[15][15],f[1<<15][15],tot[1<<15];
inline void chkmax(int &x,int y){if(x<y) x=y;}
int main(){
	n=read();m=read();lim=1<<n;
	FOR(i,1,m){
		int u=read()-1,v=read()-1;
		wsum+=e[u][v]=e[v][u]=read();
	}
	FOR(i,0,lim-1) FOR(j,0,n-1) if((i>>j)&1) FOR(k,j+1,n-1) if((i>>k)&1) tot[i]+=e[j][k];
	MEM(f,~0x3f);
	f[1][0]=0;
	FOR(i,1,lim-1) FOR(j,0,n-1) if((i>>j)&1){
		FOR(k,0,n-1) if(!((i>>k)&1) && e[j][k]) chkmax(f[i|(1<<k)][k],f[i][j]+e[j][k]);
		int re=(lim-1)^i;
		for(int k=re;k;k=((k-1)&re)) chkmax(f[i|k][j],f[i][j]+tot[k|(1<<j)]);
	}
	printf("%d\n",wsum-f[lim-1][n-1]);
}

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N, M;
int a[300], b[300], c[300];

int g[15][15];

ll dp[1<<15][15];
const ll INF = 1e+12;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    int sum = 0;
    for(int i = 0; i < M; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        g[a[i]][b[i]] = c[i];
        g[b[i]][a[i]] = c[i];
        sum += c[i];
    }
    int fin = (1<<N)-1;
    for(int i = 1; i < (1<<N); i++){
        if(i%2 == 0) continue;
        for(int j = 0; j < N; j++){
            if(!(i&(1<<j))) continue;
            for(int k = j+1; k < N; k++){
                if(!(i&(1<<k))) continue;
                dp[i][0] += g[j][k];
            }
        }
    }
    for(int i = 1; i < (1<<N); i++){
        for(int j = 0; j < N; j++){
            if(i == 1 && j == 0) continue;
            if(dp[i][j] == 0) dp[i][j] = -INF;
        }
    }
    for(int i = 1; i < (1<<N); i++){
        if(i%2 == 0) continue;
        if(i&(1<<(N-1))) continue;
        for(int j = (i+1)|i; j < (1<<N); j = (j+1)|i){
            int rem = j-i;
            ll sum_rem = 0;
            for(int k = 0; k < N; k++){
                for(int l = k+1; l < N; l++){
                    if((rem&(1<<k)) && (rem&(1<<l))) sum_rem += g[k][l];
                }
            }
            // cout << i << '-' << j << ' ' << rem << ' ' << sum_rem << endl;
            if(j&(1<<(N-1))){
                // N-1に行く
                for(int k = 0; k < N; k++){
                    if(!(i&(1<<k))) continue;
                    if(g[k][N-1] == 0) {}
                    else{
                        // if(i == 7) cout << i << "at"<< k << "dp" << dp[i][k] << '-' << j << endl;
                        dp[j][N-1] = max(dp[j][N-1], dp[i][k]+sum_rem+g[k][N-1]);
                    }
                }
            }else{
                // k -> l
                for(int k = 0; k < N; k++){
                    if(!(i&(1<<k))) continue;
                    for(int l = 0; l < N; l++){
                        if(!(rem&(1<<l))) continue;
                        if(g[k][l] == 0) {}
                        else{
                            dp[j][l] = max(dp[j][l], dp[i][k]+sum_rem+g[k][l]);
                        }
                    }
                }
            }
        }
    }
    ll g_max = 0;
    for(int i = 0; i < (1<<N); i++){
        g_max = max(g_max, dp[i][N-1]);
        // cout << dp[i][N-1] << endl;
    }
    cout << sum-g_max << endl;
}


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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#define rep(i,n) for (int i = 0; i < n; ++i)
#define reps(i,s,n) for (int i = s; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define per1(i,n) for (int i = n; i >= 1; --i)
#define all(c) begin(c),end(c)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
#define print(a) cout << a << endl;
template<typename T> void printv(vector<T>&v) {
    int n = v.size() - 1;
    rep(i, n) cout << v[i] << " ";
    cout << v.back() << endl;
}
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
// if(nextH >= 0 && nextH < H && nextW >= 0 && nextW < W)
static const long double pi = acos(-1.0);
typedef complex<ld> cd;

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

    int H, W, K; cin >> H >> W >> K;

    --K;
    vector<vector<long long> > dp(H+1, vector<long long>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int bit = 0; bit < 1<<(W-1); ++bit) {
                bool ok = true;
                for (int k = 0; k < W-2; ++k) {
                    if ((bit & (1<<k)) && (bit & (1<<(k+1)))) ok = false;
                }
                if (!ok) continue;
                int nj = j;
                if (bit & (1<<j)) nj = j+1;
                else if (j > 0 && (bit & (1<<(j-1)))) nj = j-1;
                dp[i+1][nj] += dp[i][j];
                dp[i+1][nj] %= MOD;
            }
        }
    }
    print(dp[H][K]);
}

#include <cstdio>
typedef long long LL;
const int N=1000005,mo=998244353;
LL fac[N],inv[N];
LL ksm(LL x,int y){
	LL i=1;
	for (;y;y>>=1,x=x*x%mo)
		if (y&1) i=i*x%mo;
	return i;
}
void Pre(int n){
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mo;
	inv[n]=ksm(fac[n],mo-2);
	for (int i=n;i>=1;i--) inv[i-1]=inv[i]*i%mo;
}
LL C(int n,int m){
	return n<m||m<0?0:fac[n]*inv[m]%mo*inv[n-m]%mo;
}
LL INV(int n){
	return inv[n]*fac[n-1]%mo;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	Pre(n+m);
	int ans=0,sum=0,s=C(n+m,n);
	for (int i=1;i<=n+m;i++){
		if (i&1)
			s=(s+C(i-2,i/2)*C(n+m-i+1,n-i/2))%mo;
		else
			s=(s-C(i-2,i/2-1)*C(n+m-i,n-i/2)*2)%mo;
		sum=(sum+s)%mo;
		ans=(ans+sum*INV(i))%mo;
	}
	ans=ans*ksm(C(n+m,n),mo-2)%mo;
	printf("%d\n",(ans+mo)%mo);
}


#pragma region header
#include <bits/stdc++.h>
#define int long long
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define mp make_pair
#define mt make_tuple
#define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define rrep1(i, n) for (auto i = n - 1; i > static_cast<decltype(i)>(-1); i--)
#define rep2(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep2(i, a, b) for (auto i = b - 1; i >= a; i--)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1) (__VA_ARGS__)
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep2, rrep1) (__VA_ARGS__)
#define each(i, a) for (auto &&i : (a))
using namespace std;

using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vp = vector<pii>;
using vvp = vector<vp>;
using mii = map<int, int>;
using vm = vector<mii>;
using vvm = vector<vm>;
template <class T, class U>
using umap = unordered_map<T, U>;
using umii = umap<int, int>;
using seti = set<int>;
template <class T>
using uset = unordered_set<T>;
using useti = uset<int>;
template <class T>
using less_queue = priority_queue<T>;
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = 1e18;

template <class T>
void SORT(T &a) { stable_sort(all(a)); }
template <class T>
void RSORT(T &a) { stable_sort(rall(a)); }
template <class T>
void rev(T &a) { reverse(rall(a)); }
template <class T>
void uniq(T &a) { a.erase(unique(all(a)), end(a)); }
template <class T>
auto min_of(T a) { return *min_element(all(a)); }
template <class T>
auto max_of(T a) { return *max_element(all(a)); }
template <class T>
int sum_of(T a) { return accumulate(all(a), 0ll); }
template <class T, class U>
auto sum_of(T a, U init) { return accumulate(all(a), init); }
template <class T, class U>
int count_of(T a, U i) { return count(all(a), i); }
template <class T, class U>
bool has(T a, U i) { return find(all(a), i) != end(a); }
template <class T>
int sz(T a) { return a.size(); };

template <class T>
void COUT(T x) { cout << x << endl; }
template <class T, class U>
void COUT(T x, U y) { cout << x << ' ' << y << endl; }
template <class T, class U, class V>
void COUT(T x, U y, V z) { cout << x << ' ' << y << ' ' << z << endl; }
template <class T>
void CSP(T x) { cout << x << ' '; }
template <class T>
void CVEC(T v) {
  int c = v.size() - 1;
  for (size_t i = 0; i < c; i++) cout << v[i] << ' ';
  if (c > -1) cout << v[c];
  cout << endl;
}

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

int ceil_div(int x, int y) { return (x - 1) / y + 1; }

#pragma endregion header

mii prime_factors(int n) {
  mii ret;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n]++;
  return ret;
}

void solve(int a, int b) {
  COUT(sz(prime_factors(gcd(a, b))) + 1);
}

#pragma region main
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);

  int a;
  cin >> a;
  int b;
  cin >> b;
  solve(a, b);
}
#pragma endregion main

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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;

int main(){
    int N;
    string S;
    cin >> N >> S;
    ll a=0,b=0,c=0;
    for(int i=0;i<N;i++){
        if(S[i]=='R') a++;
        else if(S[i]=='G') b++;
        else c++;
    }
    ll sum=a*b*c;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(2*j-i>N-1) break;
                if(S[i]!=S[j]&&S[i]!=S[2*j-i]&&S[j]!=S[2*j-i])
                    sum--;
        }
    }
    cout << sum << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

signed main() {
  string s;
  cin >> s;

  int N = s.size();
  int ans = N*(N-1)/2+1;

  map<char, int> m;
  REP(i, N) m[s[i]]++;

  for(auto p : m){
    ans -= p.second*(p.second-1)/2;
  }

  cout << ans << endl;

  return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <cstring>
#include <cmath>

using namespace std;
const long double eps = 1e-12;

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

#define sz(a) ((int) a.size() )
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i , a , b) for (int i = a ; i <= b ; i++)
#define Ford(i , a , b) for (int i = a ; i >= b ; i--)
#define Rep(i , n) for (int i = 0 ; i < n ; i++)

const int maxn = 1000000 + 1912;
string s;
int lenJ[maxn] , lenI[maxn];

void ReadData() {
    cin >> s;
}

void Process() {
    lenJ[0] = s[0] == 'J';
    For(i , 1 , sz(s) - 1) if (s[i] == 'J') lenJ[i] = lenJ[i - 1] + (s[i] == 'J'); else lenJ[i] = 0;
    Ford(i , sz(s) - 1 , 0) if (s[i] == 'I') lenI[i] = lenI[i + 1] + (s[i] == 'I'); else lenI[i] = 0;
    int res = 0;
    int last = 0;
    Rep(i , sz(s)) if (s[i] == 'O') {
        last++;
        if (i - last >= 0 && lenJ[i - last] >= last && lenI[i + 1] >= last) res = max(res , last);
    } else last = 0;
    cout << res << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
    ReadData();
    Process();
}


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

int main() {
    vector<int> a(4);
    vector<int> b(2);
    for (int i = 0; i<4; i++) {
        cin >> a[i];
    }
    for (int i = 0; i<2; i++) {
        cin >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    cout << a[3] + a[1] + a[2] +b[1] << endl;

    return 0;
}

#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int a[4],e,f,sum=0,x=120;
	for(int i=0;i<4;i++){
	cin >> a[i];
	sum=sum+a[i];
	if(a[i]<x)x=a[i];
	}
	sum=sum-x;
	cin >> e;
	cin >> f;
	if(e>f){sum=sum+e;}
	else if(e<f){sum=sum+f;}
	else if(e==f){sum=sum+e;}
	cout << sum << endl;
	return 0;
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}

#define DUMPOUT cerr

void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

signed main() {
    string s;
    cin>>s;

    if(s.find("AC")==s.npos) No;
    else Yes;
    return 0;
}

#include<stdio.h>
int main() {

	char character1[100];
	char character2[100];

	scanf("%s", character1);
	scanf("%s", character2);
	printf("%s%s", character2, character1);

	return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

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

    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;

int main(){
  int g;
  cin >>g;
  int a,b;
  cin >>a >>b;
  if(g==1){cout << "Hello World" << endl;}else{cout << a+b << endl;}
}


#include<iostream>
#include<climits>
using namespace std;
// 完成版。

int tree[(1 << 18)];

void Update(int s, int t, int m, int left = 0, int right = (1 << 17), int key = 0){
    if(t < left || right <= s) return;
    if(s <= left && right - 1 <= t){ tree[key] = max(tree[key], m); return; }
    Update(s, t, m, left, (left + right) / 2, 2 * key + 1);
    Update(s, t, m, (left + right) / 2, right, 2 * key + 2);
}

int Find(int i){
    i += (1 << 17) - 1;
    int m = tree[i];
    while(i){
        i = (i - 1) / 2;
        m = max(tree[i], m);
    };
    return m;
}

int main(){
    int i;
    for(i = 0; i < (1 << 18); i++) tree[i] = 0;
    int n, q;
    int x[100000];
    for(i = 0; i < 100000; i++) x[i] = INT_MAX;
    int s, t, value, m;
    m = 1;

    cin >> n >> q;
    int query;
    while(q){
        q--;
        cin >> query;
        if(query){
            cin >> i;
            cout << x[Find(i)] << endl;
        }else{
            cin >> s >> t >> value;
            x[m] = value;
            Update(s, t, m);
            m++;
        }
    };
    return 0;
}

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

using namespace std;

struct Node {
    int key;
    Node *left, *right, *parent;
};
Node *root, *NIL;

void insert(int k) {
    if(root == NIL) {
        root = (Node *)malloc(sizeof(Node));
        root->key = k;
        root->left = root->right = NIL;
    }else {
        Node *z = (Node *)malloc(sizeof(Node));
        z->key = k;
        z->left = z->right = NIL;

        Node *x = root;
        while(true) {
            if(k < x->key) {
                if(x->left == NIL) {
                    x->left = z;
                    z->parent = x;
                    break;
                }
                else x = x->left;
            }else {
                if(x->right == NIL) {
                    x->right = z;
                    z->parent = x;
                    break;
                }
                else x = x->right;
            }
        }
    }
}

Node *find(Node *node, int k) {
    Node *x = node;
    while(x != NIL && k != x->key) {
        if(k < x->key) x = x->left;
        else x = x->right;
    }

    return x;
}

Node *treeSuccessor(Node *x) {
    if(x->right != NIL) {
        x = x->right;
        while(x->left != NIL) x = x->left;
        return x;
    }
    /*else {
        Node *y = x->parent;
        while(y!=NIL && x==y->right) {
            x = y;
            y = y->parent;
        }
        return y;
    }
    */

}

void deleteNode(Node *node) {
    Node *target, *child;
    if(node->left == NIL || node->right == NIL) target = node;
    else target = treeSuccessor(node);

    if(target->left != NIL)
        child = target->left;
    else
        child = target->right;
    if(child != NIL) child->parent = target->parent;

    if(target->parent == NIL) root = child;
    else {
        if(target == target->parent->left)
            target->parent->left = child;
        else
            target->parent->right = child;
    }

    if(target != node) node->key = target->key;
    free(target);
}

void inorder(Node *node) {
    if(node == NIL) return;
    inorder(node->left);
    printf(" %d", node->key);
    inorder(node->right);
}

void preorder(Node *node) {
    if(node == NIL) return;
    printf(" %d", node->key);
    preorder(node->left);
    preorder(node->right);
}

int main()
{
    int n, x;
    char str[19];
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%s", str);
        if(str[0] == 'i') { //insert
            scanf("%d", &x);
            insert(x);
        }else if(str[0] == 'p') { //print
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }else if(str[0] == 'f') { //find
            scanf("%d", &x);
            Node *t = find(root, x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }else if(str[0] == 'd') { //delete
            scanf("%d", &x);
            deleteNode(find(root,x));
        }

    }

    return 0;
}


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

int main(void){
  int n, r;
  cin >> n >> r;
  if(n < 10) cout << r+100*(10-n) << endl;
  else cout << r << endl;
  return 0;
}

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

int main() {

	string s; int w; cin >> s >> w;
	string ans = "";
	for (int i = 0; i < s.size(); i+=w) {
		ans += s[i];
	}
	cout << ans << endl;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 45;
const int mod = 1e9 + 7;
using namespace std;

int n, x, y, z, now, lim, f[N][(1 << 17) + 5], ans;

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

int fpow(int x, int y)
{
	int res = 1;
	for( ; y; y >>= 1, x = 1ll * x * x % mod)
		if(y & 1) res = 1ll * res * x % mod;
	return res;
}

void output(int x)
{
	int a[100], cnt = 0;
	while(x) a[cnt++] = x & 1, x >>= 1;
	if(!cnt) return (void) (puts("0"));
	for(int i = cnt - 1; i >= 0; i--) printf("%d", a[i]);
	puts("");
}

int main()
{
	n = read <int> (), x = read <int> (), y = read <int> (), z = read <int> ();
	now = (1 << (x - 1 + y + z)) | (1 << (y - 1 + z)) | (1 << (z - 1)), lim = (1 << (x + y + z)) - 1;
	f[0][0] = 1;
	for(int tmp, i = 0; i < n; i++)
		for(int j = 0; j <= lim; j++)
			if(f[i][j])
			{
				for(int k = 1; k <= 10; k++)
				{
					tmp = ((j << k) | (1 << (k - 1))) & lim;
					if((tmp & now) != now) f[i + 1][tmp] = (f[i + 1][tmp] + f[i][j]) % mod;
				}
			}
	for(int j = 0; j <= lim; j++) if((j & now) != now) ans = (ans + f[n][j]) % mod;
	printf("%d\n", (fpow(10, n) - ans + mod) % mod);
	return 0;
}

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 1055050
ll dp[50][1<<20];
vector<ll> change(int x){
    vector <ll> v;
    int count=0;
    while(x){
        count++;
        if(x%2){v.pb(count);count=0;}
        x/=2;
    }
    return v;
}
int change2(vector<ll> v){
    ll now=1;
    ll ans=0;
    for(auto e:v){
        rep(i,e)now*=2;
        ans+=now/2;
    }
    return ans;
}
bool judge[N];
ll pw[50];
main(){
    ll n=in();
    ll x[3];
    rep(i,3)x[i]=in();
    int sum=x[0]+x[1]+x[2];
    swap(x[0],x[2]);
    vector<pair<vector<ll>,ll>> v;
    vector<ll> vvv;
    v.pb({vvv,1ll});
    ll ans=0;
    pw[0]=1;
    rep(i,20)pw[i+1]=pw[i]*2;
    dp[0][0]=1;
    vector<ll> tmp={2,3};
    rep(i,1<<sum){
        vector<ll> s=change(i);
        int state=0;
        int now[3]={};
        rep(kk,s.size()){
            if(state==3)break;
            if(now[state]+s[kk]<x[state])now[state]+=s[kk];
            else if(now[state]+s[kk]==x[state])state++;
            else {state=-1;break;}
        }
        judge[i]=(state==3?1:0);
    }
    rep(i,n){
        rep(k,1<<sum){
            if(dp[i][k]==0)continue;
            rep2(j,1,7){
                vector<ll> s(1,j);
                ll next=(k*pw[j]+pw[j-1])%pw[sum];
                if(!judge[next])
                dp[i+1][next]=(dp[i][k]+dp[i+1][next])%MOD;
            }
            dp[i+1][0]=(dp[i+1][0]+dp[i][k]*3)%MOD;
        }
    }
    ll p=1;
    rep(i,n){
        p=p*10ll%MOD;
    }
    rep(i,1<<sum){
        p=(p-dp[n][i]+MOD)%MOD;
    }
    cout<<p<<endl;
}


#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
long long bad[700][700] = {};
vector<pair<int,int>> vertexs[2][700][700];
int visited[2][700][700];
int coloring[2][700][700];
int main() {
	long long n, d[2];
	cin >> n;
	REP(q, 2) {
		cin >> d[q];
	}
	REP(itr, 2) {
		for (long long a = 0; a * a <= d[itr]; ++a) {
			long long b = sqrt(d[itr] - a * a);
			if (b * b + a * a != d[itr]) continue;
			for (int q = 0; q < 2 * n; ++q) {
				for (int j = 0; j < 2 * n; ++j) {
					if (bad[q][j] == 1) continue;
					int xe[4] = { 1,1,-1,-1 };
					int ye[4] = { 1,-1,1,-1 };
					REP(t, 4) {
						int now_x = q + xe[t] * a;
						int now_y = j + ye[t] * b;
						if (now_x >= 0 && now_x < 2 * n && now_y >= 0 && now_y < 2 * n) {
							if (bad[now_x][now_y] == 1) continue;
							vertexs[itr][q][j].push_back(make_pair(now_x, now_y));
							vertexs[itr][now_x][now_y].push_back(make_pair(q, j));
						}
					}
				}
			}
		}
		for (int q = 0; q < 2 * n; ++q) {
			for (int j = 0; j < 2 * n; ++j) {
				if (visited[itr][q][j] == 0 && bad[q][j] == 0) {
					queue<pair<int, int>> next;
					next.push(make_pair(q, j));
					visited[itr][q][j] = 1;
					vector<pair<int, int>> used;
					int cnt[2] = {};
					while (next.empty() == false) {
						pair<int, int> now = next.front();
						next.pop();
						used.push_back(now);
						REP(i, vertexs[itr][now.first][now.second].size()) {
							pair<int, int> going = vertexs[itr][now.first][now.second][i];
							if (visited[itr][going.first][going.second] == 0) {
								visited[itr][going.first][going.second] = 1;
								coloring[itr][going.first][going.second] = (coloring[itr][now.first][now.second] + 1) % 2;
								cnt[coloring[itr][going.first][going.second]]++;
								next.push(going);
							}
						}
					}
					int yusen = 1;
					if (cnt[0] < cnt[1]) {
						yusen = 0;
					}
					REP(q, used.size()) {
						if (coloring[itr][used[q].first][used[q].second] == yusen) {
							bad[used[q].first][used[q].second] = 1;
						}
					}
				}
			}
		}
	}
	int cnt = 0;
	REP(q, 2 * n) {
		REP(j, 2 * n) {
			if (bad[q][j] == 0) {
				cnt++;
				if (cnt <= n * n) {
					cout << q << " " << j << endl;
				}
			}
		}
	}
}

#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
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*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,d1,d2,col[610][610];

void solve(int d)
{
    int p=0;
    while (d%4==0)
    {
        d/=4;p++;
    }
    if (d&1)
    {
        rep(i,0,n*2-1) rep(j,0,n*2-1)
        {
            int tmp=(i>>p)+(j>>p);
            col[i][j]|=(tmp&1);
        }
    }
    else
    {
        rep(i,0,n*2-1) rep(j,0,n*2-1)
        {
            col[i][j]|=((i>>p)&1);
        }
    }

}

int main()
{
    n=read();d1=read();d2=read();
    solve(d1);solve(d2);
    int cnt=0;
    rep(i,0,n*2-1) rep(j,0,n*2-1)
    {
        if (!col[i][j])
        {
            printf("%d %d\n",i,j);cnt++;
            if (cnt==n*n) return 0;
        }
    }
    return 0;
}


//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 100000
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,s,n,m;
	for(;scanf("%d%d",&n,&m)>1;printf("%d\n",s)){
		for(i=0;i<m;i++)scanf("%d%d%d",a+i,b+i,&node[i].first),node[i].second=i;
		sort(node,node+m);
		for(i=0;i<n;i++)parent[i]=i;
		for(s=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))s+=node[i].first;
	}
}

#include <bits/stdc++.h>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

struct Edge{
    int from, to; ll cost;
    Edge(int from, int to, ll cost){
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
    bool operator<(const Edge &e) const{
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const{
        return cost > e.cost;
    }
};

struct Graph{
    int V,E;
    vector<vector< pair<int, ll> > > edges;

    Graph(){
        cin >> V >> E;
        edges.resize(V);
        int s,t; ll w;
        rep(E){
            cin >> s >> t >> w;
            edges[s].emplace_back(t, w);
            edges[t].emplace_back(s, w);
        }
    }

    ll kruskal(){
        ll ret = 0LL;
        priority_queue<Edge, vector<Edge>, greater<Edge> > que;
        vector<bool> used(V, false);

        used[0] = true;
        for(pair<int, ll> e: edges[0])
            que.push(Edge(0, e.first, e.second));

        while(!que.empty()){
            Edge e = que.top(); que.pop();
            while(!que.empty() && used[e.to]){
                e = que.top(); que.pop();
            }
            if(used[e.to]) break;
            ret += e.cost;
            used[e.to] = true;
            for(pair<int, ll> next: edges[e.to])
                if(!used[next.first]) que.push(Edge(e.to, next.first, next.second));
        }
        return ret;
    }
};

int main(){
    Graph g = Graph();
    cout << g.kruskal() << endl;
}


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

void fnInput(int &rnMaxSiz, vector<int> &rvnNum)
{
  cin >> rnMaxSiz;

  rvnNum.resize(rnMaxSiz);
  for (int i = 0; i < rnMaxSiz; i++)
    cin >> rvnNum[i];
}

void fnPartition(vector<int> &rvnNum, int nStart, int nEnd, int &nCur)
{
  for (int i = nStart; i < nEnd; i++)
    if (rvnNum[i] <= rvnNum[nEnd])
      swap(rvnNum[nCur++], rvnNum[i]);

  swap(rvnNum[nCur], rvnNum[nEnd]);
}

void fnResult(const vector<int> &cnrvnNum, int nCur)
{
  for (int i = 0; i < cnrvnNum.size(); i++)
  {
    if (i)  cout << " ";
    if (i == nCur) cout << "[";
    cout << cnrvnNum[i];
    if (i == nCur) cout << "]";
  }
  cout << endl;
}

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

  int nMaxSiz;
  vector<int> vnNum;

  fnInput(nMaxSiz, vnNum);
  int nStart = 0;
  int nEnd = vnNum.size() - 1;
  int nCur = nStart;

  fnPartition(vnNum, nStart, nEnd, nCur);
  fnResult(vnNum, nCur);

  return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, l;
    cin >> n >> l;

    int sum = 0;
    int best = 1e8;
    rep (i, n) {
        int x = l + i;
        sum += x;
        if (abs(best) > abs(x)) {
            best = x;
        }
    }

    sum -= best;
    println(sum)

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) cin >> s[i];

    int cnt = 0;
    queue<pii> q;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                cnt++;
                q.push(pii(i,j));
            }
        }
    }
    if (cnt == h*w) {
        cout << 0 << endl;
        return 0;
    }

    auto f = [&] (int y, int x) {
        cnt++;
        s[y][x] = '#';
        q.push(pii(y, x));
    };
    for (int i = 1; 1; i++) {
        int j = q.size();
        for (int k = 0; k < j; k++) {
            int a = q.front().first;
            int b = q.front().second;
            q.pop();
            if (a>0)   if (s[a-1][b]=='.') f(a-1,b);
            if (a<h-1) if (s[a+1][b]=='.') f(a+1,b);
            if (b>0)   if (s[a][b-1]=='.') f(a,b-1);
            if (b<w-1) if (s[a][b+1]=='.') f(a,b+1);
        }
        if (cnt == h*w) {
            cout << i << endl;
            return 0;
        }
    }
}

#include <bits/stdc++.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dc[4] = {1, -1, 0,  0};
const int dr[4] = {0,  0, 1, -1};
//const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
//const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

using namespace std;

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

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

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

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

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

int main(void)
{
    int h, w;
    cin >> h >> w;

    v_string s(h);
    cin >> s;

    queue<pii> q;
    v2_int dist(h, v_int(w, 0));
    v2_bool done(h, v_bool(w, false));
    irep(i, h) {
        irep(j, w) {
            if(s[i][j] == '#') {
                q.push(pii(i,j));
                done[i][j] = true;
            }
        }
    }

    while(q.size()) {
        pii t = q.front(); q.pop();
        irep(x,4) {
            int row = t.fi + dr[x];
            int col = t.se + dc[x];
            if(row < 0 || row >= h) { continue; }
            if(col < 0 || col >= w) { continue; }
            if(s[row][col] == '#' || done[row][col]) { continue; }
            done[row][col] = true;
            dist[row][col] = dist[t.fi][t.se] + 1;
            q.push(pii(row,col));
        }
    }

    int ans = 0;
    irep(i, h) {
        irep(j, w) {
            chmax(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

/*atcoder*/


#include<bits/stdc++.h>

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll M, D[200020], C[200020];

  void init() {
    scanf("%lld", &M);
    rep(i, M) scanf("%lld %lld", &D[i], &C[i]);
  }

  ll fold(ll n) {
    if (n < 10) return n;
    return (n/10)+(n%10);
  }

  void solve() {
    ll past = 0, ans = 0;
    rep(i, M) {
      ans += (C[i]-1) + (D[i]*C[i]/10);
      past *= 10;
      past += fold(D[i]*C[i]);
      while(past >= 10) {
        ans++;
        past = (past/10)+(past%10);
      }
    }
    printf("%lld\n", ans);
  }

  void solve2() {
    ll acc = 0, ans = 0;
    rep(i, M) {
      ans += C[i];
      acc += D[i]*C[i];
    }
    ans--;
    acc--;
    ans += acc/9;
    printf("%lld\n", ans);
  }
}

int main() {
  solver::init();
  solver::solve2();
  return 0;
}

#include <iostream>
using namespace std;

int main(int argc, char* argv[]) {
  int ina, inb, n;
  cin >> n;
  while(n != 0){
    int a=0, b=0;
    for(int i=0;i<n;i++){
      cin >> ina >> inb;
      if(ina > inb){
        a += ina+inb;
      }else if(ina < inb){
        b += ina+inb;
      }else{
        a += ina;
        b += inb;
      }
    }
    cout << a << " " << b << endl;
    cin >> n;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++)
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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 mod = 2019;

int main() {
    ll l, r;
    cin >> l >> r;
    map<ll, ll> m;
    for (ll i = l; i <= r && i <= l+5000; i++){
        m[i%mod]++;
    }
    ll ans = 2020;
    vector<ll> a;
    for (auto x: m){
        rep1(i, x.second) a.push_back(x.first);
    }
    ll n = a.size();
    for (ll i=0; i<(n); i++){
        for (ll j=i+1; j<(n); j++){
            ans = min(ans, a[i]*a[j]%2019);
        }
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

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

int main() {
  ll l, r;
  cin >> l >> r;
  if(r - l >= 2019){
    cout << 0;
  }
  else{
    ll ans = 2018;
    for(long long i = l; i <= r - 1; i++){
      for(long long j = i + 1; j <= r; j++){
        ll a, b;
        a = i % 2019;
        b = j % 2019;

        ll x;
        x = (a * b) % 2019;

        ans = min(ans, x);
      }
    }
   cout << ans;
  }

  return 0;
}


#include<iostream>
int H,W,A,B;
int main(){
    std::cin>>H>>W>>A>>B;
    for(int i=0;i<H*W;i++)std::cout<<(i%W<A^i/W<B)<<(i%W==W-1?"\n":"");
    return 0;
}

#include<stdio.h>

//this file is not a C file but a C++ file
void seisekiduke(void);//宣言

int main(void){
    int stnum;//the number of the student
    while(1) {
        scanf(" %d", &stnum);
        if(stnum == 0) {
            break;
        }
        for(int i = stnum - 1;i >= 0;i -= 1) {
            seisekiduke();//一名の生徒の成績を付ける
        }
    }
    return 0;
}

void seisekiduke(void) {
    int pm, pe, pj = 0;//score
    char grade;
     scanf(" %d %d %d", &pm, &pe, &pj);
        if((pm == 100 || pe == 100 || pj == 100) ||
           (pm + pe) / 2 >= 90                   ||
           (pm + pe + pj) / 3 >= 80) {
           grade = 'A';
        }else if((pm + pe + pj) / 3 >= 70 ||
                (((pm + pe + pj) / 3 >= 50) && (pm >= 80 || pe >= 80))){
            grade = 'B';
        }else{
            grade = 'C';
        }
        printf("%c\n", grade);

}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
    if(n == 1) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    for(int i=5; i*i<=n; i+=6){
        if((n%i == 0)||(n%(i+2) == 0)) return false;
    }
    return true;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int main()
{
    fio;
    int n;
    cin>>n;
  vi v1(n);
    loop(i,0,n)
    {
        cin>>v1[i];
    }
    int ans = 0,k1 = INT_MAX;
    loop(i,0,n)
    {
       if(k1>v1[i])
       {
           k1 = v1[i];
           ans++;
       }
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D, X, Y;
  cin >> A >> B >> C >> D;
  X = min(A, B);
  Y = min(C, D);
  cout << X + Y << endl;
}


#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=5e5;
typedef int fuko[yuzu|10];
struct node {
  int l,r,id;
  void rd(int x) {
    read(l),read(r),id=x;
  }
}qr[yuzu|10];
fuko c,cnt,lxy;
int main() {
  int i,n,q,bk;
  read(n),read(q),bk=sqrt(n);
  for (i=1;i<=n;++i) c[i]=read();
  for (i=1;i<=q;++i) qr[i].rd(i);
  sort(qr+1,qr+q+1,[&](node a,node b){return a.l/bk^b.l/bk?a.l<b.l:a.r<b.r;});
  int nl=1,nr=0,ans=0;
  for (i=1;i<=q;++i) {
    for (;nr<qr[i].r;) !cnt[c[++nr]]++?++ans:0;
    for (;nr>qr[i].r;) !--cnt[c[nr--]]?--ans:0;
    for (;nl<qr[i].l;) !--cnt[c[nl++]]?--ans:0;
    for (;nl>qr[i].l;) !cnt[c[--nl]]++?++ans:0;
    lxy[qr[i].id]=ans;
  }
  for (i=1;i<=q;++i) printf("%d\n",lxy[i]);
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

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

int main() {
  int n,q;
  cin >>n >> q;
  vi a(n);
  vi pi(n+1,-1);
  vector<vi> p(n);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    int l = pi[a[i]];
    if(l != -1)p[l].push_back(i);
    pi[a[i]] = i;
  }
  vector<vp> qs(n);
  rep(i,q){
    int l,r;
    cin >> l >> r;
    l--;r--;
    qs[l].emplace_back(r,i);
  }
  vi ans(q);
  BIT<int> d(n);
  for(int x = n-1;x>=0;x--){
    for(int y:p[x])d.add(y,1);
    for(P query : qs[x]){
      int r = query.first, i = query.second;
      ans[i] = (r-x+1) - d.sum(r);
    }
  }
  rep(i,q)cout<<ans[i]<<endl;
  return 0;
}


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

int h, w;
string s[400];
int a[400][400];
int b = 0;
pair<int, int> dyx[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

void bfs(int y, int x) {
  queue<pair<int,int>> q;
  q.push(make_pair(y, x));
  a[y][x] = b;
  while (!q.empty()) {
    int x, y;
    tie(y, x) = q.front();
    q.pop();
    for (auto d: dyx) {
      int ny = y + d.first;
      int nx = x + d.second;
      if (ny < 0 || ny >= h || nx < 0 || nx >= w) {
        continue;
      }
      if (a[ny][nx] > -1) {
        continue;
      }
      if (s[y][x] != s[ny][nx]) {
        a[ny][nx] = b;
        q.push(make_pair(ny, nx));
      }
    }
  }
}
int main() {
  cin>>h>>w;
  for (int i=0; i<h; i++) cin>>s[i];
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      a[i][j] = -1;
    }
  }
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (a[i][j] == -1) {
        bfs(i, j);
        ++b;
      }
    }
  }
  map<int, pair<int,int>> cnt;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (s[i][j] == '#') {
        ++cnt[a[i][j]].first;
      } else {
        ++cnt[a[i][j]].second;
      }
    }
  }
  long long ans = 0;
  for (auto e: cnt) {
    ans += 1LL * e.second.first * e.second.second;
  }
  cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

using State = pair<pair<int, int>, int>;

int MX = 81*2*81 + 9;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m;
    cin >> n >> m;
    //n = 80; m = 80;
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            //a[i][j] = (i+j)%81;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int v;
            cin >> v;
            //v = (81+i-j)%81;
            a[i][j] -= v;
        }
    }
    vector<vector<vector<bool>>> was(n, vector<vector<bool>>(m));
    vector<State> q;
    q.reserve(n*m*MX);
    auto add = [&] (int i, int j, int c) {
        if (i < 0 || i >= n || j < 0 || j >= m) {
            return;
        }
        auto &vec = was[i][j];
        if (vec.size() == 0) {
            vec.assign(2*MX + 1, false);
        }
        for (int mul = -1; mul <= 1; mul += 2) {
            int nxtC = c + mul*a[i][j];
            int code = nxtC + MX;
            if (!vec[code]) {
                q.push_back({{i, j}, nxtC});
                vec[code] = true;
            }
        }
    };
    add(0, 0, 0);
    int ans = 1e9;
    for (int qi = 0; qi < q.size(); qi++) {
        auto cur = q[qi];
        int i = cur.first.first;
        int j = cur.first.second;
        int c = cur.second;
        if (i == n-1 && j == m-1) {
            ans = min(ans, abs(c));
        }
        add(i+1, j, c);
        add(i, j+1, c);
    }
    cout << ans << endl;
}


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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  int n,k;
  while(cin>>n>>k){
    if(n==0) break;
    vector<int> seq(n);
    set<string> ans;
    REP(i,n) cin>>seq[i];
    for(int i = 0; i < 1<<n; i++){
      int cnt = 0;
      REP(j,n){
        cnt += (i>>j)&1;
      }
      if(cnt != k) continue;
      vector<int> selected;
      REP(j,n) if((i>>j)&1){
        selected.push_back(seq[j]);
      }
      sort(selected.begin(), selected.end());
      do{
        stringstream ss;
        REP(j,selected.size()) ss << selected[j];
        ans.insert(ss.str());
      }while(next_permutation(selected.begin(), selected.end()));
    }
    printf("%d\n",(int)ans.size());
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef pair< int, int > Pi;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};
const static int INF = 1 << 30;

int w, h, mas[20][20];
Pi S, G;

bool In(int x, int y)
{
  return(0 <= x && x < w && 0 <= y && y < h);
}

int rec(int x, int y, int d, int cost)
{
  if(cost > 10) return(INF);
  if(make_pair(x, y) == G) return(cost);
  int ret = INF;
  if(d == -1) {
    for(int i = 0; i < 4; i++) {
      if(!In(x + dx[i], y + dy[i])) continue;
      if(In(x + dx[i], y + dy[i]) && mas[y + dy[i]][x + dx[i]] == 1) continue;
      ret = min(ret, rec(x + dx[i], y + dy[i], i, cost + 1));
    }
  } else {
    x += dx[d], y += dy[d];
    if(In(x, y)) {
      if(mas[y][x] == 1) {
        mas[y][x] = 0;
        ret = rec(x - dx[d], y - dy[d], -1, cost);
        mas[y][x] = 1;
      } else {
        ret = rec(x, y, d, cost);
      }
    }
  }
  return(ret);
}

int main()
{
  while(cin >> w >> h, w) {
    S = make_pair(-1, -1);
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        cin >> mas[i][j];
        if(mas[i][j] == 2) {
          S = make_pair(j, i);
        } else if(mas[i][j] == 3) {
          G = make_pair(j, i);
        }
      }
    }
    int ret = rec(S.first, S.second, -1, 0);
    if(S == make_pair(-1, -1) || ret == INF) cout << -1 << endl;
    else cout << ret << endl;
  }
}


#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
    int N,x;
    cin >> N >> x;
    int a;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> a;
        A.at(i) = a;
    }
    sort(A.begin(), A.end());
    int count=0;
    for(int i=0;i<N;i++){
        x = x - A.at(i);
        if((x>0)&&(i!=N-1)){
            count = count + 1;
        }
        else if(x==0){
            count = count + 1;
        }

        else{
            break;
        }
    }
    cout << count << endl;
}

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define N 305

using namespace std;
typedef pair<int,int> Pair;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return (x += y) - (x >= mod ? mod : 0); }
inline void inc(int &x, int y) { (x += y) -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }

template <class T> inline T	input() {
	int x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

template <class T> inline void chkmin(T &x, T &y) { x = x < y ? x : y; }
template <class T> inline void chkmax(T &x, T &y) { x = x > y ? x : y; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

int n, m, ans = inf;
int a[N][N];
int cnt[N];
bool vis[N];

void calc() {
	memset(cnt, 0, sizeof cnt);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (vis[a[i][j]]) {
				++cnt[a[i][j]];
				break;
			}
}

int main() {
	read(n, m);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			read(a[i][j]);

	for (int i = 1; i <= m; ++i) vis[i] = true;
	calc();

	for (int i = 1; i <= m; ++i) {
		int pos = max_element(cnt + 1, cnt + m + 1) - cnt;
		ans = min(ans, cnt[pos]);
		vis[pos] = false;
		calc();
	}

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


#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  long long ans = 0;
  for (long long i = 1; i <= N; i++)
    if (i % 3 != 0 && i % 5 != 0) ans += i;
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n;
  	cin>>n;
  	cout<<n + (n*n) + (n*n*n);
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1)))
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,h,w;
	cin >> h >> w >> n;
	if(h>w)
		cout << (n+h-1)/h << "\n";
	else
		cout << (n+w-1)/w << "\n";
}

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

int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if((A<C&&C<B)||(B<C&&C<A)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
return 0;}
/*compile
g++ code.cpp
./a.out
run*/


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    vector<long long> b;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      long long cur = a[i];
      for (auto& x : b) {
        cur = min(cur, cur ^ x);
      }
      if (cur > 0) {
        if (s[i] == '1') {
          ans = 1;
          break;
        } else {
          b.push_back(cur);
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200 + 10;
ll a[maxn];

const int L = 63;
ll d[L];
bool add(ll x){
    for(int i = L - 1; i >= 0; i--) if(x & 1ll << i){
        if(d[i] == -1){d[i] = x; return true;}
        x ^= d[i];
    }
    return false;
}

int main(){
//    Fast;
    int t; scanf("%d", &t); while(t--){
        memset(d, -1, sizeof d);

        int n; scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%lld", a + i);
        char s[maxn]; scanf("%s", s);
        int flag = 0;
        for(int i = n - 1; i >= 0; i--){
            if(add(a[i]) && s[i] == '1'){
                flag = 1;
                break;
            }
        }
        printf("%d\n", flag);
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int mod;
int mypow(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return ans;
}
int n,pw2[6005],pw3[6005],ans=0,fac[6005],invfac[6005];
int main()
{
	scanf("%d%d",&n,&mod);n=3*n;
	pw2[0]=pw3[0]=1;
	pw2[1]=mypow(2,mod-2);
	pw3[1]=mypow(3,mod-2);fac[0]=fac[1]=1;
	for(int i=2;i<=n;i++)pw2[i]=1ll*pw2[i-1]*pw2[1]%mod,pw3[i]=1ll*pw3[i-1]*pw3[1]%mod,fac[i]=1ll*fac[i-1]*i%mod;
	invfac[n]=mypow(fac[n],mod-2);
	for(int i=n-1;i>=0;i--)invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	for(int i=0;i<=n/3;i++)
	{
		for(int j=0;i+j<=n/3;j++)
		{
			ans=(ans+1ll*pw2[i]*pw3[j]%mod*invfac[i]%mod*invfac[j]%mod*invfac[n-2*i-3*j])%mod;
		}
	}
	for(int i=1;i<=n;i++)ans=1ll*ans*i%mod;
	printf("%d\n",ans);
	return 0;
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);

#define l_ength size

ll MOD;

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[6060][13000];

int main(void){
	int n,i,j;
	ll ans = 0ll;
	std::cin >> n >> MOD;
	n *= 3;
	dp[0][6500] = 1ll;
	for(i=0; i<n; ++i){
		for(j=500; j<=12500; ++j){
			add_mod(dp[i+1][j-1],dp[i][j]);
			add_mod(dp[i+2][j+1],dp[i][j]*(i+1)%MOD);
			add_mod(dp[i+3][j],dp[i][j]*(i+1)*(i+2)%MOD);
		}
	}
	for(j=500; j<=6500; ++j){
		add_mod(ans,dp[n][j]);
	}
	std::cout << ans << std::endl;
	return 0;
}


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
    ll n,q,i,a1 = 0, a2 = 0;
    ump<ll, ll>mpAC,mpWA;
    string s;
    cin >> n >> q;
    while(q--){
        ll k;
        cin >> k >> s;
        if(s == "WA"){
            if(mpAC.find(k) == mpAC.end())mpWA[k]++;
        }
        else {
            if(mpAC.find(k) == mpAC.end()){
                a2 += mpWA[k];
                a1++;
            }
            mpAC[k] = 1;
        }
    }
    cout << a1 << " " << a2 << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	ll n,m; cin>>n>>m;
	vl a(m);
	vector<char> b(m);
	ll ans=-1;
	rep(i,0,m){
		cin>>a[i]>>b[i];
	}
	rep(i,0,1000){
		string s=to_string(i);
		if(s.size()!=n)continue;
		bool ok=true;
		rep(i,0,m){
			if(s[a[i]-1]!=b[i])ok=0;
		}
		if(ok){
			ans=i;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}