#include<bits/stdc++.h>
using namespace std;
long long n,K,T[3000000];
long long f(long long a){
  if(a<2)return 0;
  else if(a<=n+1)return a-1;
  else if(a<=n+n)return n+n+1-a;
  else return 0;
}
long long S(long long k){
	if(k<0) return 0;
	else if(k<n) return (k+2)*(k+1)/2;
	else if(k<2*n-2)return (9*n-3*n*n+6*k*n-6*k-2*k*k-4)/2;
	else if (k<3*n-2) return (3*n-k-1)*(3*n-k-2)/2;
	else return 0;
}
int main(){
	cin >> n >> K;
  	T[0]=1;
  	for(long long i=1;i<3*n-2;i++){
      T[i]=T[i-1]+S(i);
    }
  	long long lb = -1;
    long long ub = 3*n-2;
  	while(ub - lb>1){
    	long long mid = (lb+ub)/2;
    	if(T[mid]>=K) ub = mid;
    	else lb = mid;
  	}
  	ub+=3;
  	K-=T[lb];
  	for(long long a=1;a<=ub-2;a++){
      K-=f(ub-a);
      if(K<=0){
        if(ub-a>=n+1){
          cout << a << " " << n+K << " " << ub-a-n-K << endl;
        }else{
          cout << a << " " << ub-a-1+K << " " << 1-K << endl;
        }
        break;
      }
	}
  	return 0;
}

// Problem: B - -- - B
// Contest: AtCoder - AtCoder Regular Contest 112
// URL: https://atcoder.jp/contests/arc112/tasks/arc112_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
const int MAX_N = 2e6+10;

ll B, C;

void solve()
{
	if(!C) cout<<1<<'\n';
	else if(!B) cout << C << '\n';
	else{
		// *-1 ----- *-1
		ll L1 = B-C/2, R1 = B+(C>=2?(C-2)/2:0);
		ll L2 = -B-(C-1)/2,R2=-B+(C-1)/2;
		if(R1<L2 || R2<L1){
			cout<<R1+R2-L1-L2+2<<'\n';
		}else{
			cout<<max(R1,R2)-min(L1,L2)+1<<'\n';
		}
	}
}

int main()
{
	cin >> B >> C;
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int mod = 998244353;

int p(int a, int b) {
    if (b == 0) return 1;
    int tmp = p(a, b / 2);
    if (b % 2 == 0) return (tmp * tmp)%mod;
    return ((tmp * tmp)%mod * a)%mod;
}

int n, m;

int sum[5001];
int val[5001][5001];
int pow_m[5001];

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

    cin >> n >> m;
    pow_m[0] = 1;
    for (int i = 1; i <= 5000; i++)
        pow_m[i] = (pow_m[i - 1] * m) % mod;

    for (int j = 0; j <= m - 1; j++) {
        int tmp = 1;
        for (int i = 0; i <= n - 2; i++) {
            (sum[i] += tmp) %= mod;
            (tmp *= j) %= mod;
        }
    }
    for (int i = 1; i <= n ; i++)
        for (int j = 1; j < i - 1; j++)
            val[i][j] = sum[i - j - 1];

    int ans = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < i; j++) {
            if (j == i - 1)
                (ans += m * pow_m[n - 2] % mod ) %= mod;
            else
                (ans += pow_m[n - i + j - 1] * val[i][j] % mod ) %= mod;
        }
    ans = ((n * p(m, n) % mod - ans)%mod + mod)%mod;
    cout << ans;
}

#include <bits/stdc++.h>

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v -= MOD-o.v;
		v = (v < 0) ? v + MOD : v;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		v = (v < 0) ? v + MOD : v;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);

	using num = modnum<998244353>;

	int N, M; cin >> N >> M;
	num ans = 0;

	for (int v = 1; v <= M; v++) {
		num cnt_open = 0;
		num tot_open = 0;
		num cnt_closed = 1;
		num tot_closed = 0;
		for (int i = 0; i < N; i++) {
			num nxt_cnt_open = cnt_open * (M-v);
			num nxt_tot_open = tot_open * (M-v);
			num nxt_cnt_closed = cnt_closed * (M-v);
			num nxt_tot_closed = tot_closed * (M-v);

			// If the value is == v, must open
			{
				nxt_cnt_open += cnt_open;
				nxt_tot_open += tot_open;
				nxt_cnt_open += cnt_closed;
				nxt_tot_open += tot_closed + cnt_closed;
			}

			// If the value is < v, must close
			{
				nxt_cnt_closed += cnt_open * (v-1);
				nxt_tot_closed += tot_open * (v-1);
				nxt_cnt_closed += cnt_closed * (v-1);
				nxt_tot_closed += tot_closed * (v-1);
			}

			cnt_open = nxt_cnt_open;
			tot_open = nxt_tot_open;
			cnt_closed = nxt_cnt_closed;
			tot_closed = nxt_tot_closed;
		}
		ans += tot_open + tot_closed;
	}
	cout << ans << '\n';

	return 0;
}

// For each value v, we need to do


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w;
  cin>>h>>w;

  //(i,j)から a[i][j][k]にいける
  vector<vector<vector<pair<int,int>>>>go(h,vector<vector<pair<int,int>>>(w,vector<pair<int,int>>(0)));
  go.push_back(vector<vector<pair<int,int>>>(26,vector<pair<int,int>>(0)));
  pair<int,int>S,G;
  vector<vector<char>>a(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i][j];
      if(a[i][j]=='S'){S={i,j};}
      else if(a[i][j]=='G'){G={i,j};}
      else if(a[i][j]!='.'&&a[i][j]!='#'){
        go[i][j].push_back({h,a[i][j]-'a'});
        go[h][a[i][j]-'a'].push_back({i,j});
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='#')continue;
      if(i>0&&a[i-1][j]!='#')go[i][j].push_back({i-1,j});
      if(i<h-1&&a[i+1][j]!='#')go[i][j].push_back({i+1,j});
      if(j>0&&a[i][j-1]!='#')go[i][j].push_back({i,j-1});
      if(j<w-1&&a[i][j+1]!='#')go[i][j].push_back({i,j+1});
    }
  }
  //cout<<"ok\n";
  vector<vector<int64_t>>cost(h,vector<int64_t>(w,1e18));
  cost.push_back(vector<int64_t>(26,1e18));
  cost[S.first][S.second]=0;
  queue<pair<int,int>>bfs;
  bfs.push(S);
  pair<int,int>n;
  while(bfs.size()){
    n=bfs.front();
    bfs.pop();
    if(n.first==h){
      for(int i=0,l=go[h][n.second].size();i<l;i++){
        if(cost[go[h][n.second][i].first][go[h][n.second][i].second]>cost[h][n.second]){
          cost[go[h][n.second][i].first][go[h][n.second][i].second]=cost[h][n.second];
          bfs.push({go[h][n.second][i].first,go[h][n.second][i].second});
        }
      }
    }else{
      int i=n.first,j=n.second;
      for(int k=0,l=go[i][j].size();k<l;k++){
        if(cost[go[i][j][k].first][go[i][j][k].second]>cost[i][j]+1){
          cost[go[i][j][k].first][go[i][j][k].second]=cost[i][j]+1;
          bfs.push({go[i][j][k].first,go[i][j][k].second});
        }
      }
    }
  }
  /*
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)cout<<cost[i][j]<<' ';
    cout<<'\n';
  }
  */
  cout<<(cost[G.first][G.second]==1e18?-1:cost[G.first][G.second])<<'\n';
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=998244353;

struct unionFind{
    int* par;                       //親
    int* rank;                      //木の深さ
    int* scale;                     //木のサイズ
    unionFind(int n);
    ~unionFind();
    int find(int x);                //木の根を求める
    void unite(int x,int y);        //xとyの属する集合を併合
    bool same(int x,int y);         //xとyが同じ集合に属するか否か
    int size(int x);                //xの属する集合のサイズ
};

unionFind::unionFind(int n){
    par=new int[n];
    rank=new int[n];
    scale=new int[n];
    for(int i=0;i<n;i++){
        par[i]=i;
        rank[i]=0;
        scale[i]=1;
    }
}

unionFind::~unionFind(){
    delete[] par;
    delete[] rank;
    delete[] scale;
}

int unionFind::find(int x){
    if(par[x]==x) return x;
    return par[x]=find(par[x]);
}

void unionFind::unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(rank[x]<rank[y]){
        par[x]=y;
        scale[y]+=scale[x];
    }else{
        par[y]=x;
        scale[x]+=scale[y];
        if(rank[x]==rank[y]) rank[x]++;
    }
}

bool unionFind::same(int x,int y){
    return find(x)==find(y);
}

int unionFind::size(int x){
    x=find(x);
    return scale[x];
}

ll mfrac(ll n){
    if(n==0) return 1;
    else return n*mfrac(n-1)%MOD;
}

ll N,K;
ll a[50][50];

int main(){
    cin>>N>>K;
    rep(i,N) rep(j,N) cin>>a[i][j];

    unionFind ufr(N);
    unionFind ufc(N);
    rep(x,N-1){
        for(int y=x+1;y<N;y++){
            bool c=true, r=true;
            rep(i,N){
                c&=a[i][x]+a[i][y]<=K;
                r&=a[x][i]+a[y][i]<=K;
            }
            if(c) ufc.unite(x,y);
            if(r) ufr.unite(x,y);
        }
    }

    vector<bool> chkr(N,true);
    vector<bool> chkc(N,true);
    ll cntr=1;
    ll cntc=1;
    rep(i,N){
        if(chkr[ufr.find(i)]){
            cntr*=mfrac(ufr.size(i));
            cntr%=MOD;
            chkr[ufr.find(i)]=false;
        }
        if(chkc[ufc.find(i)]){
            cntc*=mfrac(ufc.size(i));
            cntc%=MOD;
            chkc[ufc.find(i)]=false;
        }
    }

    ll ans=cntr*cntc%MOD;
    cout<<ans<<endl;
}


#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 = 1000000007;
//vector<vector<int>> dp(m, vector<int>(n));

