akhauriyash/Code-Regression huggingface dataset:
import sys

H,W=map(int,next(sys.stdin).split())

xs=[[0]*(W+2) for _ in range(H+2)]
ys=[[0]*(W+2) for _ in range(H+2)]
for i in range(1,H+1):
    row=next(sys.stdin)
    for j in range(1,W+1):
        if row[j-1]!='.': continue
        xs[i][j]=1+xs[i][j-1]
        ys[i][j]=1+ys[i-1][j]

ans=0
for i in range(H,0,-1):
    for j in range(W,0,-1):
        if xs[i][j]==0: continue
        x=xs[i][j]=max(xs[i][j],xs[i][j+1])
        y=ys[i][j]=max(ys[i][j],ys[i+1][j])
        ans=max(ans,x+y-1)

print(ans)


Measured memory_bytes: 137136
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};


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

    char c;
    cin>>c;
    cout<<(char)(c+1)<<endl;
}


Measured memory_bytes: 256
import sys

inf = float("inf")

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

mod = 10**9+7

def sumXOR(arr, n):
    sum = 0
    for i in range(0, 64):

        #  Count of zeros and ones
        zc = 0
        oc = 0

        # Individual sum at each bit position
        idsum = 0
        for j in range(0, n):
            if (arr[j] % 2 == 0):
                zc = zc + 1

            else:
                oc = oc + 1
            arr[j] = arr[j]//2

            # calculating individual bit sum
        idsum = oc * zc * (1 << i)

        # final sum
        sum = sum + idsum
        sum%=mod

    return sum

n = int(input())
Arr = get_array()
ans = sumXOR(Arr,n)
ans %= mod
print(ans)

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

