#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int s[1505][1505];
int t[1505][1505];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int h,w,n,m,ans = 0;
    cin >> h >> w >> n >> m;
    vector<int> a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
    }
    rep(i,m){
        int c,d;
        cin >> c >> d;
        c--;d--;
        s[c][d] = 2;
        t[c][d] = 2;
    }
    rep(i,n){
        // 現時点から横
        int x = a[i];
        int y = b[i];
        s[x][y] = 1;
        while(y - 1 >= 0 && s[x][y-1] == 0){
            s[x][y-1] = 1;
            y--;
        }

        y = b[i];

        while( y + 1 < w && s[x][y+1] == 0){
            s[x][y+1] = 1;
            y++;
        }
    }
    rep(i,n){
        // 現時点から縦
        int x = a[i];
        int y = b[i];
        t[x][y] = 1;
        while(x-1 >=0 && t[x-1][y] == 0){
            t[x-1][y] = 1;
            x--;
        }
        x = a[i];
        while(x + 1 < h && t[x+1][y] == 0){
            t[x+1][y] = 1;
            x++;
        }
    }
    rep(i,h)rep(j,w){
        if(s[i][j] == 1){
            ans++;
        }
        else if(t[i][j] == 1){
            ans++;
        }
    }
    cout << ans << endl;
}

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

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

int N;
vector<int> E[200001];
pair<int, int> dfs(int u, int prev) {
	int saidai = 0;
	int ind = -1, p = u;
	rep(i, E[u].size()) {
		int to = E[u][i];
		if (to != prev) {
			auto tmp = dfs(to, u);
			if (tmp.first > saidai) {
				saidai = tmp.first;
				ind = i;
				p = tmp.second;
			}
		}
	}
	int saigo = E[u].size();
	if(ind != -1) swap(E[u][saigo - 1], E[u][ind]);

	return { saidai + 1, p };
}

int kotae[200001], k;
void dfs2(int u, int prev) {
	k++;
	kotae[u] = k;

	for (int to : E[u]) if (to != prev) {
		dfs2(to, u);
	}

	k++;
}

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

	cin >> N;
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		E[a].pb(b);
		E[b].pb(a);
	}

	auto tmp = dfs(1, -1);
	dfs(tmp.second, -1);

	dfs2(tmp.second, -1);

	rep1(i, N) cosp(kotae[i]);

	Would you please return 0;
}


#include<bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const ll LINF=1e18;
const ll MOD=998244353;
const int INF=0x3f3f3f3f;
const int MAXN=200050;

ll gcd(ll a,ll b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
ll exgcd(ll a,ll b,ll &x,ll &y){
    //注意x和y必须是引用
    if(!b){x=1,y=0;return a;}
    ll d=exgcd(b,a%b,x,y);
    ll t=x;x=y,y=t-(a/b)*y;
    return d;//d是a和b的gcd，顺便求出来
}
ll inv(ll a,ll b){
	ll x,y;
	exgcd(a,b,x,y);
	return (x%b+b)%b;
}
void solve(int T){
	ll n,s,k,ans;
	scanf("%lld%lld%lld",&n,&s,&k);
	ll gcdd=gcd(n,gcd(n-s,k));
	s=(n-s);
	//n/=gcdd,k/=gcdd,s=(n-s)/gcdd;
	if(gcd(n,k)!=gcdd){
		printf("-1\n");
	}else{
		ans=s*inv(k,n)%n;
		printf("%lld\n",ans/gcdd);
	}
}
signed main(){
	//IOS;
	int t=1;
	scanf("%d",&t);
	for(int i=1;i<=t;i++){
		solve(i);
	}
}

#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a % b);
}

ll exgcd(ll a, ll b, ll &x, ll &y) {
	if (b == 0) {
		x = 1, y = 0;
		return a;
	}

	ll d = exgcd(b, a % b, x, y);
	ll oldx = x, oldy = y;
	x = oldy;
	y = oldx - ((a - a % b) / b) * oldy;

	return d;

}

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

	for (int i = 0; i < T; i++) {
		ll N, S, K; cin >> N >> S >> K;
		ll x = 0, y = 0;
		ll d = exgcd(K, N, x, y);

		//printf("i=%d\n", i);
		//cout << x << " " << y << " " << d << endl;
		if (S % d)cout << -1 << endl;
		else {
			ll p = -S / d;
			x *= p, y *= -p;
			K /= d, N /= d;
			x %= N;
			x = (x + N) % N;
			//cout << x << " " << y << " "<<d<<endl;
			cout << x << endl;

		}
	}
	/*

	ll x = 0, y = 0;
	ll d = exgcd(2, -3, x, y);

	cout << x << " " << y << " " << d << endl;
	*/
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a,b) memset(a, b, sizeof(a))
#define dbg(x) cout << "[" << #x << "]: " << x << endl;
#define forn(i,n) for(int i=0; i < n;i++)
#define forab(i,a,b) for(int i = a; i <= b; i++)
#define forba(i,b,a) for(int i = b; i >= a; i--)
#define each(val, v) for(auto val : v)
#define abs(u) (u >= 0 ? u : -u)

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

const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;

ll cnt[MAXN][26];

void solve(){
    string s;
    cin >> s;
    ll n = s.size();

    forn(i,26){
        cnt[n][i] = 0;
    }

    ll ans= 0;
    for(int i = n-2; i >= 0; i--){
        ll d1 = s[i] - 'a';
        ll d2 = s[i+1] - 'a';
        if(d1 == d2){
            ans += n - (i+2) - cnt[i+2][d1];
            forn(j,26){
                cnt[i+2][j] = 0;
            }
            cnt[i+2][d1] = n - (i+2);
        }

        forn(j,26){
            cnt[i+1][j] = cnt[i+2][j];
        }
        cnt[i+1][ s[i+1] - 'a' ]++;

    }

    cout << ans << endl;
}

int main(){

    ios::sync_with_stdio(false); cin.tie(NULL);

    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }

    return 0;
}

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

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}
int main(void){
  ll n,k=0;
  cin >> n;
  rep(i,200000000){
    if((n-(i+1)*(i+2)/2)%(i+1)==0&&n/(i+1)-(i/2)>0)k++;
  }
  cout << k*2 << endl;
}


#include<bits/stdc++.h>
using namespace std;
const double eps=1e-7;
struct point {
	double x,y;
	friend bool operator<(point a,point b) {
		if(a.x==b.x)return a.y<b.y;
		return a.x<b.x;
	}
} p[205];
int n;
int main() {
	int x,y;
	scanf("%d",&n);
	for(register int i=1; i<=n; i++) {
		scanf("%lf%lf",&p[i].x,&p[i].y);
	}
	sort(p+1,p+n+1);
	for(register int i=1; i<n-1; i++) {
		for(register int j=i+1; j<n; j++) {
			for(register int k=j+1; k<=n; k++) {
				double k1=(p[j].y-p[i].y)/(p[j].x-p[i].x),k2=(p[k].y-p[j].y)/(p[k].x-p[j].x);
				if(fabs(k1-k2)<eps||(p[j].x==p[i].x&&p[k].x==p[j].x)) {
					puts("Yes");
					return 0;
				}
			}
		}
	}
	puts("No");
	return 0;
}

/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); ++i)
#define cont(i, n)          for(int i = 1; i <= (n); ++i)
#define circ(i, a, b)       for(int i = (a); i <= (b); ++i)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

int n;
int x[105], y[105];

int main() {
	cin >> n;
	cont(i, n) cin >> x[i] >> y[i];
	bool can = 0;
	cont(i, n) circ(j, i + 1, n) circ(k, j + 1, n) {
		int nx = x[j] - x[i], ny = y[j] - y[i];
		int mx = x[k] - x[i], my = y[k] - y[i];
		if(nx * my - ny * mx == 0) can = 1;
	}
	puts(can ? "Yes" : "No");
	return 0;
}


#include<bits/stdc++.h>
using  namespace std;
typedef long long  ll;
#define p (long long)(1e9+7)
#define  _(i,a,n) for(int i=a;i<n;i++)

ll solve(ll a,ll b)
{
a%=1000000;
    ll r=1;
    while (b)
    {
        if (b&1)
            r=(r*a)%3000000000;
        a=(a*a)%3000000000;
        b>>= 1;
    }
    return r;
}
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    a%=10;
    b=solve(b,c);
    a=solve(a,b);
    cout<<a%10<<endl;
    return 0;
}

#include <iostream>
using namespace std;
long long mod=998244353;
int llpow(long long a,long long b){
  long long r;
  if(b==0)r=1;
  else if(b==1)r=a%mod;
  else if(b%2==1){
    r=llpow(a,b-1)*a;
    r%=mod;
  }else{
    r=llpow(a,b/2);
    r*=r;
    r%=mod;
  }
  if(r<0)r+=mod;
  return r;
}
int main(){
  long long N,M,K;
  cin>>N>>M>>K;
  long long ans=0;
  long long t;
  if(N>=2&&M>=2){
    for(long long i=1;i<=K;++i){
      t=(llpow(i,N)-llpow(i-1,N))%mod;
      ans+=(t*llpow(K-i+1,M))%mod;
    }
  }else if(N==1||M==1){
    ans=llpow(K,N+M-1);
  }
  ans%=mod;
  if(ans<0)ans+=mod;
  cout<<ans<<endl;
  return 0;
}


#include<iostream>