void	solve()
{
	int n;
	cin >> n;
	map<int, string> mp;
	for (int i = 0; i < n; i++) {
		string s;
		int t;
		cin >> s >> t;
		mp[t] = s;
	}
	int i = 0;
	for (auto p : mp) {
		i++;
		if (i == n - 1) {
			cout << p.second << endl;
			return ;
		}
	}
}

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

	solve();
}

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

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> T(N);
  for(int i=0; i<N; i++) cin >> S.at(i) >> T.at(i);
  vector<int> t(N);
  for(int i=0; i<N; i++) t.at(i) = T.at(i);
  sort(t.begin(),t.end());
  int ans;
  for(int i=0; i<N; i++){
    if(T.at(i) == t.at(N-2)) ans = i;
  }
  cout << S.at(ans) << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  vector<ll> a(n+1,0);
  rep(i,n) R a[i];
  sort(all(a));
  a.erase(unique(all(a)),a.end());
  ll ans=1;
  rrep(i,a.size()-1) {
    ans*=a[i+1]-a[i]+1;
    ans%=MAX;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define ar array

const int INF = 0x3f3f3f3f;
const ll  LINF = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 2e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
	double s1,s2,g1,g2;
	cin >> s1 >> s2 >> g1 >> g2;
	double ans = (g2*s1+s2*g1)/(s2+g2);
	cout << setprecision(10) << ans << endl;
}

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

    int t = 1;

    // cin >> t;

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

    return 0;
}


// radhey krishna
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
template<typename T> T sqr(const T &x) {
    return x * x;
}
#define endl "\n"
int mx[31] , mn[31];
void solve(){
 ll a ,b ,c ,d;
 cin>>a>>b>>c>>d;
 ll flag = 0;
 if(a == b+c+d){
  flag = 1;
 }
  if(b == a+c+d){
  flag =1;
 }
 if(c == a+b+d){
  flag =1;
 }
  if(a + b == c + d){
  flag = 1;
 }
 if(b + c == a + d){
  flag = 1;
 }
 if(d + b == a + c){
  flag = 1;
 }
  if(a + b + c == d){
  flag = 1;
 }
 if(flag == 1){
  cout<<"Yes"<<endl;
 }
 else{
  cout<<"No"<<endl;
 }
}
int main(){
  #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
       ios_base::sync_with_stdio(false);
       cin.tie(NULL);
     int t =1 ;
      //cin>>t;
     while(t--){
    solve();
        }
 }

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

int32_t main(){

    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    vector<int> v(4);
    int ans = 0;

    for(int i=0;i<4;i++){
        cin>>v[i];
        ans+=v[i];
    }

    for(int i=1;i<8;i++){
        int curr = 0;
        for(int j=0;j<4;j++){
            if(i&(1ll<<j)){
                curr+=v[j];
            }
        }
        if(curr == ans - curr){
            cout<<"Yes\n";
            exit(0);
        }
    }

    cout<<"No\n";

    return 0;
}


#include<stdio.h>
int main()
{
    int N,K,M,i,sum = 0;
    scanf("%d %d %d",&N,&K,&M);
    int ar[N-1];
    for(i=0;i < N-1;i++)
    {
        scanf("%d",&ar[i]);
        sum += ar[i];
    }
    if((sum/N) >= M)
    {
        printf("0\n");
    }
    else if(((sum+K)/N)< M)
    {
        printf("-1\n");
    }
    else
    {
        printf("%d\n",((N*M)-sum));
    }
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
  int N,K,M,t;
  cin>>N;
  cin>>K;
  cin>>M;

  int sum=0;

  for(int i=0;i<N-1;i++){
    cin>>t;
    sum=sum+t;
  }
  int check=N*M-sum;
  if(check<0)
    cout<<0;
  else if(check<=K && check>=0)
    cout<<check;
  else
    cout<<-1;
  return 0;

}


#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include <numeric>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define Rep(i,n) for(int i = 1 ; i <= n ; i++)
const int maxn=2e5+5;
const ll mod = 1e9 + 7;
const bool DEBUG = 0;

int main(){

    int a,b,ans;

    cin >> a >> b;

    int sum = 500500;
    Rep(i,a){
        if( i < a ){
            cout << i << ' ';
            sum = sum - i;
        }else{
            cout << sum << ' ';
        }
    }

    sum = 500500;
    Rep(i,b){
        if( i < b){
            cout << -i << ' ';
            sum = sum - i;
        }else{
            cout << -sum << ' ';
        }
    }

    return 0;
}

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

int a, b;
vector<int> ans;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> a >> b) {
        int sum = 0;
        ans.clear();
        if (a >= b) {
            for (int i = 1; i <= a; i++) ans.push_back(i), sum += i;
            for (int i = 1; i < b; i++) ans.push_back(-i), sum -= i;
            ans.push_back(-sum);
        } else {
            for (int i = 1; i <= b; i++) ans.push_back(-i), sum -= i;
            for (int i = 1; i < a; i++) ans.push_back(i), sum += i;
            ans.push_back(-sum);
        }
        for (int i = 1; i < a + b; i++) cout << ans[i - 1] << ' ';
        cout << ans[a + b - 1] << '\n';
    }
    return 0;
}


//#include<bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string.h>
#include <vector>
#include <utility>
#include <map>

//#pragma GCC optimize "trapv"

#define int long long
#define For(i,a,b) for(int  i=a;i<b;i++)

#define pb push_back
#define endl "\n"

#define F first
#define S second

#define dracarys ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()

#define TEST_CASE int  t;cin>>t;while(t--)
#define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__);

using namespace std;
const int MOD = 1e9 + 7;

void print()  {    cout<<endl;  }
void printArray()  {    return;  }
void read() { return; }

template<typename T , typename... Args>  void print(T a , Args... arg)    {    cout << a << " " ;    print(arg...);    }

template<typename T , typename... Args> void read(T &a , Args&... arg) {   cin >> a;   read(arg...);   }

template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) {  for(auto &i : v)  cin>>i;  read(arg...);  }

template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) {   for(auto i : v)     cout<<i<<" ";   cout<<endl;  printArray(arg...);    }

int power(int a,int b) { int  res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; }

int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; }

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

int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; }

int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; }

void runCase_()
{
        int n; read(n);
        vector<pair<int,int>>v(n);
        for(auto &i : v) read(i.F,i.S);
        int aoki = 0,taka = 0,ans = 0;
        for(auto i : v) aoki += i.F;
        sort(all(v),[](pair<int,int>a,pair<int,int>b)
             {
                     return 2*a.F + a.S > 2*b.F + b.S;
             });
        int i = 0;
        while(i < n && taka <= aoki)
        {
                taka += (v[i].F + v[i].S);
                aoki -= v[i].F;
                ++ans,++i;
        }
        print(ans);
}

signed main()
{
     dracarys;
//      TEST_CASE
     runCase_();
     return 0;
}

/** TEST CASES HERE **/
/*

*/

#include "bits/stdc++.h"
#define pb push_back
#define mp make_pair

using namespace std;

using ll = long long;

signed main(){
	ll n;
	cin >> n;

	vector<ll>a(n),b(n);
	ll sum = 0;

	vector<pair<ll,pair<ll,ll>>>d;

	for(ll i=0;i<n;i++){
		cin >> a[i] >> b[i];
		sum = sum + a[i];
		d.pb(mp(-2*a[i]-b[i],mp(a[i],a[i]+b[i])));
	}

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

	ll c = 0;
	ll cnt = 0;

	for(auto u : d){
		//cout << u.first << " " << u.second.first << " " << u.second.second << "\n";
		if(sum < c){
			break;
		}
		else{
			sum = sum-u.second.first;
			c = c + u.second.second;
			cnt++;
		}
	}

	cout << cnt << "\n";

	return 0;
}


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

#define SOLVER(x) solve_B x

static void s_solve(void)
{
    long long N, X;
    string S;
    long long ans;

    cin >> N >> X;
    cin >> S;

    ans = X;
    for (long long i = 0; i < N; i++)
    {
        switch ( S.at(i) )
        {
            case 'o':
                ans += 1;
                break;
            case 'x':
                if ( ans > 0 )
                {
                    ans -= 1;
                }
                break;
        }
    }

    cout << ans << endl;

    return;
}

void SOLVER((volatile bool *do_loop))
{
    do {
        s_solve();
    } while ((do_loop != NULL) && (*do_loop));
}

#ifndef NO_PROBLEM_MAIN
int main( void )
{
    SOLVER((NULL));
    return 0;
}
#endif

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

#define BUF_SIZE 500

enum way {
    u,
    l,
    r,
    d
};

int main()
{
    short int si, sj;
    {
        char buf[1000];
        std::stringstream ss;
        std::cin.getline(buf, 1000);
        ss << buf;
        ss >> si >> sj;
    }

    short int t[52][52] = {0};
    for (short int j=0;j<52;j++)
        t[0][j] = -1;
    for (short int i=1;i<51;i++) {
        t[i][0] = -1;
        char buf[BUF_SIZE];
        std::stringstream ss;
        std::cin.getline(buf, BUF_SIZE);
        ss << buf;
        for (short int j=1;j<51;j++) {
            ss >> t[i][j];
        }
        t[i][51] = -1;
    }
    for (short int j=0;j<52;j++)
        t[51][j] = -1;
    short int p[52][52] = {0};
    for (short int i=1;i<51;i++) {
        char buf[1000];
        std::stringstream ss;
        std::cin.getline(buf, 1000);
        ss << buf;
        for (short int j=1;j<51;j++) {
            ss >> p[i][j];
        }
    }
    std::vector<short int>tiles;
    tiles.push_back(-1);
    tiles.push_back(0);
    tiles.push_back(t[si+1][sj+1]);
    short int val_t[4];
    short int val_p[4];
    std::string output = "";
    char ways[5] = "ULRD";
    short int diff_i[4] = { -1, 0, 0, +1 };
    short int diff_j[4] = { 0, -1, +1, 0 };
    while (true) {
        val_t[u] = t[si+1-1][sj+1];   //u
        val_t[l] = t[si+1]  [sj+1-1]; //l
        val_t[r] = t[si+1]  [sj+1+1]; //r
        val_t[d] = t[si+1+1][sj+1];   //d
        val_p[u] = p[si+1-1][sj+1];   //u
        val_p[l] = p[si+1]  [sj+1-1]; //l
        val_p[r] = p[si+1]  [sj+1+1]; //r
        val_p[d] = p[si+1+1][sj+1];   //d
        short int max_t = 0;
        short int max_p = -1;
        short int max_way = -1;
        for (int i=0;i<4;i++) {
            if (std::find(tiles.begin(), tiles.end(), val_t[i]) == tiles.end()) {
                if (max_p < val_p[i]) {
                    max_p = val_p[i];
                    max_t = val_t[i];
                    max_way = i;
                }
            }
        }
        if (max_way==-1)
            break;
        output += ways[max_way];
        tiles.push_back(max_t);
        si += diff_i[max_way];
        sj += diff_j[max_way];
    }
    std::cout << output << std::endl;
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mod 1000000007ll
//#define mod 998244353ll
#define endl '\n'
#define inf ((ll)1e18+1)
#include<chrono>
using namespace chrono;
mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define debr(x,y) {cout<<"-->  "<<#x<<" to "<<#y<<" :  "; auto itr=x; while(itr!=y) cout<<(*itr++)<<' '; cout<<endl; }
#define deba(x) {cout<<"-->  "<<#x<<" :  "; for(auto ele:(x)) cout<<ele<<"  "; cout<<endl; }
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s);istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a <<"  ,  ";
    err(++it, args...);
}
ll cl(ll a,ll b){
	return a/b+(a%b!=0);
}

