//Bulbul khan-420...
#include <bits/stdc++.h>
#include <cstring>
#define ll long long int
#define pb() push_back()
#define f(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
      ll t,a,b,c,d,i,j,k,l,n,m,x,y,z;
      cin>>n>>m>>x>>y;
     string s[n+6];
     for(i=0;i<n;i++)
       cin>>s[i];
     x--;
     y--;
     j=0;
    if(s[x][y]=='#')
       j=0;
    else{
       for(i=y+1;i<m;i++){
        if(s[x][i]=='.')
           j++;
         else
           break;
}
     for(i=y-1;i>=0;i--){
        if(s[x][i]=='.')
           j++;
       else
         break;
}
      for(i=x+1;i<n;i++){
       if(s[i][y]=='.')
         j++;
      else
       break;
}
     for(i=x-1;i>=0;i--){
        if(s[i][y]=='.')
          j++;
        else
         break;
}
      j++;
}
     cout<<j;
}

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

int main(){
  long long x, y, a, b;
  cin >> x >> y >> a >> b;

  long long ans = 0;
  while((long double)a * x <= 9e18 and a * x <= b + x and a * x < y){
    x *= a;
    ans++;
  }

  long long diff = (y - x - 1)/b;
  if(diff > 0ll) ans += diff;

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


#include<bits/stdc++.h>
using namespace std;
int a[5];
int ans=99999999;
int main()
{
	for(int i=1;i<=4;i++)
	{
		cin>>a[i];
		ans=min(ans,a[i]);
	}
	cout<<ans;
	return 0;
}

/***

                                Bismillahir Rahmanir Rahim
                                Rabbi Zidni Ilma
                                Author : Saidur Rahman
                                Department of CSE, City University, Bangladesh.

***/

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

#define         endl                "\n"
#define         EPS                 1e-6
#define         F                   first
#define         sf                  scanf
#define         pf                  printf
#define         S                   second
#define         done                return 0
#define         MP                  make_pair
#define         pb                  push_back
#define         start               int main()
#define         PI                  acos(-1.0)
#define         NO                  cout<<"NO\n"
#define         No                  cout<<"No\n"
#define         no                  cout<<"no\n"
#define         YES                 cout<<"YES\n"
#define         Yes                 cout<<"Yes\n"
#define         yes                 cout<<"yes\n"
#define         sz(x)               int(x.size())
#define         all(a)              a.begin(),a.end()
#define         srt(x)              sort(x.begin(),x.end())
#define         clock_start         clock_t tStart = clock()
#define         MEM(a, b)           memset(a, (b), sizeof(a))
#define         watch(x)            cout << (#x) << " is " << (x) << endl
#define         Fast                ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define         show_time           cout<<"\n\nTime Taken: "<<fixed<<setprecision(3)<<(double)(clock() - tStart) /  CLOCKS_PER_SEC<<"s"

            /****** Template of some bit operations *****/

int         ToggleBit (int n, int X)    { return n ^ (1 << X); }
int         SetBit (int n, int X)       { return n | (1 << X); }
int         ClearBit (int n, int X)     { return n & ~(1 << X); }
bool        CheckBit (int n, int X)     { return (bool)(n & (1 << X)); }

            ///////////////////////////////////////////////////////////////////////////
        ///////////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////////
            //////////////////////////////////////////////////////////////////////////

typedef     long long   ll;
const       int MAXN = 1e5 + 1;
const       int MOD  = 1e9 + 7;
const       int INF  = 1e9;
const       ll LINF  = 1e18;

start
{
    Fast;

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

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(min(a,b),min(c,d))<<endl;

#ifndef ONLINE_JUDGE
    show_time;
#endif

    done;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(it, ar) for(auto &it: ar)
#define loop(i, start, end) for(auto i = (start); i <= (end); i++)
#define loopSkip(i, start, end, skip) for(auto i = (start); i <= (end); i += skip)
#define loopRev(i, start, end) for(int i = (start); i >= (end); i--)
#define FLASH ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define testCases(t) cin >> t; while(t--)
#define readLine(s) getline(cin, s);
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << " "
#define PNN1(n) cout << (n) << "\n"
#define PNN2(a, b) cout << (a) << " " << (b) << "\n"
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << "\n"
#define PrintObject(ar) for(auto var: ar) cout << var << " "; cout << "\n"
#define PrintMap(map) for(auto var: map) PNN2(var.first, var.second)
#define PrintPair(pair) PNN2(pair.first, pair.second)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define ENTER PNN1("")
#define FLUSH cout.flush()
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int, int>
// #define ONLINE_JUDGE

// Math macros
#define M_PI 3.14159265358979323846

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;

template <typename T>
T ii() {
	T a;
	IN1(a);
	return a;
}

struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
      // http://xorshift.di.unimi.it/splitmix64.c
      x += 0x9e3779b97f4a7c15;
      x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
      x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
      return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
      static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
      return splitmix64(x + FIXED_RANDOM);
  }
};

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

	int n;
	IN1(n);
	vector<int> ar(n);
	FOR(it, ar) IN1(it);

	sort(ALL(ar));
	int total = accumulate(ALL(ar), 0);
	int start = 1, end = (int) 1e5;
	int ans = INT_MAX;

	vector<bool> dp(end + 1, false);
	dp[0] = true;
	FOR(it, ar) loopRev(i, end, 0) if(dp[i] && i + it <= end) {
			dp[i + it] = true;
			auto cur = i + it;
			if(2 * cur >= total) ans = min(ans, cur);
	}

	PNN1(ans);

	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;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  int ans = INF;
  rep(i, n) {
    int a, p, x;
    cin >> a >> p >> x;
    if(x > a) {
      ans = min(ans, p);
    }
  }
  if(ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr LL mod = 1000000007;
string c[4];
LL power(LL a, LL r){
    LL res = 1;
    for(; r; r >>= 1, a = a * a % mod)
        if(r & 1) res = res * a % mod;
    return res;
}
LL Fib(int n){
    if(n <= 2) return 1;
    LL a = 1, b = 1;
    for(int i = 0; i < n - 2; i += 1){
        LL t = (a + b) % mod;
        b = a;
        a = t;
    }
    return a;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    for(int i = 0; i < 4; i += 1) cin >> c[i];
    if(c[0] == "A" and c[1] == "A") cout << 1;
    else if(c[1] == "B" and c[3] == "B") cout << 1;
    else if(c[0] == "A" and c[1] == "B" and c[2] == "A" and c[3] == "A") cout << (N == 2 ? 1 : power(2, N - 3));
    else if(c[0] == "A" and c[1] == "B" and c[2] == "B" and c[3] == "A") cout << Fib(N - 1);
    else if(c[0] == "B" and c[1] == "A" and c[2] == "A" and c[3] == "A") cout << Fib(N - 1);
    else if(c[0] == "B" and c[1] == "A" and c[2] == "A" and c[3] == "B") cout << Fib(N - 1);
    else if(c[0] == "B" and c[1] == "A" and c[2] == "B" and c[3] == "A") cout << (N == 2 ? 1 : power(2, N - 3));
    else if(c[0] == "B" and c[1] == "A" and c[2] == "B" and c[3] == "B") cout << (N == 2 ? 1 : power(2, N - 3));
    else if(c[0] == "B" and c[1] == "B" and c[2] == "A" and c[3] == "A") cout << (N == 2 ? 1 : power(2, N - 3));
    else if(c[0] == "B" and c[1] == "B" and c[2] == "B" and c[3] == "A") cout << Fib(N - 1);
    else assert(0);
    return 0;
}
//AAABABABABABBB

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = 0; i <= (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;

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

  int m = 0, day = 1;
  do {
    m = m + day;
    day += 1;
  } while(n > m);

  cout << day - 1 << endl;

  return 0;
}


#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
#define inf INT_MAX
#define linf LLONG_MAX
#define lninf LLONG_MIN
const int mod = 1e9 + 7;
const int N = 1e5 + 4;
typedef long double ld;

int solve()
{
	int n, m, k; scn(n); scn(m); scn(k);

	pair<ld, ld> p = {0.0, 0.0};

	vector<int> mark(n + 1, 0);

	rep(i, 0, k)
	{
		int val; scn(val);

		mark[val]++;
	}

	int cnt = 0;

	rep(i, 1, n)
	{
		if(mark[i])
		cnt++;
		else
		{
			if(cnt >= m)
			{
				pri(-1); return 0;
			}

			cnt = 0;
		}
	}

	if(cnt >= m)
	{
		pri(-1); return 0;
	}

	vector<pair<ld, ld>> v(n + m + 1, {0.0, 0.0});

	for(int i = n - 1; i >= 0; i--)
	{
		p.F -= v[i + m + 1].F; p.S -= v[i + m + 1].S;

		if(mark[i])
		{
			v[i].F = 1.0;
		}
		else
		{
			v[i].F = p.F / (ld)m; v[i].S = p.S / (ld)m;

			v[i].S += 1.0;
		}

		// cout << v[i].F << " " << v[i].S << endl;

		if(i == 0)
		cout << fixed << setprecision(10) << v[i].S / (1.0 - v[i].F);

		p.F += v[i].F; p.S += v[i].S;
	}

	return 0;
}

int main()
{
	int t = 1; //scn(t);

	while(t--)
	{
		solve();
	}

    return 0;
}

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

//#define int long long

using ld = long double;

const int N = 2e5 + 7;

const ld eps = 1e-9;

ld a[N], b[N], csum_a[N], csum_b[N];

int mrkd[N];

int32_t main() {
    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m, k; cin >> n >> m >> k;
    vector <int> o(k);
    for(int &x: o) cin >> x, mrkd[x] = true;
    ld q = 1.0 / (ld)m;
    for(int i = n - 1; i >= 0; i--) {
        for(int x: o) if(i + m >= x && x > i) {
            b[i] += q;
        }

        a[i] = 1.0;

        a[i] += q * (csum_a[i + 1] - csum_a[i + m + 1]);
        b[i] += q * (csum_b[i + 1] - csum_b[i + m + 1]);
        if(mrkd[i]) {
            a[i] = b[i] = 0.0;
        }
        csum_a[i] = csum_a[i + 1] + a[i];
        csum_b[i] = csum_b[i + 1] + b[i];
    }

    if(fabs(1.0 - b[0]) < eps) {
        cout << -1 << endl;
        return 0;
    }

    cout << fixed << setprecision(10) << a[0] / (1.0 - b[0]) << endl;
}


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

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

const ll MOD = 1e9+7;

ll pow_mod(ll a, ll n, ll p)
{
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*a%p;
        a = a*a%p;
        n >>= 1;
    }
    return res;
}