int main(){
	int a, b;
	cin >> a >> b;
	if(a <= b){
		rep(i, b){
			cout << a;
		}
		cout << endl;
	}else if(b < a){
		rep(i, a){
			cout << b;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int w, h; char c;
	cin >> w >> h >> c;
	vector<string> s(h, string(w, '.'));
	rep(i, w) s[0][i] = s[h - 1][i] = '-';
	rep(i, h) s[i][0] = s[i][w - 1] = '|';
	s[0][0] = s[0][w - 1] = s[h - 1][0] = s[h - 1][w - 1] = '+';
	s[h / 2][w / 2] = c;
	rep(i, h) cout << s[i] << endl;
	return 0;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>

using namespace std;

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

    if(m*10000<n){
        printf("-1 -1 -1");
        return 0;
    }
    if(m*1000>n){
        printf("-1 -1 -1");
        return 0;
    }
    if(n%1000!=0){
        printf("-1 -1 -1");
        return 0;
    }
    for(int i=0;i<=m;i++)
     for(int j=0;j<=m;j++)
      for(int k=0;k<=m,i+j+k<=m;k++)
       {
            if(i+j+k==m && i*1000+j*5000+k*10000==n)
            {
                printf("%d %d %d",k,j,i);
                return 0;   
            }
       }
    printf("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 10003;
ll n,d;
string k;
ll dp[N][2][103];
ll solve(ll i,bool small,ll m)
{
    if(dp[i][small][m] != -1) return dp[i][small][m];
    
    if(i == n)
        return dp[i][small][m] = (m == 0 ? 1 : 0);
    
    ll res = 0;
    ll limit = (small ? 9 : k[i] - '0');
    for(ll use = 0;use <= limit;use += 1)
        res = (res + solve(i + 1,(use < k[i] - '0' ? 1 : small),(m + use) % d)) % mod;
    
    return dp[i][small][m] = res;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>k>>d;
    n = k.length();
    cout<<(solve(0,0,0) - 1 + mod) % mod;
    return 0;
}

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

int calc_sat(int D, int N, vector<int> c, vector<vector<int>> s, vector<int> t) {
	vector<int> last(N,-1);
	int sat = 0;  // 満足度
	rep(d,D) {
		last[t[d]] = d;
		sat += s[d][t[d]];
		rep(i,N) {
			sat -= c[i] * (d-last[i]);
		}
	}
	return sat;
}

int main() {
	clock_t start = clock();

	int D;
	cin >> D;
	const int N = 26; // コンテストの種類
	vector<int> c(N);
	rep(i,N) cin >> c[i];
	vector<vector<int>> s(D, vector<int>(N));
	rep(i,D) rep(j,N) cin >> s[i][j];

	vector<int> t(D); // 開催するコンテスト

	int c_sum = 0;
	rep(i,N) c_sum += c[i];

	// 初期解
	/*
	if (c_sum>0) {
		rep(i,D) {
			int r = rand() % c_sum;
			int now_c_sum = 0;
			rep(j,N) {
				now_c_sum += c[j];
				if (r<=now_c_sum) {
					t[i] = j;
					break;
				}
			}
		}
	}
	else {
		rep(i,D) t[i] = rand() % 26;
	}
	*/
	rep(i,D) t[i] = rand() % 26;

	int sat = calc_sat(D, N, c, s, t);

	// 改善
	double e_time;
	e_time = (double)(clock() - start) / CLOCKS_PER_SEC;
	vector<int> t_best(D);
	rep(i,D) t_best[i] = t[i];

	while(e_time <= 1.95) {
		int new_d, new_q;
		new_d = rand() % D;
		new_q = rand() % N;
		int old = t[new_d];
		t[new_d] = new_q;
		int new_sat = calc_sat(D, N, c, s, t);
		if (new_sat > sat) {
			sat = new_sat;
			rep(i,D) t_best[i] = t[i];
		}
		else {
			// 解が悪化しても1%の確率で採用
			if (rand()%100>=2) {
				t[new_d] = old;
			}
		}
		e_time = (double)(clock() - start) / CLOCKS_PER_SEC;
	}


	// 出力
	rep(i,D) {
		printf("%d\n", t_best[i]+1);
	}

	return 0;
}


Measured memory_bytes: 3892
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        float x[]=new float[n];
        float sum=0;
        for(int i=0; i<n; i++){
          x[i]=sc.nextFloat();
          sum+=x[i];
        }
        float p=Math.round(sum/n);
        float hp[]=new float[n];
        float ans=0;
        for(int j=0; j<n; j++){
          hp[j]=(x[j]-p)*(x[j]-p);
          ans+=hp[j];
        }
        //double d=fl.doubleValue(ans);
        //int s=fl.intValue(d);
        System.out.print(Math.round(ans));
        sc.close();
    }
}


Measured memory_bytes: 23380
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    x1, y1, x2, y2 = f()
    
    x3 = x2 + (y1 - y2)
    y3 = y2 + (x2 -x1)
    

    x4 = x1  + (y1 - y2)
    y4 = y1 - (x1-x2)


    print(x3, y3, x4, y4)


solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    ll n;
    cin >> n;
    ll v = 1;
    rep(i, n) {
        v = (v * (i + 1)) % (1000000007);
    }
    put(v)
    return 0;
}

Measured memory_bytes: 3568
s = gets.chomp.split("")
len = s.length
wi = -1
cnt = 0
len.times do |i|
  if s[len-1-i] == "B" && wi != -1
    cnt += wi - (len-1-i)
    wi -= 1
  elsif s[len-1-i] == "W" && wi == -1
    wi = len-1-i
  end
end
puts cnt

Measured memory_bytes: 30680
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans;
    if(a > b) ans = 0;
    else if(n == 1) {
        if(a == b) ans = 1;
        else ans = 0;
    } else {
        ans = (a + b * (n - 1)) - (b + a * (n - 1)) + 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long gdc(long a, long b)
{
    long temp;
    for(;b>0;)
    {
        temp=b;
        b=a%b;
        a=temp;
    }
    return a;

}
int main()
{
    long a,b,gcom,i,j,k,c=1,l=0,m=0,n=0;
    scanf("%ld%ld",&a,&b);
    gcom=gdc(a,b);
    for(i=2;gcom>= i*i;)
    {
        for(j=0;gcom%i==0;j++)
            gcom/=i;
            if(j>0)
                c++;
            if(i==2)
                i++;
            else i=i+2;
    }
    if(gcom>=i)
        c++;
    printf("%ld\n",c);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

int main(){
    char b;
    cin>>b;
    switch(b){
        case 'A':
            cout<<'T'<<endl;
            break;
        case 'T':
            cout<<'A'<<endl;
            break;
        case 'C':
            cout<<'G'<<endl;
            break;
        case 'G':
            cout<<'C'<<endl;
            break;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
  cin >> vec.at(i);
  }
  
  int x = 0;
  for(int i=0; i<N; i++){
   if(i%2 == 0){
     if((vec.at(i) % 2) == 1){
      x++; 
     }
   }
  }
  
  cout << x << endl;
}


Measured memory_bytes: 3600
using System;
using System.Linq;
using System.Collections.Generic;

class Program {
  static void Main(string[] args) {
    int[] hw = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray();
    int h = hw[0], w = hw[1];

    char[][] a = new char[h][];

    var q = new Queue<Tuple<int, int, int>>();

    for (int i = 0; i < h; i++) {
      a[i] = Console.ReadLine().ToCharArray();
      for(int j = 0; j < w; j++) {
        if (a[i][j] == '#') {
          q.Enqueue(Tuple.Create(i, j, 1));
        }
      }
    }

    int ans = 0;

    while (q.Count > 0) {
      var t = q.Dequeue();
      var i = t.Item1;
      var j = t.Item2;
      var c = t.Item3;
      var qc = q.Count;

      if (i > 0 && a[i - 1][j] == '.') {
        a[i - 1][j] = '#';
        q.Enqueue(Tuple.Create(i - 1, j, c + 1));
      }

      if (i < h - 1 && a[i + 1][j] == '.') {
        a[i + 1][j] = '#';
        q.Enqueue(Tuple.Create(i + 1, j, c + 1));
      }

      if (j > 0 && a[i][j - 1] == '.') {
        a[i][j - 1] = '#';
        q.Enqueue(Tuple.Create(i, j - 1, c + 1));
      }

      if (j < w - 1 && a[i][j + 1] == '.') {
        a[i][j + 1] = '#';
        q.Enqueue(Tuple.Create(i, j + 1, c + 1));
      }

      if (qc != q.Count && c > ans) {
        ans = c;
      }
    }

    Console.WriteLine(ans);
  }
}


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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<bool> dp(100001, false);
	dp[0] = true;
	for(int i=1;i<=100000;i++){
		for(auto x:{100, 101, 102, 103, 104, 105}){
			if(i-x >= 0){
				dp[i] = (dp[i] | dp[i-x]);
			}
		}
	}
	if(dp[n]) cout << "1\n";
	else cout << "0\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	bool A = true;
	bool B = true;
	for(int i = 0;i < N;i++) {
		if(vec.at(i) != i + 1) {
			int cnt = vec.at(vec.at(i) - 1);
			vec.at(vec.at(i) - 1) = vec.at(i);
			vec.at(i) = cnt;
			break;
		}
	}
	for(int i = 0;i < N;i++) {
		if(vec.at(i) != i + 1) {
			A = false;
		}
	}
	if(A == true) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){

  int n;
  cin>>n;
  if(n%10 == 9){
    cout<<"Yes"<<endl;
  }else if((n/10)%10 == 9){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 998244353;
const int MAXN = 4000100, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, ans;
ll F[MAXN], I[MAXN];

ll powmod(ll a, ll b){
	if (!b) return 1;
	if (b&1) return a*powmod(a*a%mod, b>>1)%mod;
	return powmod(a*a%mod, b>>1);
}

ll C(ll n, ll r){
	if (r<0 || r>n) return 0;
	return F[n]*I[r]%mod*I[n-r]%mod;
}

ll f(ll n, ll m){
	return C(m+n-1, n-1);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	F[0]=1;
	for (int i=1; i<MAXN; i++) F[i]=F[i-1]*i%mod;
	I[MAXN-1]=powmod(F[MAXN-1], mod-2);
	for (int i=MAXN-1; i; i--) I[i-1]=I[i]*i%mod;
	
	cin>>n>>m;
	for (int i=(m&1); i<=min(n, m); i+=2){
		ll tmp=f(n, (3*m-i)/2) - i*f(n, (m-i)/2) - (n-i)*f(n, (m-i)/2-1);
		tmp%=mod;
		ans+=tmp*C(n, i)%mod;
		//debug2(i, tmp*C(n, i))
	}
	ans%=mod;
	if (ans<0) ans+=mod;
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 62720
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}

uint32_t nextpint(void){
	uint_fast32_t x=0;
	while(1){
		uint_fast8_t c=getchar();
		if('0'<=c && c<='9'){
			x=x*10+c-'0';
		}else{
			break;
		}
	}
	return x;
}

int b[100000];
int main(void){
	int n, h, i;
	n=nextpint();
	h=nextpint();
	int a=0;
	for(i=0; i<n; i++){
		int A=nextpint();
		if(A>a) a=A;
		b[i]=nextpint();
	}
	qsort(b, n, sizeof(int), compr);
	for(i=0; i<n; i++){
		if(h<=0 || b[i]<=a) break;
		h-=b[i];
	}
	printf("%d\n", h>0?i+(h+a-1)/a:i);
}


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

int gcd(int m, int n){
  int r=0;
  if(m==0 || n==0)return 0;

  if(m<n)return gcd(n, m);

  while((r=m%n)!=0){
    m=n; n=r;
  }
  return n;
}

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

  long long sum=0LL;
  for(int x=1; x<=k; ++x){
    for(int y=1; y<=k; ++y){
      for(int z=1; z<=k; ++z)sum+=gcd(x, gcd(y, z));
    }
  }

  cout<<sum<<endl;
}

Measured memory_bytes: 3572
// WeirdBugsButOkay

# include <bits/stdc++.h>

# define ll long long
# define ld long double
# define pii pair <int,int>
# define pll pair <ll,ll>
# define mp make_pair
# define pb push_back
# define ff first
# define ss second
# define endl '\n'

using namespace std;

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

void solve()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    while(true)
    {
        c -= b;
        if(c <= 0)
        {
            cout << "Yes";
            return;
        }
        a -= d;
        if(a <= 0)
        {
            cout << "No";
            return;
        }
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q = 1;
    //cin >> q;
    for(ll i = 0; i < q; i++)
    {
        solve();
    }
    return 0;
}


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

int main() {
	int d, g;
	cin >> d >> g;
	vector<pair<int,int>>pc(d);
	for (int i = 0; i < d; i++)cin >> pc.at(i).first >> pc.at(i).second;
	int ans = 1e10;
	for (int bit = 0; bit < (1 << d); bit++) {
		vector<pair<int, int>>pcc = pc;
		vector<int> l(0);
		for (int i = 0; i < d; i++) if (bit & (1 << i))l.push_back(i);
		int res = 0;
		int point = 0;
		for (int i = 0; i < l.size(); i++) {
			point += pcc.at(l.at(i)).second;
			res += pcc.at(l.at(i)).first;
			point += pcc.at(l.at(i)).first * (l.at(i) + 1) * 100;
			pcc.at(l.at(i)).first = 0;
		}
		int ct = d - 1;
		while (true) {
			if (ct == -1)break;
			if (point >= g)break;
			if (pcc.at(ct).first == 0) {
				ct--;
			}
			else {
				pcc.at(ct).first--;
				res++;
				point += (ct + 1) * 100;
			}
		}
		ans = min(ans, res);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3656
// B - Popular Vote
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int cnt = 0;
    int num = 4*m;
    for(int i=0; i<n; i++){
        if(a[i] >= (sum+(num-1))/num) cnt++;
        if(cnt == m){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
  string s;
  getline(cin, s);
  for(int i = 0; i < (int)(s.length());i++){
  	if(s.at(i) == '?'){
    	s.at(i) = 'D';
    }
  }
  cout << s;
}



Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define int long long


signed main() { //[J][O][L][S][K][E][Y]
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);

        int k; cin >> k;
        int ans = 0;
        for (int a = 1; a <= k; a++)
                for (int b = 1; b <= k; b++)
                        for (int c = 1; c <= k; c++)
                                ans += __gcd(a, __gcd(b, c));


        cout << ans;
        return 0;
}

/*

*/

Measured memory_bytes: 3628
//Bismillahir Rahmanir Rahim//

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;
void solution();
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
	clock_t tStart = clock();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solution();
#ifndef ONLINE_JUDGE
	fprintf(stderr, "Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
#endif
    return 0;
}
void solution() {
    string s, t;
    int ans = INT_MAX;
    cin >> s >> t;
    for (int i = 0; i < ((int)s.size() - (int)t.size()) + 1; i++) {
        int cnt = 0;
        // if (i + (int)t.size() > s.size())
        //     break;
        string sub = s.substr(i, (int)t.size());
        for (int j = 0; j < (int)t.size(); j++) 
            if (sub[j] != t[j])
                cnt++;
        ans = min(ans, cnt);
    }
    cout << ans << '\n';
}

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

int main(){
  
  int A, B, C, X;
  cin>>A>>B>>C>>X;
  int res = 0;
  
  for(int a=0; a<=A; a++){
    for(int b=0; b<=B; b++){
      for(int c=0; c<=C; c++){
        int total = 500*a+100*b+50*c;
        if(total == X) res++;
      }
    }
  }
  
  cout<<res<<endl;
}

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  } 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<long long>;
using vvi=vector<vector<long long>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000009;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

int main(){
  int n;cin>>n;
  double ans=0;
  rep(i,n){
    double a;string b;cin>>a>>b;
    if(b=="BTC")a*=380000;
    ans+=a;
  }
  cout<<fixed<<setprecision(10);
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>
typedef long long ll;
ll max(ll a, ll b){ return (a>b)?a:b;}
ll min(ll b, ll a){ return (a>b)?b:a;}
char S[3*100000+1];

int main(void){
    // Your code here!
    int N;
    scanf("%d",&N);
    scanf("%s",S);
 
    int leader = 0;
    int change_count = 0;
    
    for(int i = 1; i < N; i++){
        if(S[i] == 'E') change_count++;
    }
    
    int min_change_count = change_count;
    //printf("leader=%d,change=%d\n",leader,change_count);
    while(leader < N){
        leader++;
        if(S[leader-1]=='W') change_count++;
        if(S[leader]=='E') change_count--;
        
      //  printf("leader=%d,change=%d\n",leader,change_count);
        
        if(min_change_count > change_count) min_change_count=change_count;
    }
    
    
    printf("%d\n",min_change_count);
}


Measured memory_bytes: 512
#include <iostream>

using ll = long long;
ll x, y, c;

int main() {
    std::cin >> x >> y;
  if (y < x) {
    std::cout << 0 << std::endl;
    return 0;
  }
  c = 0;
  while (y >= x) {
    x *= 2;
    c++;
  }
  std::cout << c << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const static int N = 8;
const static int FREE = -1;
const static int NOT_FREE = 1;

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];
bool X[N][N];

void initialize(){
    for(int i = 0; i < N; i++){
        row[i] = FREE;
        col[i] = FREE;
    }
    
    for(int i = 0; i < 2*N-1; i++){
        dpos[i] = FREE;
        dneg[i] = FREE;
    }
}

void printBoard(){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(X[i][j]){
                if(row[i] != j){
                    return;
                }
            }
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            std::cout << ( (row[i] == j) ? "Q" : "." );
        }
        std::cout << std::endl;
    }
}

void recursive(int i){
    if(i == N){
        printBoard();
        return;
    }

    for(int j = 0; j < N; j++){
        if(NOT_FREE == col[j] ||
            NOT_FREE == dpos[i+j] ||
            NOT_FREE == dneg[i-j+N-1]) continue;

        row[i] = j;
        col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
        recursive(i+1);
        row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;

    }

    
}

int main(void){
    initialize();

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            X[i][j] = false;
        }
    }

    int k;
    std::cin >> k;

    for(int i = 0; i < k; i++){
        int r, c;
        std::cin >> r >> c;
        X[r][c] = true;
    }

    recursive(0);

    return 0;
}


Measured memory_bytes: 3116
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = []
now = 0
for i in range(n)[::-1]:
    now += a[i]
    now %= mod
    b.append(now)
b = b[::-1]
res = 0
for i in range(n-1):
    res += a[i]*b[i+1]
    res %= mod
print(res)

Measured memory_bytes: 110352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


ll facc(ll k){
    ll sum = 1;
    ll MOD = 1e9 + 7;
    for (ll i = 1; i <= k; ++i) {
        sum = (sum * i) % MOD;
    }
    return sum;
}

ll calc(ll a, ll b, ll p) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = calc(a, b / 2, p);
        return (d * d) % p;
    } else {
        return (a * calc(a, b - 1, p)) % p;
    }
}