const int maxN=2e5+5;
vector<int> adj[maxN];
int n,m;
int price[maxN],deg[maxN];
ll cost[maxN];
ll ans=-inf;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t=1;
	// cin>>t;
	while(t--){
		cin>>n>>m;
		for(int x=1;x<=n;x++){
			cin>>price[x];
			cost[x]=inf;
		}
		for(int x=1;x<=m;x++){
			int xi,yi;
			cin>>xi>>yi;
			adj[xi].push_back(yi);
			deg[yi]++;
		}
		priority_queue<array<ll,2>,vector<array<ll,2>>,greater<array<ll,2>>> pq;
		for(int x=1;x<=n;x++){
			if(deg[x]==0){
				pq.push({price[x],x});
				cost[x]=price[x];
			}
		}
		while(!pq.empty()){
			auto pa=pq.top();
			pq.pop();
			ll mini=pa[0],u=pa[1];
			for(int v:adj[u]){
				if(cost[v]>mini){
					cost[v]=mini;
					pq.push({min(mini,(ll)price[v]),v});
				}
			}
		}
		for(int x=1;x<=n;x++){
			if(deg[x]>0){
				ans=max(ans,price[x]-cost[x]);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int inf = 1001001001;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  vector<vector<int>> G(N,vector<int>(0));
  for(int i=0;i<M;i++){
    int x,y;
    cin >> x >> y;
    x--;y--;
    G[x].push_back(y);
  }

  vector<int> V1(N),V2(N,inf);
  for(int i=0;i<N;i++) V1[i] = A[i];
  for(int i=0;i<N;i++){
    for(int j=0;j<G[i].size();j++){
      int v = G[i][j];
      V1[v] = min(V1[v],V1[i]);
      V2[v] = min(V2[v],V1[i]);
    }
  }

  int ans = -inf;
  for(int i=0;i<N;i++) if(V2[i]!=inf) ans = max(ans,A[i]-V2[i]);
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <string>
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

int main(){
int a, b, c;
cin >> a >> b >> c;

cout << 21 - a - b - c << endl;
return 0;
}

// Problem Link - https://www.codechef.com/UADPIP01/problems/KFIB
/* By Prateek Pani */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
// // #include<ext/pd_ds/tree_policy.hpp> // works on decommenting on my machine
// // #include<ext/pd_ds/trie_policy.hpp> // works on decommenting on my machine

using namespace __gnu_pbds;

using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				emplace_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mp 				map
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define token(str,ch)	(std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}

// tree here is red-black tree and classic problem to solve this is "invCnt"
// trie here is trie ds .. use as pdtrie
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // run on online ide
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pbtrie; // run on online ide

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

int main(int argc, char const *argv[])
{
	file_i_o();
	int a, b, c;

	cin>>a>>b>>c;
	cout<<((7-a)+(7-b)+(7-c))<<endl;

	return 0;
}


/* dont stick to an approach */

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ldb;

#define PB push_back

#define For(i, n) for (ll i = 0; i < n; i++)

#define trav(a,x) for (auto& a : x)

#define PYES cout<<"YES\n"
#define PNO cout<<"NO\n"
#define PYes cout<<"Yes\n"
#define PNo cout<<"No\n"
#define endl '\n'

#define sq(x)           (x*x)

#define vll             vector<ll>
#define pll             pair<ll,ll>
#define ff              first
#define ss              second
#define rev(v)          reverse(v.begin(),v.end())
#define srt(v)          sort(v.begin(),v.end())
#define grtsrt(v)       sort(v.begin(),v.end(),greater<int>())
#define mnv(v)          *min_element(v.begin(),v.end())
#define mxv(v)          *max_element(v.begin(),v.end())
#define all(v)          v.begin(),v.end()
#define ACC(v)          accumulate(v.begin(),v.end(),0ll)

#define Fas ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

//--------------------------------------------functions-------------------------------------------------//

ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll add(ll a, ll b,ll M){return mod(mod(a,M)+mod(b,M),M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
    ll res=1ll;
    while(b){
        if(b%2ll==1ll){
            res=mul(a,res,M);
        }
        a=mul(a,a,M);b/=2ll;
    }
    return res;
}
//------------------------------------sieve of erantothenes-----------------------------------------------//
//ll MAXN=100150;
//vector<ll> fact(MAXN+1);
//void sieve_of_erantothenes()
//{
//    fact[1] = 1;
//    for (ll i = 2; i <= MAXN; i++)
//        fact[i] = i;
//    for (ll i = 4; i <= MAXN; i += 2)
//        fact[i] = 2;
//    for (ll i = 3; i * i <= MAXN; i++){
//        if (fact[i] == i){
//            for (ll j = i * i; j <= MAXN; j += i)
//                if (fact[j] == j)
//                    fact[j] = i;
//        }
//    }
//}
//----------------------------------------nCr mod------------------------------------------------------//
ll nCr(ll n, ll k){
    if(n<k) return 0;
    if(k==0) return 1;
    ll res = 1;
    if (k > n - k) k = n - k;
    for(ll i = 0; i < k; ++i){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll modInverse(ll n,ll M){
    return powerM(n,M-2,M);
}
ll nCrM(ll n,ll r,ll M){
    if(n<r) return 0;
    if(r==0) return 1;
    vector<ll> fact(n+1);
    fact[0]=1;
    for(ll i=1;i<=n;i++){
        fact[i]=mul(fact[i-1],i,M);
    }
    return mul(mul(fact[n],modInverse(fact[r],M),M),modInverse(fact[n-r],M),M);
}
//-----------------------------------------------solve-----------------------------------------------------//
void solve(){
    ll n;cin>>n;
    vll v(n);
    trav(w,v) cin>>w;
    for(ll i=1;i<n;i++){
        if(i%2==0){
            v[i]=v[i-1]+v[i];
        }else{
            v[i]=v[i-1]-v[i];
        }
    }
    map<ll,ll> mm;
    for(ll i=0;i<n;i++){
        mm[v[i]]++;
    }
    ll ans=0;
    mm[0]++;
    trav(w,mm){
        ans+=nCr(w.ss,2);
    }
    cout<<ans<<endl;
}

int main(){
    Fas;

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

//    ll t=0;
//    cin>>t;
//    while(t--)

        solve();

    return 0;
}

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

#define ll long long
#define ull unsigned long long
#define gcd __gcd
#define INF LONG_LONG_MAX

void solve(){
	int n;
	cin>>n;
	vector<ll> arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	map<ll,ll> m1;
	m1[0]=1;
	ll sum=0;
	ll ans=0;
	for(int i=0;i<n;i++){
		if(i%2==0){
			sum+=arr[i];
		}else{
			sum-=arr[i];
		}
		ans+=m1[sum];
		m1[sum]++;
	}
	cout<<ans<<"\n";
}

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


#include <bits/stdc++.h>
using namespace std;
using ld = long double;
const int mxn = 103;
bool g[mxn][mxn], f[mxn][mxn];
int n, id;

void dfs(int v) {
	f[v][id] = true;
	for(int i = 0; i < n; i++)
		if(g[v][i] && !f[i][id])
			dfs(i);
}

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    #ifdef saarang
    freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
    freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
    #endif
    cin >> n;
    for(int i = 0; i < n; i++) {
    	for(int j = 0; j < n; j++) {
    		char c; cin >> c;
    		g[i][j] = c - '0';
    	}
    }
    for(id = 0; id < n; id++)
    	dfs(id);
    ld ans = 0;
    for(int i = 0; i < n; i++) {
    	int cnt = 0;
    	for(int j = 0; j < n; j++)
    		cnt += f[i][j];
    	ans += 1.0 / cnt;
    }
    cout << fixed << setprecision(15) << ans << '\n';
    return 0;
}

// Problem: D - Message from Aliens
// Contest: AtCoder - ZONe Energy Programming Contest
// URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

#define int long long
#define pII pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))

#define rep(i, a, b) for (int i = a; i < b; i++)
#define do(i, a, b) for (int i= (a); i <= (b); i++)

#define com(s) (s).begin(),(s).end()
#define F first
#define S second
#define pb push_back
#define s(x) (int)(x).size()
#define CASES int tc;cin>>tc;while(tc--)
#define READ_INP freopen("inp.txt", "r", stdin)
#define UNIQUE(X) (X).erase(unique(S(X)),(X).end())
#define IOs ios_base::sync_with_stdio(false);cin.tie(NULL);
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define DISPV(v) { for(auto u: v) cout << u << " "; cout << endl; }
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define endl '\n'

const int inf = 1e18; const int M = 1e9 + 7; const int MAXN = 1e7 + 1;
const double pi = acos(-1.0);

//DEBUGGING-TOOL
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr <<*it << " = " << a << endl;
    err(++it, args...);
}

//FUNC
int gcd(int a, int b) {return b == 0?a:gcd(b, a % b);}
int modMul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
int modPow(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
int calculateNcR(int n, int r){ if(n<r)return 0; int p=1,k=1;if(n-r<r)r=n-r;if(r!=0){while(r){p*=n;k*=r;int m=gcd(p, k);p/=m;k/=m;n--;r--;}return p;}}

//CODE
int32_t main() {
    IOs;
   // CASES {
        int n,m,l,r,d,b,k,u,p,a,q,x,y,z,mn,mx,rem,ans,res=0,c=0;
        string s; cin >> s;
        deque<char>Deq;
        int ok = 0;
        for (char I: s){
        	if(I == 'R') ok ^= 1;
        	else if(ok == 1) Deq.push_front(I);
        	else Deq.push_back(I);
        }
        if(ok == 1) reverse(Deq.begin(), Deq.end());
        string Ano;
        for (char d: Deq){
        	if(s(Deq) == 0) Ano.push_back(d);
        	else{
        		if(Ano.back() == d) Ano.pop_back();
        		else Ano.push_back(d);
        	}
        }
        cout << Ano << '\n';

   // }
}


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

#define sync ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) x.begin(),x.end()
#define unq(a) sort(all(a));a.resize(unique(all(a)) - a.begin())
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define mem(a , x) memset(a, x, sizeof a)
#define endl '\n'
const ld pi = atan(1) * 4.0;

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

int main(){

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

    sync

    int t = 1;
    //cin >> t;
    while(t--){
       int n, k; cin >> n >> k;
       vector<int> a(n);
       for (int& x : a) cin >> x;
       vector<ll> f(*max_element(all(a)) + 2);
       for (int& x: a) f[x]++;
       ll cnt = 0, lst = -1, mx = *max_element(all(a)), ok = k;
       for (int i = 0;i <= mx + 1;i++){
        if (f[i]){
            int mn = min(ok , f[i]);
            cnt += ((ok - mn) * 1ll * i);
            ok = mn;
        }
        else{
            cnt += (i * 1ll * ok);
            break;
        }
       }
       cout << cnt << endl;
    }

    cerr << "processor time: " << clock() / (double) CLOCKS_PER_SEC << "s    ";

    return 0;
}

#include<bits/stdc++.h>
#include <iostream>

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int n,i,j,k,x=0,y,z,sum=0;
    cin>>n>>k;
    long long int cnt[n+1]={0};
    for(i=1;i<=n;i++){
        cin>>x;
        cnt[x]+=1;
    }
    y=n;
    for(i=1;i<=k;i++){
        for(j=0;j<=n;j++){
            if(cnt[j]==0||y==0)
                break;
            cnt[j]-=1;
            y-=1;
        }
        sum+=j;
        if(y==0)
            break;
    }
    cout<<sum;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
const int p=1e9+7;
#define rint register int
#define rll register long long
#define ll long long
char s[N];
ll dp[N][20];
int n,k,st[N],a[N];
ll dfs(rint hh,rint re,bool ismx,bool iszero){
	if(re<0||re>hh)return 0;
	if(!hh)return 1;
	if(dp[hh][re]!=-1&&!ismx&&!iszero)return dp[hh][re];
	rll t=0;
	if(!ismx){
		if(!iszero)
			t=dfs(hh-1,re,0,0)*(k-re)+dfs(hh-1,re-1,0,0)*(16-k+re);
		else
			t=dfs(hh-1,re,0,1)+dfs(hh-1,re-1,0,0)*(15-k+re);
	}else {
		if(iszero)
			t=dfs(hh-1,re,!a[hh],1);
		else {
			if(st[hh+1]&1)t=dfs(hh-1,re,!a[hh],0);
			else t=dfs(hh-1,re-1,!a[hh],0);
		}
		for(rint j=1;j<=a[hh];j++){
			if(st[hh+1]&(1<<j))t+=dfs(hh-1,re,j==a[hh],0);
			else t+=dfs(hh-1,re-1,j==a[hh],0);
		}
	}
	t%=p;
	if(!ismx&&!iszero)dp[hh][re]=t;
	return t;
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	cin >> k;
	for(rint i=1;i<=n;i++){
		if('0'<=s[i]&&s[i]<='9')a[i]=s[i]-'0';
		else a[i]=s[i]-'A'+10;
		st[i]=st[i-1]|(1<<a[i]);
	}
	reverse(st+1,st+n+1);
	reverse(a+1,a+n+1);
	memset(dp,-1,sizeof(dp));
	printf("%lld\n",dfs(n,k,1,1));
	return 0;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll dp[18];
char S[200200];
int suuji(char c) {
	if (c < 'A') return c - '0';
	else return c - ('A' - 10);
}

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

	fread(S, 1, 200200, stdin);
	int K = 0;
	int N = 200200 - 1;
	while (S[N] != ' ') N--;
	int tmp = N + 1;
	while (S[tmp] >= '0') K = K * 10 + S[tmp++] - '0';

	const int mod = 1e9 + 7;
	int k = suuji(S[0]);
	dp[1] = k - 1;
	int kazu = 1 << 15 - k, kazu0 = 1;

	rep1(i, N - 1) {
		for(int j = 16; j >= 1; j--) {
			dp[j] %= mod;
			dp[j + 1] += (16 - j) * dp[j];
			dp[j] = j * dp[j];
		}
		dp[1] += 15;
		int k = suuji(S[i]);
		int k1 = __builtin_popcount(kazu >> 16 - k);
		dp[kazu0] += k1;
		dp[kazu0 + 1] += k - k1;
		kazu0 += !(kazu & 1 << 15 - k);
		kazu |= 1 << 15 - k;
	}

	ll kotae = dp[K];
	if (kazu0 == K) kotae++;
	printf("%lld", kotae % mod);

	Would you please return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MTP make_tuple
typedef long long int ll;
constexpr int kN = int(2E5 + 10);

struct BIT {
	int val[kN];
	BIT () {memset(val, 0, sizeof(val));}
	void add(int pos, int x) {
		while (pos < kN) {
			val[pos] += x;
			pos += pos & -pos;
		}
		return ;
	}
	int ask(int pos) {
		int ans = 0;
		while (pos) {
			ans += val[pos];
			pos ^= pos & -pos;
		}
		return ans;
	}
};

BIT bit;
vector<int> v[kN];
vector<tuple<int, int, int, int>> que[kN];
int p[kN], sz[kN], a[kN], b[kN], c[kN], k[kN], ans[kN], pos[kN];
int Find(int n) {return n == p[n] ? n : p[n] = Find(p[n]);}
void Merge(int l, int r) {
	l = Find(l), r = Find(r);
	if (l != r) {
		if (sz[l] < sz[r]) swap(l, r);
		for (int i : v[r]) v[l].PB(i);
		for (tuple<int, int, int, int> i : que[r])
			que[l].PB(MTP(get<0>(i) + sz[l], get<1>(i) + sz[l], get<2>(i), get<3>(i)));
		sz[l] += sz[r];
		p[r] = l;
	}
	return ;
}

int main() {
	int n, q, idx;
	vector<tuple<int, int, int, int>> events;
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
	for (int i = 1; i <= q; i++) scanf("%d%d%d", &k[i], &a[i], &b[i]);
	for (int i = 1; i <= n; i++) p[i] = i;
	for (int i = 1; i <= n; i++) sz[i] = 1;
	for (int i = 1; i <= n; i++) v[i].PB(i);
	for (int i = 1; i <= q; i++) {
		if (k[i] == 1) Merge(a[i], b[i]);
		else {
			idx = Find(a[i]);
			que[idx].PB(MTP(1, sz[idx], b[i], i));
		}
	}
	for (int i = 1; i <= n; i++) Merge(1, i);
	idx = Find(1);
	//v[idx].push_front(0);
	for (int i = 0; i < n; i++) pos[v[idx][i]] = i + 1;
	for (int i = 1; i <= n; i++) events.PB(MTP(c[i], -1, pos[i], 1));
	for (int i = 1; i <= n; i++) events.PB(MTP(c[i] + 1, -1, pos[i], -1));
	for (tuple<int, int, int, int> i : que[idx]) events.PB(MTP(get<2>(i), get<0>(i), get<1>(i), get<3>(i)));
	sort(events.begin(), events.end());
	for (tuple<int, int, int, int> i : events) {
		//printf("i = (%d, %d, %d, %d)\n",
		if (get<1>(i) == -1) bit.add(get<2>(i), get<3>(i));
		else ans[get<3>(i)] = bit.ask(get<2>(i)) - bit.ask(get<1>(i) - 1);
	}
	for (int i = 1; i <= q; i++) if (k[i] == 2) printf("%d\n", ans[i]);
}

#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5 + 5;
int fa[maxn];
unordered_map<int, int> mp[maxn];
int findfa(int x){
    if(fa[x] == x) return x;
    return fa[x] = findfa(fa[x]);
}

void merge(int x, int y){
    int fx = findfa(x), fy = findfa(y);
    if(fx==fy) return;
    if(mp[fx].size() > mp[fy].size()){
        swap(fx, fy);
    }
    for(auto& iter:mp[fx]){
        mp[fy][iter.first] += iter.second;
    }
    fa[fx] = fy;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i=1;i<=n;i++){
        int c;
        scanf("%d", &c);
        fa[i] = i;
        mp[i][c] = 1;
    }
    while(q--){
        int op, a, b;
        scanf("%d%d%d", &op, &a, &b);
        if(op==1){
            merge(a, b);
        }
        else if(op==2){
            int fx = findfa(a);
            printf("%d\n", mp[fx].find(b) == mp[fx].end()?0:mp[fx][b]);
        }
    }
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n){
    ll ans=1;
    while(n>0){ if(n&1) ans=(ans*x)%mod; x=(x*x)%mod; n/=2;}
    return ans;
}

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

    int T=1;
    //cin >> T;
    while(T--){

        int n;
        cin>>n;

        vector<ii> x,y;
        ll _x,_y;
        rep(i,n){
            cin>>_x>>_y;
            x.pb(mp(_x, _y));
            y.pb(mp(_y, _x));
        }

        sort(all(x));
        sort(all(y));

        vi z;
        if(x[n-1].ff-x[0].ff>=abs(x[n-1].ss-x[0].ss)) z.pb(x[n-1].ff-x[0].ff);
        if(x[n-1].ff-x[1].ff>=abs(x[n-1].ss-x[1].ss)) z.pb(x[n-1].ff-x[1].ff);
        if(x[n-2].ff-x[0].ff>=abs(x[n-2].ss-x[0].ss))z.pb(x[n-2].ff-x[0].ff);
        if(y[n-1].ff-y[0].ff>abs(y[n-1].ss-y[0].ss)) z.pb(y[n-1].ff-y[0].ff);
        if(y[n-1].ff-y[1].ff>abs(y[n-1].ss-y[1].ss)) z.pb(y[n-1].ff-y[1].ff);
        if(y[n-2].ff-y[0].ff>abs(y[n-2].ss-y[0].ss)) z.pb(y[n-2].ff-y[0].ff);
        sort(all(z));
        int k = z.size();
        cout<<z[k-2]<<el;

    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

// D - Circle Lattice Points
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using dbl = long double;

int main(){
	ll scale = 1e4;
	dbl x, y, r; cin>>x>>y>>r;
	ll X = round(x*scale);
	ll Y = round(y*scale);
	ll R = round(r*scale);
	ll r2 = R*R;
	ll ans = 0;
	for(ll i=0; i<=2*R+scale; i+=scale){
		ll y = floor((Y+R)/scale)*scale - i;
		ll dy = Y - y;
		ll dx2 = r2 - dy*dy;
		if(dx2 < 0) continue;
		ll dx = floor(sqrt((dbl)dx2));
		ll L = ceil((X - dx)/(dbl)scale);
		ll R = floor((X + dx)/(dbl)scale);
		ans += R - L + 1;
	}
	cout<< ans <<endl;
}


/////home/mohammed/.config/sublime-text-3/Packages/User

/*input

*/
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <list>
#include <set>

using namespace std;
using bin = std::bitset<8>;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min({a,b,c})
#define max3(a, b, c) max({a,b,c})
#define min4(a, b, c, d) min({a,b,c,d})
#define max4(a, b, c, d) max({a,b,c,d})
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ld long double
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";};cout << endl;
#define input(type, n) type n; cin>>n;

struct debugger
{
	template<typename T> debugger& operator , (const T& v)
	{
		cerr << v << " ";
		return *this;
	}
} dbg;

bool check_key(map<int, int> m, int key)
{
	if (m.find(key) == m.end())
		return false;

	return true;
}

vector<int> SieveOfEratosthenes(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));

	vector<int> res;
	for (int p = 2; p * p <= n; p++)
	{
		if (prime[p] == true)
		{
			for (int i = p * p; i <= n; i += p)
				prime[i] = false;
		}
	}

	for (int p = 2; p <= n; p++)
		if (prime[p])
			res.push_back(p);
	//cout << p << " ";
	return res;
}

// function to convert decimal to binary
bin decToBinary(int n)
{
	// array to store binary number
	int binaryNum[32];

	// counter for binary array
	int i = 0;
	while (n > 0) {

		// storing remainder in binary array
		binaryNum[i] = n % 2;
		n = n / 2;
		i++;
	}
	string x = "";
	// printing binary array in reverse order
	for (int j = i - 1; j >= 0; j--) {
		x += to_string(binaryNum[j]);
	}
	bin result{x};
	return result;
}
// for example:
// bin result = decToBinary(2);
// bin result2 = decToBinary(10);
// bin z = result xor result2;
// cout << z;
// return 0;
int convertBinaryToDecimal(long long n)
{
	int decimalNumber = 0, i = 0, remainder;
	while (n != 0)
	{
		remainder = n % 10;
		n /= 10;
		decimalNumber += remainder * pow(2, i);
		++i;
	}
	return decimalNumber;
}
int factorial(int n) {

	long long res = 1;
	for (int i = 1; i <= n; i++) {
		res = ((res * i) % mod + mod) % mod ;
	}
	return res;
}

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

	input(int, a); input(int, b); input(int, c); input(int, d);
	int cyan = a;
	int red = 0;

	for (int i = 0; i < 1e5 + 1; i++) {
		// cout << cyan << " " << red << endl;
		if (cyan <= red * d) {
			cout << i << endl;
			return 0;
		}

		cyan += b;
		red += c;
	}

	cout << -1 << endl;

}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

ll n, m, t;
ll a[1005], b[1005];

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

	cin >> n >> m >> t;
	rep(i, 1, m) cin >> a[i] >> b[i];
	a[m+1] = t;

	ll sum = n, ans = inf;
	sum -= a[1]; chmin(ans, sum);
	rep(i, 1, m){
		sum += b[i]-a[i], chmin(sum, n);
		sum -= a[i+1]-b[i], chmin(ans, sum);
	}
	if(ans <= 0) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define For(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define End return 0
#define vi vector<int>
#define pb push_back
#define YES printf("YES\n")
#define NO printf("NO\n")
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define Fors(i, s) for (int i = 0; i < s.size(); i++)
#define all(v) v.begin(), v.end()
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * (b / __gcd(a, b)))
#define Erase(s) s.erase(unique(s.begin(), s.end()), s.end());
//-----------------------------------------------------//

int main()
{
    //int T;cin >> T;while(T--)
    {
        string s;
        cin >> s;
        cout << s[1] << s[2] << s[0];
    }
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  cout << s[1] << s[2] << s[0] << endl;
}


//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define int long long
const int maxn = 2e5+10;
int lst[300];
int Minus[300];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	for(int i = 'a';i <= 'z';i++)lst[i] = n;
	ll ans = 0;
	if(s[n-1] != s[n-2])Minus[(int)s[n-1]]++;

	for(int i = n-2;i >= 0;i--){
		if(i > 0 and s[i-1] != s[i] and s[i+1] != s[i])Minus[(int)s[i]]++;
		if(s[i] == s[i+1] and lst[(int)s[i]] != i+1){
			ans += lst[(int)s[i]] - i - 2 - (Minus[(int)s[i]]?Minus[(int)s[i]]:0ll);
			// cout << i << " " << lst[(int)s[i]] << " " << Minus[(int)s[i]] << " ans: " << lst[(int)s[i]] - i - 2 - (Minus[(int)s[i]]?Minus[(int)s[i]]:0ll) << endl;
			lst[(int)s[i]] = i;
			for(int j = 'a';j <= 'z';j++)if(j != s[i])lst[j] = n;
			for(int j = 'a';j <= 'z';j++)Minus[j] = 0;
		}
		if(s[i] == s[i+1] and lst[(int)s[i]] == i+1)lst[(int)s[i]] = i;
		// lst[(char)s[i]] = i;
		// Minus[(int)s[i]]++;
	}
	cout << ans;
	return 0;
}

#include<bits/stdc++.h>
#define f(i,a,b) for( int i=a;i<=b;++i)
#define ff(i,a,b) for( int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline int in() { char ch = getchar();int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const double eps = 1e-6;
const int N = 6e5 + 5;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
#endif
	int n = in();
	ll ans = 0;
	while (n--)
	{
		int l = in();
		int r = in();
		ans += (ll)(r - l + 1)*(l + r)/2;
	}
	cout << ans << endl;
	return 0;

}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

    int T;
    cin >> T;
    int ans[100];
    REP(i, T) {
        string S;
        cin >> S;
        ans[i] = -1;
        if ("atcoder" < S)
            ans[i] = 0;
        else{
            REP(j, S.length())
            {
                if(S[j] > 'a') {
                    if(S[j] > 't')
                        ans[i] = j-1;
                    else
                        ans[i] = j;
                    break;
                }
            }
        }

    }
    REP(i,T)
    cout << ans[i] << "\n";
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
#define SZ(x) ((int)(x).size())
#define YESNO(bool)            \
    if (bool) {                \
        cout << "YES" << endl; \
    } else {                   \
        cout << "NO" << endl;  \
    }
#define yesno(bool)            \
    if (bool) {                \
        cout << "yes" << endl; \
    } else {                   \
        cout << "no" << endl;  \
    }
#define YesNo(bool)            \
    if (bool) {                \
        cout << "Yes" << endl; \
    } else {                   \
        cout << "No" << endl;  \
    }
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    } else
        return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    } else
        return false;
}
template <typename T>
inline void print(const T &x) {
    cout << x << "\n";
}
template <typename T>
inline void print(const vector<T> &v, string s = " ") {
    REP (i, v.size())
        cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");
}
const int IINF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