int main()
{
    ll i,j;
    ll h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<int>> yoko(h);
    vector<vector<int>> tate(w);
    int k = 0;
    rep(i,h) rep(j,w) if(s.at(i).at(j) == '.') ++k;
    rep(i,h){
        yoko.at(i).push_back(-1);
        rep(j,w){
            if(s.at(i).at(j) == '#') yoko.at(i).push_back(j);
        }
        yoko.at(i).push_back(w);
    }
    rep(i,w){
        tate.at(i).push_back(-1);
        rep(j,h){
            if(s.at(j).at(i) == '#') tate.at(i).push_back(j);
        }
        tate.at(i).push_back(h);
    }
    ll ans = 0;
    rep(i,h){
        rep(j,w){
            if(s.at(i).at(j) == '#') continue;
            ll tmp = 0;
            ll ind1 = lower_bound(all(yoko.at(i)), j) - yoko.at(i).begin();
            tmp += yoko.at(i).at(ind1) - yoko.at(i).at(ind1 - 1) - 1;
            ll ind2 = lower_bound(all(tate.at(j)), i) - tate.at(j).begin();
            tmp += tate.at(j).at(ind2) - tate.at(j).at(ind2 - 1) - 1;
            --tmp;
            ans += (pow_mod(2, tmp, MOD) + MOD - 1)%MOD*(pow_mod(2, k - tmp, MOD))%MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
int main() {
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> S(n);
  vector<vector<int>> A(n, vector<int>(m)), B(n, vector<int>(m)), C(n, vector<int>(m)), D(n, vector<int>(m));
  int K = 0;
  for (int i = 0; i < n; ++i) cin >> S[i], K += count(S[i].begin(), S[i].end(), '.');
  int64 md = 1e9 + 7;
  vector<int64> two(max(100, K + 2));
  two[0] = 1;
  for (int i = 1; i < SZ(two); ++i) two[i] = two[i - 1] * 2 % md;
  int64 res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (S[i][j] == '.') {
        A[i][j] = 1;
        if (i - 1 >= 0) A[i][j] += A[i - 1][j];
        B[i][j] = 1;
        if (j - 1 >= 0) B[i][j] += B[i][j - 1];
      }
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    for (int j = m - 1; j >= 0; --j) {
      if (S[i][j] == '.') {
        C[i][j] = D[i][j] = 1;
        if (i + 1 <= n - 1) C[i][j] += C[i + 1][j];
        if (j + 1 <= m - 1) D[i][j] += D[i][j + 1];
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j)
      if (S[i][j] == '.') {
        int tot = A[i][j] + B[i][j] + C[i][j] + D[i][j] - 3;
        (res += (two[tot] + md - 1) * two[K - tot] % md) %= md;
      }
  }
  cout << res;
  return 0;
}
//14.10.2020 04:31:12 CST


#include <iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
const int maxn = 5005;
int main()
{
	char s[5005];
	int a[maxn], g[maxn], c[maxn], t[maxn];
	int n;
	int cnt = 0;
	cin >> n;
	a[0] = 0;
	g[0] = 0;
	c[0] = 0;
	t[0] = 0;
	int a1, g1, c1, t1;
	for(int i = 1; i <= n; i++)
	{
		cin >> s[i];
	}
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == 'A')
		{
			a[i] = a[i - 1] + 1;
		}
		else a[i] = a[i - 1];
		if(s[i] == 'G')
		{
			g[i] = g[i - 1] + 1;
		}
		else g[i] = g[i - 1];
		if(s[i] == 'C')
		{
			c[i] = c[i - 1] + 1;
		}
		else c[i] = c[i - 1];
		if(s[i] == 'T')
		{
			t[i] = t[i - 1] + 1;
		}
		else t[i] = t[i - 1];

	}

	for(int i = 1; i <= n; i++)
		{
			for(int j = i + 1; j <= n; j++)
			{
				if((a[j] - a[i - 1] == t[j] - t[i - 1]) && (c[j] - c[i - 1] == g[j] - g[i - 1]))
				cnt++;
			}
		}
	cout << cnt << endl;
}

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

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

  int ans = 0;
  rep(i, N) {
    int c1 = 0, c2 = 0;
    for (int j = i; j < N; j++) {
      if (S[j] == 'A')
        c1++;
      else if (S[j] == 'T')
        c1--;
      else if (S[j] == 'G')
        c2++;
      else if (S[j] == 'C')
        c2--;
      if (c1 == 0 && c2 == 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


// Problem: D - Base n
// Contest: AtCoder - AtCoder Beginner Contest 192
// URL: https://atcoder.jp/contests/abc192/tasks/abc192_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Disclaimer: Don't copy my template, it may lead to plagiarism.
/* Author: Soumy Jain
   Handle: soumy_jain || soumyjain
   "Beautiful flowers too, eventually wither and fall. That's the fate of all living beings."
   "I hate perfection. To be perfect is to be unable to improve any furthur." - Mayuri Kurotsuchi | Bleach
   "I smile to show the pressure of heroes and to trick the fear inside of me."
   "Gravel may be gravel, but me? I'm the gravel that shatters diamonds."
   "If you were to write a story with me in the lead role, it would certainly be...a TRAGEDY." - Kaneki Ken | Tokyo
   Ghoul
*/
/******************************************************************************/
// clang-format off
#include <bits/stdc++.h>
#define ll        long long
#define ull       unsigned long long
#define SPEEDHACK ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Tc        ll tc; cin>>tc; while(tc--)
#define Qu        ll qu; cin>>qu; while(qu--)
#define ff        first
#define ss        second
#define sz(v)     (ll)(v).size()
#define file      freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define MOD       1000000007      // 998244353
using namespace std;
/******************************************************************************/
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(ll x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(ull x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

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

/***********************************MAIN***************************************/
// Are you ready to face the wrath of test cases? Good luck noob Soumy!

int main()
{
    SPEEDHACK
    // file
    string s;
    cin >> s;
    ll m;
    cin >> m;
    ll d = 0;
    for (ll i = 0; i < sz(s); i++)
    {
        d = max(d, (ll)s[i] - 48);
    }
    if (sz(s) == 1)
    {
        if (s[0] - 48 > m)
            cout << 0;
        else
            cout << 1;
        return 0;
    }
    ll c = 0;
    if (sz(s) == 2 || sz(s) == 3 || sz(s) == 4)
    {
        for (ll i = pow(m / (s.front() * 1.0 - 48), 1.0 / (sz(s) - 1)); i > d; i--)
        {
            ll k = 0, b = 1;
            for (ll j = sz(s) - 1; j >= 0; j--, b *= i)
            {
                k += (s[j] - 48) * b;
            }
            if (k <= m)
            {
                c = i;
                break;
            }
        }
        cout << c - d;
        return 0;
    }
    for (ll i = d + 1; i <= pow(m, 1.0 / (sz(s) - 1)); i++)
    {
        ll k = 0, b = 1;
        for (ll j = sz(s) - 1; j >= 0; j--, b *= i)
        {
            k += (s[j] - 48) * b;
        }
        if (k > m)
            break;
        c++;
    }
    cout << c;
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

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

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

void solve(std::string X, long long M){
  if(X.size()==1){
    ll x=stoll(X);
    if(x<=M){
      cout<<1<<endl;
      return;
    }else{
      cout<<0<<endl;
      return;
    }
  }
  ll maxchar=0;
  for (auto &&i : X)
  {
    ll ii=i-'0';
    chmax(maxchar,ii);
  }

  ll r=M+1,l=maxchar;
  while(l+1<r){
    ll mid=(l+r)/2;
    ll tmp=0;
    bool f=false;
    for (auto &&i : X)
    {
      ll ii=i-'0';
      if(tmp>(M-ii)/mid){
        f=true;
        break;
      }
      tmp=tmp*mid+ii;
      if(tmp>M){
        f=true;
        break;
      }
    }
    if(f){
      r=mid;
    }else{
      l=mid;
    }
  }
  cout<<l-maxchar<<endl;
}

int main(){
  cout<<setprecision(1000);
  std::string X;
    std::cin >> X;
    long long M;
    scanf("%lld",&M);
  solve(X, M);
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update>
#define int long long int
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int32_t main()
{
    fastIO;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x,y,val,val1;
    val=(b+c-1)/c;
    if(val>d)
    {
        cout<<-1<<endl;
    }
    else{
        x=a;
        y=(d*c);
        y-=b;
        if(y==0)
        {
            cout<<-1<<endl;
        }
        else{
            val=(x+y-1)/y;
            cout<<val<<endl;
        }
    }
}

#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250005
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define __ template<typename T, typename... Types>
void in() {rt;} __ void in(T &a, Types&... b){cin>>(a); in(b...);}
void o() {rt;}  __ void o(T a, Types... b){cout<<(a);sp; o(b...);}
#define fr(Hi,a,n) for(ll Hi=a;Hi<=n;Hi++)
#define frm(Hi,a,n) for(ll Hi=n;Hi>=a;Hi--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS],tem[AS];
int main()
{
    fast;
    in(a,b,c,x);
    if(c*x<=b)o(-1);
    else
    {
        p=c*x-b;
        o((a+p-1)/p);
    }
}


#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main() {
    int n, m;
    cin >> n >> m;
    vi w(n);
    rep(i, n) cin >> w[i];
    vector<pll> vl;
    rep(i, m) {
        int v, l;
        cin >> l >> v;
        vl.emplace_back(v, l);
    }
    sort(all(vl), [](const pll &a, const pll &b) {
        if (a.first == b.first) return a.second > b.second;
        return a.first < b.first;
    });
    if (vl[0].first < *max_element(all(w))) {
        cout << -1 << '\n';
        return 0;
    }
    ll now = 0;
    rep(i, m) {
        chmax(now, vl[i].second);
        vl[i].second = now;
    }
    vi perm(n);
    iota(all(perm), 0);
    ll ans = LINF;
    do {
        vll wnow(n);
        rep(i, n) {
            wnow[i] = w[perm[i]];
        }
        vll dist(n);
        rep(r, n) rep(l, r) {
            if (r - l <= 0) continue;
            ll now = 0;
            repi(i, l, r + 1) {
                now += wnow[i];
            }
            auto it = lower_bound(all(vl), pll{now, -1});
            int idx = it - vl.begin() - 1;
            ll limit = 0;
            if (idx >= 0) {
                limit = vl[idx].second;
            }
            repi(i, l + 1, r) {
                limit -= dist[i];
            }
            chmax(dist[r], limit);
        }
        ll res = 0;
        rep(i, n) {
            res += dist[i];
        }
        chmin(ans, res);

    } while (next_permutation(all(perm)));
    cout << ans << '\n';
}

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

int main(){
    int N,K,sum=0;
    cin >> N >> K;

    rep(i,N){
        rep(j,K){
            sum+=100*i +j;
        }
    }
    cout << sum <<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=100010;

vector<pi> adj[N];

vector<vector<ll> > dis;

void func(ll start)
{
    set<pi> s;
    s.insert(mp(0,start));
    int firstdone=0;
    while(!s.empty()){
        ll v=(*s.begin()).second;
        ll d=(*s.begin()).first;
        s.erase(s.begin());
        if(dis[start][v]<=d){continue;}
        if(v==start){
            if(firstdone==0){
                firstdone=1;
            }
            else{
                dis[start][v]=d;
            }
        }
        else{
            dis[start][v]=d;
        }
        for(auto x:adj[v]){
            ll u=x.first,w=x.second;
            if(dis[start][u]>d+w){
                s.insert(mp(d+w,u));
            }
        }
    }
}

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

    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;++i){
        ll a,b,w;
        cin>>a>>b>>w;
        adj[a].pb(mp(b,w));
    }

    dis.resize(n+1,vector<ll>(n+1,INT_MAX));

    for(ll i=1;i<=n;++i){
        func(i);
    }

    for(ll i=1;i<=n;++i){
        if(dis[i][i]==INT_MAX){
            dis[i][i]=-1;
        }
        cout<<dis[i][i]<<endl;
    }

    return 0;
}

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

struct edge{
        int to;
        ll cost;
        edge(){}
        edge(int a, ll b) : to(a), cost(b){}
    };

using ve = vector<edge>;

void dijkstra(int s, vec &dist, vector<ve> &G){
    priority_queue<P, vector<P>, greater<> > pque;
    for(edge &e : G[s]){
        if(chmin(dist[e.to], e.cost)){
            pque.emplace(dist[e.to], e.to);
        }
    }
    while(!pque.empty()){
        P p = pque.top(); pque.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        for(const edge &e : G[v]){
            if(chmin(dist[e.to], dist[v] + e.cost)){
                pque.emplace(dist[e.to], e.to);
            }
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>N>>M;
    vector<ve> G(N);
    rep(i, M){
        int a, b;
        ll c;
        cin>>a>>b>>c;
        --a; --b;
        G[a].emplace_back(b, c);
    }
    rep(i, N){
        vec dist(N, INF);
        dijkstra(i, dist, G);
        cout<<(dist[i] == INF ? -1 : dist[i])<<endl;
    }
}


// Never gonna give you up
// Never gonna let you down
// Never gonna run around and desert you
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;
const ld pi=acos(-1);
ll gcd(ll a, ll b) {return (!b?a:gcd(b,a%b));}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}
ll mul(ll a, ll b) {return a*b%MOD;}
ll modpow(ll b, ll i){
  ll s=1;
  while(i){
    if(i%2) s=(s*b)%MOD;
    b=(b*b)%MOD; i/=2;
  }
  return s;
}
ll inv(ll a) {return modpow(a,MOD-2);}

void solve(){
  int h,w,n,m; cin >>h >>w >>n >>m;
  int a[h][w],cnt=0; memset(a,-1,sizeof(a));
  while(n--){int x,y; cin >>x >>y; a[x-1][y-1]=1;}
  while(m--){int x,y; cin >>x >>y; a[x-1][y-1]=0;}
  for(int i=0; i<h; i++) for(int j=0; j<w; j++) if(a[i][j]==1){
    for(int k=i-1; k>=0; k--){if(a[k][j]==-1||a[k][j]==2) a[k][j]=2; else break;}
    for(int k=i+1; k<h; k++){if(a[k][j]==-1||a[k][j]==2) a[k][j]=2; else break;}
    for(int k=j-1; k>=0; k--){if(a[i][k]==-1||a[i][k]==2) a[i][k]=2; else break;}
    for(int k=j+1; k<w; k++){if(a[i][k]==-1||a[i][k]==2) a[i][k]=2; else break;}
  }
  for(int i=0; i<h; i++) for(int j=0; j<w; j++) if(a[i][j]>0) cnt++;
  cout <<cnt;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  solve();
  return 0;}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

int main(){
  int h, w, n, m;
  cin >> h >> w >> n >> m;
  vector<vector<int>> v(h, vector<int>(w,0));
  rep(i,n){
    int a,b;
    cin >> a >> b;
    a--; b--;
    v[a][b] = 1;
  }
  rep(i,m){
    int c,d;
    cin >> c >> d;
    c--; d--;
    v[c][d] = -1;
  }

  vector<vector<int>> x(h,vector<int>(w,0));

  for(int i = 0; i < h; i++){
    bool flag = false;
    for(int j = 0; j < w; j++){
      if(v[i][j] == 1) flag = true;
      else if(v[i][j] == -1) flag = false;
      if(flag) x[i][j]++;
    }
  }
  for(int i = 0; i < h; i++){
    bool flag = false;
    for(int j = w-1; j >= 0; j--){
      if(v[i][j] == 1) flag = true;
      else if(v[i][j] == -1) flag = false;
      if(flag) x[i][j]++;
    }
  }

  for(int j = 0; j < w; j++){
    bool flag = false;
    for(int i = 0; i < h; i++){
      if(v[i][j] == 1) flag = true;
      else if(v[i][j] == -1) flag = false;
      if(flag) x[i][j]++;
    }
  }

  for(int j = 0; j < w; j++){
    bool flag = false;
    for(int i = h-1; i >= 0; i--){
      if(v[i][j] == 1) flag = true;
      else if(v[i][j] == -1) flag = false;
      if(flag) x[i][j]++;
    }
  }

  int ans = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(x[i][j] != 0) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> P;
typedef tuple<int,int,int> tii;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<pll,pll> ppll;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define bit(n,k) (n>>k&1)

ll INFL = ll(5e18)+5;
int INF = 1001001001;
const ll M = (ll)(1e9)+7;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,1,-1};

int main(){
  string x; cin >> x;
  int n = x.size();
  string ans = "";
  rep(i,0,n){
    if(x[i]=='.') break;
    ans += x[i];
  }
  cout << ans << endl;
}

// raggarwalg01

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

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

    string s{};
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='.')
            break;
        else cout<<s[i];
    }

}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll a,b,c,d; cin >> a >> b >> c >> d;
    if(c*d-b <= 0){
        cout << "-1" << endl;
        return 0;
    }
    else{
        cout << (a+c*d-b-1)/(c*d-b) << endl;
    }
}

#include <cstdio>
#include <cctype>
#define FOR(i,j,k) for(int i=j; i<=k; ++i)
inline int read (void) {
	int x = 0, f = 1, ch = getchar();
	while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
	while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int maxn = 20;
int h, w, ans, tot1, tot2;
bool flag[maxn][maxn];
void dfs (int x, int y) {
	if(y > w) {	y = 1; ++ x; }
	if(x > h) { ++ ans; return ; }
	if(flag[x][y]) dfs (x, y+1);
	else {
		if(tot2) {
			-- tot2; flag[x][y] = 1;
			dfs (x, y+1);
			++ tot2; flag[x][y] = 0;
		}
		if(tot1 && y + 1 <= w && !flag[x][y+1]) {
			-- tot1; flag[x][y] = flag[x][y+1] = 1;
			dfs (x, y+2);
			++ tot1; flag[x][y] = flag[x][y+1] = 0;
		}
		if(tot1 && x + 1 <= h && !flag[x+1][y]) {
			-- tot1; flag[x][y] = flag[x+1][y] = 1;
			dfs (x, y+1);
			++ tot1; flag[x][y] = flag[x+1][y] = 0;
		}
	}
}
int main (void) {
	h = read(), w = read(), tot1 = read(), tot2 = read();
	dfs (1, 1);
	printf("%d\n", ans);
	return 0;
}


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

int main() {

  int N;
  int64_t X;
  cin >> N >> X;

  X *= 100;

  int64_t ans = 0;

  for (int i = 0; i < N; i++) {
    int64_t V,P;
    cin >> V >> P;
    ans += V*P;
    if(ans > X){
      cout << i+1 << endl;
      return 0;
    }

  }

  cout << -1 << endl;
}

#include<bits/stdc++.h>
#include <iterator>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x)
#define pdd pair<dd,dd>
#define read_arr(a,n) for(ll i=1;i<=n;i++)cin>>a[i];
#define init_arr(a,n) for(ll i=1;i<=n;i++)a[i]=n-i+1;
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
#define arr array
using namespace std;
ll a[200005];
int main(){
	ll n,x;
	cin>>n>>x;
	ll tot=0;
	ll sol=-1;
	for(ll i=1;i<=n;i++){
		ll v,p;
		cin>>v>>p;
		tot+=v*p;
		if(tot>x*100 and sol==-1){
			sol=i;
		}
	}
	cout<<sol;

}


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

const int N=2e+5+10;
pair<long double,long double> dp[N];
int A[11],n,m,k;
bool isp[N];

bool ispos()
{
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(isp[i]==1)
			cnt++;
		else
			cnt=0;
		if(cnt==m)
			return false;
	}
	return true;
}

int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>A[i];
		isp[A[i]] = true;
	}
	if(!ispos())
	{
		cout<<-1;
		return 0;
	}
	pair<long double,long double> S={0,0};
	for(int i=n-1;i>=0;i--)
	{
		S.first -= dp[i+m+1].first;
		S.second -= dp[i+m+1].second;
		if(isp[i])
		{
			dp[i]={1,0};
		}
		else
		{
			dp[i]={S.first/(long double)m,1+S.second/(long double)m};
		}
		S.first += dp[i].first;
		S.second += dp[i].second;
	}
	long double ans = dp[0].second/(1 - dp[0].first);
	cout<<setprecision(10)<<fixed<<ans;
}

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

#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
int N, M, K, x, a[MAX];
lf sum[2*MAX];

lf solve(lf m) {
    PER(i, N-1, 0) {
        if(a[i]) sum[i] = m + sum[i+1];
        else sum[i] = 1 + (lf)((0.0 + sum[i+1] - sum[i+M+1]) / M) + sum[i+1];
    }
    return sum[0] - sum[1];
}

lf search(lf i, lf j, int k) {
    lf m = (i+j) / 2.0;
    if(!k) return m;
    if(solve(m) >= m) return search(m, j, k-1);
    else return search(i, m, k-1);
}

int main(int argc, char ** argv) {
    cout << fixed << setprecision(6);
    scanf("%d%d%d", &N, &M, &K);
    rep(i, 0, K) {
        scanf("%d", &x);
        a[x] = true;
    }
    lf ans = search(1, 1e12, 100);
    if(abs(ans-1e12) < 1e-5) puts("-1");
    else cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

const int N = 2e5 + 20;
typedef long long LL;
typedef pair<LL, LL> PLL;

int n, m, q;
struct Node
{
	int l, r;
	LL sum, cnt;
}tra[N << 2], trb[N << 2];
int a[N], b[N];
int t[N], x[N], y[N];
vector<int> nums;

void push_up(Node tr[], int u)
{
	tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
	tr[u].cnt = tr[u << 1].cnt + tr[u << 1 | 1].cnt;
}

void build(Node tr[], int u, int l, int r)
{
	tr[u] = {l, r, 0, 0};
	if(l == r) return;
	int mid = l + r >> 1;
	build(tr, u << 1, l, mid);
	build(tr, u << 1 | 1, mid + 1, r);
}

void modify(Node tr[], int u, int x, int d)
{
	if(tr[u].l == x && tr[u].r == x)
	{
		tr[u].cnt += d;
		tr[u].sum += nums[x] * d;
		return;
	}
	int mid = tr[u].l + tr[u].r >> 1;
	if(x <= mid) modify(tr, u << 1, x, d);
	else modify(tr, u << 1 | 1, x, d);
	push_up(tr, u);
}

PLL query(Node tr[], int u, int l, int r)
{
	if(tr[u].l >= l && tr[u].r <= r)
	{
		return {tr[u].cnt, tr[u].sum};
	}
	int mid = tr[u].l + tr[u].r >> 1;
	PLL res = {0, 0}, right = {0, 0}, left = {0, 0};
	if(l <= mid) left = query(tr, u << 1, l, r);
	if(r > mid) right = query(tr, u << 1 | 1, l, r);
	res.first = left.first + right.first;
	res.second = left.second + right.second;
	return res;
}

int find(int x)
{
	return lower_bound(nums.begin(), nums.end(), x) - nums.begin();
}

int main()
{
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= q; ++ i)
	{
		scanf("%d%d%d", &t[i], &x[i], &y[i]);
		nums.push_back(y[i]);
	}

	nums.push_back(0);
	sort(nums.begin(), nums.end());
	nums.erase(unique(nums.begin(), nums.end()), nums.end());

	LL res = 0;
	build(tra, 1, 0, nums.size() - 1);
	build(trb, 1, 0, nums.size() - 1);

	for(int i = 1; i <= q; ++ i)
	{
		if(t[i] == 1)
		{
			auto p = query(trb, 1, find(a[x[i]]) + 1, nums.size() - 1);
			modify(tra, 1, find(a[x[i]]), -1);
			res -= p.second + (m - p.first) * a[x[i]];
			a[x[i]] = y[i];
			modify(tra, 1, find(a[x[i]]), 1);
			p = query(trb, 1, find(a[x[i]]) + 1, nums.size() - 1);
			res += p.second + (m - p.first) * a[x[i]];
		}
		else
		{
			auto p = query(tra, 1, find(b[x[i]]) + 1, nums.size() - 1);
			modify(trb, 1, find(b[x[i]]), -1);
			res -= p.second + (n - p.first) * b[x[i]];
			b[x[i]] = y[i];
			modify(trb, 1, find(b[x[i]]), 1);
			p = query(tra, 1, find(b[x[i]]) + 1, nums.size() - 1);
			res += p.second + (n - p.first) * b[x[i]];
		}
		printf("%lld\n", res);
	}
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;
#define T pair<pair<ll, ll>, bool>

int main()
{
    ll n, c;
    scanf("%lld%lld", &n, &c);
    priority_queue<T, vector<T>, greater<T>> pq;
    for (ll i = 0; i < n; i++)
    {
        ll a, b, c;
        scanf("%lld%lld%lld", &a, &b, &c);
        pq.push({ {a, c}, 1 });
        pq.push({ {b + 1, c}, 0 });
    }
    ll sum = 0;
    ll cur = 0;
    while (!pq.empty())
    {
        ll day = pq.top().first.first;
        while (!pq.empty() && pq.top().first.first == day)
        {
            ll num = pq.top().first.second;
            bool type = pq.top().second;
            if (type) cur += num;
            else cur -= num;
            pq.pop();
        }
        if (pq.empty()) break;
        ll nxt = pq.top().first.first;
        sum += min(cur, c) * (nxt - day);
    }
    printf("%lld", sum);
    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (ll i = (a); i <= (b); i+=x)
#define debug(x) cout <<" || "<< #x << " is= " << x<<endl; //use for debug
#define read(a) ll a; cin >> a;
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define pr         pair<ll,ll>
#define vpll       vector<pair<ll,ll>>
#define all(v)     v.begin(),v.end()
#define rall(v)    v.rbegin(),v.rend()  //reverse of above;
#define sz(container) int((container).size())
#define cut(x) {cout<<x<<"\n"; continue;}
#define setprec(x) cout << fixed << showpoint << setprecision(15)<<x<<"\n";
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl '\n';
#define mod2 1000000007
#define mod 998244353
#define pi  3.141592653589793238
#define fi first
#define se second
#define test(i) cout<<"Case #"<<i<<": ";
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

//*s.find_by_order() ->returns an iterator to the k-th largest element (counting from zero);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
//sort(a+1,a+n+1,[](ll x,ll y){return abs(x)>abs(y);});
//sort(v.begin(), v.end(), greater<int>()); -> not sure work for first also if second are equal;
//q=lower_bound(all(v[a[i]]),i)-v[a[i]].begin()+1;
// s.substr(start_ind,length);
// vpll shift={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}} ->shift operator;
//bool comp(pr a,pr b){return a.second<b.second;} // use for differentiate order of comparision;
// cntbit(x) __builtin_popcount(x); -> no. of bits in given no.;

//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
const ll MAXN=2e7+5;
const ll inf=1e18+5;

int main()
{
  fast_io;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  //“Don’t wish it were easier. Wish you were better.” – Jim Rohn;
  read(t);
  while(t--)
  {
    ll n; cin>>n;
    ll cnt=0;
    while(n%2==0)
    {
      cnt++;
      n/=2;
    }
    if(cnt==0) cut("Odd");
    if(cnt==1) cut("Same");
    cut("Even");
  }
 }

#include <bits/stdc++.h>
#define INF 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef long long int  lli;
typedef long double ld;
typedef vector<int> vi;
typedef unordered_map<int,int> umi ;
typedef unordered_set<int> usi ;
typedef pair<int,int> pi;
#include <bits/stdc++.h>

using namespace std;

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

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

//declare here -------------------------------------------------------------------------------
const int N =1e5+2;

// solve here ---------------------------------------------------------------------------------
// read the problem carefull
// have rough idea of code before writing
void solve(){
	ll l ,r ;
	cin>>l>>r ;
	ll val = r- 2*l +1 ;
	if(val<0){ cout<<0; return ;}
	val= (val*(val+1))/2 ;
	cout<<val ;

}

//--------------------------------------------------------------------------------------------
// make sure boundries are correct and all imputs are taken properly
//check for edge cases and boundary values

int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long test =1 ;
   	cin>>test ;
    while(test--){
        solve() ;
        cout<<"\n" ;
    }
    return 0 ;
}


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

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define MAX(v) (*max_element((v).begin(), (v).end()))
#define MIN(v) (*min_element((v).begin(), (v).end()))
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

ll exp(ll base, ll e, ll md) {
    ll mul = base % md;
    ll res = 1;
    while(e){
        if(e & 1) res = (res*mul) % md;
        e >>= 1;
        mul = mul*mul % md;
    }
    return res;
}

const int N = 2e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    int n, m; cin>>n>>m;
	int cnt[2] = {};
	ll ans = 0;
	FOR(i, n){
		bool par = 0;
		FOR(i, m){
			char c; cin>>c;
			par ^= c == '1';
		}
		ans += cnt[!par];
		cnt[par]++;
	}
	cout<<ans<<"\n";
}

#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m;
string str[MAXN];
int main()
{
    scanf("%d%d",&n,&m);
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>str[i];
        int s=0;
        for(int j=0;j<m;j++) if(str[i][j]=='1') s++;
        if(s&1) cnt++;
    }
    printf("%lld\n",1LL*cnt*(n-cnt));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
using ll = long long;
#define endl "\n";
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x);
#define pvector(x) for(auto i : x)cout << i << " ";cout << "\n";
#define ivector(x) for(auto &i : x)cin >> i;
const int MOD = 1e9 + 7;
int main() {
	fast;
	auto S = [](int n){
		string s = to_string(n);
		int sum=0;
		for(char i : s)sum += (i-'0');
		return sum;
	};
	int a,b; cin >> a >> b;
	cout << max(S(a),S(b)) << "\n";
}