const int MAX = 5100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll X, Y;
    cin >> X >> Y;
    ll a = min(X, Y);
    ll b = max(X, Y);
    ll MOD = 1e9 + 7;

    if(X == 1 && Y == 1) {
        cout << 0 << endl;
        return 0;
    }

    for (ll i = 0; i < min(X, Y); ++i){
        if(b == 2 * a) break;
        if(b > 2 * a){
            cout << 0 << endl;
            return 0;
        } else{
            b++;
            a--;
        }
    }
    // cout << a << " " << b << endl;
    ll up = facc(b / 2);
    ll down = (facc(b - X) * facc(b / 2 - b + X)) % MOD;

    COMinit();
    cout << COM(b / 2, b - X) << endl;


}

Measured memory_bytes: 119808
# -*- coding: utf-8 -*-

N = int(input())
A_list = list(map(int, input().split()))

negative_number = len([n for n in A_list if n < 0])

A_list_abs = [abs(n) for n in A_list]
A_list_abs.sort()
total = sum(A_list_abs)

if negative_number % 2 == 0:
    print (total)
else:
    print (total - 2*A_list_abs[0])

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=1000000007;

int main(){
    std::ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b)/2;
}


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

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

// code starts
vector<int> topo_sort1(vector<vector<int>> e)
{
  int n=e.size();
  vector<int> ans(0);
  vector<int> ins(n,0);
  int i,j;
  rep(i,n)
  {
    rep(j,e[i].size())
    {
      ins[e[i][j]]++;
    }
  }
  queue<int> s;
  rep(i,n) if(ins[i]==0)s.push(i);
  while(!s.empty())
  {
    int now=s.front();
    s.pop();
    ans.emplace_back(now);
    rep(i,e[now].size())
    {
      ins[e[now][i]]--;
      if(ins[e[now][i]]==0)
      {
        s.push(e[now][i]);
      }
    }
  }
  return ans;
}