string solve(string S) {
    // TODO: edit here
    string ret = "";
    for (ll i = SZ(S) - 1; i >= 0; i--) {
        if (S[i] == '0') ret += "0";
        else if (S[i] == '1') ret += "1";
        else if (S[i] == '6') ret += "9";
        else if (S[i] == '8') ret += "8";
        else if (S[i] == '9') ret += "6";
    }
    return ret;
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string S;
    cin >> S;
    auto ans = solve(S);
    cout << ans << endl;
    return 0;
}


/**
 *    author:  Taara Sinh Aatrey
 *    created: 26.06.2021 17:33:36
**/

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

template<typename A, typename B> istream& operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second;} template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> istream& operator>>(istream &is, T_container &v) { for (T& x : v) is >> x; return is;} bool debug;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return debug ? os << '(' << p.first << ", " << p.second << ')' : os << p.first << " " << p.second;} template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { if(debug) { os << "{"; string sep; for (const T &x : v) os << sep << x, sep = ", "; os << '}'; } else { bool f = false; for (const T &x : v) { if(f) {os << " ";} os << x, f = true; } } return os;}
template <typename T, typename T1, typename... Tail> T amin(T& a, T1 b, Tail... c) { if(b < a) a = b; if constexpr (sizeof...(c) != 0) { amin(a, c...); } return a; } template <typename T, typename T1, typename... Tail> T amax(T& a, T1 b, Tail... c) { if(b > a) a = b; if constexpr (sizeof...(c) != 0) { amax(a, c...); } return a; }
void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef ONLINE_JUDGE
#define dbg(...)
#else
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug = true, dbg_out(__VA_ARGS__), debug = false
#endif