using namespace std;

int main(void)
{
  char s,t; cin>>s>>t;

  if(s=='Y'){cout<<(char)(t-32)<<endl;}
  else{cout<<t<<endl;}

  return 0;
}

#include<bits/stdc++.h>
#define FULL(x,y) memset(x,y,sizeof(x))
#define ll long long
#define pb push_back
using namespace std;

int x,y;

int main() {
	cin>>x>>y;
	if (abs(x-y)<3) printf("Yes");
	else printf("No");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,b,c) for(int (i)=a;(i)<=b;(i)+=c)
string S;
deque<char> ans;
bool op;
int main() {
    cin>>S;
    int L=S.size();
    fo(i,0,L-1,1) {
        if(S[i]=='R') op^=1;
        else {
            if(op) {
                if(ans.size()&&ans.front()==S[i]) ans.pop_front();
                else ans.push_front(S[i]);
            }
            else {
                if(ans.size()&&ans.back()==S[i]) ans.pop_back();
                else ans.push_back(S[i]);
            }
        }
    }
    if(op) {
        while(ans.size()) {
            cout<<ans.back();
            ans.pop_back();
        }
    }
    else {
        while(ans.size()) {
            cout<<ans.front();
            ans.pop_front();
        }
    }
}

#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#define VIND(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem,--_elem
#define OUT(x) cout << (x);
#define OUTL(x) cout << (x) << endl;
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    TIN(string, s);
    deque<char> d;
    bool rev = false;
    rep(i, s.size()) {
        if (s[i] == 'R') rev = !rev;
        else {
            if (rev) {
                if (!d.empty() && d.front() == s[i]) d.pop_front();
                else d.push_front(s[i]);
            } else {
                if (!d.empty() && d.back() == s[i]) d.pop_back();
                else d.push_back(s[i]);
            }
        }
    }
    string t(d.begin(), d.end());
    if (rev) reverse(t.begin(), t.end());
    OUTL(t);
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}


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

const int maxn = 2e5+8, inf = 1e18+9, mod = 1e9+7;

char ans[maxn * 2];
struct node { int v, id, b; } a[maxn * 2];
int n, m;

void solve() {
    int i, j, cnt = 0;
    cin >> n;
    for (i = 1; i <= (n * 2); i++) cin >> a[i].v, a[i].id = i;
    sort(a + 1, a + n * 2 + 1, [](node &o1, node &o2) { return o1.v < o2.v; });
    for (i = 1; i <= (n * 2); i++) a[i].b = (i <= n) ? -1 : 1;
    sort(a + 1, a + n * 2 + 1, [](node &o1, node &o2) { return o1.id < o2.id; });
    for (i = 1; i <= (n * 2); i++) {
        if (cnt * a[i].b < 0) ans[i] = ')';
        else ans[i] = '(';
        cnt += a[i].b;
    }
    cout << ans + 1 << endl;
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;

int main() {
    int N; cin>>N;
    vi A(2*N);
    for (int i = 0; i < 2*N; i++)cin >> A[i];

    vector<pair<int,int>> B(2*N);
    for (int i = 0; i < 2*N; i++)B[i] = make_pair(A[i], i);
    sort(B.begin(),B.end());

    string S(2*N, '#');
    for (int i = 0; i < N; i++)S[B[i].second] = '-';
    for (int i = N; i < 2*N; i++)S[B[i].second] = '+';

    stack<int> sp, sm;
    vector<pair<int,int>> vp;
    for (int i = 0; i < 2*N; i++){
        if(S[i]=='-'){
            if(!sp.empty()){
                vp.push_back(make_pair(sp.top(), i));
                sp.pop();
            }else{
                sm.push(i);
            }
        }else{
            if(!sm.empty()){
                vp.push_back(make_pair(sm.top(), i));
                sm.pop();
            }else{
                sp.push(i);
            }
        }
    }

    string ans = string(2*N, '#');
    for(auto e:vp){
        auto [l, r] = e;
        ans[l] = '(';
        ans[r] = ')';
    }
    cout << ans << endl;
}


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

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

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

int main() {
    ll n, p;
    scanf("%lld %lld", &n, &p);

    printf("%lld", (p-1) * mp(p - 2, n-1) % MOD);
}

// author: rdd6584

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// const int mod = 1000000007;
const int mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  mint a, b, c;
  cin >> a >> b >> c;
  mint ans = a*(a+1)/2 *b*(b+1)/2 * c*(c+1)/2;
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll x, y, z;
    cin >> x >> y >> z;
    cout << (y * z - 1) / x << endl;
    return 0;
}

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define X first
#define Y second
#define nl '\n'
#define AC return 0
#define pb(a) push_back(a)
#define mst(a,b) memset(a, b, sizeof a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a,b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f;
ll a, b;

int main()
{
	IOS;
	ll n, m, t, pre = 0;
	cin>>n>>m>>t;
	ll now = n;
	bool ok = 1;
	rep1(i, m)
	{
		cin>>a>>b;
		now -= a-pre;
		if(now <= 0)
		{
			ok = 0;
			break;
		}
		now = min(n, now+b-a);
		pre = b;
	}
	now -= t-pre;
	if(now <= 0)
		ok = 0;
	if(ok)
		puts("Yes");
	else
		puts("No");
	AC;
}


#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=998244353;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
const int INF = 1e9;
const int A = 1000005;

int main(){
    int n;cin>>n;
    vector<int> a(n,0);
    rep(i,n)cin>>a[i];
    vector<ll> sum(n,0),max_v(n,0);
    sum[0] = a[0];
    max_v[0] = max(0,a[0]);
    for(int i = 1;i < n;i++){
        sum[i] = sum[i-1] + a[i];
        max_v[i] = max(sum[i],max_v[i-1]);
    }
    ll ans = 0,cal = 0;
    rep(i,n){
        ans = max(cal + max_v[i],ans);
        cal += sum[i];
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)

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

    int n; cin >> n;
    vector <int> A(n);
    for (int &i: A) cin >> i;
    ll mx = 0, curr = 0, ans = -1e18, p = 0;
    for (int i = 0; i < n; ++i) {
        ans = max(ans, curr + mx);
        curr += p + A[i];
        p += A[i];
        mx = max(mx, p);
    }

    cout << max(curr, ans);

    return 0;
}


#include <iostream>

int main()
{
  int X, Y, Z;
  std::cin >> X >> Y >> Z;
  auto ans = (Z * Y - 1) / X;

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

#include<iostream>
#include<vector>
#include<stdio.h>
#include<stdint.h>
#include<string>
#include<algorithm>

using namespace std;

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

    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    int ans = b * c / a;

    if((b * c) % a == 0) cout << ans-1 << endl;
    else cout << ans << endl;

    return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)
#define vi vector<ll>
#define vii vector<vector<ll>>
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? " " : "") << a[i];
  return os << '\n';
}
template <typename T>
std::ostream& operator<<(std::ostream& os, pair<T, T>& p) {
  return os << "{ " << p.first << ", " << p.second << " }" << std::endl;
}
template <typename T>
std::istream& operator>>(std::istream& is, pair<T, T>& p) {
  return is >> p.first >> p.second;
}
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& a) {
  for (T& x : a) is >> x;
  return is;
}