vector<int> topo_sort2(vector<vector<int>> e)
{
  int i,j;
  int n=e.size();
  vector<bool> visited(n,false);
  vector<int> ans(0);
  stack<int> st;
  rep(i,n)
  {
    if(!visited[i])
    {
      st.push(i);
      visited[i]=true;
    }
    while(!st.empty())
    {
      int now=st.top();
      bool found=false;
      rep(j,e[now].size())
      {
        if(!visited[e[now][j]])
        {
          st.push(e[now][j]);
          visited[e[now][j]]=true;
          found=true;
          break;
        }
      }
      if(found)continue;
      else
      {
        ans.emplace_back(now);
        st.pop();
      }
    }
  }
  reverse(all(ans));
  return ans;
}

int main()
{
  int n,m;cin>>n>>m;
  vector<int> x(m);
  vector<int> y(m);
  int i,j;
  rep(i,m)cin>>x[i]>>y[i];
  rep(i,m){
    x[i]--;
    y[i]--;
  }
  vector<vector<int>> e(n);
  rep(i,m)
  {
    e[x[i]].emplace_back(y[i]);
  } 
  //vector<int> row=topo_sort1(e);
  vector<int> row=topo_sort2(e);
  vector<int> len(n,0);
  rep(i,n)
  {
    rep(j,e[row[i]].size())
    {
      len[e[row[i]][j]]=max(len[e[row[i]][j]],len[row[i]]+1);
    }
  }
  int ans=0;
  rep(i,n)ans=max(ans,len[i]);
  cout<<ans<<endl;
}