#define int int64_t
const int mod = 1e9 + 7; const int INF = 1e18L + 5; const int N = 2e5 + 5;

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

    if(d * c <= b) {
        cout << -1 << '\n';
        return;
    }

    int op = 0;
    int x = a, y = 0;
    if(x > d * y && b >= c) {}
    do {
        x += b;
        y += c;
        op++;
    } while(x > y * d);

    cout << op;
}

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

    int t = 1;

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

    return 0;
}

#include <iostream>
#include <cstdint>

int main() {
  std::int64_t A, B, C, D;
  std::cin >> A >> B >> C >> D;
  std::int64_t count = -1;
  if (B < C * D) {
    const auto denom = C * D - B;
    count = (A + denom - 1) / denom;
  }
  std::cout << count << std::endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N;
    cin >> N;
    ll bn = (1 << N);
    cout << bn - 1 << '\n';

    repe(i, 1, bn){
        string ans;
        rep(j, bn) {
            if(__builtin_popcount(i & j) % 2 == 0)
                ans += 'A';
            else
                ans += 'B';
        }
        cout << ans << '\n';
    }
}

#include <bits/stdc++.h>

using namespace std;

bool brute(int n,int k,vector<vector<int>> &a,vector<int> &b){
	if(k==0){
		bool bo=true;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(a[i][j]!=a[0][1]){
					bo=false;
					break;
				}
			}
			if(!bo) break;
		}
		if(bo){
			cout << "conglats" << a[0][1] << "\n";
			for(int i=0;i<(int)b.size();i++) cout << b[i] << " ";
			cout << "\n";
			return true;
		}
		return false;
	}
	for(int i=0;i<(1<<n);i++){
		if(__builtin_popcount(i)!=(n/2)) continue;
		for(int s=0;s<n;s++){
			for(int t=s+1;t<n;t++){
				if(((i>>s)&1)==((i>>t)&1)){
					a[s][t]++;
				}
			}
		}
		b.push_back(i);
		if(brute(n,k-1,a,b)) return true;
		b.pop_back();

		for(int s=0;s<n;s++){
			for(int t=s+1;t<n;t++){
				if(((i>>s)&1)==((i>>t)&1)){
					a[s][t]--;
				}
			}
		}
	}
	return false;
}
void kasan(string str,vector<vector<int>> &a){
	for(int i=0;i<(int)str.size();i++){
		for(int j=i+1;j<(int)str.size();j++){
			if(str[i]==str[j]) a[i][j]++;
		}
	}
}
string xors(string &a,string &b){
	int n=(int)a.size();
	string res;
	for(int i=0;i<n;i++){
		if(a[i]==b[i]) res.push_back('A');
		else res.push_back('B');
	}
	return res;
}
int main(){
	//ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	int m=1<<n;
	int kumi=m*(m-1)/2;
	int sou=(m/2-1)*(m/2);

	int g=__gcd(sou,kumi);

	cout << kumi/g << "\n";

	int cnt=0;
	vector<vector<int>> a(m,vector<int>(m));
	vector<string> st;
	for(int h=1;h<m;h*=2){
		//000...111...
		string str;
		for(int j=0;j<m;j++){
			if((j/h)&1) str.push_back('B');
			else str.push_back('A');
		}
		kasan(str,a);
		int sz=(int)st.size();
		cout << str << "\n";
		for(int j=0;j<sz;j++){
			string str2=xors(st[j],str);
			cout << str2 << "\n";
			kasan(str2,a);
			st.push_back(str2);
		}
		st.push_back(str);
	}
	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;

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

#define int long long
#define reset(x) memset(x,0,sizeof(x))
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
#define PI 3.1415926535897932384626433832795
#define INF 1000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6
#define pb push_back
#define fi first
#define se second
#define mp make_pair

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

const int MAXN = 100005;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    int n; cin >> n;
    int arr[n + 1], brr[n + 1], crr[n + 1];

    vector<vector<int>> equal(n + 1, vector<int>());
    int exist[n + 1];
    reset(exist);
    for (int i = 0; i < n; i++)
    {
    	cin >> arr[i + 1];
    	exist[arr[i + 1]]++;
    }
    for (int i = 0; i < n; i++)
    {
    	cin >> brr[i + 1];
    	equal[brr[i + 1]].pb(i + 1);
    }
    int num_time[n + 1];
    reset(num_time);
    for (int i = 0; i < n; i++)
    {
    	cin >> crr[i + 1];
    	num_time[crr[i + 1]]++;
    }
    int sum = 0;
    bool used[n + 1]; reset(used);
    for (int i = 1; i <= n; i++)
    {
    	int tmp = 0;
    	if (used[arr[i]] == true)
    	{
    		continue;
    	}
    	for (int x : equal[arr[i]])
    	{
    		tmp += num_time[x];
    	}
    	sum += (tmp * exist[arr[i]]);
    	used[arr[i]] = true;
    }
    cout << sum;
}

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

