akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
		int  W,H,x,y,r;
		int flag1,flag2;
		flag1=0;flag2=0;
		cin>>W>>H>>x>>y>>r;
		if(x+r<=W&&x-r>=0)flag1=1;
		if(y+r<=H&&y-r>=0)flag2=1;
		if(flag1==1&&flag2==1)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;

		return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void) {
    int x, ans;
    scanf("%d", &x);
    if (x == 2) ans = 2;
    for (int i = 2; i <= x-1; i++) {
        if (x%i == 0) {
            int flag = 0;
            while (flag == 0) {
                x++;
                for (int j = 2; j <= x-1; j++) {
                    if (x%j == 0) break;
                    if (j == x-1) flag = 1;
                }
            }
            ans = x;
            break;
        }
    }
    printf("%d\n", x);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main() {
 int n,temp=0;
 string s;
 cin>>s;
 n=s.length();
 for(int i=0;i<n-2;i+=2)
 { int f=1;
   for(int j=0;j<(n-2-i)/2;j++)
   {
     if(s[j]!=s[(n-2-i)/2 +j ])
     {f=0;
       break;
     }
   }
   if(f)
   {temp=i;
     break;
   }
 }
 cout<<n-temp-2<<endl;

 
}

Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    double cx, cy, r, x1, y1, x2, y2;
    int q, i;
    double l1x, l1y, l2x, l2y, d, t1, t2, ax, ay, bx, by, a, bb, c, tmp;

    cx = sc.nextDouble(); cy = sc.nextDouble(); r = sc.nextDouble();
    q = sc.nextInt();

    for(i = 0;i < q;i++){
      x1 = sc.nextDouble(); y1 = sc.nextDouble();
      x2 = sc.nextDouble(); y2 = sc.nextDouble();

      l1x = x2 - x1; l1y = y2 - y1;
      l2x = x1 - cx; l2y = y1 - cy;
      a = l1x * l1x + l1y * l1y;
      bb = l1x * l2x + l1y * l2y;
      c = l2x * l2x + l2y * l2y - r * r;
      d = Math.sqrt(bb * bb - a * c);

      t1 = (-bb + d) / a;
      t2 = (-bb - d) / a;
      ax = x1 + t1 * l1x; ay = y1 + t1 * l1y;
      bx = x1 + t2 * l1x; by = y1 + t2 * l1y;

      if(ax > bx || (ax == bx && ay > by)){
        tmp = ax; ax = bx; bx = tmp;
        tmp = ay; ay = by; by = tmp;
      }

      out.println(ax + " " + ay + " " + bx + " " + by);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 24052
#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 int
#define ld              long double
#define F               first
#define S               second
#define pb              push_back
#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpi             vector <pii>
#define vpp             vector <pair<int, pii>>
#define mii             map <int, int>
#define mpi             map <pii, int>
#define spi             set <pii>
#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl
#define fast            ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

inline ll power(ll a, ll b)
{
     ll x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}
////// Variables //////
int tc;

//////////////////////////////

void solve(){
    ll n;
    cin >> n;
    ll a[n+5];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans = 0;//23
    sort(a,a+n);
    for(int i=n-1;i>=1;i--){
        int l = 0,r=i-1;
        while(l<r){
            if(a[l] + a[r] > a[i]){
                ans += (r-l);
                r--;
            }
            else{
                l++;
            }
        }
    }
    cout<<ans;
}
int32_t main(){
    fast
    cout<< setprecision(10) << fixed;
    tc=1;
    clock_t z = clock();
    //cin >> tc;
    while(tc--){
        solve();
    }
   // cerr << "Runtime: "<<((double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    
    int ans = 0;
    for (int i = a; i <= b; ++i) {
        if (c % i == 0) {
            ++ans;
        }
    }
    cout << ans << endl;    
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
using namespace std;
int n,a,b,s,ans;
int main()
{
	cin>>n>>a>>b;
	for(int i=0;i<n;i++) {
		cin>>s;
		if(s<a||s>=b) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef complex<double> P;

const double inf = 1e100;
const double pi = acos(-1);

namespace std {
  bool operator < (const P &a, const P &b) {
    if(a.real() != b.real()) return a.real() < b.real();
    return a.imag() < b.imag();
  }
}

const int MAXN = 100005;
int N;
pair<P,double> ps[MAXN];
double maxR[MAXN];

P getRotateP(P p, double rad) {
  return P(cos(rad)*p.real() - sin(rad)*p.imag(),
           sin(rad)*p.real() + cos(rad)*p.imag());
}

int main() {
  while(cin >> N && N) {
    double rad = (double)rand() / (double)RAND_MAX * 2.0 * pi;
    for(int i = 0; i < N; ++i) {
      cin >> ps[i].second >> ps[i].first.real() >> ps[i].first.imag();
      ps[i].first = getRotateP(ps[i].first, rad);
    }
    sort(ps, ps+N);
    maxR[N] = -inf;
    for(int i = N-1; i >= 0; --i) {
      maxR[i] = max(maxR[i+1], ps[i].second);
    }
    double ans = inf;
    for(int i = 0; i < N; ++i) {
      P p1 = ps[i].first;
      double r1 = ps[i].second;
      for(int j = i+1; j < N; ++j) {
        P p2 = ps[j].first;
        double r2 = ps[j].second;
        if(p2.real() - p1.real() - r1 - maxR[j] >= ans) break;
        double dist = sqrt((p1.real()-p2.real())*(p1.real()-p2.real())
                           +(p1.imag()-p2.imag())*(p1.imag()-p2.imag())) - r1 - r2;
        ans = min(ans, dist);
      }
    }
    printf("%.8f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 4388
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define YYDBG

int A[100001];
int B[100001];
int N;
int main(void) {
    int Q;
    int i,j,k;
    int clist[18];
    int tmp_result;
    int result = -1;

    memset(A, 0, sizeof(A));
    memset(B, 0, sizeof(B));

    scanf("%d\n", &N);
    for(i=0;i<N+1;i++) { 
        scanf("%d ", &(A[i]));
    }
    for(i=0;i<N;i++) { 
        scanf("%d ", &(B[i]));
    }


    long long int ans = 0;
    for(i=0;i<N;i++) {
//        printf("(%d,%d,%d) -> ", A[i], B[i], A[i+1]);
        if(A[i] <= B[i]) {
            ans+=A[i];
            B[i]-=A[i];
            A[i]=0;
            if (A[i+1] <= B[i]) {
                ans+=A[i+1];
                B[i] -= A[i+1];
                A[i+1] = 0;
            } else {
                A[i+1] -= B[i];
                ans+=B[i];
                B[i] = 0;
            }
        } else {
            ans+=B[i];
            B[i] = 0;
        }

//        printf("[%d] -> ", ans);
    }

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



Measured memory_bytes: 896
r, c = map(int, input().split())
table = []

for i in range(r):
    table.append(list(map(int, input().split())))
    table[i].append(sum(table[i]))

for i in range(r):
    print(' '.join(list(map(str, table[i]))))

row = []

for j in range(c + 1):
    rsum = 0
    for i in range(r):
        rsum += table[i][j]
    row.append(rsum)
print(' '.join(list(map(str, row))))


Measured memory_bytes: 5696
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
int32_t main(){
    fast;
    int x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    int y=x/d;
    if(y>k)
        cout<<x-k*d;
    else{
        k-=y;
        int ans;
        if(k%2)
            ans=(d-x%d);
        else
            ans=x%d;
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 K;
  cin >> K;

  v(string) lunlun{"1", "2", "3", "4", "5", "6", "7", "8", "9"};

  i64 l = 0, r = 9;
  while(r < K + 1){
    rep(i,l,r){
      for(char c = '0'; c <= '9'; c++){
        if(lunlun[i] == "" or abs(lunlun[i][lunlun[i].size() - 1] - c) <= 1){
          lunlun.push_back(lunlun[i] + c);
        }
      }
    }
    l = r;
    r = lunlun.size();
  }

  cout << lunlun[K - 1] << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N, D; cin >> N >> D;
	int cnt = 0;

	vector<vector<int>> X(N, vector<int>(D));
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < D; j++)
		{
			cin >> X[i][j];
		}
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = i+1; j <N; j++)
		{
			if (j > i) {
				double dis = 0;
				for (int k = 0; k < D; k++)
				{
					dis += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
				}
				dis = sqrt(dis);
				if (ceil(dis) == floor(dis))cnt++;
			}
		  
		}
	}
	cout << cnt << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
#include <string>
using namespace std;

int main() {
  int n, q;
  queue< pair<string, int> > tasks;
  
  cin >> n >> q;
  for (int i=0; i<n; i++) {
    pair<string, int> task;
    cin >> task.first >> task.second;
    tasks.push(task);
  }
  
  int time = 0;
  
  while (!tasks.empty()) {
    auto current = tasks.front(); tasks.pop();
    if (current.second > q) {
      time += q;
      current.second -= q;
      tasks.push(current);
    } else {
      time += current.second;
      cout << current.first << ' ' << time << endl;
    }
  }
}

Measured memory_bytes: 6300
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i++)
using namespace std;

const int maxn = 200005;
const int mod = 1000000007;
int pa[maxn], c[maxn], w[maxn], rk[maxn], fac[maxn];
int n, X, Y, sz, sum, tmp, ans = 1;
map<int,int> cnt[maxn];
vector<int> p[maxn];

inline int power(int x, int p) {
	int res = 1;
	while (p) {
		if (p & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod; p >>= 1;
	}
	return res;
}

inline int getpa(int x) {
	return pa[x] == x ? x : pa[x] = getpa(pa[x]);
}

inline bool cmp(int a, int b) {
	return w[a] < w[b];
}

int main() {
	scanf("%d%d%d", &n, &X, &Y);
	fac[0] = 1;
	rep (i, 1, n)
		fac[i] = 1ll * fac[i-1] * i % mod;
	rep (i, 1, n) {
		scanf("%d%d", &c[i], &w[i]);
		p[c[i]].push_back(i);
		rk[i] = pa[i] = i;
	}
	rep (i, 1, n) if (p[i].size() >= 2) {
		sort(p[i].begin(), p[i].end(), cmp);
		sz = p[i].size();
		rep (j, 1, sz - 1)
			if (w[p[i][0]] + w[p[i][j]] <= X) {
				pa[getpa(p[i][j])] = getpa(p[i][0]);
			}
	}
	sort(rk+1, rk+n+1, cmp);
	int cur = 0;
	rep (i, 2, n) {
		if (w[rk[1]] + w[rk[i]] <= Y && c[rk[1]] != c[rk[i]]) 
			pa[getpa(rk[i])] = getpa(rk[1]);
		if (!cur && c[rk[i]] != c[rk[1]]) cur = i;
	}
	if (cur) {
		rep (i, 1, n)
			if (w[rk[cur]] + w[rk[i]] <= Y && c[rk[cur]] != c[rk[i]]) 
				pa[getpa(rk[i])] = getpa(rk[cur]);
	}
	rep (i, 1, n) 
		cnt[getpa(i)][c[i]]++;
	rep (i, 1, n) if (pa[i] == i) {
		sum = 0; tmp = 1;
		for (auto x : cnt[i]) {
			sum += x.second;
			tmp = 1ll * tmp * power(fac[x.second], mod - 2) % mod;
		}
		ans = 1ll * ans * fac[sum] % mod;
		ans = 1ll * ans * tmp % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 31872
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def count_unique_pairs(n):
    return n * (n - 1) // 2

def main():
    GI()
    arr = LGIS()

    d = {}
    for x in arr:
        d[x] = d.get(x, 0) + 1

    tot = sum(count_unique_pairs(v) for v in d.values())
    
    for x in arr:
        print(tot - count_unique_pairs(d[x]) + count_unique_pairs(d[x]-1))

def main():
    GI()
    arr = LGIS()

    d = {}
    for x in arr:
        d[x] = d.get(x, 0) + 1

    tot = sum(count_unique_pairs(v) for v in d.values())
    
    for x in arr:
        print(tot - d[x] + 1)

main()

Measured memory_bytes: 87756
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, Q; cin >> N >> Q;
    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];

    while(Q--) {
        long long x; cin >> x;

        int right = 0;
        long long sum = 0, res = 0;;
        for(int left = 0; left < N; ++left) {
            while(right < N && sum + A[right] <= x) sum += A[right++];
            
            res += (right - left);

            if(left == right) ++right;
            else sum -= A[left];
        }
        
        cout << res << endl;
    }
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define itn int
int q[1500][1500];
bool date[1500][1500];
signed main(){
    int a,b,m=0;
    cin>>a>>b;
    for(int i=0;i<a;i++){
	for(int j=0;j<b;j++) cin>>date[i][j];
    }
    for(int i=0;i<a;i++){
	for(int j=0;j<b;j++){
	    if(date[i][j]==0){
		if(i==0||j==0) q[i][j]=1;
		else q[i][j]=min(q[i-1][j],min(q[i][j-1],q[i-1][j-1]))+1;
		m=max(m,q[i][j]);
	    }
	}
    }
    cout<<m*m<<"\n";
}



Measured memory_bytes: 18908
#include "bits/stdc++.h"

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<long> as(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
    }
    long ans = 0;
    vector<int> vst(n);
    for (int d = 1; d <= (n - 1) / 2; d++)
    {
        long res = 0;
        fill(vst.begin(), vst.end(), 0);
        for (int k = 0; (k + 1) * d < n; k++)
        {
            int l = k * d, r = n - 1 - l;
            if (vst[l] || vst[r] || l == r)
                break;
            vst[l] = vst[r] = 1;
            res += as[l] + as[r];
            ans = max(ans, res);
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    cerr << "\"努力不足ですね！\"" << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
using namespace std;
int main(){
int t , AC = 0 , WA = 0 , TLE = 0 , RE = 0;
cin >> t;
string x;
while(t--){
cin >> x;
if(x == "AC")AC++;
else if(x == "WA") WA++;
else if(x == "TLE")TLE++;
else if(x == "RE")RE++;
}
/*
AC x 3
WA x 1
TLE x 2
RE x 0
*/
cout << "AC" << " " << "x" << " " << AC <<endl;
cout << "WA" << " " << "x" << " " << WA <<endl;
cout << "TLE" << " " << "x" << " " << TLE <<endl;
cout << "RE" << " " << "x" << " " << RE <<endl;

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

Measured memory_bytes: 3228
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const long long MOD=1004535809;
const long long LMOD=154590409516822759;
//const long long LMOD=1000000007;
#define Fi first
#define Se second
#define P2 pair
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define Cb make_pair
#define ll long long
#define Ull unsigned long long
#define Sf scanf
#define Pf printf
#define Pb push_back
#define Psh push
#define Stc stack
#define Vct vector
#define Ret return
#define Re0 return 0
#define Sz size
#define Is insert
#define Que queue
#define Emp empty
#define Fro front
#define Rv reverse
#define Er erase
#define Bg begin
#define Srt sort
#define Pq priority_queue
#define Ins insert
#define Ite iterator
#define Cou count
#define Cot continue
#define Beg begin
vector<int>v[100005];
int dis[3][100005];
int len[100005];
int n;
int ypa1(int k,int p)
{
	for(int i=0;i<v[k].Sz();i++)
	{
		if(v[k][i]==p)continue;
		dis[0][v[k][i]]=dis[0][k]+1;
		ypa1(v[k][i],k);
	}
	return 0;
}
int ypa2(int k,int p)
{
	len[k]=1;
	for(int i=0;i<v[k].Sz();i++)
	{
		if(v[k][i]==p)continue;
		dis[1][v[k][i]]=dis[1][k]+1;
		len[k]=max(len[k],ypa2(v[k][i],k)+1);
	}
	return len[k];
}
int main()
{
	int n,u,vt;
	Sf("%d%d%d",&n,&u,&vt);
	int x,y;
	for(int i=1;i<n;i++)
	{
		Sf("%d%d",&x,&y);
		v[x].Pb(y);
		v[y].Pb(x);
	}
	ypa1(u,0);
	ypa2(vt,0);
	int mx=0;
	for(int i=1;i<=n;i++)
	{
		if(dis[0][i]<dis[1][i])
		{
			//cout<<i<<endl;
			mx=max(mx,dis[0][i]+len[i]-((dis[1][i]-dis[0][i]==2)?0:1));
		}
	}
	Pf("%d",mx);
	return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string S;
  cin>>S;
  
  deque<char> ans;
  
  
  for(int i=0;i<S.size();i++){
    if(S[i]=='0'){
      ans.push_back('0');
    }
    else if(S[i]=='1'){
      ans.push_back('1');
    }
    else if(S[i]=='B'){
      if(!(ans.empty())){
        ans.pop_back();
      }
    }
  }
  
  while(!(ans.empty())){
    cout<<ans.front();
    ans.pop_front();
  }
}

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

vector<P> prime_factorize(ll n) {
    vector<P> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
  ll n,p,ans = 1;
  cin >> n >> p;
  vector<P>factor = prime_factorize(p);
  rep(i,0,factor.size()){
    rep(j,0,factor[i].second/n) ans *= factor[i].first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
#https://atcoder.jp/contests/tenka1-2019-beginner/submissions/5063821
from itertools import accumulate
N=int(input())
S=input()
black=[0]*N
white=[0]*N

for i,s in enumerate(S):
    if s=="#":
        black[i]=1
    elif s==".":
        white[i]=1
#累積和を取る
black =[0]+black
black =list(accumulate(black))
white =[0]+white[::-1]
white =list(accumulate(white))[::-1]

ans =[]

for i in range(N+1):
    ans.append(black[i]+white[i])
print(min(ans))

Measured memory_bytes: 29176
from math import sqrt

N, M = map(int, input().split())

result = 1
for i in range(1, int(sqrt(M)) + 1):
    if M % i != 0:
        continue
    t = M // i
    if t >= N:
        result = max(result, i)
    if M // t >= N:
        result = max(result, t)
print(result)


Measured memory_bytes: 3060
// D - Brick Break
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0, tmp = 0;
  string s, t;
  cin >> n;
  vlli d(n);
  rep(i, 0, n)
  {
    cin >> d[i];
  }
  tmp = 1;
  rep(i, 0, n)
  {
    if (d[i] != tmp)
    {
      ans++;
    }
    else
    {
      tmp++;
    }
  }
  // cout << ans << endl;
  // cout << tmp << endl;
  if (ans == n)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << ans << endl;
  }
}

Measured memory_bytes: 1792
n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(n)]
B.sort(key = lambda x:x[0])
R.sort(key = lambda x:x[1], reverse = True)

#print(R)
ans = 0
for bx,by in B:
 #   print(bx,by)
    for i in range(len(R)):
        if R[i][0] < bx and R[i][1] < by:
  #          print(R[i],"とマッチ")
            del R[i]
            ans += 1
            break
print(ans)



Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
   int a;
   scanf("%d",&a);
   if(a==25){                                                                   
      printf("Christmas\n",a);}
   else if(a==22){
      printf("Christmas Eve Eve Eve\n",a);}
   else if(a==23){
      printf("Christmas Eve Eve\n",a);}
   else if(a==24){
      printf("Christmas Eve\n",a);}
   return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
const int NMAX = 1000010;
long long int fac[NMAX+1];
long long int ifac[NMAX+1];
const long long int MOD = 998244353;
int main(){
    vector<long long int> fac(NMAX+1);
    vector<long long int> ifac(NMAX+1);
    fac[0] = 1;
    for(long long int i=1;i<=NMAX;++i){
        fac[i] = fac[i-1] * i % MOD;
    }
    long long tmp = 1;
    long long e = MOD-2;
    for(int i=62;i>=0;--i){
        tmp = tmp*tmp % MOD;
        if(e&(1LL<<i)){
            tmp = tmp * fac[NMAX] % MOD;
        }
    }
    //cout<<fac[NMAX]<<" "<<tmp<<" "<<fac[NMAX]*tmp%MOD<<endl;
    ifac[NMAX] = tmp;
    for(long long int i=NMAX;i>=1;--i){
        ifac[i-1] = ifac[i] * i % MOD; 
    }
    long long int n;
    long long int a;
    long long int b;
    long long int k;
    cin>>n>>a>>b>>k;
    long long ans = 0;
    for(int i=0;i<=n;++i){
        if( (k-a*i)>=0 && (k-a*i)%b==0){
            long long x = i;
            long long y = (k-a*i)/b;
            if(y>=0 && y<=n)
                ans = (ans + fac[n]*ifac[x] % MOD *ifac[n-x] %MOD *fac[n] %MOD * ifac[y] %MOD* ifac[n-y] %MOD ) % MOD;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 15872
from collections import deque

n = int(input())
e = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)
l = sorted(list(map(int,input().split())),reverse=True)
ans = [-1]*n

q = deque([])
q.append(0)
ans[0] = l[0]
now = 1
while q:
    b = q.popleft()
    for nex in e[b]:
        if ans[nex] == -1:
            ans[nex] = l[now]
            now += 1
            q.append(nex)
count = 0
for j in range(n):
    for k in e[j]:
        count += min(ans[j],ans[k])
print(count//2)
print(*ans)






Measured memory_bytes: 12092
#include <stdio.h>
#include <stdlib.h>

  int main(void){

        int a;
	scanf("%d",&a);


	if(a < 1 || 3000 < a){
	  printf("存在しません\n");
	  exit(0);

	}else if(a < 1200){

	   printf("ABC\n");

	}else if(a <= 3000){

	   printf("ARC\n");

}

}





Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

class mint {
public:
    long long x;
    constexpr mint(long long x=0) : x((x%mod+mod)%mod) {}
    constexpr mint operator-() const { 
      return mint(-x);
    }
    constexpr mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i,n) {
    cin >> a[i];
    if (i == 0) b[i] = a[i];
    else b[i] = b[i-1]+a[i];
  }
  mint ans = 0;
  rep(i,n) {
    ans += (b[n-1]-b[i])%mod * a[i]%mod;
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 6416
N, K = map(int, input().split())
hs = list(map(int, input().split()))

dp = [float("inf")]*N

dp[0] = 0
for i in range(N-1):
    for k in range(1, K+1):
        if i+k >= N:
            break

        dp[i+k] = min(dp[i+k], dp[i]+abs(hs[i+k]-hs[i]))
        #print(dp)
print(dp[N-1])


Measured memory_bytes: 55008
#include<bits/stdc++.h>
using namespace std;

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e9
#define MOD 1000000007

int main()
{

   ll n, X;
   cin >> n >> X;
   vector<ll> v;
   v.pb(X);
   for(ll i = 0; i < n; i++)
   {

       ll x;
       cin >> x;
       v.pb(x);
   }
   sort(v.begin(), v.end());
   vector<ll> ds;
   for(ll i = 1; i < v.size(); i++)
   {

       ll y = v[i]-v[i-1];
       ds.pb(y);
   }
   ll ans = 0;
   for(ll i = 0; i < ds.size(); i++)
   {

       ans = __gcd(ans,ds[i]);
   }
   cout << ans;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
  ll n;
  cin>>n;
  ll a,b;
  cin>>a>>b;
  ll flag=0;
  for(ll i=a;i<=b;i++)
  {
    if(i%n==0)
    {
      flag=1;
      break;

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

Measured memory_bytes: 3636
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long[] b = new long[n];
    for (int i=0;i<n;i++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    sc.close();
    long ans = 0;
    for (int i=n-1;i>=0;i--){
      ans += (b[i]-(a[i]+ans)%b[i])%b[i];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 87756
/*Lower_Rating*/
/*dianfenzhi*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<bitset>
#include<set>
using namespace std;

#define LL long long
#define DB double
#define MOD 998244353
#define Pr pair<int,int>
#define X first
#define Y second
#define MAXN (1<<18)
#define eps 1e-10
#define INF 2147483647
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}
int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(LL a,int b){return a*b%MOD;}
int fst_pow(int a,int b){
    int res=1;
    while(b){
        if(b&1)res=mul(res,a);
        a=mul(a,a);
        b>>=1;
    }return res;
}

int inv2;
int FWT(int len,int *a,int x){
    for(int i=1;i<len;i<<=1)
        for(int j=0;j<len;j+=(i<<1))
            for(int k=0;k<i;k++){
                int X=a[j+k],Y=a[i+j+k];
                a[j+k]=add(X,Y),a[i+j+k]=dec(X,Y);
                if(x==-1)a[j+k]=mul(a[j+k],inv2),a[i+j+k]=mul(a[i+j+k],inv2);
            }
}

int n,m,p[MAXN+5],f[MAXN+5],sum;
int main(){
    n=read(),m=1<<n,inv2=(MOD+1)>>1;
    for(int i=0;i<m;i++)
    p[i]=read(),sum=add(sum,p[i]);
    sum=fst_pow(sum,MOD-2);
    for(int i=0;i<m;i++)p[i]=mul(p[i],sum);
    p[0]=dec(p[0],1),f[0]=m-1;
    for(int i=1;i<m;i++)f[i]=MOD-1;
    FWT(m,p,1),FWT(m,f,1);
    for(int i=1;i<m;i++)f[i]=mul(f[i],fst_pow(p[i],MOD-2));
    f[0]=0;FWT(m,f,-1);
    for(int i=0;i<m;i++)
    printf("%d\n",dec(f[i],f[0]));
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;

enum DATE{ FAST, SAME, LATE };
DATE realcomp(const string& a, const string& b, int idx)
{
  if(idx == 10) return(SAME);
  if(a[idx] == b[idx]) return(realcomp(a, b, idx + 1));
  if(a[idx] < b[idx]) return(FAST);
  return(LATE);
}
DATE DateCompare(const string& a, const string& b)
{
  return(realcomp(a, b, 0));
}
bool Compare(const string& a, const string& b) {
  return(a == "*" || b == "*" || b.find(a) != string::npos);
}


int main()
{
  int N, Q;
  char buffer[256];
  char t[256], a[256], d[256];
  int yy, mm, dd;

  cin >> N;
  vector< string > title(N), author(N), date(N);
  for(int i = 0; i < N; i++) {
    cin >> title[i] >> author[i] >> date[i];
  }
  cin >> Q;
  for(int i = 0; i < Q; i++) {
    if(i) cout << endl;
    
    string Qtitle, Qauthor, Qfrom, Qto;
    cin >> Qtitle >> Qauthor >> Qfrom >> Qto;
    for(int j = 0; j < N; j++) {
      if(Compare(Qtitle, title[j]) &&
         Compare(Qauthor, author[j]) &&
         (Qfrom == "*" || DateCompare(Qfrom, date[j]) != LATE) &&
         (Qto   == "*" || DateCompare(Qto  , date[j]) != FAST)){
        cout << title[j] << endl;
      }
    }
  }

  return(0);
}

Measured memory_bytes: 1240
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

    ll ans = 0, x;
    REP(i,n){
        ll a;
        scanf("%lld", &a);
        if (i == 0){
            ans += a-1;
            x = 2;
            continue;
        }
        if (a == x) x++;
        else if (a > x){
            ans += (a-1)/x;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int A[3];

void solve() {
	rep(i, 0, 3) cin >> A[i];
	sort(A, A + 3);
	cout << A[0] + A[1] + A[2] * 10 << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll inf=1e18;
const long double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
const double pi=acos(-1);

ll wu[103040];

int main(){
    TB
    ll x,y,a,b,c,g;
    cin>>x>>y>>a>>b>>c;
    priority_queue<ll,vector<ll>,greater<ll> > hong;
    priority_queue<ll,vector<ll>,greater<ll> > lv;
    fd(a){
        cin>>g;
        hong.push(g);
        if(hong.size()>x) hong.pop();
    }
    fd(b){
        cin>>g;
        lv.push(g);
        if(lv.size()>y) lv.pop();
    }
    fd(c) cin>>wu[i];
    sort(wu,wu+c);
    int flag=c-1;
    while(flag>=0){
        if(lv.top()>=wu[flag]&&hong.top()>=wu[flag]) break;
        if(lv.top()>hong.top()){
            hong.pop();hong.push(wu[flag]);
        }else{
            lv.pop();lv.push(wu[flag]);
        }
        flag--;
    }
    ll ans=0;
    while(!lv.empty()){
        ans+=lv.top();
        lv.pop();
    }while(!hong.empty()){
        ans+=hong.top();
        hong.pop();
    }
    cout<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 2548
#create date: 2020-07-05 21:00

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    print(0 if n % 1000 == 0 else 1000 - (n%1000))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9104
#include <iostream>
#include <map>
#include <array>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>

#define forn(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define eb emplace_back
#define pb push_back

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef long long i64;

void solve_a() {
  int n;
  cin >> n;
  map<i64, int> M;
  M[0] = 1;
  i64 ans = 0, s = 0;
  forn(i, n) {
    int x;
    cin >> x;
    ans += M[s += x] += 1;
    ans -= 1;
  }
  cout << ans << endl;
}

int main() {
#ifdef HOME
  freopen("input.txt", "rt", stdin);
#endif
  solve_a();
  return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fi first
#define se second
using ll=long long int;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<ll>t(n),a(n);
	rep(i,n)cin>>t[i]>>a[i];
	ll x=1,y=1;
	rep(i,n){
		ll maxv=max(x/t[i]+1-(x%t[i]==0),(y/a[i])+1-(y%a[i]==0));
		t[i]*=maxv;
		a[i]*=maxv;
		x=t[i];y=a[i];
	}
	cout<<x+y<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    using ll = long long;
    vector<ll> a(3*n);
    for(int i = 0; i < 3*n; i++)
    {
        cin >> a[i];
    }

    vector<ll> s(2*n+1);
    vector<ll> e(2*n+1);
    ll tmp = 0;
    priority_queue<ll, vector<ll>, greater<ll>> sa;
    priority_queue<ll> ea;
    for(int i = 0; i < n; i++)
    {
        tmp += a[i];
        sa.push(a[i]);
    }
    s[n] = tmp;
    for(int i = n+1; i <= 2*n; i++)
    {
        ll cand = sa.top();
        if(cand < a[i-1])
        {
            s[i] = s[i-1] + a[i-1] - cand;
            sa.pop();
            sa.push(a[i-1]);
        }
        else
        {
            s[i] = s[i-1];
        }
    }
    tmp = 0;
    for(int i = 0; i < n; i++)
    {
        tmp += a[3*n-1-i];
        ea.push(a[3*n-1-i]);
    }
    e[n] = tmp;
    for(int i = n+1; i <= 2*n; i++)
    {
        ll aa = a[3*n-i];
        ll cand = ea.top();
        if(cand > aa)
        {
            e[i] = e[i-1] + aa - cand;
            ea.pop();
            ea.push(aa);
        }
        else
        {
            e[i] = e[i-1];
        }
    }
  
    ll ans = -1e15;
    for(int i = n; i <= 2*n; i++)
    {
        ans = max(ans, s[i] - e[3*n-i]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 8052
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
r = range

n = int(input())
a = np.array(list(map(int, input().split())))

ret = 0
i = 0
while i < len(a):
    j = i
    while j < n - 1 and a[j] <= a[j+1]:
        j += 1
    h = i
    while h < n - 1 and a[h] >= a[h+1]:
        h += 1
#    print(i, j, h)
    i = max(h, j) + 1
    ret += 1

print(ret)


Measured memory_bytes: 23116
#include<iostream>
#include<string>

using namespace std;

int main(void){
  string s,t;
  cin >> s >> t;
  int count = 0;
  
  for(int i = 0; i < s.size(); i++){
   if(s[i] != t[i])
    count++;
  }
  
  cout << count;
  
  

}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << #x << "=" << x << "]" << '\n';
#define deb2(x,y) cout << "[" << #x << "=" << x << "] [" << #y << "=" << y << "]" << '\n';
#define deb3(x,y,z) cout << "[" << #x << "=" << x << "] [" << #y << "=" << y << "] [" << #z << "=" << z << "]" << '\n';

const int N=2e5+7;

void solve(){
	int n; cin>>n;
	int a[n];
	vector<int> v(n+1,0);
	for(int i=0 ; i<n ; i++) cin>>a[i],++v[a[i]];
	vector<int> lol(n+1,0);
    //for(int i=1 ; i<=n ; i++) cout<<v[i]<<' ';LOL
	int cnt=0;
        for(int i=1 ; i<=n ; i++){
		if(v[i]>=2) cnt+=max(0LL,((v[i]-1)*(v[i]))/2);
	}
    
    //for(int i=1 ; i<=n ; i++) cout<<v[i]<<' ';LOL
	
    
    for(int i=0 ; i<n ; i++){
		cout<<cnt-v[a[i]]+1;LOL
	}
}

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

Measured memory_bytes: 7928
/* Bubble Sort */
#include <iostream>
using namespace std;

inline void swap(int *a, int *b) {
  int c = *a;
  *a = *b;
  *b = c;
}

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

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - i - 1; j++) {
      if (nums[j] > nums[j + 1]) {
        swap(&nums[j], &nums[j + 1]);
        cnt++;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << nums[i];
    if (i != n - 1) cout << " ";
  }
  cout << endl << cnt << endl;
}


Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
	int A, B;
	scanf("%d %d", &A, &B);
	
	if (A >= B+1){
		printf("%d", 2*A-1);
	}
	
	else if (A+1 <= B){
		printf("%d", 2*B-1);
	}
	
	else{
		printf("%d", A+B);
	}
	
	return 0;
}

Measured memory_bytes: 128
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a(), k = o.a();
  var x = o.l();
  var ans = 9e9;
  var u, v;
  if(x[0] >= 0)return x[k-1];
  if(x[n-1] <= 0)return -x[n-k];
  for(var i = 0; i < n; i++){
    if(i + k <= n){
      u = Math.abs(x[i]) * 2 + Math.abs(x[i+k-1]);
      v = Math.abs(x[i]) + Math.abs(x[i+k-1]) * 2;
      ans = Math.min(ans, u, v);
    }
    if(i - k >= 0){
      u = Math.abs(x[i]) * 2 + Math.abs(x[i-k+1]);
      v = Math.abs(x[i]) + Math.abs(x[i-k+1]) * 2;
      ans = Math.min(ans, u, v);
    }
  }
  return ans;
}

Measured memory_bytes: 21708
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    def factorize(n):
        ret = {}
        d = 2
        mx = int(n ** 0.5) + 1
        while d < mx:
            if n % d == 0:
                ret[d] = 0
            while n % d == 0:
                ret[d] += 1
                n //= d
            d += 1
        if n > 1:
            if n not in ret:
                ret[n] = 1
            else:
                ret[n] += 1
        return ret
    divs = {}
    cur = 1
    ret = 0
    for val in A:
        facs = factorize(val)
        tmp = 1
        for k, cnt in facs.items():
            if not k in divs:
                divs[k] = 0
            if divs[k] < cnt:
                tmp *= k ** (cnt - divs[k])
                divs[k] = cnt
        cur *= tmp
        ret *= tmp
        ret += cur // val
        ret %= MOD
        #print(tmp, cur)
        #print(divs)
        #print(ret)
        #print('-------')
    print(ret)
    return ret

def solve_(N: int, A: "List[int]"):
    def gcd(a, b):
        return a if b == 0 else gcd(b, a % b)
    g = A[0]
    for v in A:
        tmp = gcd(g, v)
        g = g * v // tmp
    ret = 0
    for v in A:
        ret += g // v
        ret %= MOD
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 47196
//written by NewbieChd
#include <cstdio>
#include <cctype>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 103;
int n, m, k[maxN], s[maxN][maxN];
bool p[maxN], f[maxN];

int dfs(int x) {
    if (x > n) {
        int i, j;
        bool flag;
        for (i = 1; i <= m; ++i) {
            flag = 0;
            for (j = 1; j <= k[i]; ++j)
                flag ^= f[s[i][j]];
            if (flag ^ p[i])
                return 0;
        }
        return 1;
    }
    int o = 0;
    f[x] = 1, o += dfs(x + 1), f[x] = 0, o += dfs(x + 1);
    return o;
}

int main() {
    int i, j;
    n = read(), m = read();
    for (i = 1; i <= m; ++i) {
        k[i] = read();
        for (j = 1; j <= k[i]; ++j)
            s[i][j] = read();
    }
    for (i = 1; i <= m; ++i)
        p[i] = read();
    printf("%d\n", dfs(1));
    return 0;
}


Measured memory_bytes: 128