Measured memory_bytes: 12668
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a + b >= c){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  
  return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	int n; cin >> n;
	unordered_map<string, int> ms;
	string s1, s2;
	rep(i, 0, n) {
		cin >> s1 >> s2;
		if(s1 == "insert") {
			++ms[s2];
		} else {
			P(ms[s2] != 0 ? "yes" : "no");
		}
	}
	return 0;
}

Measured memory_bytes: 45688
S = input()
if S[0]=="A" and S[2:-1].count("C")==1:
    b = 0
    for s in S:
        if not 97<=ord(s)<=122:
            b += 1
    if b==2:
        print("AC")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mpp make_pair
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    fast;
    ll sum=0;
    string s;
    cin>>s;
    for(ll i=0; i<s.size(); i++)
    {
        sum+=s[i]-'0';
    }
    if(sum%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3700
#include <stdio.h>
#define N 100

int bubble(int a[],int n);
void printline(int a[], int n);

int main(){

	int i,n,a[N],change;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	change = bubble(a,n);

	printline(a,n);
	printf("%d\n",change);


}

int bubble(int a[], int n){

	int i,j,change=0,dum;
	for(i=n;i>0;i--){
		for(j=1;j<i;j++){
			if(a[j]<a[j-1]){
				dum=a[j];
				a[j]=a[j-1];
				a[j-1]=dum;
				change++;
			}
		}
	}

	return change;

}

void printline(int a[],int n){

	int i;
	for(i=0;i<n-1;i++){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[n-1]);

}

Measured memory_bytes: 1772
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI3(a, b, c);
  print((a + b + c == max({a, b, c}) * 2) ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  if (A>9 or A <1){
  	cout << -1 << endl;
  }
  else if(B>9 or B <1){
  	cout << -1 << endl;
  }
  else{
  	cout << A*B <<endl;
  }
}

Measured memory_bytes: 256
while True:
  a, b = map(int, input().split())
  if a == b == 0:
    break
  a += 1
  c = 0
  for i in range(1, a):
    for j in range(i + 1, a):
      for k in range(j + 1, a):
        if i + j + k == b:
          c += 1
  print(c)


Measured memory_bytes: 5592
N,M=map(int, input().split()) 
X = list(map(int, input().split()))

if (N>=M):
    print(0)
else:
    X.sort()
    diff = [X[i] - X[i-1] for i in range(1,M)]
    diff.sort()
    print(sum(diff[:M-N]))

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

const int MAX = 25;

struct Node {int parent, left, right; };
Node node[MAX];
int depth[MAX], height[MAX];

int getDepth(int i) {
	if (depth[i] != -1)
		return depth[i];
	if (node[i].parent == -1)
		return depth[i] = 0;
	else
		return depth[i] = getDepth(node[i].parent) + 1;
}

int getHeight(int i) {
	if (height[i] != -1)
		return height[i];
	if (node[i].left == -1 && node[i].right == -1)
		return height[i] = 0;
	else
		return height[i] = max(getHeight(node[i].left), getHeight(node[i].right)) + 1;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		node[i].parent = -1;
		node[i].left = -1;
		node[i].right = -1;
		depth[i] = -1;
		height[i] = -1;
	}
	for (int i = 0; i < n; i++) {
		int id, l, r;
		cin >> id >> l >> r;
		if (l != -1) {
			node[id].left = l;
			node[l].parent = id;
		}
		if (r != -1) {
			node[id].right = r;
			node[r].parent = id;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << "node " << i << ": ";
		cout << "parent = " << node[i].parent << ", ";
		int p = node[i].parent;
		if (p == -1)
			cout << "sibling = " << -1 << ", ";
		else if (i == node[p].left)
			cout << "sibling = " << node[p].right << ", ";
		else
			cout << "sibling = " << node[p].left << ", ";
		int deg = 0;
		if (node[i].left != -1) deg++;
		if (node[i].right != -1) deg++;
		cout << "degree = " << deg << ", ";
		cout << "depth = " << getDepth(i) << ", ";
		cout << "height = " << getHeight(i) << ", ";
		if (node[i].parent == -1)
			cout << "root" << endl;
		else if (node[i].left != -1 || node[i].right != -1)
			cout << "internal node" << endl;
		else
			cout << "leaf" << endl;
	}
}



Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n,a[100005];
  cin>>n;
  rep(i,n)cin>>a[i];
  ll ans=0;
  rep(i,n-1){
    ans+=a[i]/2;
    a[i]%=2;
    if(a[i]==1&&a[i+1]>=1){
      ans++;
      a[i+1]--;
    }
  }
  ans+=a[n-1]/2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
import java.io.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException err){
			err.printStackTrace();
		}
	}

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while((line = in.readLine()) != null){
			long[] a = new long[3];
			long[] m = new long[3];
			String[] dst = line.split(" ");

			int end = 0;
			for(int i=0; i<3; i++){
				a[i] = Long.parseLong(dst[2*i]);
				m[i] = Long.parseLong(dst[2*i+1]);

				if(a[i] != 0 || m[i] != 0){
					end = 1;
				}
			}

			if(end == 0){
				break;
			}

			long j = countLoop(a[0], m[0]);
			long k = countLoop(a[1], m[1]);
			long l = countLoop(a[2], m[2]);
			System.out.println(lcm(lcm(j, k), l));
		}
	}

	public long countLoop(long a, long m){
		long n = 1;
		long count = 0;
		do{
			count++;
			n = (a * n) % m;
		}while(n != 1);

		return count;
	}

	public long lcm(long n, long m){
		long p = n*m;
		long tmp;
		while(m%n != 0){
			tmp = n;
			n = m%n;
			m = (long)tmp;
		}

		return p / n;
	}
}

