akhauriyash/Code-Regression huggingface dataset:
import math
N = int(input())
grid = []
for i in range(N-1):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
for x in range(N): 
    time = 0
    for i in range(x, N-1):
        if time <= grid[i][1]:
            time = grid[i][0] + grid[i][1]
        else :
            time = (math.ceil((time - grid[i][1])/grid[i][2]))*grid[i][2] + grid[i][1] + grid[i][0]
    print(time)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define deb(x)     cerr << (#x) << " : " << (x) << "\n"
#define ll long long int
#define ld long double
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
using namespace std;
 
ll powmod(ll a, ll b, ll MOD = MOD){
	if(!a and !b)	return 1ll;
	if(!a)	return a;
	ll res = 1ll;
	b %= (MOD - 1ll), a %= MOD;
	while(b){
		if(b%2 == 1)	res = (res * a) % MOD;
		a = (a * a) % MOD;
		b /= 2;
	}
	return res;
}
 
ll dp[5010][5010];	
 
int main(){	
   
 
	ios::sync_with_stdio(false);
	cin.tie(NULL);
 
	int n;
	cin >> n;
 
	pair<ll, ll> arr[n];
	for(int i = 0; i < n; i++){
		cin >> arr[i].first >> arr[i].second;
		arr[i].first += arr[i].second;
	}
 
	sort(arr, arr + n);
	for(int i = 0; i < n; i++)	arr[i].first -= arr[i].second;
 
	for(int i = 0; i <= n; i++)	for(int j = 0; j <= n; j++)	dp[i][j] = INF;
 
	dp[0][1] = arr[0].second;
	dp[0][0] = 0;
 
	for(int i = 1; i < n; i++){
		dp[i][0] = 0;
		for(int j = 1; j <= (i + 1); j++){
			dp[i][j] = dp[i-1][j];
			if((dp[i-1][j-1]) <= arr[i].first){
				dp[i][j] = min(dp[i][j], dp[i-1][j-1] + arr[i].second);
			}
		//	cout << dp[i][j] << " ";
		}
		//cout << endl;
	}
 
	for(int i = n; i >= 0; i--){
		if(dp[n-1][i] != INF){
			cout << i << "\n";
			return 0;
		}
	}
 
	cout << 0 << "\n";
}

Measured memory_bytes: 196096
#include <iostream>

using namespace std;

int judge(int x, int y, int *a, int n){
	int p;
	p = 0;
	for (size_t i = 0; i < n; i++) {
		if (a[i] == x) {
			p++;
		}
		if (a[i] == y) {
			p++;
		}
	}
	if (p == 2) {
		std::cout << "Yes" << '\n';
		return 0;
	}
	return 1;
}

int main(int argc, char const *argv[]) {
	int x,y,p,an,bn,cn;
	int a[] = {1,3,5,7,8,10,12};
	int b[] = {4,6,9,11};
	int c[] = {2};
	an = sizeof(a) / sizeof(a[0]);
	bn = sizeof(b) / sizeof(b[0]);
	cn = sizeof(c) / sizeof(c[0]);
	std::cin >> x >> y;
	p = 0;
	p += judge(x, y, a, an);
	p += judge(x, y, b, bn);
	p += judge(x, y, c, cn);
	if (p == 3) {
		std::cout << "No" << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	int N;
	char str[] = "MARCH";
	long long num[5];
	for(int i=0;i<5;i++) num[i] = 0;

	scanf("%d", &N);

	for(int i=0;i<N;i++){
		char s[11];
		scanf("%s", s);
		for(int j=0;j<5;j++){
			if(s[0]==str[j]) num[j]++;
		}
	}
	long long ans = 0;
	for(int i=0;i<5;i++){
		for(int j=i+1;j<5;j++){
			for(int k=j+1;k<5;k++){
				ans += num[i]*num[j]*num[k];
			}
		}
	}


	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	vector<int> A(N);
		for(int i=0;i<N;i++) cin>>A[i];
	vector<int> rev(N);
		for(int i=0;i<N;i++) rev[A[i]-1]=i+1;
		for(int i=0;i<N;i++) cout<<rev[i]<<endl;
}

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

using namespace std;

int main()
{
//    freopen("in.txt","r",stdin);

    int a,b,c;
    while(cin>>a>>b>>c)
    {
        double s=((double)a*b*sin(c*M_PI/180))/2;
        double h=sqrt(a*a+b*b-2*a*b*cos(c*M_PI/180));
        double l=s*2/a;
        printf("%.8lf\n",s);
        printf("%.8lf\n",h+a+b);
        printf("%.8lf\n",l);
    }
}



Measured memory_bytes: 3440
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0
for i in range(H):
    A = list(map(int, input().split()))
    for j in range(W):
        if A[j] != -1:
            ans += c[A[j]][1]
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
template <class T> using vec = vector<T>;
using P = pair<long long,long long>;
const ll mod = 1e9+7;

int main(){
    ll n,m; cin >> n >> m;
    vec<ll> a(n); rep(i,m)cin >> a[i];
    vec<ll> dp(n+1,0); dp[0] = 1; if(a[0] != 1)dp[1] = 1;
    ll next = dp[1] == 1 ? 0 : 1;
    for(ll i = 2;i<n+1;i++){
        if(a[next] == i)next++;
        else{
            dp[i] = dp[i-1] + dp[i-2];
            dp[i] %= mod;
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll LL_MAX=LLONG_MAX;

struct In{
    template<typename T>
    operator T(){
        T x;
        cin >> x;
        return x;
    }
};
In in;

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

template <typename T>
void out(T x){
    cout << x << endl;
}

template <typename T>
T gcd(T x,T y){
    if (y == 0) return x;
    return gcd(y,x%y);
}

template <typename T>
T lcm(T x,T y){
    return x*y/gcd(x,y);
}

int main(){
    string n=in;
    int m=0,n_size=n.size();
    for (int i=0;i<n_size;i++){
        m+= ((int)n[i]-(int)'0');
    }
    if (m%9==0) out("Yes");
    else out("No");
}

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

int main(int argc, const char * argv[]) {
    int n,m;
    
    cin >> n;
    int t[n];
    for (int i=0; i<n; i++) {
        cin >> t[i];
    }
    cin >> m;
    int p[m],x[m];
    for (int i=0; i<m; i++) {
        cin >> p[i] >> x[i];
    }
    int total = 0;
    for (int i=0; i<n; i++) {
        total += t[i];
    }
    
    for (int i=0; i<m; i++) {
        cout << total - (t[p[i]-1] - x[i]) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 210
#define MAX_V 10
#define MAX_M 101
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"

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

int W, H, N;
int X1[MAX_N], X2[MAX_N], Y1[MAX_N], Y2[MAX_N];

bool fld[MAX_N*6][MAX_N*6];

int compress(int *x1, int *x2, int w){
	vector<int> xs;
	
	for(int i = 0; i < N; i++){
		for(int d = -1;d <= 1; d++){
			int tx1 = x1[i] + d, tx2 = x2[i] + d;
			if(0 <= tx1 && tx1 <= w) xs.push_back(tx1);
			if(0 <= tx2 && tx2 <= w) xs.push_back(tx2);
		}
	}
	
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	
	for(int i = 0; i < N; i++){
		x1[i] = find(xs.begin(),xs.end(),x1[i]) - xs.begin();
		x2[i] = find(xs.begin(),xs.end(),x2[i]) - xs.begin();
	}
	
	return xs.size();
}

void solved(){
	W = compress(X1,X2,W);
	H = compress(Y1,Y2,H);
	
	memset(fld, 0, sizeof(fld));
	for(int i = 0; i < N; i++){
		for(int y = Y1[i]; y <= Y2[i]; y++){
			for(int x = X1[i]; x <= X2[i]; x++){
				fld[y][x] = true;
			}
		}
	}
	int ans = 0;
	// for(int y = 0; y < H; y++){
		// for(int x = 0; x < W; x++){
			// cout<<fld[y][x]<<" ";
		// }cout<<endl;
	// }
	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			if(fld[y][x]) continue;
			bool flag = false;
			ans++;
			queue<pair<int, int>> que;
			que.push(make_pair(x,y));
			while(!que.empty()){
				int sx = que.front().first, sy = que.front().second;
				que.pop();
				
				for(int i = 0; i < 4; i++){
					int tx = sx + dx[i], ty = sy + dy[i];
					if(tx < 0 || W <= tx || ty < 0 || H <= ty){
						flag = true;
						continue;
					}
					if(fld[ty][tx]) continue;
					que.push(make_pair(tx,ty));
					fld[ty][tx] = true;
				}
			}
			if(flag)ans--;
		}
	}
	cout<<ans+1<<endl;
}

signed main(){
	while(true){
		int l, t, r, b, i;
		H = W = (int)(1e6)*2;
		cin>>N;
		if(!N) break;
		for(int j = 0; j < N; j++){
			cin>>l>>t>>r>>b;
			l*=2,t*=2,r*=2,b*=2;
			 // l++,t++,r++,b++;
			//l,t,r,b;
			i = j*4;
			X1[i]   = l;X2[i]   = r;Y1[i]   = t;Y2[i]   = t;
			X1[i+1] = l;X2[i+1] = r;Y1[i+1] = b;Y2[i+1] = b;
			X1[i+2] = l;X2[i+2] = l;Y1[i+2] = b;Y2[i+2] = t;
			X1[i+3] = r;X2[i+3] = r;Y1[i+3] = b;Y2[i+3] = t;
		}
		N *= 4;
		solved();
	}
	
	return 0;
}


Measured memory_bytes: 4708
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

int n, h, w, ans;
string s[1010];
vector<int> vec[1010], V;
priority_queue<Q, vector<Q>, greater<Q>> que;


int main()
{
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		cin >> s[i];
	}
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (s[i][j] == '#')
			{
				que.push(Q(0, P(i, j)));
			}
		}
	}
	while (que.size())
	{
		Q q = que.top(); que.pop();
		ans = max(ans, q.first);
		int i = q.second.first, j = q.second.second;
		if (i > 0 && s[i - 1][j] == '.')
		{
			que.push(Q(q.first + 1, P(i - 1, j)));
			s[i - 1][j] = '#';
		}
		if (i < h - 1 && s[i + 1][j] == '.')
		{
			que.push(Q(q.first + 1, P(i + 1, j)));
			s[i + 1][j] = '#';
		}
		if (j > 0 && s[i][j - 1] == '.')
		{
			que.push(Q(q.first + 1, P(i, j - 1)));
			s[i][j - 1] = '#';
		}
		if (j < w - 1 && s[i][j + 1] == '.')
		{
			que.push(Q(q.first + 1, P(i, j + 1)));
			s[i][j + 1] = '#';
		}
	}
	cout << ans << endl;
	
	cin >> n;
}

Measured memory_bytes: 15340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 200005
const ll MOD = 1000000007;

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

	ll n,m;
	cin>>n>>m;
	ll a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	ll pre[n+1];
	pre[0] = 0;
	for(int i=1;i<=n;i++)
		pre[i] = pre[i-1]+a[i-1];
	ll lo = 0;
	ll hi = MAX;
	ll ans;
	while(lo<hi){
		ll mid = (lo+hi)/2;
		ll shakes = 0;
		ll j=0;
		ans = 0;
		for(ll i=n-1;i>=0;i--){
			while(j<=i && a[i]+a[j]<mid)
				++j;
			if(j>i)
				break;
			shakes += 2*(i-j)+1;
			ans += 2*(i+1-j)*a[i];
			ans += 2*(pre[i]-pre[j]);
		}

		if(shakes >= m){
			ans -= mid*(shakes-m);
			lo = mid+1;
		}
		else{
			ans += (mid-1)*(m-shakes);
			hi = mid;
		}
	}

	cout<<ans<<endl;
	// lo is smallest value not possible
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
ll mulmod(ll a,ll b,ll c) 
{ 
    if (b==0) 
        return 0; 
    ll s = mulmod(a, b/2, c); 
    if (b%2==1) 
        return (a%c+2*(s%c)) % c; 
 
    else
        return (2*(s%c)) % c; 
} 

  
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{ll int t;
t=1;
//cin>>t;

while(t--)
{ll int h,a;
cin>>h>>a;
;;ll int ans = h/a;
if(h%a!=0)ans++;
cout<<ans<<endl;

    
}
 
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(map(int, input().rstrip()))

ans = 0
for i in range(10):
    if i in s[:n - 2]:
        x = s.index(i)

        for j in range(10):
            if j in s[x + 1:n - 1]:
                y = x + s[x + 1:n - 1].index(j) + 1

                for k in range(10):
                    if k in s[y + 1:]:
                        ans += 1

print(ans)

Measured memory_bytes: 3640
S = input()

string = list(S)
judge = True

for i in range(1,len(string)+1):
    if string[i-1] == 'U' or string[i-1] == 'D':
        pass
    elif string[i-1] == 'L' and i % 2 == 0:
        pass
    elif string[i-1] == 'R' and i % 2 == 1:
        pass
    elif string[i-1] == 'R' and i == 1:
        pass
    else:
        judge = False
if judge == True:
    print('Yes')
elif judge == False:
    print('No')

Measured memory_bytes: 3060
#include<iostream>
#include<numeric>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXN = 2e5;
int const MAXNN = 1<<18;

struct seg_tree {
  int data_[MAXNN*2-1], e_;
  int NN;
  
  seg_tree(int N, int e) : e_(e) {
    NN = 1;
    while(NN < N) NN *= 2;
    std::fill_n(data_, NN*2-1, e);
  }
  void update(int k, int v) {
    k += NN-1;
    data_[k] = v;
    while(k > 0) {
      k = (k-1)/2;
      data_[k] = std::max(data_[k*2+1], data_[k*2+2]);
    }
  }
  int query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return e_;
    if(a <= l && r <= b) return data_[k];
    int m = (l+r)/2;
    int vl = query(a, b, k*2+1, l, m);
    int vr = query(a, b, k*2+2, m, r);
    return std::max(vl, vr);
  }
  int query(int a, int b){ return query(a, b, 0, 0, NN); }
};

uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int ix[MAXN+1];

int main() {
  int N = getZ();
  seg_tree s(N, 0);
  for(int i = 0; i < N; ++i) s.update(i, getZ());
  int64_t ans = 0;
  std::iota(ix, ix+N+1, 0); // 0 ... N
  for(int i = 0; i < N; ++i) {
    int p = s.query(i, i+1);
    int il2 = -1, il1 = -1, ir1 = N, ir2 = N;
    // search left
    il1 = i - *std::partition_point(ix, ix+i+1, [&](int j){ return s.query(i-j, i) <= p; });
    // search right
    ir1 = i + *std::partition_point(ix, ix+N-i, [&](int j){ return s.query(i, i+j+1) <= p; });
    if(il1 >= 0) {
      il2 = il1 - *std::partition_point(ix, ix+il1+1, [&](int j){ return s.query(il1-j, il1) <= p; });
      ans += (int64_t)(il1 - il2)*(ir1 - i)*p;
    }
    if(ir1 < N) {
      ir2 = ir1 + *std::partition_point(ix, ix+N-ir1, [&](int j){ return s.query(ir1+1, ir1+j+1) <= p; });
      ans += (int64_t)(i - il1)*(ir2 - ir1)*p;
    }
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) ((v).begin(), (v).end())
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    ll n;
    cin >> n;
    if(n == 1) {
        cout << 4 << endl;
        return 0;
    }
    if(n == 2) {
        cout << 4 << endl;
        return 0;
    }
    ll count = 0; 
    // cout << n << endl;
    while(n != 4) {
        if (n % 2 == 1) {
            n = 3 * n + 1;
            // cout << n << endl;
            count++;
        }
        else {
            n = n / 2;
            // cout << n << endl;
            count++;
        }
    }
    cout << count + 4 << endl;
    return 0;
}

Measured memory_bytes: 3532
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        String S = in.s();
        int N = S.length();
        boolean b = true;
        
        for(int i = 0; i < N; i++){
            int c = S.charAt(i);
            if(b){
                b = false;
                if(c != 'h'){
                    break;
                }
            } else if(!b){
                if(c == 'i'){
                    b = true;
                } else {
                    break;
                }
            }
        }
        out.println(b ? "Yes" : "No");
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 21716
#include<stdio.h>
void sorting(long long int ara[]){

           int  temp=1,temp1,i;
             while (temp)
             {
                 temp=0;
                for (i=0;i<9 ;i++ )
                {
                    if (ara[i]<ara[i+1])
                    {
                            temp1=ara[i];
                    ara[i]=ara[i+1];
                    ara[i+1]=temp1;
                    temp=1;

                    }

                }

             }

}
int main()
{
    long long int ara[10],i,flag=0;

    for (i=0;i<10 ;i++ )
    {
        scanf("%lld",&ara[i]);

    }
    sorting(ara);
    for (i=0;i<3 ;i++ )
    {
       printf("%lld\n",ara[i]);

    }



  return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


int main()
{
	int N;
	cin >> N;
	int counter = 0;
	for (int i = 1; i <= N; i++)
	{
		int keta = 0;
		for (int n = i; n > 0; n /= 10) {
			keta++;
		}
		if (keta % 2 == 1)
		{
			counter++;
		}
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
signed main(){
	int x;
	for(int i = 1; ; i++){
		cin >> x;
		if(x == 0){
			cout << i << endl;
			return 0;
		}
	}
 
	return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

long N, K;

bool sub(vector<long> vec, long y) {
  rep (i, N) vec[i] %= y;
  sort(vec.begin(), vec.end());
  long sum = 0;
  for (auto it: vec) sum += it;
  long fill = sum / y;
  long require = 0;
  for (long i = 0; i < N - fill; i++) require += vec[i];
  if (require <= K) {
    cout << y << endl;
    return true;
  }
  return false;
}

void solve() {
  cin >> N >> K;
  vector<long> A(N);
  rep (i, N) cin >> A[i];

  long sum = 0;
  for (auto it: A) sum += it;
  set<long> yakusuu;
  for (long i = 1; i * i <= sum; i++) {
    if (sum % i == 0) {
      yakusuu.insert(i);
      yakusuu.insert(sum / i);
    }
  }
  
  for (auto it = yakusuu.rbegin(); it != yakusuu.rend(); it++) {
    if (sub(A, *it)) return;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 384
import java.util.*;
//import java.io.*;
import java.util.stream.IntStream;


public class Main{
    static int sum=0;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
        int n = sc.nextInt();

        for(int i=0; i<n; i++){
            Vector p0 = new Vector(sc.nextInt(), sc.nextInt());
            Vector p1 = new Vector(sc.nextInt(), sc.nextInt());
            Vector p2 = new Vector(sc.nextInt(), sc.nextInt());
            Vector p3 = new Vector(sc.nextInt(), sc.nextInt());

            Vector s1 = p0.minus(p1);
            Vector s2 = p2.minus(p3);
            if(Vector.cross(s1, s2)==0){
                System.out.println(2);
                continue;
            }else if(Vector.dot(s1, s2)==0){
                System.out.println(1);
            }else{
                System.out.println(0);
            }
        }

    }
}

class Vector{
    public static double EPS = 1e-10;
    public double x,y;

    public Vector(){}
    public Vector(double x, double y){this.x=x;this.y=y;}

    public Vector plus(Vector p){return new Vector(this.x+p.x, this.y+p.y);}
    public Vector minus(Vector p){return new Vector(this.x-p.x, this.y-p.y);}
    public Vector multiple(Vector p){return new Vector(this.x*p.x, this.y*p.y);}
    public Vector divide(Vector p){return new Vector(this.x/p.x, this.y/p.y);}

    public double abs(){return Math.sqrt(this.norm());}
    public double norm(){return x*x+y*y;}

    
    public static double dot(Vector a, Vector b){
        return a.x*b.x+a.y*b.y;
    }

    public static double cross(Vector a, Vector b){
        return a.x*b.y-a.y*b.x;
    }
    
}


Measured memory_bytes: 40264
#include <stdio.h>

int W, H, x, y, r;

int main(){
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    W -= r, H -= r;
    if (r <= x && x <= W && r <= y && y <= H)
    {
        printf("Yes\n");
    }else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a,b,c;
 	cin >> a >> b >> c;
 	vector<int> x {a,b,c};
 	sort(x.begin(),x.end());
 	cout << x.at(2)-x.at(0) << endl;
 }

Measured memory_bytes: 256
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = []

    num = A[0]
    for i in range(1, N):
        num += (-1)**i * A[i]
    ans.append(num)

    for i in range(N - 1):
        ans.append(2 * (A[i] - (ans[i] / 2)))
        
    for value_ in ans:
        print(int(value_), end=" ")
    print()


if __name__ == '__main__':
    main()

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e8;
int mask[1001],cost[1001];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i= 0 ;i<m;i++){
        cin>>cost[i];
        int b;
        cin>>b;
        while(b--){
            int c;
            cin>>c;
            c--;
            mask[i] = mask[i]|(1<<c);
        }
    }
    vector<int> dp(1 << n, INF), e(1 << n);
    dp[0]=0;
    for(int i=0;i<m;i++){
        copy(dp.begin(),dp.end(),e.begin());
        for(int j=0;j<(1<<n);j++){
            int mas = j|mask[i];
            e[mas] = min(dp[j]+cost[i],e[mas]);
        }
        swap(dp,e);
    }
    if(dp[(1<<n)-1]==INF){
        cout<<-1<<endl;
    }else{
        cout<<dp[(1<<n)-1]<<endl;
    }
    
    return 0;
}

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int k;
	string s;
	cin >> k >> s;
	if (s.size() <= k) cout << s << endl;
	else cout << s.substr(0, k) << "..." << endl;
	
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
long long M=1000000007;
vector<int> num;
int isprime[105];
int n,m,d;
string a,b;
long long dp[10005][2][2][105];
long long solve(int idx,int flag,int flag2,int rem)
{
    //cout<<rem<<endl;
    if(idx==b.size())
        {
            if(rem==0)
                return 1;
            else
                return 0;
        }
    if(dp[idx][flag][flag2][rem]!=-1)
        return dp[idx][flag][flag2][rem];

    int lim=flag?9:(b[idx]-'0');
    int lim1=flag2?0:(a[idx]-'0');
    long long ans=0;
    for(int i=lim1;i<=lim;i++)
    {
        ans=(ans+solve(idx+1,flag||(i<lim),flag2||(i>lim1),(rem+i)%m)%M)%M;

    }
    return dp[idx][flag][flag2][rem]=ans%M;
}

 
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
{
    memset(dp,-1,sizeof(dp));
    a="1";
    cin>>b;
    cin>>m;
    n=b.size();
    for(int i=0;i<n-1;i++)
        a="0"+a;
    cout<<solve(0,0,0,0)<<endl;
 
 
    
}
 
return 0;
} 

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

int main() {
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> length(N);
  int64_t SUM = 0;
  for(int i = 0; i < N; i++) {
    cin >> length.at(i);
    SUM += length.at(i);
  }
  if(K >= SUM) {
    cout << 1 << endl;
    return 0;
  }
  sort(length.begin(), length.end());
  int a = 1;
  int b = length.at(N - 1);
  while(b - a > 1) {
    int c = (a + b) / 2;
    int64_t sum = 0;
    for(int i = 0; i < N; i++) {
      sum += (length.at(i) - 1) / c;
    }
    if(sum > K) {
      a = c;
    }
    else { 
      b = c;
    }
  }
  cout << b << endl;
}


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

int main(){
    long long A,B,N;
    cin>>A>>B>>N;
    long long X=0;
    long long maxans=0;
    if(N<B){
        X=N;
    }
    else X=B-1;

    cout<<floor(A*X/B)-A*floor(X/B)<<endl;

    
   return 0;
}


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

int f(const void *a,const void *b){
  return strcmp((char*)a,(char*)b);
}

int main(){
  int N,c=1;
  char S[200002][12];
  scanf("%d\n",&N);
  for(int i=0;i<N;i++){
    scanf("%s\n",S[i]);
  }
  qsort((void*)S,N,sizeof(S[0]),f);
  for(int i=0;i<N-1;i++){
    if(strcmp(S[i],S[i+1])!=0) c++;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 6264
#解説見ながら作った。
#DFSで行う。停止条件・分岐処理の二つが大枠。

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

    #curはcurrentのことで現在の状態
def dfs(cur, a, b, c):
    
    '''
    停止条件(終端処理)
    深さに限らず，任意の停止条件を書く
    
    深さがNだったら使用MPを評価
    1本も竹を使用していなかったら棄却→MPを無限に使うこととしている
    
    (-30って引いてるのは、最初の 1 本目は合体コストなし、
    2 本目からはコスト 10 かかるため、その1本目のコストの分
    を加えてしまっているため、それを引いている（たぶん）)
    '''
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF


    '''
    cur(current) を進めながら,（末端に進みながら）分岐処理
    末端まで到達した時それぞれの分岐から値が返される
    for 文で書ける場合は for 文で実装
    
    cur番目の竹に対して
        ret0:ABCどれにも使わない
        ret1:Aに使う（合成:MP+10）
        ret2:Bに使う（合成:MP+10）
        ret3:Cに使う（合成:MP+10）
    '''
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10

    #それぞれの分岐からの戻り値の処理を行う関数
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include <stdio.h>
void trace(int A[],int N){
    int i;
    for (i = 0; i < N; ++i) {
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}
void InsertionSort(int Aa[],int Nn){
    int j,i,v;
    for (i = 1; i < Nn; ++i){
        v=Aa[i];
        j=i-1;
        while (j>=0&&Aa[j]>v) Aa[j+1]=Aa[j],j--;
        Aa[j+1]=v;
        trace(Aa,Nn);
    }
}
int main() {
    int n,i,j,a[110];
    scanf("%d",&n);
    for (i = 0; i < n; ++i)scanf("%d",&a[i]);
    trace(a,n);
    InsertionSort(a,n);
    return 0;
}



Measured memory_bytes: 2756
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
   std::string S, T;
   std::cin >> S >> T;

   std::vector<int> v1;
   std::vector<int> v2;
   for(char moji='a'; moji!='z'+1; ++moji){
      int count1 = 0;
      int count2 = 0;
      for(int j=0; j<S.size(); ++j){
	 if(S[j]==moji) ++count1;
	 if(T[j]==moji) ++count2;
      }
      if(count1>0) v1.push_back(count1);
      if(count2>0) v2.push_back(count2);
   }

   if(v1.size()!=v2.size()){
      std::cout << "No" << std::endl;
      return 0;
   }

   std::sort(v1.begin(),v1.end());
   std::sort(v2.begin(),v2.end());
   for(int i=0; i<v1.size(); ++i){
      if(v1[i]!=v2[i]){
	 std::cout << "No" << std::endl;
	 return 0;
      }
   }
   std::cout << "Yes" << std::endl;
   return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
    cout << fixed;
    cout << setprecision(10);
    while(1){
        double x,h;
        cin >> x >> h;
        if(x==0) break;
        cout << x*x + x*sqrt(h*h+x*x/4)*2 << endl;
    }
    return 0;
}



Measured memory_bytes: 3188
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> >sc(m);
    for(int i = 0; i < m; i++){
        cin >> sc.at(i).first >> sc.at(i).second;
    }
    vector<int>ans(n + 1);
    for(int i = 1; i <= n; i++){
        ans.at(i) = 10;
    }//初期化
    for(int i = 0; i < m; i++){
        if(ans.at(sc.at(i).first) == 10){
            ans.at(sc.at(i).first) = sc.at(i).second;//初めてならそのまま入れる
        }
        else{
            if(ans.at(sc.at(i).first) != sc.at(i).second){
                cout << -1 << endl;
                break;
            }
        }
        if(i == m - 1){
            if(n == 1 || ans.at(1) != 0){
            for(int j = 1; j <= n; j++){
                if(j == 1){
                    if(ans.at(j) == 10){
                        cout << 1;
                    }
                    else{
                        cout << ans.at(j);
                    }
                }
                else{
                    if(ans.at(j) == 10){
                        cout << 0;
                    }
                    else{
                        cout << ans.at(j);
                    }
                }
            }
            cout << endl;
        }
        else{
            cout << -1 << endl;
        }
    }
    }
    if(m == 0){
        if(n == 1){
            cout << 0 << endl;
        }
        else if(n == 2){
            cout << 10 << endl;
        }
        else{
            cout << 100 << endl;
        }
    }
}



Measured memory_bytes: 256
K, A, B = list(map(int, input().split()))

if B - A <= 2:
    print(K + 1)

else:
    if K <= A:
        print(K + 1)
    else:
        bisket = 1
        K -= A - 1
        bisket += A - 1
        if K % 2 != 0:
            K -= 1
            bisket += 1
        bisket += (B - A) * int(K / 2)

        print(bisket)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
ll n, m, x, y, q, d, z, w, sum = 0, ans = 0;
const int MOD = 1000000007;
vector<ll> a;
int main(void) {
	cin >> n; a.resize(n);
	rep(i, n) cin >> a[i];
	w = a[0] + a[1];
	for (int i = 2; i < n; i++) sum ^= a[i];
	if (w < sum || ((w - sum) & 1)) { // dが負,共通するbitがある
		cout << -1 << endl;
		return 0;
	}x = (w - sum) / 2;
	if (x & sum) {// 共通するbitがある
		cout << -1 << endl;
		return 0;
	}y = x;
	for (int bit = 59; bit >= 0; bit--) {
		if (x & (1LL << bit))continue;
		else if (sum & (1LL << bit)) {
			if ((y + (1LL << bit)) <= a[0]) {//a[0] < y ならbitを立てる
				y += (1LL << bit);
			}
		}
	}
	if (y == 0 || y > a[0]) cout << -1; // y= 0の時不適
	else cout << a[0] - y << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a,b,c,k;cin >> a >> b >> c >> k;
  if (a>k) cout << k << endl;
  else if (a+b>=k) cout << a << endl;
  else cout << a-(k-a-b) << endl;
  
  
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >>N;
  vector<int> A(0,0);
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    A.push_back(a);
  }
  int num=1, ans=0;
  for(int i=0; i<N; i++){
    if(A[i] == num){
      num++;
      ans++;
    }
//    cout<<"i:"<<i<<" A[i]:"<<A[i]<<" num:"<<num<<" ans:"<<ans<<endl;
  }
  if(num==1) ans=N+1;
  cout << N-ans << endl;
}

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

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


#define rep(i,n) for(ll i=0; i<n; i++)
#define frep(i,m,n) for(ll i=m; i<=n; i++)

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, k, ans = -1*INF; cin >> n >> k;
    vector<ll> p(n), c(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i, n) cin >> c[i];

    rep(i, n) {
        ll m = -1*INF, now = p[i]; // 得点、現在地
        vector<ll> sum(1, 0);
        sum.push_back(c[now]);
        while(now != i) {
            ll len = sum.size();
            now = p[now];
            sum.push_back(sum[len-1]+c[now]);
        }

        ll len = sum.size()-1; // サイクルの長さ
        if(k < len) {
            frep(j, 1, k) {
                if(m < sum[j]) m = sum[j];
            }
        }
        else if(sum[len] < 0) {
            frep(j, 1, len) {
                if(m < sum[j]) m = sum[j];
            }
        }
        else {
            frep(j, 0, k%len) {
                if(m < sum[j]) m = sum[j];
            }
            ll a = sum[len]*(k/len) + m;
            frep(j, 0, len) {
                if(m < sum[j]) m = sum[j];
            }
            ll b = sum[len]*(k/len-1) + m;
            if(a < b) m = b;
            else m = a;
        }
        if(ans < m) ans = m;
    }

    cout << ans << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>  
using namespace std;  
typedef long long ll; 
typedef long double ld; 
const int INF = 0x3f3f3f3f;  
const int N = 100000 + 5;
const ll mod = 1e9+7;
ll vis[N];
ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
int main()
{
	ll n,k;
	cin >> n >> k;
	ll sum = 0;
	for(ll i = k; i >= 1; i--){
		vis[i] = mod_pow(k/i,n,mod);
		for(ll j = 2*i; j <= k; j+=i){
			vis[i] = (vis[i] - vis[j] + mod) % mod;
		}
	}
	for(int i = 1; i <= k; i++){
		sum = (sum + (i * vis[i])%mod)%mod;
	}
	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4368
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second
const lint INF = 2000LL * 1145141919LL;
signed main(){
    lint N, M; cin >> N >> M;
    vector<lint> A(M);
    vector<lint> B(M);
    vector<lint> C(M);
    REP(i, M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;
        B[i]--;
        C[i] *= -1;
    }
    vector<lint> d(N, INF);
    d[0] = 0;
    bool neglp = false;
    REP(i, N){
        REP(j, M){
            lint f = A[j];
            lint t = B[j];
            lint c = C[j];
            if(d[f]==INF) continue;
            if(d[t] > d[f]+c){
                d[t] = d[f]+c;
                if(i==N-1 and t==N-1) neglp = true;
            }
        }
        if(neglp) break;
    }
    if(neglp){
        cout << "inf" << endl;
    }
    else{
        cout << -d[N-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void ans(long n);

int main() {
    long n; scanf("%ld", &n);
    ans(n);
    printf("\n");
}

void ans(long n) {
    long m = n % 26;
    char c; if (m == 0) { c = 'z'; } else { c = 'a'+m-1; }
    if (n <= 26) {
        printf("%c", c);
    } else {
        ans((n-1)/26);
        printf("%c", c);
    }
}


Measured memory_bytes: 1660
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	rep(i,n){
		set<char> st, st2;
		for(int j = 0; j < i; ++j) st.insert(s[j]);
		for(int j = i; j < n; ++j) st2.insert(s[j]);
		int score = 0;
		for(auto p : st){
			if(st2.find(p) != st2.end()) ++score;
		}
		chmax(ans, score);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String ans = "";
		for (int i = 0; i < 3; i++) {
			String s = sc.next();
			ans += s.charAt(i);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <bitset>
#include <queue>
#include <set>
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

#define LL long long 
#define ULL unsigned long long
#define eps 1e-9
#define N 100010
#define M 600050
#define pii pair<int,int>
#define MP make_pair
#define inf 100000000
#define md (ll+rr>>1)
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define ls rt<<1
#define rs rt<<1|1
#define Pi acos(-1.0)
#define mod 1000000007
#define ui unsigned int
#define pb push_back
LL powmod(LL a,LL b,LL p){
	if(b < 0) return 0;
	LL res = 1; a %= p;
	for(;b;b>>=1){
		if(b & 1) res = res * a % p;
		a = a * a % p;
	}
	return res;
}

LL ans = 0;
LL gcd(LL a,LL b){
	while(b){
		LL t = a % b;
		ans += a / b * b * 2;
		a = b;
		b = t;
	}
	return a;
}

int main(){
	LL n,x;
	cin>>n>>x;
	LL _gcd = gcd(n-x,x);
	ans += n - _gcd;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono>
#include <climits>
#include <unordered_map>
#include <iomanip> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	auto start = high_resolution_clock::now(); 

	double a,b,x;
	cin >> a >> b >> x;

	double vol_rem = (a*a*b - x);
	if (vol_rem > a*a*b/2.0){
		double adash = (x*2.0)/(a*b);
		double ans = (atan(b/adash) * 180.0) / 3.1415926535897932 ;
		cout << fixed << setprecision(12) << ans << endl;	
	}
	else{
		double h_rem = ((a*a*b - x)*2.0)/(a*a);
		double ans = (atan(h_rem/a) * 180.0) / 3.1415926535897932 ;
		cout << fixed << setprecision(12) << ans << endl;	
	}


	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << fixed << setprecision(9) << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>

int n;

int main(){
    while (true) {
        int ans = 0;
        std::cin >> n;
        if(n == 0)
            break;
        n /= 4;

        for(int i = 0; i < n; ++i){
            int in;
            std::cin >> in;
            ans += in;
        }

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

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    h[0]--;
    rep(i,n-1){
        if(h[i+1]<h[i]) {
            cno;
            return 0;
        }
        if(h[i+1] > h[i]) h[i+1]--;
    }
    cyes;
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
bool operator > (Edge<int> e1, Edge<int> e2) {
    return e1.cost < e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
template <typename T>
std::vector<T> dijkstra(const Graph<T> &g, int s) {
    int sz = (int)(g.size());
    std::vector<T> dist(sz, std::numeric_limits<T>::max());
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> pq;
    dist[s] = 0;
    pq.push({0, s});
    while(!pq.empty()) {
        T d = pq.top().first;
        int now = pq.top().second;
        pq.pop();
        if(d > dist[now]) continue;
        for(int i=0;i<(int)(g[now].size());++i) {
            int next = g[now][i].to;
            T cost = g[now][i].cost;
            if(dist[next] > dist[now] + cost) {
                dist[next] = dist[now] + cost;
                pq.push({cost, next});
            }
        }
    }
    return dist;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(1) {
    int n, m, l; cin >> n >> m >> l;
    if(n == 0) break;
    Graph<int> g(n*(l+1));
    for(int i=0;i<m;++i) {
      int a, b, d, e; cin >> a >> b >> d >> e;
      a--; b--;
      for(int i=0;i<=l;++i) {
        g[a*(l+1) + i].push_back(Edge<int>(a*(l+1) + i, b*(l+1) + i, e));
        g[b*(l+1) + i].push_back(Edge<int>(b*(l+1) + i, a*(l+1) + i, e));
        if(i >= d) g[a*(l+1) + i].push_back(Edge<int>(a*(l+1) + i, b*(l+1) + i - d, 0));
        if(i >= d) g[b*(l+1) + i].push_back(Edge<int>(b*(l+1) + i, a*(l+1) + i - d, 0));
      }
    }
    vector<int> dist = dijkstra(g, l);
    int mi = INF;
    for(int i=0;i<=l;++i) {
      mi = min(mi, dist[(n-1) * (l+1) + i]);
    }
    cout << mi << endl;
  }
}



Measured memory_bytes: 11268
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
const int N=1e4+50;
const long long INF=0x3f3f3f3f3f3f3f3f;
typedef long long ll;
double length[N][N];
double d[N];
bool vis[N];
int n;
struct circular
{
   double x,y;
   double r=0;
}c[N];
void dijkstra(int s)
{
    for(int i=0;i<=n+1;i++)
        d[i]=INF;
    d[s]=0;
    while(1)
    {
        int v=-1;
        for(int i=0;i<=n+1;i++)
        {
            if(!vis[i]&&(v==-1||d[i]<d[v]))
                v=i;
        }
        if(v==-1)
         break;
        vis[v]=1;
        for(int i=0;i<=n+1;i++)
        d[i]=min(d[i],d[v]+length[v][i]);
    }
}
int main()
{
    double x1,y1;
    scanf("%lf%lf%lf%lf",&c[0].x,&c[0].y,&x1,&y1);
    scanf("%d",&n);
    c[n+1].x=x1;
    c[n+1].y=y1;
    for(int i=1;i<=n;i++)
    {
        scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);
    }
    for(int i=0;i<=n+1;i++)
    {
        for(int j=i+1;j<=n+1;j++)
        {
           length[i][j]=(double)sqrt((double)(c[i].x-c[j].x)*(c[i].x-c[j].x)+(double)(c[i].y-c[j].y)*(c[i].y-c[j].y));
            length[i][j]-=c[i].r+c[j].r;
            if(length[i][j]<0)
             length[i][j]=0;
            length[j][i]=length[i][j];
        }
    }
    dijkstra(0);
    printf("%.9f\n",d[n+1]);
    return 0;
}


Measured memory_bytes: 78592
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    print(0 if ni() == 1 else 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#!/usr/bin/env python3
import sys


def solve(K: int, A: int, B: int):
    for i in range(A, B+1):
        if i % K == 0:
            return 'OK'
    return 'NG'

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(K, A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9192