[[maybe_unused]] constexpr ll MOD = 1e9 + 7;
[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;
[[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n + 1);
  cin >> a;
  int k = 100000;
  rep(i, 0, n) { k = min(k, abs(a[i] - a[i + 1])); }

  cout << k << '\n';
  rep(i, 0, k) {
    rep(j, 0, n + 1) { cout << (a[j] + i) / k << ' '; }
    cout << '\n';
  }

  return 0;
}

// clang-format off
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()

using namespace std;
using namespace __gnu_pbds;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
// clang-format on

string s[100];

int main() {
    fastio();

    int h, w;

    cin >> h >> w;
    forn(i, h) cin >> s[i];

    int ans = 0;
    forn(i, h) forn(j, w) {
        if (s[i][j] == '#') continue;

        if (j < w - 1) {
            ans += s[i][j + 1] == '.';
        }

        if (i < h - 1) {
            ans += s[i + 1][j] == '.';
        }
    }

    cout << ans << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <random>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>

//#include <atcoder/all>

#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[8]={-1,0,1,0,1,1,-1,-1},dy[8]={0,1,0,-1,1,-1,1,-1};

//using namespace atcoder;

int n,m;
vi a;

vi f(){
	vi b(n/2+1);
	for(int i=1;i<=n/2;i++){
		b[i]=abs(a[2*i-1]-a[2*i-2])+b[i-1];
	}
	reverse(a.begin(),a.end());
	return b;
}

int main(){
	cin>>n>>m;
	a=vi(n);
	for(auto &i:a) cin>>i;
	sort(a.begin(),a.end());
	vi b=f(),c=f();
	int res=inf;
	for(int i=0;i<m;i++){
		int x;
		cin>>x;
		int j=upper_bound(a.begin(),a.end(),x)-a.begin();
		res=min(res,b[j/2]+c[(n-j)/2]+abs(x-a[(j%2==1?j-1:j)]));
	}
	cout<<res<<endl;
}

//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include <string.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define INF 2e9
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> void chmax(T& a, T b){if(a<b)a=b;}
template<class T> void chmin(T& a, T b){if(a>b)a=b;}

ll n,x[20],y[20],z[20];
ll dp[1<<17][20];

ll dif(int i1,int i2){
    return abs(x[i1]-x[i2])+abs(y[i1]-y[i2])+max(0LL,z[i2]-z[i1]);
}

int main(){
    cin >> n;
    REP(i,n)cin >> x[i] >> y[i] >> z[i];

    REP(i,n)REP(j,1<<n)dp[j][i] = 1LL<<60;
    dp[1][0] = 0;
    REP(S,1<<n){
        REP(x,n){
            REP(y,n){
                if(S & (1<<x)){
                    dp[S|(1<<y)][y] = min(dp[S|(1<<y)][y], dp[S][x]+dif(x,y));
                }
            }
        }

    }

    cout << dp[(1<<n)-1][0] << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 5e3 + 5;
const int INF = 0x3f3f3f3f;
#define DEBUG(x) cout << (x) << '\n'
#define fi first
#define se second

char s[MAXN];
int n;
void run(){
    cin >> n >> s + 1;
    int ans = 0;
    for(int i = 1; i < n; i++){
        int f1 = 0, f2 = 0;
        for(int j = i; j <= n; j++){
            f1 += s[j] == 'A';
            f2 += s[j] == 'C';
            f1 -= s[j] == 'T';
            f2 -= s[j] == 'G';
            ans += f1 == 0 && f2 == 0;
        }
    }
    DEBUG(ans);
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios_base::sync_with_stdio(false);

    run(); return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int sum[5010][4];

int main() {
	int N;
	string S;
	cin >> N >> S;
	for(int i=0; i<4; ++i) sum[0][0]=0;
	for(int i=0; i<N; ++i){
		for(int j=0; j<4; ++j) sum[i+1][j]=sum[i][j];
		if(S[i]=='A') ++sum[i+1][0];
		else if(S[i]=='T') ++sum[i+1][1];
		else if(S[i]=='C') ++sum[i+1][2];
		else ++sum[i+1][3];
	}
	int ans=0;
	for(int i=0; i<N; ++i){
		for(int j=i+1; j<=N; ++j){
			if(sum[j][0]-sum[i][0]==sum[j][1]-sum[i][1] && sum[j][2]-sum[i][2]==sum[j][3]-sum[i][3]) ++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	rep(i, v.size()) {
		if (i) os << " ";
		os << v[i];
	}
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
#ifdef LOCAL
#define dbg(x) cerr << #x << ": " << (x) << '\n'
#define say(x) cerr << (x) << '\n'
#else
#define dbg(x)
#define say(x)
#endif
string solve(bool a) { return ((a) ? "Yes" : "No"); }
int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	pair<double, double> ans, a, b, center, dis;
	cin >> n >> a >> b;
	double turn = 2.0 * PI / n;
	dbg(turn);
	center = mp(a.F + b.F, a.S + b.S);
	center.F /= 2.0;
	center.S /= 2.0;
	dbg(center);
	dis = mp(a.F - center.F, a.S - center.S);
	dbg(dis);
	ans.F = dis.F * cos(turn) - dis.S * sin(turn);
	ans.S = dis.F * sin(turn) + dis.S * cos(turn);
	dbg(ans);
	ans.F += center.F;
	ans.S += center.S;
	cout << fixed << setprecision(15) << ans.F << " " << ans.S << '\n';
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fcout cout << fixed << setprecision(18)

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

  double N; cin >> N;
  double X0, Y0; cin >> X0 >> Y0;
  double Xn, Yn; cin >> Xn >> Yn;

  double Xc = (X0 + Xn) / 2.0;
  double Yc = (Y0 + Yn) / 2.0;

  double X00 = (X0 - Xc);
  double Y00 = (Y0 - Yc);

  double theta = (2 * 3.1415926535) / N;
  double X10 = (X00 * cos(theta) - Y00 * sin(theta));
  double Y10 = (X00 * sin(theta) + Y00 * cos(theta));

  double ansX = X10 + Xc;
  double ansY = Y10 + Yc;
  fcout << ansX << ' ' << ansY << '\n';
  return 0;
}


#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<double, double> PL;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9, DIG = 50;
int n, m, k;
set<int> a;
PL bit[MAX_N + 1][DIG + 1];
double divi[DIG + 1];

PL sum(int i, int d) {
    ll fi = 0, se = 0;
    while (i > 0) {
        fi += bit[i][d].fi;
        se += bit[i][d].se;
        i -= i & -i;
    }
    return PL(fi, se);
}

void add(int i, int d, ll x, ll y) {
    while (i <= n) {
        bit[i][d].fi += x;
        bit[i][d].se += y;
        i += i & -i;
    }
}

int main() {
    ci3(n, m, k);
    rep(i, k) {
        int tmp;
        ci(tmp);
        a.ep(tmp);
    }
    rep(i, n) {
        if (a.find(i) != a.end()) continue;
        rep (j, DIG) {
            PL p = (i == 0 && j == 0) ? PL(0, 1) : sum(i, j);
            ll x = p.fi + p.se, y = p.se;
            add(i + 1, j, x / m, y / m);
            add(i + 1, j + 1, x % m, y % m);
            if (i + m + 1 <= n) {
                add(i + m + 1, j, -x / m , -y / m);
                add(i + m + 1, j + 1, -x % m , -y % m);
            }
            else {
                add(n, j, x * (i + m - n) / m, y * (i + m - n) / m);
                add(n, j + 1, x * (i + m - n) % m, y * (i + m - n) % m);
            }
        }
    }

    divi[0] = 1.0;
    rep(i, DIG) divi[i + 1] = divi[i] / m;

    ll coe[DIG + 1], ans[DIG + 1];
    coe[0] = 1.0;
    fill(coe + 1, coe + DIG + 2, 0.0);
    rep(i, DIG + 1) ans[i] = sum(n, i).fi;
    double jdg = 0.0;
    rep(i, DIG + 1) jdg += ans[DIG - i] * divi[DIG - i];
    if (abs(jdg) < 1e-10) {
        co(-1);
        return 0;
    }

    for (auto &i : a) {
        rep(j, DIG + 1) {
            PL tmp = sum(i, j);
            ans[j] += tmp.fi;
            coe[j] -= tmp.se;
        }
    }
    double res1 = 0.0, res2 = 0.0;
    rep(i, DIG + 1) {
        res1 += ans[DIG - i] * divi[DIG - i];
        res2 += coe[DIG - i] * divi[DIG - i];
    }
    co(res1 / res2);
    return 0;
}

#include<bits/stdc++.h>
#define double long double
#define maxn 100010
using namespace std;
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int n,m,K,v[maxn];
double k[maxn],b[maxn],sk[maxn],sb[maxn];
#define ABS(x) ((x)<0?-(x):(x))
signed main()
{
	n=read(),m=read(),K=read();
	for(int i=1,x;i<=K;i++) v[x=read()]=1,k[x]=1;
	for(int i=n-1;~i;i--)
	{
		if(!v[i]) k[i]=(sk[i+1]-sk[i+m+1])/m,b[i]=(sb[i+1]-sb[i+m+1])/m+1;
		sk[i]=sk[i+1]+k[i],sb[i]=sb[i+1]+b[i];
	}
	if(ABS(k[0]-1)<1e-7) cout<<-1<<'\n';
	else cout<<fixed<<setprecision(10)<<b[0]/(1-k[0])<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
	T t=0;
	char k;
	bool vis=0;
	do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
	while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
	return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
void exgcd(ll u,ll v,ll &x,ll &y){
	if(!v){x=1,y=0;return;}
	if(u<v){
		exgcd(v,u,y,x);x=-x;y=-y;
		return;
	}ll i=u/v;
	exgcd(u%v,v,x,y);
	y+=x*i;
}
int main(){
	for(int T=read;T--;){
		int x=read,y=read,p=read,q=read;
		ll a=x+y<<1,b=p+q,d=__gcd(a,b);ll ans=-1;
		for(int i=x;i<x+y;++i)
			for(int j=p;j<p+q;++j){
				ll c=j-i;//ax-by=c
				if(c/d*d!=c)continue;
				ll l=a/d,r=b/d,u=0,v=0;c/=d;//lu-rv=c
				exgcd(l,r,u,v);//lu-rv=1
				u*=c;v*=c;//lu-rv=c
				ll m=max(max((r-u-1)/r,(l-v-1)/l),0ll);
				u+=r*m,v+=l*m;
				m=max(min(u/r,v/l),0ll);
				u-=r*m;v-=l*m;
				//cout<<u*a+i<<' '<<v*b+j<<endl;
				if(!~ans||ans>v*b+j)ans=v*b+j;
			}if(~ans)cout<<ans<<endl;
			else puts("infinity");
	}
	return 0;
}

//abc193_e.cpp
//Mon Mar 15 23:09:25 2021

#include <bits/stdc++.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

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

inline ll mod(ll a, ll m){
	return (a%m+m)%m;
}

ll extGCD(ll a, ll b, ll &p, ll &q){
	if (b == 0){
		p = 1;
		q = 0;
		return a;
	}
	ll d = extGCD(b, a%b, q, p);
	q -= a/b*p;
	return d;
}

//中国剰余定理。
//リターンは(r,m)。x ≡ r (mod m)
//解なしの時は(0,-1)が帰ってくる。
pair<ll,ll> ChineseRem(ll b1, ll m1, ll b2, ll m2){
	ll p,q;
	ll d = extGCD(m1,m2,p,q);
	if ((b2-b1)%d!=0) return make_pair(0,-1);
	ll m = m1*(m2/d);
	ll tmp = (b2-b1)/d*p%(m2/d);
	ll r = mod(b1+m1*tmp,m);
	return make_pair(r,m);
}

int main(){
	int t;
	cin >> t;
	rep(i,t){
		ll x,y,p,q;
		cin >> x >> y >> p >> q;
		ll ans = LLINF;
		for(ll j=x;j<x+y;j++){
			for(ll k=p;k<p+q;k++){
				pair<ll,ll> tmp = ChineseRem(j,2*x+2*y,k,p+q);
				if (tmp.second!=-1){
					ans = min(ans,tmp.first);
				}
			}
		}
		if (ans == LLINF)cout << "infinity" << endl;
		else cout << ans << endl;
	}
}


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

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

pair<int64_t, int64_t> crt(int64_t b1, int64_t m1, int64_t b2, int64_t m2){
    int64_t p, q;
    int64_t d = extgcd(m1, m2, p, q);
    if((b2-b1) % d != 0) return {-1, -1};
    int64_t m = m1 * (m2/d);
    int64_t tmp = (b2 - b1) / d * p % (m2/d);
    int64_t r = ((b1 + m1 * tmp) % m + m) % m;
    return make_pair(r, m);
}

void solve(){
    int64_t X, Y, P, Q;
    cin >> X >> Y >> P >> Q;
    int64_t INF = 8e18;
    int64_t ans = INF;
    for(int a=X; a<X+Y; a++) for(int b=P; b<P+Q; b++){
        auto res = crt(a, 2*X+2*Y, b, P+Q).first;
        if(res != -1) ans = min(ans, res);
    }
    if(ans == INF){
        cout << "infinity" << endl;
    }else{
        cout << ans << endl;
    }

}

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


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;

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

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

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

//グラフ関連
struct Edge {
    int to, rev;
    ll cap;
    Edge(int _to, ll _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

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

void solve() {
    ll n;
    string s;
    cin >> n >> s;
    vec<ll> a(n + 1);
    REP(i, n + 1) {
        cin >> a[i];
    }

    ll d = INF;
    REP(i, n) {
        chmin(d, abs(a[i + 1] - a[i]));
    }

    vvec<ll> b(d, vec<ll>(n + 1, 1));

    REP(i, d) {
        REP(j, n + 1) {
            b[i][j] = a[j] / d;
            if(i < a[j] % d)
                b[i][j]++;
        }
    }

    cout << d << en;
    for(auto i : b) {
        for(auto j : i)
            cout << j << " ";
        cout << en;
    }
}

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

    // ll t;
    // cin >> t;
    // REP(i, t - 1) {
    //     solve();
    // }

    solve();

    return 0;
}

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

int a[110];
int b[110];

int main() {
	int n,k,m,mi;
	string s;

	cin >> n >> s;
	rep(i,n+1)cin >> a[i];
	rep(i,n) b[i]=a[i+1]-a[i];
	k=10010;
	rep(i,n){
		if(b[i]>0) k=min(k,b[i]);
		else k=min(k,-b[i]);
	}
	cout << k << endl;
	rep(j,k) {
		rep(i,n+1) cout << (int)((a[i]+j)/k)<<" ";
		cout << endl;
	}
	return 0;
}


#line 1 "main_b.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>

/* template start */

using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...)                                                    \
  std::cerr << "LINE: " << __LINE__ << "  [" << #__VA_ARGS__ << "]:", \
      debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << std::endl; }

template <typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
  std::cerr << " " << h;
  if (sizeof...(t) > 0) std::cout << " :";
  debug_out(t...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
  return a > b && (a = b, true);
}

template <typename Num>
constexpr Num mypow(Num a, u64 b, Num id = 1) {
  if (b == 0) return id;
  Num x = id;
  while (b > 0) {
    if (b & 1) x *= a;
    a *= a;
    b >>= 1;
  }
  return x;
}

template <typename T>
std::vector<std::pair<std::size_t, T>> enumerate(const std::vector<T>& data) {
  std::vector<std::pair<std::size_t, T>> ret;
  for (std::size_t index = 0; index < data.size(); index++)
    ret.emplace_back(index, data[index]);
  return ret;
}

/* template end */

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

  i64 n,m;
  std::cin>>n>>m;

  std::vector<i64> a(n),b(n);
  for(auto&& e:a)std::cin>>e;
  for(auto&& e:b)std::cin>>e;

  std::vector<std::vector<i64>> graph(n);
  rep(i,0,m){
    i64 c,d;
    std::cin>>c>>d;
    c--;d--;
    graph[c].emplace_back(d);
    graph[d].emplace_back(c);
  }

  std::vector<bool> visit(n,false);

  i64 aval=0,bval=0;

  auto dfs=[&](auto f,i64 now)->void{
    visit[now]=true;
    aval += a[now];
    bval += b[now];
    for(const auto& e:graph[now]){
      if(!visit[e])f(f,e);
    }
  };

  rep(i,0,n){
    if(!visit[i]){
      aval = 0;
      bval = 0;
      dfs(dfs,i);
      if(aval!=bval){
        std::cout<<"No\n";
        return 0;
      }
    }
  }

  std::cout<<"Yes\n";

  return 0;
}

//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#include <bits/stdc++.h>

#ifdef LOCAL
#include "debug-template.hpp"
#endif

using namespace std;

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	vector<int> f(n);
	iota(f.begin(), f.end(), 0);
	vector<long long> g(n);
	for (int i = 0; i < n; i++) {
		g[i] = a[i] - b[i];
	}
	function<int(int)> find_set = [&](int u) {
		return f[u] == u ? f[u] = u : f[u] = find_set(f[u]);
	};
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		u--, v--;
		u = find_set(u);
		v = find_set(v);
		if (u != v) {
			g[v] += g[u];
			g[u] = 0;
			f[u] = v;
		}
	}
	for (int i = 0; i < n; i++) {
		if (g[i]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char S[200200]; int K, bc[1 << 16], tr[200200], dig[200200];

const long long mod = 1000000007;
long long prv[17][17], nxt[17][17];

int main()
{
	scanf ("%s %d", S, &K);
	int l = 0;
	while (S[l]) l++;

	for (int i = 0; i < l; i++){
		if ('0' <= S[i] && S[i] <= '9') tr[i] = S[i] - '0';
		else tr[i] = S[i] - 'A' + 10;
		dig[i + 1] = dig[i] | (1 << tr[i]);
	}
	for (int i = 1; i < (1 << 16); i++) bc[i] = bc[i - (i & (-i))] + 1;
	for (int i = 0; i <= 16; i++) prv[i][i] = 1;

	long long ans = (bc[dig[l]] == K);
	for (int i = l - 1; i >= 0; i--){
		if (i) ans = (ans + prv[1][K] * 15) % mod;
		for (int s = 0; s < tr[i]; s++){
			if (s == 0 && i == 0) continue;
			int b = bc[dig[i] | (1 << s)];
			ans = (ans + prv[b][K]) % mod;
		}
		memset(nxt, 0, sizeof(nxt));
		for (int j = 0; j <= 16; j++){
			for (int k = j; k <= 16; k++){
				nxt[j][k] = (nxt[j][k] + prv[j][k] * k) % mod;
				if (k < 16) nxt[j][k + 1] = (nxt[j][k + 1] + prv[j][k] * (16 - k)) % mod;
			}
		}
		memcpy(prv, nxt, sizeof(nxt));
	}

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

#include<bits/stdc++.h>
using namespace std;
const int N=5005,mod=998244353;
int n,m,ans,v[N][N];
int qp(int a,int b)
{
	if(v[a][b]!=-1)
		return v[a][b];
	int ma=a,mb=b;
	int ans=1;while(b){if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;b>>=1;}
	v[ma][mb]=ans;
	return ans;
}
int main()
{
	memset(v,-1,sizeof(v));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		ans=(ans+1ll*qp(m-1,i-1)*qp(m,n-i))%mod;
	ans=1ll*ans*m%mod;
	for(int i=0;i<=n-2;i++)
	{
		int t=n-1-i;
		for(int j=1;j<=m;j++)
			ans=(ans+1ll*t*(qp(m-1,i)+mod-qp(j-1,i))%mod*qp(m,n-2-i))%mod;
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef map<ll, ll> ml;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

ll itr1, itr2, M1 = 0, M2 = 0;
bool found = 0;
vl e, d1, d2;
vb diam;
vvl G;

void dfs1(ll v) {
  for(ll u: G[v]) {
    if(d1[u] == INF) {
      d1[u] = d1[v] + 1;
      dfs1(u);
    }
  }
  return;
}

void dfs2(ll v) {
  for(ll u: G[v]) {
    if(d2[u] == INF) {
      d2[u] = d2[v] + 1;
      dfs2(u);
    }
  }
  return;
}

void dfs3(ll v) {
  if(v == itr2) {
    found = 1;
    return;
  }
  for(ll u: G[v]) {
    if(found) break;
    if(d2[v] < d2[u]) dfs3(u);
    if(found) diam[u] = 1;
  }
  return;
}

ll dfs4(ll v, ll num) {
  e[v] = num;
  ll last = -1;
  for(ll u: G[v]) {
    if(e[u] == INF) {
      if(diam[u]) {
        last = u;
        continue;
      }
      num = dfs4(u, num+1);
    }
  }
  if(last != -1) num = dfs4(last, num+1);
  return num+1;
}

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

  ll n, a, b;
  cin >> n;
  e = vl(n, INF);
  d1 = vl(n, INF);
  d2 = vl(n, INF);
  diam = vb(n, 0);
  G = vvl(n);
  rep(_, n-1) {
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  d1[0] = 0;
  dfs1(0);
  rep(i, n) if(chmax(M1, d1[i])) itr1 = i;
  d2[itr1] = 0;
  dfs2(itr1);
  rep(i, n) if(chmax(M2, d2[i])) itr2 = i;
  dfs3(itr1);
  dfs4(itr1, 1);
  //cout << itr1 << " " << itr2 << newl;
  //rep(i, n) if(diam[i]) cout <<i << newl;
  rep(i, n) cout << e[i] << ' ';
  cout << newl;
  return 0;
}

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

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

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

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
    cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int n; cin >> n;
    vector<int> s(2*n), d(2*n);
    for(int i=0; i<n; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        if(a>=0&&b>=0){
            if(b<=a||s[a]!=0||s[b]!=0) {
                cout << "No" << endl;
                return 0;
            }
            s[a] = (i+1);
            s[b] = -(i+1);
            d[a] = b-a;
            d[b] = a-b;
        } else if(a>=0){
            if(s[a]!=0){
                cout << "No" << endl;
                return 0;
            }
            s[a] = i+1;
        } else if(b>=0){
            if(s[b]!=0){
                cout << "No" << endl;
                return 0;
            }
            s[b] = -(i+1);
        }
    }

    vector<bool> dp(n+1);

    dp[0] = true;

    for(int i=0; i<n; i++){
        if(!dp[i]) continue;
        for(int j=1; i+j<=n; j++){
            bool ok = true;
            for(int k=0; k<j; k++){
                int p = 2*i+k, q = 2*i+j+k;
                if(d[p]!=0&&d[p]!=j) ok = false;
                if(d[q]!=0&&d[q]!=-j) ok = false;

                if(s[p]!=0&&s[q]!=0&&s[p]+s[q]!=0) ok = false;
                if(s[p]<0 || 0<s[q]) ok = false;
            }
            dp[i+j] = dp[i+j] || ok;
        }
    }

    cout << (dp[n]?"Yes":"No") << endl;

    return 0;
}


#include <bits/stdc++.h>

using ll = long long;
const int N(1010);
ll n, f[N];
int pos, fl[N];
std::vector<int> ans;

int main()
{
	std::scanf("%lld", &n), f[1] = 1;
	for (int i = 2; i <= 90; i++) f[i] = f[i - 1] + f[i - 2];
	for (int i = 90; i; i--)
		if (n >= f[i]) n -= f[i], fl[i] = 1, pos = std::max(pos, i);
	for (int i = pos, j = 1; i; i--, j++)
	{
		if (fl[i])
		{
			if (i & 1) ans.push_back(1);
			else ans.push_back(2);
		}
		if (j & 1) ans.push_back(4);
		else ans.push_back(3);
	}
	printf("%lu\n", ans.size());
	for (auto i : ans) printf("%d\n", i);
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define rep0(i,n) for ((i)=0;(i)<(n);(i)++)
using namespace std;
long long n,m,s,i;
vector<int> ans;
long long gcd(long long x,long long y){
	if(!y) return x;
	long long t=gcd(y,x%y);
	s+=x/y;return t;
}
void print(long long x,long long y){
	if(!x){
		while(y--)ans.push_back(2);
		return;
	}
	if(!y){
		while(x--)ans.push_back(1);
		return;
	}
	if(x>y){
		while(x>=y){
			ans.push_back(3);
			x-=y;
		}
	}
	else{
		while(x<=y){
			ans.push_back(4);
			y-=x;
		}
	}
	print(x,y);
}
int main(){
	srand(time(NULL));
	cin>>n;
	for(;;){
		m=(rand()+rand()*65536ll+rand()*65536ll*65536ll/*+rand()*65536ll*65536ll*65536ll*/)%n;
		s=0;
		long long g=gcd(n,m);
		if(s+g>130) continue;
		print(n,m);
		printf("%d\n",ans.size());reverse(ans.begin(),ans.end());
		rep0(i,ans.size())printf("%d\n",ans[i]);
		return 0;
	}
	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;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 100012
#define ll long long
#define int ll
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair
#define f first
#define s second
#define mod 1000000007
ll Mod(ll x, ll y, int p)
{   ll res = 1; x = x % p;
    while (y > 0)
    {   if (y & 1) res = (res * x) % p;
        y = y >> 1; x = (x * x) % p;
    } return res;
}
int* getlps(string pattern) {
    int len = pattern.length();
    int * lps = new int[len];
    lps[0] = 0;
    int i = 1 , j = 0;
    while (i < len) {
        if (pattern[i] == pattern[j]) {
            lps[i] = j + 1;
            i++;
            j++;
        }
        else {
            if (j != 0) {
                j = lps[j - 1];
            }
            else {
                lps[i] = 0;
                i++;
            }
        }
    }
    return lps;
}
class Triplet {
public:
    int x ;
    int y ;
    int gcd;
};
Triplet extendedEuclid(int a , int b) {
    if (b == 0) {Triplet ans; ans.gcd = a; ans.x = 1; ans.y = 0; return ans;}
    Triplet smallAns = extendedEuclid(b , a % b);
    Triplet ans;
    ans.gcd = smallAns.gcd;
    ans.x = smallAns.y;
    ans.y = smallAns.x - (a / b) * smallAns.y;
    return ans;
}
int mmInverse(int a , int m) {
    Triplet ans = extendedEuclid(a , m);
    return (ans.x + m) % m;
}
int fact[N];
void calfac(int n ) {
    fact[0] = 1;
    for (int i = 1 ; i <= n + 2; i++) {
        fact[i] = (((fact[i - 1] % mod) * (i % mod)) % mod + mod) % mod;
    }
}
int calc(int n , int r) {
    if (r > n)return 0;
    if (r == n)return 1;
    int ans = 1;
    ans = ((ans % mod) * (fact[n]) % mod + mod) % mod;
    ans = ((ans % mod) * (mmInverse(fact[n - r] , mod) % mod) + mod) % mod;
    ans = ((ans % mod) * (mmInverse(fact[r] , mod) % mod) + mod) % mod;
    return (ans + mod) % mod;
}

void solve(int cntt) {
    int n;
    cin >> n;
    double x;
    cin >> x;
    x = x * 100.0;
    double ans = 0;
    int val = 1010;
    for (int i = 0 ; i <  n ; i++) {
        double am , per;
        cin >> am >> per;
        double z = (1.0 * am) * (1.0 * per);
        double jaadu = z;
        // cout << "jaadu:" << jaadu << endl;
        x = x - jaadu;
        if (x < 0) {
            //cout << ans << endl;
            //cout << x << endl;
            //cout << "hello" << endl;
            val = min(i + 1 , val);
            // cout << i + 1 << endl;
            // return;
        }
    }
    if (val == 1010)
        cout << "-1" << endl;
    else
        cout << val << endl;
}

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

    // preprocess();
    int t;
    t = 1;

    int l = 0;
    while (t--) {
        l++;

        solve(l);
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll bin(ll a[],ll l,ll r,ll x){
	ll m=(l+r)/2;
	if(l>=r)return -1;
	if(a[m]==x)return m;
	if(a[m]>x)return bin(a,l,m-1,x);
	return bin(a,m+1,r,x);
}
ll exp(ll a,ll b){
	if(b==0)return 1;
	ll res=exp(a,b/2);
	if(b%2==0)return res*res;
	return res*res*a;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int x;
	cin>>x;
	x*=100;
	int a[n],b[n];
	double f[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		f[i]=(a[i]*b[i]);
	}
	int s=0;
	int flag=0,cnt=0;
	for(int i=0;i<n;i++){
		s+=f[i];
		cnt++;
		if(s>x){
			flag=1;
			break;
		}
	}
	cout<<(flag?cnt:-1);
}


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

typedef long long ll;
typedef long double ld;
const int N = (int)5e5 + 77;
const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e18;

ll n, m, ans;
map<ll, ll> mp;

int main()
{
  int t = 1;
  // cin >> t;
  while (t--)
  {
    cin >> n;
    ans = 0;
    for (int i = 0; i < n; i++)
    {
      cin >> m;
      ans += i - mp[m];
      mp[m] += 1;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> dp(2, 1);
  rep(i, n) {
    vector<ll> temp(2);
    swap(dp, temp);
    string s;
    cin >> s;
    rep(y, 2) rep(x, 2){
      int l;
      if (s == "AND")  l = y & x;
      else l = y | x;
      dp[l] += temp[y];
    }
  }
  cout << dp[1] << endl;
  return 0;
}


#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#define VIND(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem,--_elem
#define OUT(x) cout << x;
#define OUTL(x) cout << x << endl;
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

int mins(ll a, ll b)
{
    if (a == 0 && b == 0) return 0;
    if (a == b || a == -b) return 1;
    if (abs(a) + abs(b) <= 3) return 1;
    if (abs(a - b) <= 3 || abs(a + b) <= 3) return 2;
    if (abs(a) + abs(b) <= 6) return 2;
    if ((a + b) % 2 == 0) return 2;
    return 3;
}

void solve()
{
    IN(a, b, c, d);
    OUTL(mins(c-a, d-b));
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

#define fast ios_base::sync_with_stdio; cin.tie(0); cout.tie(0)
#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
//#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{fast;
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 #endif
 int t=1;
 //cin>>t;
 while(t--)
 {int n,m;
  cin>>n>>m;
  vector<string> v(n);
  rep(i,0,n){
    cin>>v[i];
  }
  int ans=0;
  rep(i,1,n){
    rep(j,0,m){
        int f=0;
        while(v[i][j]=='#'&&v[i-1][j]=='.'){
            f=1;
            j++;
        }
        if(f){
            ans++;
        }
    }
  }
  rep(i,0,n-1){
    rep(j,0,m){
        int f=0;
        while(v[i][j]=='#'&&v[i+1][j]=='.'){
            f=1;
            j++;
        }
        if(f){
            ans++;
        }
    }
  }
  rep(j,1,m){
    rep(i,0,n){
        int f=0;
        while(v[i][j]=='#'&&v[i][j-1]=='.'){
            f=1;
            i++;
        }
        if(f){
            ans++;
        }
    }
  }
  rep(j,0,m-1){
    rep(i,0,n){
        int f=0;
        while(v[i][j]=='#'&&v[i][j+1]=='.'){
            f=1;
            i++;
        }
        if(f){
            ans++;
        }
    }
  }
  cout<<ans<<endl;
 }
 return 0;
}


#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds;
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
const long double PI = acos(-1.0L);
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
//const int mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
VL dx={1,0,-1,0};
VL dy={0,1,0,-1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
const int N=500000;
vector<vector<PLL>> adj;
VL visit2;
map<ll,ll> gg;
bool dfs(ll v,ll p)
{
    gg[v]=1;
    visit2[v]=1;
    bool cyc=false;
    for(auto to:adj[v])
    {
        if(visit2[to.F]==1)
        {
            if(to.S!=p)
            {
                cyc=true;
            }
        }
        else
        {
            cyc|=dfs(to.F,to.S);
        }
    }
    return cyc;
}
void solve()
{
    ll n;
    cin>>n;
    vector<PLL> arr;
    map<ll,ll> mp,visited;
    map<PLL,VL> store;
    VL pres(N,0);
    visit2.assign(N,0);
    adj.assign(N,vector<PLL>());
    fr(i,0,n)
    {
        ll a,b;
        cin>>a>>b;
        pres[a]=1,pres[b]=1;
        if(a>b)
        {
            swap(a,b);
        }
        if(a==b)
        {
            mp[a]=1;
            visited[i]=1;
        }
        arr.pb({a,i});
        arr.pb({b,i});
        store[{a,b}].pb(i);
    }
    sort(ALL(arr));
    for(auto i:store)
    {
        if(SZ(i.S)>1)
        {
            PLL tmp=i.F;
            mp[tmp.F]=1;
            mp[tmp.S]=1;
            VL fk=i.S;
            visited[fk[0]]=1;
            visited[fk[1]]=1;
        }
        PLL tmp=i.F;
        VL fk=i.S;
        for(auto pp:fk)
        {
            adj[tmp.F].pb({tmp.S,pp});
            adj[tmp.S].pb({tmp.F,pp});
        }
    }
    //cout<<SZ(mp)<<endl;
    mp.clear();
    ll ans=0;
    fr(i,0,N)
    {
        if(pres[i]==1&&visit2[i]==0)
        {
            gg.clear();
            if(dfs(i,-1))
            {
                ans+=SZ(gg);
            }
            else
            {
                ans+=SZ(gg)-1;
            }
        }
    }
    cout<<ans<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1,pp;
    //cin>>t;
    pp=t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<": ";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc
        * BE very careful in int vs long long vs unsigned long long
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithmQ

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<string> s(n);
    ll odd = 0, even = 0;
    rep(i,n){
        string s;
        cin>>s;
        int sum=0;
        rep(j,m)sum+=s[j]-'0';
        if(sum%2)++odd;
        else ++even;
    }
    cout<<odd*even<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<list>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define vvll vec<vll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define repset(itr,a) for(auto itr=a.begin();itr!=a.end();itr++)
#define repnck(bit,n,k) for(ll bit=(1<<(k))-1;bit<(1<<(n));bit=nec(bit))
#define bi1(bit,i) ((bit)&1<<(i)?true:false)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define kai "\n"
#define prque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define bis binary_search
#define nep next_permutation
#define MOD 1000000007ll
#define MAX 2147483647
#define MIN (1e-10)
#define equal(a,b) (abs((a)-(b))<MIN)
using namespace std;
void solve();
struct ll2{ll x,y;bool operator<(const ll2 &l)const{return x!=l.x?x<l.x:y<l.y;};};
struct ll3{ll x,y,z;bool operator<(const ll3 &l)const{if(x!=l.x)return x<l.x;if(y!=l.y)return y<l.y;return z<l.z;};};

class ufset{
public:
	ufset(ll n) {rank.resize(n,0);rep(i,0,n)p.pub(i);}
	bool same(ll i,ll j){return find(i)==find(j);}
	void unite(ll i,ll j){link(find(i),find(j));}
private:
  vll rank,p;
	void link(ll i,ll j){if(rank[i]>rank[j])p[j]=i;else{p[i]=j;if(rank[i]==rank[j])rank[j]++;}}
	ll find(ll i){if(i!=p[i])p[i]=find(p[i]);return p[i];}
};

class nck{
public:
	nck(ll maxn,ll mod=MOD){
		NUM=maxn+1;p=mod;
		fac.resize(NUM);finv.resize(NUM);inv.resize(NUM);
		fac[0]=fac[1]=finv[0]=finv[1]=inv[1]=1;
		rep(i,2,NUM){fac[i]=fac[i-1]*i%p;inv[i]=p-inv[p%i]*(p/i)%p;finv[i]=finv[i-1]*inv[i]%p;}
	}
	ll c(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%p)%p;}
private:
  ll NUM,p;
	vll fac,finv,inv;
};

ll gcd(vector<ll> a){rep(i,1,a.size()){ll k=a[i-1]%a[i];while(k!=0){a[i-1]=a[i];a[i]=k;k=a[i-1]%a[i];}}return a.back();}
ll lcm(vector<ll> a){ll n;rep(i,1,a.size()){n=a[i-1]*a[i];ll k=a[i-1]%a[i];while(k!=0){a[i-1]=a[i];a[i]=k;k=a[i-1]%a[i];}n/=a[i];a[i]=n;}return n;}
ll pow2(ll a,ll b,ll p=MOD){if(b==-1)return pow2(a,p-2);ll res=1;if(b>0){res=pow2(a,b/2);if(b%2==0)res=res*res%p;else res=res*res%p*a%p;}return res;}
ll nec(ll bit){ll x=bit&-bit,y=bit+x;return (((bit&~y)/x)>>1)|y;}
ll bisz(ll bit){ll size=0;while(bit>0){bit/=2;size++;}return size;}
ll ransu(){static unsigned int TX=123456789, TY=362436069, TZ=521288629, TW=88675123;unsigned int tt=(TX^(TX<<11));TX=TY;TY=TZ;TZ=TW;return (TW=(TW^(TW>>19))^(tt^(tt>>8)));}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}

void solve(){
	ll x,y,a,b;cin>>x>>y>>a>>b;
	ll ans=0;
	if(x<=b){
	while(x*(a-1)<=b){
		x*=a;
		if(x>=y){
			cout<<ans<<kai;
			return;
		}
		ans++;
	}}
	ans+=(y-x+b-1)/b-1;
	cout<<ans<<kai;
}

#include<iostream>
using namespace std;
int main()
{
	int v,t,s,d,s1,s2;
	cin>>v>>t>>s>>d;
	s1=t*v;
	s2=v*s;

	if(d>=s1&&d<=s2)
		cout<<"No";
	else
		cout<<"Yes";

 return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>

/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;

void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

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

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

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

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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int ans = 0, s = 0;
  REP(i, N){
    ans += A[i]*A[i];
    s += A[i];
  }

  cout << N*ans-s*s << "\n";

  return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define int long long int
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define F first
#define S second
#define inf 1e18
#define vi vector<int>
#define Point complex<int>
#define X real()
#define Y imag()
#define pii pair<int,int>
#define num0Beg(x) __builtin_clz(x) // no. of zero in beginning of bit representation
#define num0end(x) __builtin_ctz(x) // no. of zero in the end
#define numOf1(x) __builtin_popcount(x) // no. of ones in bit rep.
#define parity(x) __builtin_parity(x) // parity of 1
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int32_t main()
{
    FAST
    int tt=1;
    //cin >> tt;
    while(tt--)
    {
      int n;
      cin>>n;
      int a[n];
      map<int,int> mp;
      for(int i=0;i<n;i++)
        cin>>a[i];
      for(int i=0;i<n;i++)
        mp[a[i]]++;
      int ans=0;
      for(int i=-200;i<=200;i++)
      {
        for(int j=i+1;j<=200;j++)
        {
          ans+=((mp[i]*mp[j])*(i-j)*(i-j));
        }
      }
      cout<<ans;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 20;

int h,w,a,b,ans;
bool vis[N][N];

void dfs(int now,int x,int y,int a,int b){
	if (now==h*w){
		ans++;
		return ;
	}
	int nx=x+1,ny=y;
	if (x==w) nx=1,ny++;
	if (vis[x][y]) return dfs(now+1,nx,ny,a,b);
	if (a){
		if (x!=w&&!vis[nx][ny]){
			vis[x][y]=vis[nx][ny]=true;
			dfs(now+1,nx,ny,a-1,b);
			vis[x][y]=vis[nx][ny]=false;
		}
		if (y<h){
			vis[x][y]=vis[x][y+1]=true;
			dfs(now+1,nx,ny,a-1,b);
			vis[x][y]=vis[x][y+1]=false;
		}
	}
	if (b){
		vis[x][y]=true;
		dfs(now+1,nx,ny,a,b-1);
		vis[x][y]=false;
	}
}

int main(){
	cin>>h>>w>>a>>b;
	dfs(0,1,1,a,b);
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define endl '\n'
#define F first
#define S second
#define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++)
#define fill(name, val) memset(name, val, sizeof(name));
#define mop(a, op, b) (((a%mod) op (b%mod))%mod + mod)%mod
#define precise fixed<<setprecision(9)
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define get(a, n) for(ll it = 0; it < n; it++) cin>>a[it];
#define pbds tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
template<typename T1, typename T2> ostream& operator<<(ostream& out, const pair<T1, T2>& p){ return(out<<'('<< p.first<< ", "<< p.second<<')'); }
template<typename T> ostream& operator<<(ostream& out, const vector<T>& v){ out<<'['; for(auto i = v.begin(); i != v.end(); i++) out<<(i!=v.begin()?", ":"")<<(*i); return(out<<']'); }
template<typename T> ostream& operator<<(ostream& out, const set<T>& s){ out<<'['; for(auto i = s.begin(); i != s.end(); i++) out<<(i!=s.begin()?", ":"")<<(*i); return(out<<']'); }
template<typename T1, typename T2> ostream& operator<<(ostream& out, const map<T1, T2>& m){ out<<'{'<<endl; for(auto x : m) out<<"    "<<x.first<<" -> "<<x.second<<endl; return(out<<'}'); }
const ll MX = 1000001, mod = 1e9+7, inf = 1e18; const double eps = 1e-9;
template<typename T> T mpow(T x, ll n){ T ans = 1; while(n){ if(n&1) ans = mop(ans, *, x); n >>= 1, x = mop(x, *, x); } return ans; } ll modinv(ll x){ return mpow(x, mod-2); }
vll sieve(ll n = MX){ vll primes; vector<bool> nums(n, 1); primes.push_back(2); for(ll i = 4; i < n; i += 2) nums[i] = 0; for(ll i = 3; i < n; i += 2){ if(nums[i]){ primes.push_back(i); for(ll j = i*i; j < n; j += i) nums[j] = false; } } return primes; }
vll FACT(1, 1); ll ncr(ll n, ll r){ if(n < r) return 0; while(n >= FACT.size()) FACT.push_back(mop(FACT[FACT.size()-1], *, FACT.size())); return mop(FACT[n],*,mop(modinv(FACT[r]),*,modinv(FACT[n-r]))); } ll fact(ll n){ while(n >= FACT.size()) FACT.push_back(mop(FACT[FACT.size()-1], *, FACT.size())); return FACT[n]; }
void init(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	#endif
}

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

ll h, w, a, b;
map<ll, map<ll, map<ll, map<ll, set<vvll>>>>> dp;
vvll g;	set<vvll> ans;	ll ctr = 0;
void calc(ll a, ll b, ll i, ll j){
	if(i == h){
		vvll v = g;
		ans.insert(v);
		return;
	}
	if(dp[a][b][i][j].count(g))	return;
	dp[a][b][i][j].insert(g);
	if(j == w)	return calc(a, b, i+1, 0);
	if(g[i][j])	return calc(a, b, i, j+1);
	if(b > 0)	calc(a, b-1, i, j+1);
	if(i+1 < h && !g[i+1][j] && a > 0){
		g[i][j] = g[i+1][j] = 1;
		calc(a-1, b, i, j+1);
		g[i][j] = g[i+1][j] = 0;
	}
	if(j+1 < w && !g[i][j+1] && a > 0){
		g[i][j] = g[i][j+1] = 2;
		calc(a-1, b, i, j+1);
		g[i][j] = g[i][j+1] = 0;
	}
}
int main(){
	init();
	cin>>h>>w>>a>>b;
	g.resize(h, vll(w));
	calc(a, b, 0, 0);
	// for(auto x : ans){
	// 	for(auto y : x){
	// 		for(auto z : y)	cout<<z<<' ';
	// 		cout<<endl;
	// 	}
	// 	cout<<endl;
	// }
	cout<<ans.size();
}


#include "bits/stdc++.h"
#include "random"
#include <unistd.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; ++i)

const int dx2[4] = {0,1,0,1};
const int dy2[4] = {0,0,1,1};
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) return(gcd(b, a%b));
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int Uniform_Random(int a, int b){ // (a <= x <= b)

  random_device rd;
  mt19937 mt(rd());

  uniform_int_distribution<int> rv1(a, b);
  return rv1(mt);
}

int main(){

  ll N; cin >> N;
  ll ans = N;
  set<ll> st;
  for(ll i = 2; i <= sqrt(N); ++i){
    ll cnt = 2;
    if(st.find(i) == st.end()){
      while(pow(i, cnt) <= N){
        st.insert(pow(i, cnt));
        ans --;
        cnt ++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define dbg(x) cout<< #x <<" "<<x<<"\n";
#define pii pair<ll,ll>
using namespace std;

void solve(){
    ll n;
    cin>>n;
    unordered_set<ll> s;
    for(ll i=2; i*i<=n; ++i){
        ll x = i*i;
        while(x<=n){
            s.insert(x);
            x*=i;
        }
    }
    cout<<n-s.size()<<"\n";
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t,tt=0;
    // cin>>t;
    t=1;
    while(t--){
        //cout<<"Case #"<<++tt<<": ";
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  int ans = 1;
  for (int i = 1; i <= B; i++){
    int X = (A + i - 1) / i * i + i;
    if (X <= B){
      ans = i;
    }
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin >> n;
  string s;cin >> s;
  ll res = -1;
  if(s[0] != s[s.size() - 1])res = 1;
  else{
    for(int i = 1;i < (int)(s.size() - 2);i++){
      if(s[0] != s[i] && s[i + 1] != s[s.size() - 1])res = 2;
    }
  }
  cout << res << endl;
}


    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<ll,ll>;
    const int INF=1001001001;
    const int mod=1e9+7;

    void solve(){
      int n;
      string s,t;
      cin>>n>>s>>t;
      vector<int>l,r;
      rep(i,n){
        if(s[i]=='0'){l.push_back(i);}
        if(t[i]=='0'){r.push_back(i);}
      }
      if(l.size()!=r.size()){
        cout<<-1<<endl;
        return;
      }
      int cnt=0;
      rep(i,l.size()){
        if(l[i]!=r[i]){cnt++;}
      }
      cout<<cnt<<endl;
    }
    int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      solve();
      return 0;
    }

#line 2 "/home/snow/competitive-programming/competitive-programming-library/snow/template.hpp"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

constexpr long long INF = 1LL << 60;
constexpr long double PI = 3.141592653589;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define to_s to_string
#define len(v) (ll) v.size()
#define debug(x) cout << #x << ": " << (x) << '\n'

using namespace std;

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

template <typename T = ll>
using vec = vector<T>;

template <typename T = ll>
using vec2 = vector<vector<T>>;

template <typename T = ll>
using vec3 = vector<vector<vector<T>>>;

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

template < typename T >
inline bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#line 4 "/home/snow/competitive-programming/competitive-programming-library/snow/io/setup.hpp"

namespace snow{

struct IoSetup {
    IoSetup() {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
        std::cout << std::fixed << std::setprecision(10);
    }
} iosetup;

}
#line 5 "/home/snow/competitive-programming/competitive-programming-library/snow/io/helper.hpp"

template< typename T1, typename T2 >
std::ostream &operator << (std::ostream &os, const std::pair< T1, T2 > &p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
std::istream &operator >> (std::istream &is, std::pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T1, typename T2, typename T3 >
std::ostream &operator << (std::ostream &os, const std::tuple< T1, T2, T3 > &t) {
    auto &[a, b, c] = t;
    os << a << " " << b << " " << c;
    return os;
}

template< typename T1, typename T2, typename T3 >
std::istream &operator >> (std::istream &is, std::tuple< T1, T2, T3 > &t) {
    auto &[a, b, c] = t;
    is >> a >> b >> c;
    return is;
}

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

template< typename T >
std::istream &operator >>  (std::istream &is, std::vector< T > &v){
    for(T &in : v) is >> in;
    return is;
}

template< typename T >
std::ostream &operator << (std::ostream &os, const std::set< T > &st){
    int ct = 0;
    for(auto& s : st) os << s << (++ct != st.size() ? " " : "");
    return os;
}

template<class... T>
void input(T&... a){
    (std::cin >> ... >> a);
}

void print() {
    std::cout << '\n';
}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){
    std::cout << a;
    (std::cout << ... << (std::cout << ' ', b));
    std::cout << '\n';
}

int drop() {
    std::cout << '\n';
    exit(0);
}
template<class T, class... Ts>
int drop(const T& a, const Ts&... b){
    std::cout << a;
    (std::cout << ... << (std::cout << ' ', b));
    std::cout << '\n';
    exit(0);
}
#line 4 "main.cpp"
using namespace snow;

// #include "snow/algorithm/binary-search.hpp"

// #include "atcoder/modint"
// using namespace atcoder;
// using mint = modint1000000007;

int main() {
    ll N, M;
    cin >> N >> M;
    vec<> A(N), B(M);
    cin >> A >> B;

    set<ll> a(ALL(A));

    rep(i, M){
        if(a.count(B[i])) a.erase(B[i]);
        else a.insert(B[i]);
    }

    print(a);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef map<ll, ll> ml;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

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

  ll n, u, v, w, ans = 0;
  cin >> n;
  vl d(n, INF);
  vector<vpl> G(n);
  rep(_, n-1) {
    cin >> u >> v >> w;
    u--, v--;
    G[u].push_back(pl(v, w));
    G[v].push_back(pl(u, w));
  }
  ql q;
  d[0] = 0;
  q.push(0);
  while(!q.empty()) {
    ll x = q.front();
    q.pop();
    for(pl p: G[x]) {
      if(d[p.first] == INF) {
        d[p.first] = d[x] ^ p.second;
        q.push(p.first);
      }
    }
  }
  vl exp2(60), cnt(60);
  exp2[0] = 1;
  rep(j, 59) exp2[j+1] = exp2[j] * 2;
  rep(i, n) rep(j, 60) if(d[i] & exp2[j]) cnt[j]++;
  rep(j, 60) (ans += exp2[j] % MOD * cnt[j] % MOD * (n - cnt[j]) % MOD) %= MOD;
  cout << ans << newl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const int mod=1e9+7;
char s[maxn];int n,vis[300],ans=0,cnt=0;
int dp[maxn][17],f[maxn][17][17];
int mp[300];
void dfs(int pos)
{
	if(pos>n)	return;

	for(int i=1;i<=16;i++){
		dp[pos][i]=(dp[pos][i]+1LL*i*dp[pos-1][i]%mod)%mod;
		dp[pos][i]=(dp[pos][i]+1LL*(17-i)*dp[pos-1][i-1]%mod)%mod;
	}
	if(pos!=1){
		dp[pos][1]=(dp[pos][1]+15)%mod;
	}else{
		dp[pos][1]=(dp[pos][1]+(mp[s[pos]]-1))%mod;
	}

	if(pos!=1){
		for(int i=0;i<mp[s[pos]];i++){
			if(vis[i]==0)
				dp[pos][cnt+1]=(dp[pos][cnt+1]+1)%mod;
			else
				dp[pos][cnt]=(dp[pos][cnt]+1)%mod;
		}
	}

	if(vis[mp[s[pos]]]==0)	cnt++,vis[mp[s[pos]]]=1;
	//cout<<pos<<" "<<dp[pos][1]<<endl;
	dfs(pos+1);
}
int main()
{
	for(int i=0;i<10;i++)	mp[i+'0']=i;
	for(int i=0;i<6;i++)	mp[i+'A']=i+10;
	scanf("%s",s+1);n=strlen(s+1);int k;scanf("%d",&k);
	dfs(1);if(cnt==k)	dp[n][k]++;
	cout<<dp[n][k]<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX
#define MAXN 1000000000
#define mod 1000000007
#define PI 3.14159265
#define pb push_back
#define all(x) x.begin(),x.end()
#define d1(x) cerr<<#x<<":"<<x<<endl;
#define d2(x,y) cerr<<#x<<":"<<x<<' '<<#y<<":"<<y<<endl;
#define fast std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

void solve(){
	int m , h ;
	cin>>m>>h ;
	if(h%m == 0 )
		cout<<"Yes" ;
	else
		cout<<"No" ;
}

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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>
// #include "atcoder/all"

using namespace std;

using i64 = long long;

const long long MOD = 1000000007;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

// doc: https://shibh308.github.io/library/library/lib/classes/modint.cpp.html
template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;

void solve(long long n, long long p){
    // doc: https://shibh308.github.io/library/library/lib/functions/modpow.cpp.html
    auto mpow = [](auto x, i64 y){
     auto z = x;
     decltype(x) val = y & 1 ? x : decltype(x)(1);
     while(z *= z, y >>= 1)
      if(y & 1)
       val *= z;
     return val;
    };

    cout << (mint(p - 1) * mpow(mint(p - 2), n - 1)) << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    long long P;
    scanf("%lld",&P);
    solve(N, P);
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <ctime>
using namespace std;

template<class T>
T gcd(T a, T b)
{
    while (a > 0)
    {
        T t = a;
        a = b%a;
        b = t;
    }
    return b;
}

int main()
{
    int N;
    cin>>N;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    int m = A[0];
    for (int a: A)
        m = min(a, m);

    set<int> F;
    for (int a: A)
        for (int f=1; f*f<=a; f++)
            if (a%f==0)
                F.insert(f),
                F.insert(a/f);

    int ans = 0;
    for (int f: F)
        if (f<=m)
        {
            int g = 0;
            for (int a: A)
                if (a%f==0)
                    if (g==0)
                        g = a;
                    else
                        g = gcd(g, a);
            if (g==f)
                ans++;
        }
    cout<<ans<<endl;
}

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

#ifdef LOCAL
#include "debug.h"
#endif

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repi(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())

template<typename T> void umin(T &a, T b) { a = min(a, b); }
template<typename T> void umax(T &a, T b) { a = max(a, b); }

ll nxt() {
	ll x; cin >> x; return x;
}

void setIO(string s) {
	#ifndef LOCAL
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
	#endif
}

void yes() {
	cout << "YES\n";
}

void no() {
	cout << "NO\n";
}

const ll mod = 1e9 + 7;
const ll INF = 2e9;

void solve() {
	ll n = nxt();
	vll a(n); rep(i, 0, n) cin >> a[i];

	ll mn = *min_element(all(a));

	map<ll, set<ll>> multiples;
	rep(i, 0, n) {
		ll x = a[i];
		ll mxfac = sqrt(x) + 2;
		for (ll fac = 1; fac <= mxfac; fac++) {
			if (x % fac == 0) {
				multiples[fac].insert(i);
				multiples[x / fac].insert(i);
			}
		}
	}

	ll ans = 1;
	debug(multiples);
	for (auto &it : multiples) {
		if (sz(it.se) == 1) continue;
		ll fac = it.fi;
		ll g = 0;
		for (auto x : it.se) {
			g = __gcd(g, a[x]);
		}
		debug(g, fac, it.se);
		if (g == fac && g < mn) {
			ans++;
		}
	}
	cout << ans << endl;
}

int32_t main(){
	// setIO("trapped");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int T = 1;
	// cin >> T;

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


#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " "
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	LLi m;
	cin>> m;

	int fsz;
	vector<LLi> f;
	for(LLi i=1;i*i<m;i++){
		if(m%i==0) f.push_back(i);
	}
	fsz=f.size();
	if((LLi)sqrt(m)*(LLi)sqrt(m)==m) f.push_back((int)sqrt(m));//平方根が約数の場合
	rep(i, fsz) f.push_back(m/f[fsz-1-i]);

	rep(i, f.size()) cout<< f[i] <<endl;

	return 0;
}

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

int main() {
    string x;
    cin >> x;
    int n = x.find(".");
    if (n == std::string::npos) cout << x << endl;
    else {
        cout << x.substr(0, n) << endl;
    }

    return 0;
}


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

const int MOD = 1000000007;

long long modpow(long long a, long long p){
    if(p == 0)return 1;
    if(p % 2 == 1)return a * modpow(a, p - 1) % MOD;

    long long r = modpow(a, p / 2);
    return r * r % MOD;
}
long long modinv(long long a){
    return modpow(a, MOD - 2);
}

long long C(int n, int r){
    long long res = 1;
    for(int i = 1; i <= r; i++){
        res = res * (n - i + 1) % MOD;
        res = res * modinv(i) % MOD;
    }
    return res;
}

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

    int sum = 0;
    for(int i = 0; i < n; i++){
        int a;
        scanf("%d", &a);
        sum += a;
    }
    printf("%lld\n", C(m + n, sum + n));

    return 0;
}

#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return (temp*temp);
    else
        return (((x*temp))*temp);
}

//nCr % mod
const int N0 = 2e6 + 5;
ll fact[6*N0];
ll inv[6*N0],invfac[6*N0];
ll mod = 1e9 + 7;

void factorial()
{
    fact[0] = invfac[0] = fact[1] = invfac[1] = 1;
    inv[1] = 1;
    for(int i=2;i<=5*N0 + 10;i++)
    {
        fact[i] = (fact[i-1]*i)%mod;
        inv[i] = (inv[mod%i]*(mod - mod/i))%mod;
        invfac[i] = (invfac[i-1]*inv[i])%mod;
    }
}

vector<ll> primes;

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    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])
          primes.push_back(p);
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

const int N = 2e5 + 5;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,m;
    ll sum = 0;
    cin >> n >> m;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin >> x;
        sum += x;
    }
    m += n;
    sum += n;
    if(m < sum)
        return cout << 0,0;
    ll ans = 1;
    factorial();
    //cout << m << " " << sum << '\n';
    for(int i=0;i<sum;i++)
    {
        ll val = (m - i)*(inv[sum - i])%mod;
        //cout << val << "\n";
        ans = (ans * val)%mod;
    }
    cout << ans;
}