Measured memory_bytes: 9744
#include <iostream>
#include <vector>

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void solve() {
    int n, k;
    std::cin >> n >> k;

    mint ans = 0;
    std::vector<mint> dp(k + 1, 0);
    for (int g = k; g >= 1; --g) {
        dp[g] = mint(k / g).pow(n);
        for (int p = g * 2; p <= k; p += g) {
            dp[g] -= dp[p];
        }
        ans += dp[g] * g;
    }

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

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

    solve();

    return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std; 
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int N;
  cin >>N;
  vector <int> P(N),Q(N),R(N);
  for(int i=0;i<N;i++)
    R[i]=i+1;
  rep(i,N)
    cin >> P[i];
  rep(i,N)
    cin >> Q[i];
  int countP=0,countQ=0;
  do{
    countP++;
    if(P==R)
      break;
  }while(next_permutation(R.begin(),R.end()));
   for(int i=0;i<N;i++)
    R[i]=i+1;
do{
  countQ++;
  if(Q==R)
    break;
    
}while(next_permutation(R.begin(),R.end()));

cout <<abs(countP-countQ)<<endl;

  return 0;
}


Measured memory_bytes: 256
### constant

START = 0
GOAL = 5

NBRS = [[1, 2], [nil, 3], [1, nil], [4, 5], [5, 2], [2, 1]]