using namespace std;
using namespace __gnu_pbds;

#define iambharatks                   \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

#define bitcount __builtin_popcount
#define setbits(x) __builtin_popcountll(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define fo(i, j, n) for (int i = j; i <= n; i++)
#define rev(i, j, n) for (int i = n; i >= j; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define INF 2e18
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;
typedef vector<vector<pll>> vvpll;
typedef vector<pll> vpll;
typedef vector<pi> vpi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 998244353;
const int N = 2e5 + 5;
double eps = 1e-12;
const int mod = 1e9 + 7;

void solve()
{

    string s;
    cin >> s;
    for (char &c : s)
    {
        if (c == '9')
            c = '6';
        else if (c == '6')
            c = '9';
    }
    reverse(all(s));
    cout << s << ln;
}

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


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aurinegro (Nicolás Álvarez)
 */

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define pb push_back

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

class DChoosingUpSides {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n;
        cin >> n;
        vector<bitset<256>> ans;
        bitset<256> x = 3;
        ans.pb(2);
        for (int lvl = 2; lvl <= n; lvl++) {
            for (auto &x : ans) x |= x << (1 << (lvl - 1));
            int sz = si(ans);
            forn (i, sz) ans.pb(ans[i] ^ (x << (1 << (lvl - 1))));
            ans.pb(x);
            x |= x << (1 << (lvl - 1));
        }
        cout << si(ans) << endl;
        for (auto x : ans) {
            forn(i, 1 << n) cout << char('A' + x[i]);
            cout << endl;
        }
    }
};

int main() {
    DChoosingUpSides solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint x(n); rep(i,n) cin>>x[i];

    ll a1 = 0;
    double a2 = 0;
    ll a3 = 0;
    for(auto e:x){
        a1 += abs(e);
        a2 += e*e;
        chmax(a3, abs(e));
    }
    cout<<a1<<endl;
    a2 = sqrt(a2);
    cout<<a2<<endl;
    cout<<a3<<endl;

    return 0;

}


#include <bits/stdc++.h>

#define pb(a) push_back(a)
#define rep(i, d, e) for (int i = d; i < e; i++)
#define ffor(i, a, b) for (int i = a; i <= b; i++)
#define rloop(i, c, d) for (int i = c; i >= d; i--)
#define ll long long
#define vc vector<ll>
#define pp pop_back()
#define mod 1000000007
#define MAX 1000000
using namespace std;
int main()
{

    ll n;
    cin >> n;

    double l[n], r[n];
    ffor(i, 0, n - 1)
    {
        int c;
        cin >> c >> l[i] >> r[i];
        if (c == 2)
            r[i] -= 0.5;
        if (c == 3)
            l[i] += 0.5;
        if (c == 4)
        {
            l[i] += 0.5;
            r[i] -= 0.5;
        }
    }
    ll cnt=0;
    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(max(l[i],l[j])<=min(r[i],r[j]))
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n,vector<int>(3));
    rep(i,n){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    int ans = 0;
    rep(i,n){
        for(int j = i+1; j<n; j++){
            bool ok = false;
            if(a[i][1]<=a[j][2] && a[i][2]>=a[j][1]){
                ok = true;
                if(a[i][1]==a[j][2] && !(a[i][0]<= 2&&a[j][0]%2==1))ok = false;
                else if(a[i][2]==a[j][1] && !(a[j][0]<= 2&&a[i][0]%2==1))ok = false;
            }
            if(ok)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e9+6969;

int h,w,t[11][11],cnt[11],tmp[11][11];
int ans;

void solve()
{
	for(int i=1;i<=10;i++) cnt[i] = 0;
	for(int i=2;i<=h;i++)
	{
		for(int j=2;j<=w;j++)
		{
			if(t[i][j] != t[i-1][j]) cnt[j] = 1;
			else cnt[j] = 0;
		}
		int last = 0;
		for(int i=1;i<=w;i++)
		{
			if(last == 0 && cnt[i] == 1) ans++;
			last = cnt[i];
		}
	}
}

int main()
{
	scanf("%d%d", &h, &w);
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			char c;
			cin >> c;
			if(c == '#') t[i][j] = 1;
		}
	}
	solve();
	//  cout << ans << "\n";
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			tmp[j][i] = t[i][j];
		}
	}
	swap(h,w);
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) t[i][j] = tmp[i][j];
	solve();
	cout << ans << "\n";
	return 0;
}

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

struct fastio{fastio(){cin.tie(nullptr);ios_base::sync_with_stdio(false);std::cout<<std::fixed<<setprecision(10);}}oitsaf;
#define rep(i,n) for(int i=0;i<int(n);++i)
constexpr char newl = '\n';
template<class T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){for(auto const& vi:v)os<<vi<<" ";return os;}
#if _local
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){std::cerr<<elm<<std::flush;return*this;}}dout;
#else
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){return*this;}}dout;
#endif

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  cin >> s;
  int ans = 0;
  bool prv = false;
  rep(i, h - 1) rep(j, w) {
    if (s[i][j] != s[i + 1][j]) {
      dout << "{" << i << "," << j << "} : " << (s[i][j] != s[i + 1][j]) << " "
           << prv << " " << ans << newl;
      ;
      if (!prv) {
        prv = true;
        ans++;
      }
    } else {
      prv = false;
    }
  }
  prv = false;
  rep(j, w - 1) rep(i, h) {
    if (s[i][j] != s[i][j + 1] ) {
      dout << "{" << i << "," << j << "} : " << (s[i][j] != s[i + 1][j]) << " "
           << prv << " " << ans << newl;
      if (!prv) {
        prv = true;
        ans++;
      }
    } else {
      prv = false;
    }
  }
  cout << (ans) << endl;
}