/*
    solution and tut used...
    credits : @yash_daga
    author : Aryan Agarwal, IIT KGP
    created : 13-December-2020 19:44:17 IST
*/

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

const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007; /*more than (10)^9*/ /*7 + 1e9*/
// const int32_t M = 998244353; /*less than (10)^9*/   /*1 + 7*17*(2)^23*/
const long double pie = acos(-1);

#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

#define dbg(a) cout<<"["<<#a<<" : "<<a<<"]\n"
#define dbg2(a,b) cout<<"["<<#a<<" : "<<a<<"], "<<"["<<#b<<" : "<<b<<"]\n"
#define dbg3(a,b,c) cout<<"["<<#a<<" : "<<a<<"], "<<"["<<#b<<" : "<<b<<"], "<<"["<<#c<<" : "<<c<<"]\n"

void solve()
{
    int n,m;
    cin>>n>>m;
    int a[n+1],b[m+1];

    F(i,1,n)cin>>a[i];
    F(i,1,m)cin>>b[i];

    int dp[n+1][m+1];
    dp[0][0]=0;
    F(i,1,n)
    {
        F(j,1,m)
        {
            dp[i][j]=n+m;
        }
    }
    F(i,1,n)dp[i][0]=i;
    F(i,1,m)dp[0][i]=i;
    F(i,1,n)
    {
        F(j,1,m)
        {
            dp[i][j]=min(dp[i-1][j]+1,dp[i][j]);
            dp[i][j]=min(dp[i][j-1]+1,dp[i][j]);
            dp[i][j]=min(dp[i-1][j-1]+(a[i]!=b[j]),dp[i][j]);
        }
    }

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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    // defualt mxn_sieve = 1e5
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    // default [L,R] = [1,1e5]
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    // default mxn_fact = 1e5
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    // cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;

bool checkSubstring(string s){
    ll firstZeroP = -1;
    rep(i, s.size()){
        if(firstZeroP == -1){
            if(i == 0 && s[i] == '0'){
                firstZeroP = 0;
            }else if(i == 1 && s[i] == '0'){
                firstZeroP = 1;
            }else if(i == 2 && s[i] == '0'){
                firstZeroP = 2;
            }else if(i == 2 && s[i] == '1'){
                return false;
            }
            continue;
        }

        if(s[i] == '0'){
            if((i - firstZeroP) % 3 != 0){
                return false;
            }
        }else{
            if((i - firstZeroP) % 3 == 0){
                return false;
            }
        }
    }

    return true;
}

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

    if(T == "1"){
        cout << 20000000000 << endl;
        return 0;
    }

    if(!checkSubstring(T)){
        cout << 0 << endl;
    }else{
        ll countZero = 0;
        rep(i, T.size()){
            if(T[i] == '0'){
                countZero++;
            }
        }
        if(T[T.size() - 1] == '0'){
            cout << 10000000000 - countZero + 1 << endl;
        }else{
            cout << 10000000000 - countZero << endl;
        }
    }

    return 0;
}

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