### main

while true
  line = gets.strip
  break if line == '#'

  pos = START
  for rt in line.split('').map{|s| s.to_i}
    pos = NBRS[pos][rt]
    break if pos.nil?
  end

  puts (pos == GOAL ? 'Yes' : 'No')
end

Measured memory_bytes: 6108
x_1,y_1,x_2,y_2 = map(int,input().split())
x_3 = x_2 - (y_2 - y_1)
y_3 = y_2 + (x_2 - x_1)
x_4 = x_1 - (y_2 - y_1)
y_4 = y_1 + (x_2 - x_1)
print(x_3,y_3,x_4,y_4)

Measured memory_bytes: 3060
n=int(input())
lista=list(map(int,input().split()))

goukei=0
count=0

for i in range(n):
    number=lista[i]+goukei
    if i%2==0:
        if number>=0:
            count=count+number+1
            goukei=-1
        else:
            goukei=number
    else:
        if number<=0:
            count=count+abs(number)+1
            goukei=1
        else:
            goukei=number

count1=count

goukei=0
count=0

for i in range(n):
    number=lista[i]+goukei
    if i%2==1:
        if number>=0:
            count=count+number+1
            goukei=-1
        else:
            goukei=number
    else:
        if number<=0:
            count=count+abs(number)+1
            goukei=1
        else:
            goukei=number