//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime> // へびになりたい
#include <bitset> // へびになった ｼｬｰ

// #include <atcoder/all>
// using namespace atcoder; // コンパイル重い

#define DB cerr<<"D"<<endl

using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  int _; cin>>_;
  while(_-->0) {
    int n; cin>>n;
    ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
    if (n%2==0) {
      // 先手はXOR!=0にすれば勝ち
      sort(a,a+n,greater<ll>());
      ll an=0;
      for(int i=0;i<n;i++) {
        if (i%2==0) an+=a[i];
        else an-=a[i];
      }
      if (an==0) {
        cout<<"Second"<<endl;
      } else {
        cout<<"First"<<endl;
      }
    } else {
      // 必ず後手にXOR!=0で渡してしまう
      cout<<"Second"<<endl;
    }
  }
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e9+6969;

struct P
{
	PLL x;
	PLL y;
	int typ;
	void op2()
	{
		PLL tmp = y;
		y = x;
		x = mp(-tmp.fi, -tmp.se);
		typ ^= 1;
	}
	void op1()
	{
		PLL tmp = x;
		x = y;
		y = mp(-tmp.fi, -tmp.se);
		typ ^= 1;
	}
	void op3(ll p)
	{
		x = mp(2*p - x.fi, -x.se);
	}
	void op4(ll p)
	{
		y = mp(2*p - y.fi, -y.se);
	}
	void f(PLL val)
	{
		if(typ) swap(val.fi, val.se);
		PLL tmp = mp(x.fi + x.se * val.fi, y.fi + y.se * val.se);
		cout << tmp.fi << " " << tmp.se << "\n";
	}
};

int n,m;
PLL point[nax], ans[nax];
P ops[nax];
bool rev[nax];
vector <pair<PLL,int>> Q;
P p;

int main()
{
	p.x = mp(0,1);
	p.y = mp(0,1);
	p.typ = 0;
	ops[0] = p;
	cin >> n;
	for(int i=1;i<=n;i++) cin >> point[i].fi >> point[i].se;
	cin >> m;
	for(int i=1;i<=m;i++)
	{
		ll a,b = 0;
		cin >> a;
		if(a > 2) cin >> b;
		if(a == 1) p.op1();
		if(a == 2) p.op2();
		if(a == 3) p.op3(b);
		if(a == 4) p.op4(b);
		ops[i] = p;
	}
	int q;
	cin >> q;
	for(int i=1;i<=q;i++)
	{
		ll a,b;
		cin >> a >> b;
		PLL tmp = point[b];
		ops[a].f(tmp);
	}
	return 0;
}


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

inline ll read() {
    ll sum = 0, ff = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9') {
        if(ch == '-') {
            ff = -1;
        }
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
    	sum = sum * 10 + ch - 48;
        ch = getchar();
    }
    return sum * ff;
}

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

int a, b, c;

int main() {
//  	freopen(".in", "r", stdin);
//  	freopen(".out", "w", stdout);
	a = read(), b = read(), c = read();
	if(a * a + b * b < c * c)
		puts("Yes");
	else
		puts("No");
    return 0;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	long long ans = 0;
	int abmin = max(2, K + 2);
	int abmax = min(2 * N, K + 2 * N);
	for (int ab = abmin; ab <= abmax; ab++) {
		long long abl = max(ab - N, 1);
		long long abr = min(N, ab-1);
		long long cdl = max(ab - K - N, 1);
		long long cdr = min(N, ab - K - 1);
		ans += (abr - abl + 1) * (cdr - cdl + 1);
	}
	cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define all(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0)  )
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }

void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

#define NO "UNSOLVABLE\n"
string s[3];
int mp[27];
bool used[10];
int sz[3];

void solve(int idx,int carry=0){
    FOR(i,3) {
        if (idx == sz[i] - 1 && mp[s[i][idx] - 'a'] == 0) return;
    }
    if (idx==sz[2]){
        if (carry) return;
        FOR(i,3){
            reverse(all(s[i]));
            for(char c:s[i]){
                int d = c-'a';
                if (d==26) continue;
                cout << mp[d];
            }
            cout << '\n';
        }
        exit(0);
    }
    FOR(i,3) {
        if (mp[s[i][idx] - 'a'] == -1) {
            FOR(j, 10) {
                if (used[j]) continue;
                mp[s[i][idx] - 'a'] = j;
                used[j]=1;
                solve(idx, carry);
                used[j]=0;
            }
            mp[s[i][idx] - 'a'] = -1;
            return;
        }
    }
    int num = mp[s[0][idx]-'a']+mp[s[1][idx]-'a']+carry;
    int d = num%10;
    if (d!=mp[s[2][idx]-'a']) return;
    solve(idx+1,num/10);
}

int main() {
    READ(0);
    FOR(i,3) {cin>>s[i];sz[i]=s[i].size();}
    if (sz[2] < max(sz[0],sz[1])) {cout << NO;return 0;}
    if (sz[2] > max(sz[0],sz[1])+1) {cout << NO;return 0;}
    FOR(i,3) reverse(all(s[i]));
    FOR(i,2) while(s[i].size()<s[2].size()) s[i] += char('z'+1);
    memset(mp,-1,sizeof(mp));
    mp[26]=0;
    solve(0);
    cout << NO;

    return 0;
}

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