vector<int> po, ne;
int a, b;

int main(void) {
	scanf("%d %d", &a, &b);
	for (int i = 1; i <= a; i++) {
		po.push_back(i);
	}
	for (int i = 1; i <= b; i++) {
		ne.push_back(-i);
	}

	if (po.size() < ne.size()) {
		for (int i = po.size(); i < ne.size(); i++) {
			po[po.size() - 1] -= ne[i];
		}
	}
	else if (ne.size() < po.size()) {
		for (int i = ne.size(); i < po.size(); i++) {
			ne[ne.size() - 1] -= po[i];
		}
	}

	for (int e : ne) {
		printf("%d ", e);
	}
	for (int e : po) {
		printf("%d ", e);
	}
	puts("");
}


#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define even(x) (x % 2 == 0 ? true : false)
#define odd(x) (x % 2 ? true : false)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;
const int mod = 1e9 + 7;
//vector<vector<int>> dp(m, vector<int>(n));

struct mint {
	uint x;
	mint(): x(0) {}
	mint(ll x):x((x%mod+mod)%mod) {}
	mint operator-() const { return mint(0) - *this;}
	mint operator~() const { return mint(1) / *this;}
	mint& operator+=(const mint& a) { if((x+=a.x)>=mod) x-=mod; return *this;}
	mint& operator-=(const mint& a) { if((x+=mod-a.x)>=mod) x-=mod; return *this;}
	mint& operator*=(const mint& a) { x=(ull)x*a.x%mod; return *this;}
	mint& operator/=(const mint& a) { x=(ull)x*a.pow(mod-2).x%mod; return *this;}
	mint operator+(const mint& a) const { return mint(*this) += a;}
	mint operator-(const mint& a) const { return mint(*this) -= a;}
	mint operator*(const mint& a) const { return mint(*this) *= a;}
	mint operator/(const mint& a) const { return mint(*this) /= a;}
	mint pow(ll t) const {
		if(!t) return 1;
		mint res = pow(t/2);
		res *= res;
		return (t&1)?res*x:res;
	}
	mint inv() const { return pow(mod-2);}
	bool operator<(const mint& a) const { return x < a.x;}
	bool operator>(const mint& a) const { return x > a.x;}
	bool operator==(const mint& a) const { return x == a.x;}
	bool operator!=(const mint& a) const { return x != a.x;}
};