print(min(count,count1))

Measured memory_bytes: 14464
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;

int main() {
  string S;
  cin >> S;
  map<char, int> mp;
  rep(i, S.size()) {
    if(mp[S[i]]) {
      cout << "no" << endl;
      return 0;
    }
    mp[S[i]]++;
  }
  cout << "yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#include <unistd.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef vector <ll> vll;
typedef vector <ull> vull;
typedef vector <vll> vvll;
typedef long double ld;
typedef vector <ld> vld;
typedef pair <ll, ll> pii;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <vpii> vvpii;
typedef vector <bool> vbool;

#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define rforn(i, x, y) for (ll i = x; i >= y; --i)
#define add push_back
#define del pop_back
#define ins insert
#define ers erase
#define F first
#define S second
#define int ll
#define _ inline
#define sqr(x) ((x) * (x))
#define pw(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(x) reverse(x)
#define sz(x) (int)(x).size()
#define rsz resize
#define cpy(x, T, c) copy(all(x), ostream_iterator <T>(cout, c))
#define mem(x, val) memset(x, val, sizeof(x))
_ ll gcd(ll a, ll b) { while (b) { a %= b, swap(a, b); } return a; }
_ ll lcm(ll a, ll b) { return a * b / max(1LL, gcd(a, b)); }

const ll INF = (ll)1e9 + 2017;
const ll MOD = (ll)1e9 + 7;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);
mt19937 rnd((int)time(0));

void source()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a ^ b ^ c);
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    cout.precision(10);
#ifdef _F1A4X_
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    source();
#ifdef _F1A4X_
    cerr << endl << endl << "\t" << (ld)clock() / CLOCKS_PER_SEC << " sec" << endl;
    sleep(INF);
#endif
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        StringBuilder sb = new StringBuilder();
        
        for (int i = 0; i < s.length(); i += 2) {
            sb.append(s.charAt(i));
        }
        
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 23380