vector<int> check;
string get(string s){
	string n="";
	for (char&c:s){
		n.push_back(check[c-'a']+'0');
	}
	return n;
}
int main(){
	string s1,s2,s3;cin>>s1>>s2>>s3;
	check.assign(26,-1);
	for (char&c:s1) check[c-'a']=1;
	for (char&c:s2) check[c-'a']=1;
	for (char&c:s3) check[c-'a']=1;

	int cnt=0;for(int &v:check) cnt+=(v==1);
	if (cnt>10) {
		cout<<"UNSOLVABLE\n";
		return 0;
	}
	queue<vector<int>> q;
	q.push(vector<int>());
	while (q.front().size()<cnt){
		vector<int> v=q.front();
		q.pop();
		vector<bool> inside(10);
		for (int i:v) inside[i]=true;
		v.push_back(0);
		for (int i=0;i<10;++i){
			if (inside[i]) continue;
			v.back()=i;
			q.push(v);
		}
	}
	while (!q.empty()){
		vector<int> v=q.front();
		q.pop();
		int cur=0;
		for (int i=0;i<26;++i){
			if (check[i]!=-1) check[i]=v[cur++];
		}
		string n1=get(s1),n2=get(s2),n3=get(s3);
		if (n1[0]!='0'&&n2[0]!='0'&&n3[0]!='0'){
			long long z1=stoll(n1),z2=stoll(n2),z3=stoll(n3);
			if (z1+z2==z3){
				cout<<z1<<'\n';
				cout<<z2<<'\n';
				cout<<z3<<'\n';
				return 0;
			}
		}
	}
	cout<<"UNSOLVABLE\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int ans = 0;
  for(int i = 0; i < S.size(); i++){
    if(i % 2 == 0 && S.at(i) > 'Z') ans++;
    if(i % 2 == 1 && S.at(i) < 'a') ans++;
  }
  if(ans == S.size()) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

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

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

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

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

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

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

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

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

void solve(){
    str x;
    cin>>x;

    int a = 1, b = 1;
    for(int i=0;i<(int)x.size();i+=2)
        if(x[i] >= 'A' && x[i] <= 'Z')
            a = 0;
    for(int i=1;i<(int)x.size();i+=2)
        if(x[i] >= 'a' && x[i] <= 'z')
            b = 0;
    if(a && b)  cout<<"Yes";
    else    cout<<"No";
    cout<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    // cout.tie(nullptr);
    // debug_output;
    // debug;

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


#include <bits/stdc++.h>

using namespace std;

int main() {
    string str;
    int count = 1;
    cin >> str;
    for (auto s : str) {
        if (count%2 == 1 && isupper(s)) {
            cout << "No";
            return 0;
        }
        else if (count%2 == 0 && islower(s)) {
            cout << "No";
            return 0;
        }
        ++count;
    }

    cout << "Yes";
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define REP(i, k, n) for(ll i = k; i < n; ++i)
#define REPI(i, k, n) for(ll i = k; i >= n; --i)
#define vi vector<int>
#define vch vector<char>
#define vstr vector<string>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vpl vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define F first
#define S second
#define el "\n"
#define sz(x) x.size()
#define ld long double
#define sortar(v) sort(v.begin(),v.end())
#define rsort(v) sort(v.rbegin(),v.rend())
#define all(x) x.begin(), x.end()
#define div 1000000007
#define div2 998244353
#define pi 3.14159265358979323846
#define inf 1000000000000000000
#define blk 455
#define pb push_back
#define ppb pop_back
#define print(x) for(auto p:x) cout<<p<<' '; cout<<el;
#define N 1000005
bool isPrime[N] = {false};
vll prm;
vll SPF(N);

void sieve()
{
    isPrime[1] = isPrime[0] = 0;
    ll i;

    for(i=2;i<N;++i) isPrime[i] = 1;

    for(i=2;i*i<N;++i)
    {
        if(isPrime[i])
        {
            for(ll j = i*i; j<N; j += i)
                isPrime[j] = 0;
        }
    }

    if(!prm.empty())
        prm.clear();

    REP(i,2,N)
    {
        if(isPrime[i])
            prm.pb(i);
    }

}

bool flip(bool f)
{
    if(f) return 0;
    return 1;
}

ll fastPower(ll a, ll b)
{
    if(b == 0) return 1;
    ll prod = 1;
    while(b > 0)
    {
        if(b & 1)
            prod = prod * a;
        b = b >> 1;
        a = a * a;
    }
    return prod;
}

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

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

void printa(bool f){
    if(f) cout<<"YES"<<el;
    else cout<<"NO"<<el;
}

void solve()
{
    string a;
    cin>>a;
    ll n = a.length(), i;
    REP(i,0,n){
        int v = (int)a[i];
        if(i&1){
            if(v>=65 && v <=90) continue;
            else{cout<<"No"<<el; return;}
        }
        else{
            if(v >= 97 && v <= 122) continue;
            else{cout<<"No"<<el; return;}
        }
    }
    cout<<"Yes"<<el;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("C:/Users/Lenovo/Desktop/inpOut/input.txt", "r", stdin);
    freopen("C:/Users/Lenovo/Desktop/inpOut/output.txt", "w", stdout);
    #endif

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

    int tc = 1, i = 1;
    scanf("%d", &tc);
    while(tc--)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
        // ++i;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fz(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define ffe(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define fill0(a) memset(a,0,sizeof(a))
#define fill1(a) memset(a,-1,sizeof(a))
#define fillbig(a) memset(a,63,sizeof(a))
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
int n;
char s[500005],t[500005];
int p1[500005],n1=0;
int p2[500005],n2=0;
int main(){
	scanf("%d%s%s",&n,s+1,t+1);
	for(int i=1;i<=n;i++) if(s[i]=='1') p1[++n1]=i;
	for(int i=1;i<=n;i++) if(t[i]=='1') p2[++n2]=i;
	if(n1<n2||(n1-n2)%2) return puts("-1"),0;
	ll ans=0;
	set<int> st;
	for(int i=1;i<=n1;i++) st.insert(p1[i]);
	for(int i=n2;i;i--){
		set<int>::iterator it=st.lower_bound(p2[i]);
		if(it==st.end()) return puts("-1"),0;
		ans+=*it-p2[i];st.erase(*it);
	}
	vector<int> v;
	ffe(it,st) v.pb(*it);
	for(int i=0;i<v.size();i+=2) ans+=v[i+1]-v[i];
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;

const int INF = 1e9+7;

int show_matrix(vector<vector<int>> &dp) {
  loop(0, dp.size(), i) {
    loop(0, dp[i].size(), j) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

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

  ll H, W;
  cin >> H >> W;

  ll gx ,gy;

  vector<vector<char>> MAP(H, vector<char>(W, '.'));
  vector<vector<ll>> DIST(H, vector<ll>(W, INF));
  queue<pair<int, int>> Q;
  vector<pair<int, int>> WARP[26];

  loop(0, H, i) {
    loop(0, W, j) {
      char inp;
      cin >> inp;

      if (inp == 'S') {
        Q.push(make_pair(i, j));
        MAP[i][j] = '.';
        DIST[i][j] = 0;
      } else if (inp == 'G') {
        MAP[i][j] = '.';
        gx = i;
        gy = j;
      } else if (inp == '.') {
        MAP[i][j] = '.';
      } else if (inp == '#') {
        MAP[i][j] = '#';
      } else {
        MAP[i][j] = inp;
        ll pos = inp - 'a';
        WARP[pos].push_back(make_pair(i, j));
      }
    }
  }

  ll dx[] = {0, 1, 0, -1};
  ll dy[] = {1, 0, -1, 0};
  while(!Q.empty()) {
    auto top = Q.front(); Q.pop();
    ll x = top.first;
    ll y = top.second;
    ll c = DIST[x][y];

    loop(0, 4, i) {
      ll nx = x + dx[i];
      ll ny = y + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W) {
        if (MAP[nx][ny] == '#' || DIST[nx][ny] <= c+1) continue;
        DIST[nx][ny] = c+1;
        Q.push(make_pair(nx, ny));
      }
    }

    if (MAP[x][y] != '.') {
      ll pos = MAP[x][y] - 'a';
      for (auto &p : WARP[pos]) {
        ll nx = p.first;
        ll ny = p.second;
        if (DIST[nx][ny] > c+1) {
          DIST[nx][ny] = c+1;
          Q.push(make_pair(nx, ny));
        }
        MAP[nx][ny] = '.';
      }
    }
    MAP[x][y] = '.';
  }
  ll result = DIST[gx][gy];
  if (result == INF) {
    print(-1);
  } else {
    print(result);
  }
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
#define max_value 0x3f3f3f
/*0 0, 0, 1, 0],     [0, 1, 0, 0, 0],     [0, 0, 0, 0, 1],     [0, 0, 1, 0, 0],     1, 0, 0, 0, 0
freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);*/
using namespace std;
typedef pair<ll,ll> pii;
const int  inf=1e9+7;
const int mod=998244353;
const int maxn=3001;
ll modexpo(ll a,ll b){
    a%=inf;
ll res=1;
 while(b>0){
    if(b&1)
        res=res*a%inf;
    a=a*a%inf;
    b>>=1;
 }
 return res;

}

int arr[maxn][5];

bool good(int mid,int n){
 set<int>masks;
 for(int i=0;i<n;i++){
    int mask=0;
    for(int j=0;j<5;j++){
        if(arr[i][j]>=mid)
            mask|=(1<<j);
    }
    masks.insert(mask);
 }
for(auto i:masks){
    for(auto j:masks){
        for(auto k:masks){
           if((i|j|k)==31)
                return true;
        }
    }
}
return false;
}
void solve(){
int n;
cin>>n;

for(int i=0;i<n;i++){
    for(int j=0;j<5;j++)
        cin>>arr[i][j];
}
int h=1e9+7;
int low=1;
while(h-low>1){
    int mid=(h+low)/2;
    if(good(mid,n))
        low=mid;
    else
        h=mid;
}
cout<<low;
}

int main(){
 int t;
t=1;
 while(t--){
 solve();
}
}

// abc196_e
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e15)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

void solve(){
    ll N;
    cin >> N;
    vector<ll> A(N), T(N);
    REP(i, N) cin >> A[i] >> T[i];

    ll Q;
    cin >> Q;
    vector<ll> X(Q);
    REP(i, Q) cin >> X[i];

    ll sm = 0;
    ll sup=INF, inf=-INF;
    REP(i, N){

        if (T[i] == 1){
            sm += A[i];
            sup += A[i];
            inf += A[i];
        } else if (T[i] == 2){
            inf = max(inf, A[i]);
            sup = max(sup, A[i]);
        } else {
            sup = min(sup, A[i]);
            inf = min(inf, A[i]);
        }
    }

    REP(i, Q){
        ll ans = max(min(X[i] + sm, sup), inf);
        print(ans);
    }
}

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

class unionfind{
    /*
    Copyright (c) 2020 0214sh7
    https://github.com/0214sh7/library/
    */
    private:
    std::vector<int> UF,rank;
    public:

    void init(int N){
        UF.clear();
        rank.clear();
        for(int i=0;i<N;i++){
            UF.push_back(i);
            rank.push_back(0);
        }
    }

    int root(int k){
        if(UF[k]==k){
            return k;
        }else{
            UF[k]=root(UF[k]);
            return UF[k];
        }
    }

    bool same(int p,int q){
        return root(p)==root(q);
    }

    void unite(int P,int Q){
        int p=root(P);
        int q=root(Q);
        if(p==q)return;
        if(rank[p]<rank[q])std::swap(p,q);
        UF[q]=p;
        if(rank[p]==rank[q])rank[p]++;
    }

};

int main(void){
    ll H,W;
    vector<string> S;
    cin >> H >> W;
    REP(i,H){
        string s;
        cin >> s;
        S.push_back(s);
    }

    if(H<=2 || W<=2){
        cout << 0 << endl;
        return 0;
    }

    unionfind UF;
    UF.init(H+W-3);

    //0:外周
    //1~H-2:横線
    //H-1~H+W-4:縦線

    for(ll i=1;i<H-1;i++){
        if(S[i][0]=='#' || S[i][W-1]=='#'){
            UF.unite(0,i);
        }
    }

    for(ll j=1;j<W-1;j++){
        if(S[0][j]=='#' || S[H-1][j]=='#'){
            UF.unite(0,H-2+j);
        }
    }

    for(ll i=1;i<H-1;i++){
        for(ll j=1;j<W-1;j++){
            if(S[i][j]=='#'){
                UF.unite(i,H-2+j);
            }
        }
    }

    set<ll> Y,X;
    Y.insert(UF.root(0));
    X.insert(UF.root(0));
    for(ll i=1;i<H-1;i++){
        Y.insert(UF.root(i));
    }
    for(ll i=H-1;i<H+W-3;i++){
        X.insert(UF.root(i));
    }

    ll R=Y.size()-1,C=X.size()-1;

    //cout << R MM C << endl;
    cout << min(R,C) << endl;

    return 0;
}

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

typedef long long int ll;

#ifndef ONLINE_JUDGE
#define F_AND_L	__FUNCTION__ << ":" << __LINE__
#define X(x) { cerr << F_AND_L << "[ " << #x << " : " << x << " ]" << endl;}
#define D(x) << "[ " << #x << " : " << x << " ] "
#define S(...) cerr << F_AND_L __VA_ARGS__ << endl;
#define PC(a) { cerr << F_AND_L << " " << #a << "=["; for(auto __xmmp: a) { cerr << __xmmp << " "; } cerr << "]" << endl; }
#define PA(a,s,l) { cerr << F_AND_L << " " << #a << "=["; for(int __xmmp=s; __xmmp<s+l; __xmmp++) { cerr << a[__xmmp] << " "; } cerr << "]" << endl; }
#else
#define X(x)
#define D(x)
#define S(...)
#define PC(a)
#define PA(a,s,l)
#endif

#define rep(i, s, e) for(int i=s; i<e; i++)
#define reps(i, s, e, stp) for(int i=s; i<e; i+=stp)
#define per(i, s, e) for(int i=e; i>=0; i--)
#define pers(i, s, e, stp) for(int i=e; i>=0; i+=stp)
#define F(i, n) for(int i=0; i<n; i++)
#define R(i, n) for(int i=n-1; i>=0; i--)

int main() {

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

	int h, w, m=0;
	cin >> h >> w;

	int a[h][w];
	for(int i=0; i<h; i++) {
		for(int j=0; j<w; j++) {
			cin >> a[i][j];
			if(i == 0 && j == 0)
				m = a[i][j];
			m=min(a[i][j], m);
		}
	}
	ll ans=0;
	for(int i=0; i<h; i++) {
		for(int j=0; j<w; j++) {
			ans += a[i][j] - m;
		}
	}
	cout << ans << endl;
}