istream& operator>>(istream&i,mint&a) {i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a) {o<<a.x;return o;}

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

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(all(a));
	mint ans = a[0] + 1;
	for (int i = 1; i < n; i++) {
		ans *= a[i] - a[i - 1] + 1;
	}
	cout << ans << endl;
}

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

	solve();
}

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

ll dis(vector<ll> r, vector<ll> g) {
  ll mi = 1000100100100100100;
  ll gn = g.size();
  ll rn = r.size();
  if (gn == 0 || rn == 0)
    return mi;
  for (auto a : r) {
    ll i = lower_bound(g.begin(), g.end(), a) - g.begin();
    if (gn > i) {
      mi = min(mi, abs(a - g[i]));
    }
    if (i > 0)
      mi = min(mi, abs(a - g[i - 1]));
  }
  return mi;
};

int main() {
  ll N;
  cin >> N;
  vector<ll> rs;
  vector<ll> gs;
  vector<ll> bs;
  rep(i, 0, 2 * N) {
    ll cute;
    string color;
    cin >> cute >> color;
    if (color == "R") {
      rs.push_back(cute);
    }
    if (color == "G") {
      gs.push_back(cute);
    }
    if (color == "B") {
      bs.push_back(cute);
    }
  }

  ll size_rs = rs.size();
  ll size_gs = gs.size();
  ll size_bs = bs.size();

  // 全て偶数
  if (size_rs % 2 == 0 && size_gs % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  // 2つ奇数
  vector<ll> even_vec;
  vector<ll> odd1_vec;
  vector<ll> odd2_vec;
  if (size_rs % 2 == 0) {
    even_vec = rs;
    odd1_vec = gs;
    odd2_vec = bs;
  }
  if (size_gs % 2 == 0) {
    even_vec = gs;
    odd1_vec = rs;
    odd2_vec = bs;
  }
  if (size_bs % 2 == 0) {
    even_vec = bs;
    odd1_vec = rs;
    odd2_vec = gs;
  }

  sort(even_vec.begin(), even_vec.end());
  sort(odd1_vec.begin(), odd1_vec.end());
  sort(odd2_vec.begin(), odd2_vec.end());

  ll cur_mini;
  cur_mini = dis(odd1_vec, odd2_vec);

  if (even_vec.size() == 0) {
    cout << cur_mini << endl;
    return 0;
  }
  ll oe1_cur_mini;
  oe1_cur_mini = dis(odd1_vec, even_vec);

  ll oe2_cur_mini;
  oe2_cur_mini = dis(odd2_vec, even_vec);

  ll ans;
  ans = min(cur_mini, oe1_cur_mini + oe2_cur_mini);
  cout << ans << endl;
  return 0;
}


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

ll modpower(ll a, ll r, ll mod){ //a^r
    ll x = 1;
    if (r < 0) r = r%(mod-1)+mod-1;
    a %= mod;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a, ll mod) {
    //a*ret%mod == gcd(a, mod)
    ll x = 0, y = 1, u = 1, v = 0, b = mod;
    while (b != 0) {
        ll q = a/b;
        a %= b;
        swap(a, b);
        u -= q*x;
        swap(u, x);
        v -= q*y;
        swap(y, v);
    }
    if (u > 0) return u;
    else return u+mod;
}

vector<ll> fact;
vector<ll> invfact;

void set_fact(ll n, ll mod){
    fact.resize(n+1, 1);
    invfact.resize(n+1, 1);
    for (ll i = 2; i <= n; i++) {
        fact[i] = fact[i-1] * i % mod;
    }
    invfact[n] = modinv(fact[n], mod);
    for (ll i = n-1; i >= 2; i--) {
        invfact[i] = invfact[i+1] * (i+1) % mod;
    }
    return;
}

ll comb(ll n, ll k, ll mod) {
    if (k > n || k < 0) return 0;
    if (k == n || k == 0) return 1;
    return fact[n] * invfact[n-k] % mod * invfact[k] % mod;
}

int main() {
    ll N, M;
    cin >> N >> M;
    ll mod = 998244353;
    set_fact(N+M+10, mod);
    vector<vector<ll>> dp(M+1, vector<ll>(21, 0));
    for (ll i = M; i >= 2; i--) {
        dp[i][1] = 1;
        for (ll j = 2; j <= 20; j++) {
            for (ll k = i*2; k <= M; k += i) {
                dp[i][j] += dp[k][j-1];
                if (dp[i][j] >= mod) dp[i][j] -= mod;
            }
        }
    }
    ll ans = 1;
    for (ll i = 2; i <= M; i++) {
        for (ll j = 1; j <= 20; j++) {
            ans = (ans+dp[i][j]*comb(N, j, mod))%mod;
        }
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
    char ch = getchar(); x = 0; int f = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    if (f) x = -x;
} const int N = 2e5 + 5, mod = 998244353;
int qpow (int x, int y) {
    int t = 1;
    while (y) {
        if (y & 1) t = t * x % mod;
        x = x * x % mod, y >>= 1;
    }
    return t;
}
int n, m, res, a[N], t, p[N * 2], in[N * 2], b[N], tot, k[N];
int C (int x, int y) {
    return p[x] * in[y] % mod * in[x - y] % mod;
}
void prework () {
    p[0] = 1;
    for (int i = 1; i <= n + m; ++i) p[i] = p[i - 1] * i % mod;
    in[n + m] = qpow (p[n + m], mod - 2);
    for (int i = n + m; i >= 1; --i) in[i - 1] = in[i] * i % mod;

    for (int i = 2; i * i <= m; ++i)
        if (!k[i]) {
            b[++tot] = i;
            for (int j = i; j * j <= m; j += i) k[j] = 1;
        }
}
void work (int x) {
    t = 0;
    for (int i = 1; i <= tot && b[i] <= x; ++i) {
        int cnt = 0;
        while (x % b[i] == 0) ++cnt, x /= b[i];
        if (cnt) a[++t] = cnt;
    }
    if (x > 1) a[++t] = 1; int tmp = 1;
    for (int i = 1; i <= t; ++i) {
        tmp = tmp * C (a[i] + n - 1, a[i]) % mod;
    }
    // printf ("%lld %lld %lld\n", x, tmp, b[1]);
    (res += tmp) %= mod;
}
signed main() {
    read (n), read (m); prework ();
    // printf ("%d\n", tot);
    for (int i = 1; i <= m; ++i) work (i);
    printf ("%lld\n", res);
}


#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

template <typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template <typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T, size_t sz> ostream &operator<<(ostream &os, const array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T, typename TH> ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV, typename TH> ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }

#define DEBUG

#ifdef DEBUG
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << " in " << __FILE__ << ")" << COLOR_RESET << endl
#else
#define dbg(x) (x)
#endif

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

	int A, B, C;
	cin >> A >> B >> C;

	if (A * A + B * B < C * C) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

string s;

int main()
{
	int n,x;
	cin>>n>>x>>s;
	rep(i,n)
	{
		if(s[i]=='x') x=max(x-1,0);
		else x++;
	}
	cout<<x<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>
#include<math.h>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll modq=998244353;
const ll INF=1e18;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

ll modpow(ll a,ll n) {
    ll res = 1;
    while (n>0) {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

int main(void){
    vector<ll> Fib(1050);
    Fib.at(0)=0,Fib.at(1)=1;
    rep(i,1010) Fib.at(i+2)=(Fib.at(i+1)+Fib.at(i))%mod;

    ll N;
    cin>>N;
    char caa,cab,cba,cbb;
    cin>>caa>>cab>>cba>>cbb;
    if(N<4){
        cout<<1<<endl;
        return 0;
    }
    if(caa=='A' && cab=='A'){
        cout<<1<<endl;
        return 0;
    }
    if(cbb=='B' && cab=='B'){
        cout<<1<<endl;
        return 0;
    }
    if(cab=='B' && cbb=='A'){
        if(cba=='A'){
            cout<<modpow(2,N-3)<<endl;
            return 0;
        }
        cout<<Fib.at(N-1)<<endl;
        return 0;
    }
    if(cba=='B'){
        cout<<modpow(2,N-3)<<endl;
        return 0;
    }
    cout<<Fib.at(N-1)<<endl;
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
// using namespace atcoder;

void solve()
{
	int n;
	cin>>n;
	vector<ll>a(n),b(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	ll maxv=0;
	ll pre=0;
	rep(i,n){
		ll res=0;

		chmax(maxv,a[i]);
		res=b[i]*maxv;
		chmax(res,pre);
		cout<<res<<"\n";
		pre=res;
	}
}

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


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define ft first
#define sec second
#define pr pair<int,int>
#define ISCC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int t ,n ,m ,a ,sum;
string s;
int main()
{
	cin >> n;
	for(int i=0 ;i<n ;i++)
	{
		cin >> a;
		sum += max(0 ,a-10);
	}
	cout << sum;
	return 0;
}

/***   -God give me the power −   ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void test()
{
    int n;
    cin>>n;
    vector <ll> arr(n);
    map <ll,int> mp;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        mp[arr[i]]--;
        ans+=max(0,n-i-1-mp[arr[i]]);
    }
    cout<<ans<<"\n";

}
int main()
{

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


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int A, B, W;
	cin >> A >> B >> W;
	W *= 1000;
	int mini = INT_MAX, maxi = 0;
	if (W%A==0) {
		maxi = W / A;
	}
	if (W%B==0) {
		mini = W / B;
	}
	if (maxi>0&&mini>0) {
		doublece(mini,maxi)
	}
	else {
		if (W/A==W/B) {
			ce("UNSATISFIABLE")
		}
		else {
			doublece(W / B+1, W / A)
		}
	}
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
	int A, B, W;
	cin >> A >> B >> W;
	W *= 1000;
	int most = 0;
	int least = 0;
	// most = W / A + (W % A == 0 ? 1 : 0);
	// least = W / B + (W % B == 0 ? 0 : 1);
	if (W % A == 0)
		most = W / A;
	else
	{
		int n = W / A;
		float avg = float(W) / n;
		if (avg > A && avg < B)
			most = n;
	}
	if (W % B == 0)
		least = W / B;
	else
	{
		int n = W / B + 1;
		float avg = float(W) / n;
		if (avg > A && avg < B)
			least = n;
	}
	if (most == 0 || least == 0)
		cout << "UNSATISFIABLE" << endl;
	else
		cout << least << " " << most << endl;
	// cout << least << " " << most << endl;
}


#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

typedef long long ll;

#define rep(i,n) for(long long (i)=0;(i)<(n);(i)++)
#define FOR(i, m, n) for(long long (i) = (m);(i) < (n);(i)++)

#define INF 1e9
const long long MOD = 1000000007;//1e9+7

int main() {
    ll X, Y, A, B;
    cin >> X >> Y >> A >> B;

    ll ans = 0;
    while ((double)A*X <= 2e18 &&X*A<X+B&&X*A<Y) {
        X *= A;
        ans++;
    }
    ans += (Y - 1 - X) / B;
    cout << ans;

    return 0;
}

#include<bits/stdc++.h>

typedef long long int lli;
typedef long double lld;
typedef long long ll;

//Fast Input I/O
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL);
//Datatype
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vvlli vector<vector<long long int>>
#define ppi pair<int, int>
#define rppi pair<int, pair<int, int>>
#define lppi pair<pair<lli, lli>, lli>
#define vppi vector<pair<int, int>>
#define sppi stack<pair<int int>>
#define qppi queue<pair<int, int>>
//function
#define f first
#define s second
#define pb(x) push_back(x)
#define mkp(i, j) make_pair(i, j)
#define lmkp(i,j,k) make_pair(make_pair(i,j),k)
#define rmkp(i,j,k) make_pair(i,make_pair(j,k))
//loop
#define loop(i,n) for (i = 0; i < n; ++i)
#define loops(i,k,n) for (i = k; i <= n; ++i)
#define looprev(i,k,n) for (i = k; i >= n; --i)
//Const
#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//Print
#define prd(n) printf("%d", n)
#define prl(n) printf("%lld", n)
#define prdn(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define prf(n) printf("%f", n)
//Scan
#define scd(n) scanf("%d", &n)
#define scd2(a, b) scanf("%d %d", &a, &b)
#define scd3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scl(n) scanf("%lld", &n)
#define scl2(a, b) scanf("%lld %lld", &a, &b)
#define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define scf(n) scanf("%f", &n)
#define all(x) (x).begin(), (x).end()

using namespace std;
void online_judge() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void solve() {
	lli i, j, k, n;
	cin >> n;
	vector<lppi> A;
	loop(i, n) {
		lli t, l, r;
		cin >> t >> l >> r;
		A.push_back(lmkp(l, r, t));
	}
	sort(A.begin(), A.end());
	lli res = 0;
	loop(i, n) {
		lli l = A[i].f.f, r = A[i].f.s, t = A[i].s;
		loops(j, i + 1, n - 1) {
			if (A[j].f.f < r || (A[j].f.f == r && (t == 1 || t == 3) && (A[j].s == 1 || A[j].s == 2))) {
				res += 1;
			}
		}
	}
	cout << res << "\n";
}

int main() {
	fio;
	online_judge();
	lli t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define ff(i,n) for(i=0;i<n;i++)
//ncr(n,r) = ncr(n-1,r-1) + ncr(n-1,r)
const ll bg = 1e9+7;
void solve(){
	ll i,n,x;
	cin>>n>>x;
	x = x*100;
	ll ans = -1,sum=0;
	ll v[n],p[n];
	ff(i,n){
		cin>>v[i]>>p[i];
	}
	ff(i,n){
		sum += v[i]*p[i];
		if(sum>x)
		{
			ans = i+1;
			break;
		}
	}
	cout<<ans;
}
int main(){
	ll t;
	t=1;
	while(t--){
		solve();
	}
}

#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int,int>
#define VPII vector<PII>
#define LD long double
#define INF 1000000000000
#define MOD 1000000007
//#define MAXR 100000 // array max range
#define MAXR 200000+10
#define FI first
#define SE second
#define PQG priority_queue<int,VI,greater<int>>
#define PQL priority_queue<int,VI,less<int>>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    int n;
    int p[MAXR],mem[MAXR];
    int m=0,mm=0;
    R(i,MAXR) mem[i] = false;
    cin >> n;
    R(i,n){
        cin >> p[i];
        mem[p[i]] = true;
        if(mm==p[i]){
            FOR(j,mm+1,MAXR){
                if(!mem[j]){
                    mm=j;
                    m=j;
                    break;
                }
            }
        }
        cout << m << endl;
    }
    //int cnt=0;
    //R(i,MAXR){
    //    if(ans[i]){
    //        cout << i-1 << endl;
    //        cnt++;
    //    }
    //    if(n==cnt){
    //        break;
    //    }
    //}
    return 0;
}


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

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

    ll n,k;
    cin>>n>>k;

    ll arr[n][2];

    ll sum=0;
    ll x,y;

    for(ll i=0;i<n;i++){
        cin>>x>>y;
        arr[i][0]=x;
        arr[i][1]=y;

    }

    int flag=0;
    for(ll i=0;i<n;i++){

        ll a = arr[i][0];
        ll b = arr[i][1];

        sum +=a*b;
        double z= sum;
        if(z/100>k){
            flag=i+1;
            break;
        }
    }

    if(flag==0)
    cout<<"-1"<<endl;
    else
    cout<<flag<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long lli;
const lli M = 1000000007;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        lli n,s,d,flag=0; cin>>n>>s>>d;
        for(int i=0; i<n ; i++)
        {
            int x,y;
            cin>>x>>y;
            if(x<s && y>d)
            {
                flag=1;
            }
        }
        if(flag==1)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

pi operator - (pi a, pi b) { return { a.first - b.first, a.second - b.second }; }
pi operator + (pi a, pi b) { return { a.first + b.first, a.second + b.second }; }
ll operator * (pi a, pi b) { return a.first * 1LL * b.first + a.second * 1LL * b.second; }

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

// 최대공약수, x, y
vector<ll> ee(ll a, ll b) {
	if (b == 0)
		return { a, 1, 0 };
	ll g, x, y;
	vector<ll> t = ee(b, a % b);
	g = t[0];
	x = t[1];
	y = t[2];
	return { g, y, x - (a / b) * y };
}

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

	int T;
	cin >> T;
	while (T--) {
		ll x, y, p, q;
		cin >> x >> y >> p >> q;

		ll mn = 9e18;
		for (int t1 = 0; t1 < y; ++t1)
			for (int t2 = 0; t2 < q; ++t2) {
				ll a = (2 * x + 2 * y), b = -(p + q);
				ll c = p - x + t2 - t1;
				vector<ll> res = ee(a, b);
				if (c % res[0] != 0)
					continue;

				ll u = res[1] * c / res[0];

				ll k = u - u * res[0] / b * b / res[0];

				while (u != 0 && k - abs(u * b / res[0]) >= 0)
					k -= abs(b / res[0]);
				while (u != 0 && k < 0)
					k += abs(b / res[0]);

				mn = min(mn, a * k + x + t1);
			}

		if (mn == 9e18)
			cout << "infinity\n";
		else
			cout << mn << "\n";
	}

	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#define rep(i,begin, end) for (ll i = begin; i < (ll)(end); i++)

using namespace std;
using ll = long long;

template<typename T>
using vec2 = vector<vector<T>>;
template<typename T>
using vec3 = vec2<vector<T>>;
template<typename T>
using vec4 = vec3<vector<T>>;
template<typename T>
using vec5 = vec4<vector<T>>;
template<typename T>
using vec6 = vec5<vector<T>>;

ll extGCD(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    ll g = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return g;
}
ll MOD = 1000000007;

vector<ll> mfact(1,1);

ll minv(ll a){
    ll x;ll y;
    extGCD(a, MOD, x, y);
    if(x<0){
        x+= ((-x)/MOD+1)*MOD;
        x %= MOD;
    }
    return x;
}

ll mpow(ll a,ll b){
    ll res = 1;
    while(b > 0){
        if(b%2==1)res=(res*a)%MOD;
        b/=2;
        a = (a*a)%MOD;
    }
    return res;
}

ll mfactorial(ll a){
    if(mfact.size()-1 >= a)return mfact[a];
    for(ll i = mfact.size();i<=a;i++){
        mfact.push_back((i * mfact[i-1])%MOD);
    }
    return mfact[a];
}

ll mcomb(ll n, ll r){
    return (((mfactorial(n) * minv(mfactorial(r)))%MOD) * minv(mfactorial(n-r)))%MOD;
}
ll ipow(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b % 2 == 1)res*=a;
        a*=a;
        b/=2;
    }
    return res;
}

void factorize(map<ll,ll>& fac, vector<ll>& sieved, ll a){
    while(a != 1){
        if(fac.find(sieved[a]) == fac.end())fac[sieved[a]] = 0;
        fac[sieved[a]]++;
        a/=sieved[a];

    }
}
void primesieve(vector<ll>& res,ll n){
    res = vector<ll>(n+1, -1);
    for(int i = 2;i <= n;i++){
        if(res[i] != -1)continue;
        res[i] = i;
        for(int j = 2;j*i <= n;j++){
            res[j*i] = i;
        }
    }
}
vector<ll> primesuntil(ll n){
    vector<ll> res;
    vector<ll> sieved;
    primesieve(sieved, n);
    for(int i = 2;i <= n;i++){
        if(sieved[i] == i)res.push_back(i);
    }
    return res;
}
int gcd(int a, int b){
    if(b == 0)return a;
    return gcd(b, a%b);
}

void solve(){
    // cout<<"##########"<<endl;
    ll X,Y,P,Q;cin>>X>>Y>>P>>Q;
    ll res = -1;
    rep(q,0,Q){
        rep(y,0,Y){
            ll d = gcd(2*X+2*Y, -(P+Q));
            if((P+q-X-y) % d != 0)continue;
            // cout<<(P+q-X-y)<<endl;
            // cout<<d<<endl;
            ll s,t;
            extGCD((2*X+2*Y)/d, -(P+Q)/d, s,t);
            // cout<<s<<" "<<t<<endl;
            s *= (P+q-X-y)/d;
            t *= (P+q-X-y)/d;
            ll k = d<0 ? floor(min(-(double)d*(double)s/(double)(P+Q), -(double)d*(double)t/(double)(2*X+2*Y)))
                        : ceil(max(-(double)d*(double)s/(double)(P+Q), -(double)d*(double)t/(double)(2*X+2*Y)));
            // cout<<k<<endl;
            s += k*(P+Q)/d;
            t += k*(2*X+2*Y)/d;
            // cout<<2*X+2*Y<<" "<< (P+Q)<<" "<<s<<" "<<t<<endl;

            // cout<<2*X+2*Y<<" "<< (P+Q)<<" "<<s<<" "<<t<<endl;
            ll a = (2*X+2*Y)*s+X+y;
            if(res == -1)res = a;
            res = min(res,a);
            // cout<<a<<endl;
            // cout<<"!!!!!!!!!!!!!!!!"<<endl;

        }
    }

    cout<<(res==-1 ? "infinity" : to_string(res))<<endl;
}

int main(){
    int T;cin>>T;
    rep(i,0,T)solve();
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef long long int i64;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 mod = 998'244'353ll;

const i64 inf = 1'000'000'000'000'000'000ll / 1'000'000'000ll;

const long double eps = 1e-8;

i64 gcd(i64 a, i64 b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    if (sizeof(i64) != sizeof(long long int)) {
        cerr << "i64 != long long int" << endl;
    }

    i64 R = 0;
    i64 n;
    string s;
    cin >> n >> s;

    i64 cnt = 0;
    stringstream ss;
    while (cnt < n) {
        ss << "110";
        cnt += 3;
    }
    ss << "110";
    string t = ss.str();

    for (i64 l = 0; l < 3; l++) {
        if (t.substr(l, s.size()) != s) {
            continue;
        }
        const i64 m = 30'000'000'000ll - n - l;
        R += m / 3 + 1;
    }

    cout << R << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
string ss="",str;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long n;
    cin>>n;
    cin>>str;
    for(int i=0;i<=n+100;i++)
    if(i%3==0)ss+="1";
    else if(i%3==1)ss+="1";
    else ss+="0";
    if(str=="1")cout<<20000000000<<"\n";
    else if(ss.substr(0,n)==str){
        int p=(n-1)/3;
        cout<<10000000000-p<<"\n";
    }
    else if(ss.substr(1,n)==str){
        int p=n/3;
        cout<<10000000000-p<<"\n";
    }
    else if(ss.substr(2,n)==str){
        int p=(n+1)/3;
        cout<<10000000000-p<<"\n";
    }
    else cout<<0<<"\n";
    return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> II;
inline II make_key(int a, int b) {
	return make_pair(min(a, b), max(a, b));
}

int solve(int N, int M, std::vector<int> &A, std::vector<int> &B, std::vector<char> &C) {
	vector<vector<int>> v(26);
	for (int i = 0; i < M; i++) {
		v[C[i] - 'a'].emplace_back(i);
	}
	map<II, set<II>> m;
	set<II> adj;
	for (int ch = 0; ch < 26; ++ch) {
		for (int i = 0; i < v[ch].size(); ++i) {
			int a = A[v[ch][i]], c = B[v[ch][i]];
			adj.emplace(make_key(a, c));
			for (int j = i + 1; j < v[ch].size(); ++j) {
				int b = A[v[ch][j]], d = B[v[ch][j]];
				m[make_key(a, b)].insert(make_key(c, d));
				m[make_key(a, d)].insert(make_key(b, c));
				m[make_key(b, c)].insert(make_key(a, d));
				m[make_key(c, d)].insert(make_key(a, b));
			}
		}
	}
	set<II> q;
	q.emplace(II(0, N - 1));
	for (int i = 0; i < M && !q.empty(); ++i) {
			set<II> nq;
		for (auto x : q) {
			if (adj.find(x) != adj.end()) {
				return i * 2 + 1;
			}
			for (auto y : m[x]) {
				if (y.first == y.second) {
					return (i + 1) * 2;
				}
				nq.insert(y);
			}
		}
		q = nq;
	}
	return -1;
}

int main() {
    int N, M;
	std::cin >> N >> M;
	std::vector<int> A(M), B(M);
	std::vector<char> C(M);
	for (int i = 0; i < M; i++) {
		std::cin >> A[i] >> B[i] >> C[i];
		--A[i], --B[i];
	}
	cout << solve(N, M, A, B, C) << endl;
	return 0;
}

#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const int MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return (c>r||c<0) ? 0:fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

vector<pci> v[1000];
int dist[1000][1000][27];

/*
int go(int o, int oo, int al) {
    if (o == oo) return 0;
    if (dp[o][oo][al] != -1) return dp[o][oo][al];

    int miv = 1e9;

    return dp[o][oo][al];
}*/

struct node {
    int o, oo, al;
};
queue<node> q;

int main() {
    memset(dist, -1, sizeof(dist));
    int n, m;
    scanf("%d %d", &n, &m);

    for (int i = 0; i < m; i++) {
        int a,b;
        char c;
        scanf("%d %d %c", &a, &b, &c);
        a--; b--;
        c -= 'a';
        v[a].push_back({c, b});
        v[b].push_back({c, a});
    }

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

    while (!q.empty()) {
        node tv = q.front();
        q.pop();

        int o = tv.o, oo = tv.oo, al = tv.al, co = dist[o][oo][al];
        if (o == oo) return !printf("%d", co);

        if (al == 26) {
            for (pci i : v[o]) {
                if (dist[i.second][oo][i.first] == -1) {
                    dist[i.second][oo][i.first] = co + 1;
                    q.push({i.second, oo, i.first});
                }
            }
        }
        else {
            for (pci i : v[oo]) {
                if (i.first == al && dist[o][i.second][26] == -1) {
                    dist[o][i.second][26] = co + 1;
                    q.push({o, i.second, 26});
                }
            }
        }
    }
    printf("-1");
}

// author: rdd6584


#include<bits/stdc++.h>
using namespace std;
int main()
{

       int n,m,i;
       char x[1000];
       cin>>x;
       char *dot_pos = strchr(x, '.');
	if (dot_pos) *dot_pos = '\0';
	puts(x);
     cout<<endl;
}

#include <bits/stdc++.h>

using namespace std;

const long long INFll = 8223372036854775807;
const int INFii = 1147483647;
const long long mod = (long long) 1e9 + 7;
typedef long long ll;
typedef int ii;
typedef double dbl;
#define endl '\n'
#define S second
#define F first
#define MP make_pair
#define PB push_back

#define maxn 110

string x;

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

    cin >> x;

    for(ii i = 0; i < x.size(); i++) {
        if(x[i] == '.') break;

        cout << x[i];
    }

    cout << endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

#define mp make_pair
#define fr first
#define sc second

int gcd(int x,int y){
	if(y==0)return x;
	return gcd(y,x%y);
}

int main(){
	int n,ret=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		ret=gcd(ret,a);
	}
	cout<<ret<<endl;
}

	#include <bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define PI 3.14159265358979
	#define EPS 1e-8
	#define mod  1000000007
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define endl "\n"
	#define NEG_INF -2e18

	const ll INF=1e15;
	const int N=4e5+50;

	ll fac[N];

	 long long binpow(long long a, long long b, long long m) {
						a %= m;
						long long res = 1;
						while (b > 0) {
							if (b & 1)
								res = res * a % m;
							a = a * a % m;
							b >>= 1;
			}
			return res;
	}

	ll modinverse(ll a,ll m)
	{
		return binpow(a,m-2,m);
	}

	ll nck(ll n,ll r)
	{
		return ((fac[n]*modinverse(fac[r],mod)) % mod)*modinverse(fac[n-r],mod)%mod;

	}

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

		ll n;
		cin>>n;

		vector<ll> v(n);

		for(ll i=0;i<n;i++)
			cin>>v[i];

		sort(v.begin(),v.end());
		ll g=v[0];

		for(ll i=1;i<n;i++)
		{
			g=__gcd(g,v[i]-v[0]);
		}
		cout<<g;

	}


/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - GCD or MIN
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 2000;
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;
typedef unordered_map<int,int> mii;

/* global variables */

int as[MAX_N];
mii mp;

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m > 0, n > 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int mina = INF;
  for (int i = 0; i < n; i++) {
    scanf("%d", as + i);
    mina = min(mina, as[i]);
  }
  //printf("mina=%d\n", mina);

  for (int i = 0; i < n; i++) {
    int ai = as[i];
    for (int p = 1; p <= mina && p * p <= ai; p++)
      if (ai % p == 0) {
	mii::iterator mit = mp.find(p);
	if (mit == mp.end()) mp.insert(pii(p, ai));
	else mit->second = gcd<int>(mit->second, ai);

	int q = ai / p;
	if (q <= mina) {
	  mii::iterator mit = mp.find(q);
	  if (mit == mp.end()) mp.insert(pii(q, ai));
	  else mit->second = gcd<int>(mit->second, ai);
	}
      }
  }

  int c = 0;
  for (mii::iterator mit = mp.begin(); mit != mp.end(); mit++)
    if (mit->first == mit->second) c++;

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

#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<cmath>
using namespace std;
const int INF=0x3f3f3f3f,maxn=60,MOD=998244353;
#define ll long long
//vector<int>v[maxn];
//map<int,string>mp[maxn];
//queue<int>q[maxn];
int a[maxn][maxn],n,K,siz[maxn],fa[maxn],ans;
int quick_read_num()
{
	int x=0,flag=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
			flag=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<3)+(x<<1)+(c-'0');
		c=getchar();
	}
	return flag*x;
}
void Init()
{
	for(int i=1;i<=n;i++)
		fa[i]=i;
}
int Find(int x)
{
	if(fa[x]==x)
		return x;
	return fa[x]=Find(fa[x]);
}
void Add(int x,int y)
{
	x=Find(x),y=Find(y);
	if(x==y)
		return;
	if(x<y)
		fa[x]=y;
	else
		fa[y]=x;
}
ll jc(int x)
{
	if(x<2)
		return 1;
	ll mul=1;
	for(int i=2;i<=x;++i)
	{
		mul*=i;
		mul%=MOD;
	}
	return mul;
}
void _gather1()
{
	int i,j;
	for(i=1;i<=n;++i)
	{
		//vis[i]=false;
		for(j=i+1;j<=n;++j)
		{
			bool flag=true;
			for(int k=1;k<=n;++k)
				if(a[i][k]+a[j][k]>K)
				{
					flag=false;
					break;
				}
			if(flag)
			{
			//	cout<<i<<" "<<j<<endl;
				Add(i,j);
			}
		}
	}
}
void _gather2()
{
	int i,j;
	for(i=1;i<=n;++i)
	{
		//vis[i]=false;
		for(j=i+1;j<=n;++j)
		{
			bool flag=true;
			for(int k=1;k<=n;++k)
				if(a[k][i]+a[k][j]>K)
				{
					flag=false;
					break;
				}
			if(flag)
			{
			//	cout<<i<<" "<<j<<endl;
				Add(i,j);
			}
		}
	}
}
void ans_count()
{
	int i,j,si=0;
	for(i=1;i<=n;i++)
		siz[Find(fa[i])]++;
	for(i=1;i<=n;i++)
	{
	//	cout<<siz[i]<<endl;
		ans=(ans*jc(siz[i]))%MOD;
	}

}
int main()
{
	int i,j,k;
	ans=1ll;
	n=quick_read_num();
	K=quick_read_num();
	//cout<<n<<" "<<k<<endl;
	Init();
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			a[i][j]=quick_read_num();
	_gather1();
	ans_count();
	Init();
	memset(siz,0,sizeof(siz));
	_gather2();
	ans_count();
	cout<<ans;
	return 0;
}