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

int main(){
	long N;
	cin>>N;
	string ans;
	int keta;
	int ketap=-1;
	while(ketap!=1){
		if(N>0){
			long tmp=0;
			keta=1;
			while(true){
				if(N<=tmp+pow(2,keta-1))break;
				else{
					tmp+=pow(2,keta-1);
					keta+=2;
				}
			}
			if(ketap==-1 || ketap==keta+1){
				N-=pow(2,keta-1);
				ketap=keta;
				ans+='1';
			}
			else{
				ketap--;
				ans+='0';
			}
		}
		else if(N<0){
			long tmp=0;
			keta=2;
			while(true){
				if(N>=tmp-pow(2,keta-1))break;
				else{
					tmp-=pow(2,keta-1);
					keta+=2;
				}
			}
			if(ketap==-1 || ketap==keta+1){
				N+=pow(2,keta-1);
				ketap=keta;
				ans+='1';
			}
			else{
				ketap--;
				ans+='0';
			}
		}
		else{
			if(ketap==-1){
				ans+='0';
				break;
			}
			ketap--;
			ans+='0';
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;


int main() {
	int n;
	double v[50];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	double ave;
	for (int i = 0; i < n - 1; i++) {
		sort(v, v + n);
		ave = (v[i] + v[i + 1]) / 2;
		v[i + 1] = ave;
	}
	cout << v[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
n = 0
while n != 1:
 m = raw_input().split()
 if m[1] == "?":
     break

 if m[1] == "+":
     print int(m[0])+int(m[2])
 if m[1] == "-":
     print int(m[0])-int(m[2])
 if m[1] == "*":
     print int(m[0])*int(m[2])
 if m[1] == "/":
     print int(m[0])/int(m[2])

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

int main(){
  int n,k,q;
  cin >>  n >> k >> q;
  
  vector<int> a(q);
  for(int i=0; i < q; i++){
    cin >> a.at(i);
  }
  
  vector<int> count(n);
  
  for(int i=0; i < q; i++){
    count.at(a.at(i)-1)++;
  }
  
  for(int i =0; i < n; i++){
    if(count.at(i) >= q-k+1){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 1408
#include<stdio.h>
int main(){
	int d[4][4],i,j;
	scanf("%d %d %d",&d[0][0],&d[0][1],&d[1][1]);
	i=d[1][1]*3;
	d[2][2]=i-d[1][1]-d[0][0];
	d[2][1]=i-d[1][1]-d[0][1];
	d[2][0]=i-d[2][2]-d[2][1];
	d[1][0]=i-d[0][0]-d[2][0];
	d[0][2]=i-d[0][0]-d[0][1];
	d[1][2]=i-d[1][0]-d[1][1];
	for(i=0;i<3;i++){
		for(j=0;j<3;j++)printf("%d%c",d[i][j],j%3==2?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

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

    //(a < b) b - (a + W)  (a > b)a - (b + W)
    int res, higher,lower;
    
    higher = max(a,b);
    lower = min(a,b);

    res = higher - (lower + W);
    
    if(res < 0) res = 0;
    
    cout << res << endl;
    return 0;    

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n, k;
    
    scanf("%d%d", &n, &k);
    
    if (n%k==0) {
        printf("%d", 0);
    } else {
        printf("%d", 1);
    }

    
    return 0;
}



Measured memory_bytes: 1732
/*
 *
 *    I am o0o0oo00.
 *
 */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define p7          1000000007
#define p9          998244353
#define pb          push_back
#define ff          first
#define ss          second
#define vll         vector<ll>
#define pll         pair<ll,ll>
#define vpll        vector<pll>
#define mll         map<ll,ll>
#define test        ll T;cin>>T;while(T--)
#define ad(a,n)     vll a;a.resize(n);for(ll i=0;i<n;i++)cin>>a[i];
#define as(a,n)     for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define all(x)      x.begin(),x.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll powm(ll x, ll y, ll m = p7) {
    x = x % m; ll res = 1; while (y)
    {if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res;
}
ll modi(ll a, ll m = p7) {return powm(a, m - 2, m);}
void yesno(bool f) {f ? cout << "YES" << endl : cout << "NO" << endl;}


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

vll adj[100005];
ll dp[100005] = {0};
bool vis[100005] = {false};

ll dfs(ll node)
{
    if (vis[node] == true)
        return dp[node];
    ll cur = 0;
    for (auto x : adj[node])
    {
        cur = max(cur, dfs(x) + 1ll);
    }
    dp[node] = cur;
    vis[node] = true;
    return cur;
}

void dfs1(ll n)
{
    ll cur = dfs(1);
//    as(vis,n+1);
    for (ll i = 1; i <= n; i++)
    {
        //      cout<<i<<endl;
        if (!vis[i])
            ll base = dfs(i);
        //   as(vis,n+1);
    }
//    as(vis,n+1);
}


int32_t main()
{
//    ss99();
//    test
    {
        ll n, m; cin >> n >> m;
        for (ll i = 0; i < m; i++)
        {
            ll u, v; cin >> u >> v;
            adj[u].pb(v);
        }
        ll ans = 0;
        dfs1(n);
        //       as(dp,n+1);
        //    as(vis,n+1);
        for (ll i = 1; i <= n; i++)
        {
            ans = max(ans, dp[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 8704
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif

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

    string S; cin >> S;
    int SL = S.size();
    string T; cin >> T;
    int TL = T.size();

    string ans = "UNRESTORABLE";

    string RS = S;
    reverse(RS.begin(), RS.end());
    string RT = T;
    reverse(RT.begin(), RT.end());

    for(int i=0; i<=SL-TL; i++) {
        bool match = true;
        for(int j=0; j<TL; j++) {
            if (RS[i+j] != '?' && RS[i+j]!=RT[j]) {
                match = false;
                break;
            }
        }

        if (match) {            
            ans = RS.substr(0, i) + RT + RS.substr(i + TL);
            for(int k=0; k<SL; k++) {
                if (ans[k] == '?') ans[k] = 'a';
            }

            reverse(ans.begin(), ans.end());
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){

	int n,m,i,j;
	int a[101][101], b[101],c[101];

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

	for(j=0; j<m; j++){
		scanf("%d",&b[j]);
	}
	
	for(i=0; i<n; i++){
		c[i] =0;
		for(j=0; j<m; j++){
			c[i]+= a[i][j]*b[j];
		}
		printf("%d\n", c[i]);
    }
		return 0;
}


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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

int gcd(int a, int b) {
	if (a < b) {
		int c = a;
		a = b;
		b = c;
	}
	if (b == 0) return a;
	return gcd (b, a % b);
}

ll sum(ll x) { // sum of subsequent numbers from 0 to x
	return x*(x + 1)/2;
}

int main() {
	int s, w;
	cin >> s >> w;

	if (w >= s) cout << "unsafe" << endl;
	else cout << "safe" << endl;
}


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws IOException {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			String W = in.readLine();

			int N = Integer.parseInt(W.split(" ")[0]);
			int M = Integer.parseInt(W.split(" ")[1]);

         int allPatternsNM = (N + M)*(N + M -1)/2;
         int eachPatternsNM = N*M;
         int ans= allPatternsNM - eachPatternsNM;
         System.out.println(ans);
	}

}


Measured memory_bytes: 21332
s=input()
n=len(s)
answer=1
for i in range(n):
    if i%2==0:
        if s[i]=='L':
            answer=answer*0
    else:
         if s[i]=='R':
            answer=answer*0
if answer==0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
	string a, b, c;
	cin >> a >> b >> c;
	char d = a[0] - 32;
	char e = b[0] - 32;
	char f = c[0] - 32;
	cout << d << e << f << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[1000010];
long long dp[100007][17],w=1;
int main()
{
	scanf("%s",a);
	int len=strlen(a);
	dp[len][0]=1;
	for(int i=len-1;i>=0;i--){
		if(a[i]=='?'){
			for(int k=0;k<=9;k++){
				for(int j=0;j<=12;j++){
					dp[i][(j+w*k)%13]=(dp[i][(j+w*k)%13]+dp[i+1][j])%1000000007;	
				}
			}
		}
		else
		for(int j=0;j<=12;j++)dp[i][(j+w*(a[i]-'0'))%13]=dp[i+1][j];
		w=w*10%13;
	}
	printf("%lld\n",dp[0][5]);
	return 0;
}

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

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

  double ans=0.0;
  for(int i=1; i<=n; ++i){
    int j=i;
    double win=1.0/n;
    while(j<k){
      j*=2;
      win/=2.0;
    }
    ans+=win;
  }

  cout<<setprecision(15)<<ans<<endl;
    
}


Measured memory_bytes: 256
N = int(input())
AB = [[]]*(N-1)
for i in range(N-1):
    AB[i] = list(map(int,input().split()))
from collections import defaultdict as ddict
from collections import deque
tree = ddict(list)
B = [0]*(N-1)
for i,ab in enumerate(AB):
    tree[ab[0]].append(ab[1])
    B[i] = ab[1]
# 各エッジの色を格納する変数の初期化
# C[0]は使わない
C = [0]*N
# 幅優先探索用のcue
Q = deque([1])
while Q:
    q = Q.popleft()
    c = 0
    for w in tree[q]:
        # 色をインクリメントした際に親の色とかぶったら更に1を加算する
        # 他は単純なインクリメント
        c += 1 + int(C[q-1] == c+1)
        # エッジの色を格納
        C[w-1] = c
        # 子供をcueに追加
        Q.append(w)
print(max(C))
for b in B:
    print(C[b-1])

Measured memory_bytes: 85848
import sys
input = sys.stdin.readline

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 2*10**5

for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans,a[x-1]+b[y-1]-c)
ans = min(ans, min(a)+min(b))
print(ans)

Measured memory_bytes: 64928
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
int n,m,fa[200010],du[200010],vis[200010],c[200010];
inline int getfather(int x){return fa[x]==x?x:fa[x]=getfather(fa[x]);}
int main()
{
	n=read();m=read();
	for(int i=1;i<=1000;i++)fa[i]=i;
	for(int i=1;i<=n;i++){
		int a=read(),b=read(),c=read(),d=read();
		int x=(c==0)?a:-c,y=(d==0)?-b:d;
		x+=500;y+=500;int fx=getfather(x),fy=getfather(y);
		fa[fx]=fy;vis[x]=1;du[x]++;du[y]--;
	}
	bool flag=1;
	for(int i=1;i<500;i++)if(du[i]>0)flag=0;
	for(int i=501;i<=1000;i++)if(du[i]<0)flag=0;
	for(int i=1;i<=1000;i++){
		int fi=getfather(i);
		vis[fi]|=vis[i];
		if(du[i])c[fi]=1;
	}
	for(int i=1;i<=1000;i++)if(fa[i]==i&&!c[i]&&vis[i])flag=0;
	puts(flag?"YES":"NO");
	return 0;
}

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

int main(){
  string s;
  
  cin >> s;
  
  if(s.at(0) == 'A'){
    if(s.at(2) == 'C'){
      if(s.at(1) == 'B')
        cout << "ARC" << endl;
      if(s.at(1) == 'R')
        cout << "ABC" << endl;
    }
  }
}  

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

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

    int P[N];
    int tmp = N+1;
    int ans = 0;

    for (int i = 0; i < N; i++){
        cin >> P[i];
        if (P[i] <= tmp){
            tmp = P[i];
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	ll N,sum=0,ans1,ans2;
	cin>>N;
	vector<ll> A(N);
	for(int i=0;i<N;i++) cin>>A[i];
	sort(A.begin(),A.end());
	cout<<A[N-1]<<" ";
	auto ite=lower_bound(A.begin(),A.end(),A[N-1]/2);
	if(*ite==A[N-1]) cout<<*(ite-1);
	else if(*ite==A[0]) cout<<*ite;
	else{
		if(abs(A[N-1]/2 - *ite) > abs(A[N-1]/2 - *(ite-1))){
			cout<<*(ite-1);
		}else{
			cout<<*ite;
		}
	}
	return 0;
}


Measured memory_bytes: 1152
primes = Array.new(1_000_000, true)
primes[0, 2] = [false, false]
2.upto(999_999){|x|
    if primes[x]
        m = 2
        while x * m <= 999_999
            primes[x * m] = false
            m += 1
        end
    end
}

while true
    n = gets.to_i
    break if n == 0
    sum = 0
    3.upto(n/2){|x| sum += 1 if primes[x] && primes[n - x]}
    puts sum
end



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

extern inline char gc() {
    static char RR[23456], *S = RR + 23333, *T = RR + 23333;
    if(S == T) fread(RR, 1, 23333, stdin), S = RR;
    return *S ++;
}
inline int read() {
    int p = 0, w = 1; char c = gc();
    while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }
    while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
    return p * w;
}

#define ri register int
#define ll long long
#define sid 200050

int n;
ll a[sid];

inline ll Solve(int p) {
    ll sum = 0, ret = 0;
    for(ri i = 1, t = p; i <= n; i ++, t *= -1) {
        sum += a[i];
        if(t > 0 && sum <= 0) ret += 1 - sum, sum = 1;
        else if(t < 0 && sum >= 0) ret += 1 + sum, sum = -1;
    }
    return ret;
}

int main() {
    n = read();
    for(ri i = 1; i <= n; i ++) a[i] = read();
    printf("%lld\n", min(Solve(1), Solve(-1)));
    return 0;
}

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

#define INF 2147483647
//1024*1024*1024*2-1
#define ASTART (1<<17)
int a[1<<18];

void update(int i,int x){
  i+=ASTART-1;
  a[i]=x;
  //cout << i << " = " << a[i];
  while (i>0){
    i=(i-1)/2;
    a[i]=min(a[i*2+1],a[i*2+2]);
  }
}
int find(int s,int t,int k,int l,int r){
  if (r<=s||l>=t)return INF;
  if (l>=s&&r<=t)return a[k];
  int m=(l+r)/2;
  return min(find(s,t,k*2+1,l,m),find(s,t,k*2+2,m,r));
}

int main(){
  int n,q,com,x,y;
  for (int i=0;i<262150;i++)a[i]=INF;
  cin >> n>>q;

  for (int i=0;i<q;i++){
    cin >> com >> x >> y;
    if (com==0) update(x,y);
    else cout << find(x,y+1,0,0,ASTART)<< endl;
    //for (int i=0;i<5;i++)cout << a[i] << endl;
    //cout << a[ASTART];
  }

  return 0;
}

Measured memory_bytes: 4120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL << 60; 

int main()
{
  int A[3][3];
  rep(i,3) rep(j,3) cin >> A[i][j];
  int N; cin >> N;
  int b[N]; rep(i,N) cin >> b[i];
  bool ans = false;
  //穴あけ
  rep(i,N)
  {
    rep(j,3) rep(k,3)
    {
      if(b[i] == A[j][k]) A[j][k] = 0;
    }
  }
  //揃っているかチェック
  //横
  rep(i,3)
  {
    if(A[i][0] == A[i][1] && A[i][1] == A[i][2])
    {
      ans = true;
      break;
    }
  }
  //縦
  rep(i,3)
  {
    if(A[0][i] == A[1][i] && A[1][i] == A[2][i])
    {
      ans = true;
      break;
    }
  }
  //斜め
  if(A[0][0] == A[1][1] && A[1][1] == A[2][2]) ans = true;
  if(A[2][0] == A[1][1] && A[1][1] == A[0][2]) ans = true;
  //出力
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int s, d, i;
	
	while (scanf("%d", &d) != EOF){
		s = 0;
		i = 1;
		while (i * d < 600){
			s += (i * d) * (i * d) * d;
			i++;
		}
		
		printf("%d\n", s);
	}
	
	return (0);
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define ll long long int 
#define fori(i,n) for(int i=0; i<n; ++i)
#define ford(i,n) for(int i=n-1; i>=0; --i)
#define vi vector<int> 
#define vs vector<string>
#define vll vector<ll>
#define di deque<int>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define mod1 1000000007
#define mod2 998244353
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gcd __gcd


#define fast_cin() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using namespace std::chrono;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> i_set;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ll_set; 
/* new_data_set p; */
/* *p.find_by_order(3); The value at third place */
/* p.order_of_key(7); The expected index in the set in sorted order */



int main(int argc, char const *argv[]){
	fast_cin();
    int n,r;
    cin>>n>>r;
    if(n>=10) cout<<r<<"\n";
    else cout<<r+100*(10-n)<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
ll q, t, n, m, k, ans;
priority_queue<ll> pr;
string s, ss[maxn], str;
void sol()
{
    cin >> n;
    for(int i = 0; i < n; i ++)
        cin >> ss[i];
    sort(ss, ss+n);
    ans = 0;
    for(int i = 0; i < n; i ++)
    {
        ++ans;
        while(ss[i] == ss[i+1] && i + 1 < n)
            ++i;
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    sol();
}


Measured memory_bytes: 34928
#include <bits/stdc++.h>
//#include <ext/numeric>
#define oo 0x3f3f3f3f
#define long long long

using namespace std;
//using namespace __gnu_cxx;

long nxt(long curX, long curY, long t, long a) {
    long ch1 = (curX + t - 1) / t;
    long ch2 = (curY + a - 1) / a;
    return max(ch1, ch2);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    int n;
    cin >> n;
    long curX = 1, curY = 1;
    while (n--) {
        int t, a;
        cin >> t >> a;
        long e = nxt(curX, curY, t, a);
        curX = t * e;
        curY = a * e;
    }

    cout << curX + curY << '\n';

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
const long long mod=1000000007;
long long n,a,b;
void ext_gcd(long long a,long long b,long long &x,long long &y)
{
    if(b==0)
    {
        x=1,y=0;
        return;
    }
    ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return;
}
inline long long inverse(long long a)
{
    long long x,y;
    ext_gcd(a,mod,x,y);
    if(x<0) x+=mod;
    return x;
}
inline long long pow_mod(long long a,long long b)
{
    if(b==0) return 1;
    if(b==1) return a;
    long long x=pow_mod(a,b>>1);
    x*=x,x%=mod;
    if(b&1) x*=a,x%=mod;
    return x;
}
long long ans=0;
int main()
{
    read(n),read(a),read(b);
    ans=pow_mod(2,n);
    long long tmp=1;
    for(int i=1;i<=a;i++) tmp*=(long long)(n-i+1),tmp%=mod,tmp*=inverse(i),tmp%=mod;
    ans-=tmp;
    tmp=1;
    for(int i=1;i<=b;i++) tmp*=(long long)(n-i+1),tmp%=mod,tmp*=inverse(i),tmp%=mod;
    ans-=tmp;
    ans--;
    ans=(ans%mod+mod)%mod;
    write(ans),putchar('\n');
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;



int main(){
    
    
    ll ans=0;
    
    
    int N;
    cin >> N;
    ll x[100], y[100];
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
    }
    
    
    for(double th=0; th<2*M_PI; th+=0.0001*M_PI){
        double tx=cos(th);
        double ty=sin(th);
        
        ll sumx=0, sumy=0;
        for(int i=0; i<N; i++){
            if(tx*(double)x[i]+ty*(double)y[i]>=0){
                sumx += x[i];
                sumy += y[i];
            }
        }
        
        ans = max(ans, sumx*sumx+sumy*sumy);
    }
    
    cout << fixed << setprecision(20) << sqrt(ans)<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;

int main() {
    int h, w;
    cin >> h >> w;
    int d[10][10];
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++){
            cin >> d[i][j];
        }
    }

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int a;
            cin >> a;
            if (a == -1) continue;
            ans += d[a][1];
        }
    }

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

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  string k;
  int d;
  cin >> k >> d;
  int n = sz(k);

  const ll mod = 1e9+7;
  vector<vvl> dp(n+1, vvl(d, vl(2, 0)));
  dp[0][0][0] = 1;

  rep(i,0,n) {
    rep(j,0,d) {
      rep(o,0,2) {
        rep(l,0,10) {
          if (not o and l > k[i]-'0') break;
          int s = o;
          if (l < k[i]-'0') s=1;
          dp[i+1][(j+l)%d][s] += dp[i][j][o];
          dp[i+1][(j+l)%d][s] %= mod;
        }
      }
    }
  }

  cout << (accumulate(all(dp[n][0]), 0LL)-1+mod)%mod << '\n';
}

Measured memory_bytes: 55424
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        switch(s){
            case "Sunny":
                System.out.println("Cloudy");
                break;
            case "Cloudy":
                System.out.println("Rainy");
                break;
            case "Rainy":
                System.out.println("Sunny");
                break;
        }
    }
}

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

using namespace std;

char star[1050][1050];
long long int dp[1050][1050];

const int MODE = 1e9 + 7;

int main() {                   
	long long int w, h;
	cin >> w >> h;
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			cin >> star[i][j];
		}
	}
	dp[0][0] = 1;
	for (int i = 1; i < w; i++) {
		if (star[0][i] == '.')
			dp[0][i] = dp[0][i - 1];
	}
	for (int j = 1; j < h; j++) {
		if (star[j][0] == '.')
			dp[j][0] = dp[j - 1][0];
	}
	for (int i = 1; i < w; i++) {
		for (int j = 1; j < h; j++) {
			if (star[i][j] == '.')
				dp[i][j] = (dp[i - 1][j] % MODE) + (dp[i][j - 1] % MODE);
				dp[i][j] %= MODE;
		}
	}
	cout << dp[w - 1][h - 1] << '\n';
	return 0;
}


Measured memory_bytes: 9472
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int>pii;
 
const int pps=1e9+7;
 
int n,m,ans;
vector<pii>q[305];
int f[305][305][305];
vector<pii>::iterator it;
 
int read() {
    int x=0,f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return x*f;
}
 
int main() {
    n=read(),m=read();
    for(int i=1;i<=m;i++) {
        int l=read(),r=read(),x=read();
        q[r].push_back(make_pair(l,x));
    }f[0][0][0]=1;
    for(int i=1;i<=n;i++) {
        for(int j=0;j<i;j++)
            for(int k=0;k<=j;k++) {//<=是因为j,k可以全部等于0
                f[i][j][k]=(f[i][j][k]+f[i-1][j][k])%pps;
                f[i][i-1][k]=(f[i][i-1][k]+f[i-1][j][k])%pps;
                f[i][i-1][j]=(f[i][i-1][j]+f[i-1][j][k])%pps;
                for(it=q[i].begin();it!=q[i].end();it++) {
                    int tmp=(j>=(*it).first)+(k>=(*it).first)+1;
                    if(tmp!=(*it).second)f[i][j][k]=0;
                }
            }
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<=i;j++)
            ans=(ans+f[n][i][j])%pps;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 108800
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;

double BTC2JPY(double BTC){
    return BTC*380000.0;
}

int main(){
    int N;
    cin >> N;
    double total = 0.0;
    for(int i=0;i<N;i++){
        string x, u;
        cin >> u >> x;

        if(x=="JPY"){
            total += stoi(u);
        } else{
            total += BTC2JPY(stod(u));
        }
    
    }
    cout << total << endl;

}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var k int
	var s string
	fmt.Scan(&k, &s)
	if len(s) <= k {
		fmt.Println(s)
	} else {
		for i, ss := range s {
			if i >= k {
				break
			}
			fmt.Printf("%s", string(ss))
		}
		fmt.Println("...")
	}
}


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

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

    if(N%2==0){
        vector<vector<int>> v(N/2, vector<int>(2));
        for(int i=0; i<N/2; ++i){
            v[i][0] = i+1;
            v[i][1] = N-i;
        }

        // calc M
        int M = 0;
        for(int i=1; i<N/2; ++i){
            M += N/2 - i;
        }
        M *= 4;
        cout << M << endl;

        for(int i=0; i<N/2-1; ++i){
            for(int j=i+1; j<N/2; ++j){
            cout << v[i][0] << ' ' << v[j][0] << endl;
            cout << v[i][0] << ' ' << v[j][1] << endl;
            cout << v[i][1] << ' ' << v[j][0] << endl;
            cout << v[i][1] << ' ' << v[j][1] << endl;
            }
        }

    }
    else{
        vector<vector<int>> v(N/2,vector<int>(2));

        for(int i=0; i<N/2; ++i){
            v[i][0] = i+1;
            v[i][1] = N-i-1;
        }

        // calc M
        int M = 0;
        for(int i=1; i<N/2; ++i){
            M += N/2 - i;
        }
        M *= 4;
        M += 2*(N/2);
        cout << M << endl;

        for(int i=0; i<N/2; ++i){
            cout << v[i][0] << ' ' << N << endl;
            cout << v[i][1] << ' ' << N << endl;
        }

        for(int i=0; i<N/2-1; ++i){
            for(int j=i+1; j<N/2; ++j){
            cout << v[i][0] << ' ' << v[j][0] << endl;
            cout << v[i][0] << ' ' << v[j][1] << endl;
            cout << v[i][1] << ' ' << v[j][0] << endl;
            cout << v[i][1] << ' ' << v[j][1] << endl;
            }
        }

    }

    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int dt1[10], dt2[10];

void left( int dt[] ) {
    int x = dt[1];
    dt[1] = dt[3];
    dt[3] = dt[6];
    dt[6] = dt[4];
    dt[4] = x;
}

void right( int dt[] ) {
    int x = dt[1];
    dt[1] = dt[4];
    dt[4] = dt[6];
    dt[6] = dt[3];
    dt[3] = x;
}

void up( int dt[] ) {
    int x = dt[1];
    dt[1] = dt[2];
    dt[2] = dt[6];
    dt[6] = dt[5];
    dt[5] = x;
}

void down( int dt[] ) {
    int x = dt[1];
    dt[1] = dt[5];
    dt[5] = dt[6];
    dt[6] = dt[2];
    dt[2] = x;
}

bool ok( int a[], int b[] ) {
    for( int i = 1; i <= 6; ++i ) if( a[i] != b[i] ) return false;
    return true;
}

bool check( int dt1[], int dt2[] ) {
    for( int i = 0; i < 4; ++i ) {
        left( dt1 );
        for( int j = 0; j < 4; ++j ) {
            up( dt1 );
            for( int k = 0; k < 4; ++k ) {
                left( dt1 );
                if( ok( dt1, dt2 ) ) return true;
            }
        }
    }
    return false;
}



int main( void ) {
    ios::sync_with_stdio( false );
    for( int i = 1; i <= 6; ++i ) cin >> dt1[i];
    for( int i = 1; i <= 6; ++i ) cin >> dt2[i];
    if( check( dt1, dt2 ) ) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}



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

#define BR "\n"
#define SP " "

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

  cout << (a / b) << SP;
  cout << (a % b) << SP;
  cout << fixed << setprecision(9) << ((double)a / (double)b) << BR;
  return 0;
}


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


int main() {
	
	int N, i;
	cin>>N;
	
	string S;
	cin>> S;
  
    map<char, int64_t> S_Num; 
  
    for(i = 0; i < N; i++){
      
      S_Num[S.at(i)]++;
    }

  int64_t Sum = S_Num['R'] * S_Num['G'] * S_Num['B'];
  
  for (i = 0; i < N; i++){
    for(int j = 0; true; j++){
      
      int x = i - j;
      int y = i + j;
      if (x < 0 || y >= N) break;
      if (S.at(x) != S.at(i) && S.at(x) != S.at(y) && S.at(y) != S.at(i)) Sum--;
    }
  }
  cout << Sum << endl;
}


/*
int main() {
	
	int N;
	cin>>N;
	
	string S;
	cin>>S;
	
	long long ans = 0;
	
	map<char,long long> mp;
	
	for(int i=0;i<N;i++)mp[S[i]]++;
	
	ans = mp['R']*mp['G']*mp['B'];
	
	for(int i=0;i<N;i++){
		for(int j=0;true;j++){
			int x = i-j;
			int y = i+j;
			if(x<0||y>=N)break;
			if(S[i]!=S[x]&&S[x]!=S[y]&&S[y]!=S[i])ans--;
		}
	}
	
	cout<<ans<<endl;
	
    return 0;
}*/



Measured memory_bytes: 3628
<?php
  fscanf(STDIN, "%s", $s);
  $cnt = [];
  $chars = str_split($s);
  foreach($chars as $c) $cnt[$c]++;

  foreach(range('a','z') as $c) {
    if ($cnt[$c] <= 0) {
      echo $c . "\n";
      exit;
    }
  }

  echo "None\n";
?>

Measured memory_bytes: 10744
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				boolean include3 = false;
				
				do {
					if (x % 10 == 3)
						include3 = true;
					x /= 10;
				} while (x > 0);
				
				if (include3)
					System.out.print(" " + i);
			}
		}
		System.out.println();
	}

}



Measured memory_bytes: 28560
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];
    map<int, int> mp;
    rep(i, n) mp[a[i]]++;
    lint sum = accumulate(all(a), 0LL);
    int q;
    cin >> q;
    rep(i, q) {
        lint b, c;
        cin >> b >> c;

        sum -= mp[b] * b;
        sum += mp[b] * c;
        mp[c] += mp[b];
        mp[b] = 0;

        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 8008
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = 0;
		int[] d = new int[a];
		for(int i = 0; i < a; i++){
			d[i] = sc.nextInt();
		} 
		for(int i = 0; i < a; i++){
			for(int j = i + 1; j < a ; j++){
				for(int k = j + 1;k < a; k++){
					if((d[i] + d[j] > d[k]) && (d[i] + d[k] > d[j]) && (d[j] + d[k] > d[i]) && d[i] != d[j] && d[k] != d[j] && d[i] != d[k] ){
						b++;
                      // System.out.println(d[i] + "と" + d[j] + "と" + d[k]);
					}
				}
			}
		}
		System.out.println(b);
		
		
	}
}

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

int color[1000];
string s[1000];
int n;
vector<int> G[1000];
ll d[1000][1000];

void warshall_floyd(){
  rep(k,n){
    rep(i,n){
      rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    }
  }
}

bool dfs(int v,int c){
  color[v]=c;
  for(int i=0;i<G[v].size();i++){
    if(color[G[v][i]]==c)return false;
    if(color[G[v][i]]==0 && !dfs(G[v][i],-c))return false;
  }
  return true;
}

int main(){
  cin >> n;
  rep(i,n){
    cin >> s[i];
    rep(j,n){
      if(s[i][j]=='1'){
        G[i].push_back(j);
        d[i][j]=1;
      }else d[i][j]=inf;
      if(i==j)d[i][j]=0;
    }
  }
  /*
  rep(i,n){
    for(int j=0;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(s[i][j]=='1' && s[i][k]=='1' && s[j][k]=='1'){
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  */
  for(int i=0;i<n;i++){
    if(color[i]==0){
      if(!dfs(i,1)){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  ll ans=0;
  warshall_floyd();
  rep(i,n){
    rep(j,n){
      ans=max(ans,d[i][j]);
    }
  }
  /*
  rep(i,n){
    ll cnt=0;
    rep(j,n){
      cnt+=s[i][j]-'0';
    }
    ans=max(ans,cnt);
  }
  */
  cout << ans+1 << endl;
return 0;}

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

typedef long long ll;
const int inf = 1000000000; // 10^9

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

  int n,m,c,res;
  cin>>n>>m>>c;

  int arr[m];

  for(int i=0; i<m; i++) {
    cin>>arr[i]; 
  }

  res = 0;
  while(n--) {
    ll ans = 0;
    int a;

    for(int i=0; i<m; i++) {
      cin>>a;
      ans += a*arr[i]; 
    }
    ans+=c;
    if(ans>0) {
      res++;
    }
  }

  cout << res << '\n';

  return 0;
}



Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner stdIn = new Scanner (System.in);
		int i,j,tmp;
		int[] a = new int[3];
		for(i = 0; i < a.length; i++){
			a[i] = stdIn.nextInt();
		}
		for(i = 0; i < a.length; i++){
			for(j = i+1; j < a.length; j++){
				if(a[i] > a[j]){
					tmp = a[i];
					a[i] = a[j];
					a[j] = tmp;
				}

			}
		}

		System.out.println(a[0] + " " + a[1] + " " + a[2]);
	}

}

Measured memory_bytes: 26328
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
#define MOD 1e9 + 7
#define N 1e5 + 10
struct store
{
	ll p,t;
};
bool cmp(store a,store b)
{
	return(a.p<b.p);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll i=0;
	store s[n];
	for(i=0;i<n;i++)
	{
		cin>>s[i].p>>s[i].t;
	}
	sort(s,s+n,cmp);
	ll price=0,req=m;
	for(i=0;i<n;i++)
	{
		if(req>=s[i].t)
		{
			req-=s[i].t;
			price=price+s[i].p*s[i].t;
		}
		else
		{
			price+=req*s[i].p;
			req=0;
			break;
		}
	}
	cout<<price;
}	

Measured memory_bytes: 1792
a , b , c = map(int,input().split())
if a <= b <= c:
    print(a,b,c)
elif a <= c <= b:
    print(a,c,b)
elif b <= a <= c:
    print(b,a,c)
elif b <= c <= a:
    print(b,c,a)
elif c <= a <= b:
    print(c,a,b)
elif c <= b <= a:
    print(c,b,a)



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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> mem(n+1, vector<int>(n+1));
    for (int v = 1; v <= n; v++) {
        for (int u = 1; u <= n; u++) {
            mem[v][u] = __gcd(u, v);
        }
    }
    long long ans = 0;
    for (int a = 1; a <= n; a++) {
        for (int b = 1; b <= n; b++) {
            for (int c = 1; c <= n; c++) {
                ans += mem[c][mem[a][b]];
            }
        }
    }
    cout << ans << endl;
}



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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	
	bool dp[k + 1];
	for (int i = 0; i < a[0]; i++) dp[i] = 0;
	for (int i = a[0]; i <= k; i++) {
		for (int j : a) {
			if (i - j >= 0) dp[i] = !dp[i - j];
			if (dp[i]) break;
		}
	}
	cout << (dp[k] ? "First" : "Second");
}

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

#define MIN(x,y) (((x)<(y))?(x):(y))
#define INFTY (1<<21)


int m, n, k, d, C[7], G[110][110], N, D[110][64];

int getID(char *str);
int isC(int x);
int bellman(void);

int main(void){
  char source[16], target[16];
  int cost,s,t;
  int i,j;
  while(scanf("%d%*c%d%*c%d%*c%d%*c",&m,&n,&k,&d) && m ){
    N = 2 + n + m;
    for(i=1;i<m+1;i++) scanf("%d%*c",&C[i]);
    for(i=0;i<N;i++) for(j=0;j<N;j++) G[i][j] = INFTY;
    for(i=0;i<d;i++){
      scanf("%s%*c%s%*c%d%*c",source,target,&cost);
      s = getID(source);
      t = getID(target);
      G[t][s] = G[s][t] = MIN(G[s][t], cost * k);
    }
    printf("%d\n",bellman());
  }
  return 0;
}

int getID(char *str){
  char num[16];
  if ( str[0] == 'H' ) return 0;
  if ( str[0] == 'D' ) return N - 1;
  strcpy(num,str+1);
  if ( str[0] == 'C' ) return atoi(num);
  return atoi(num) + m;
}

int isC(int x){
  return (1 <= x) && (x <= m);
}

int bellman(void){
  bool change;
  int minv;
  int i,i1,i2,i3,i4,j;

  for(i=0;i<N;i++) for(j=0;j<(1<<m);j++) D[i][j] = INFTY;
  D[0][0] = 0;
  for(i1=0;i1<N*(1<<m);i1++){
	change=false;
    for(i2=0;i2<N;i2++){
      for(i3=0;i3<N;i3++){
	if ( i2 == i3 || G[i2][i3] == INFTY ) continue;
	for(i4=0;i4<(1<<m);i4++){
	  if (isC(i3) && (i4&(1<<(i3-1))) != 0 ) continue;
	  if ( isC(i3) ) {
	    if ( D[i2][i4] + G[i2][i3] - C[i3] < D[i3][i4|(1<<(i3-1))] ) {
	      D[i3][i4|(1<<(i3-1))] = D[i2][i4] + G[i2][i3] - C[i3];
	      change = true;
	    }
	  } else {
	    if ( D[i2][i4] + G[i2][i3] < D[i3][i4] ){
	      D[i3][i4] = D[i2][i4] + G[i2][i3];
	      change = true;
	    }
	  }
	}
      }
    }
    if ( !change ) break;
  }
  minv = INFTY;
  for(i=0;i<(1<<m);i++) minv = MIN(minv, D[N-1][i]);
  return minv;
}

Measured memory_bytes: 688
import numpy as np
H,W = map(int,input().split())
a = np.array([list(input()) for _ in range(H)])
dlisx = np.any(a == "#",axis = 0)
dlisy = np.any(a == "#",axis = 1)
dlx = []
dly = []
for i,x in enumerate(dlisx):
    if not x:
        dlx.append(i)
for i,y in enumerate(dlisy):
    if not y:
        dly.append(i)

ans = np.delete(np.delete(a,dlx,1),dly,0)
for a in ans:
    print("".join(a))




Measured memory_bytes: 12556
from collections import deque
import sys

K = int(input())
q = deque()
if K < 10:
    print(K)
    sys.exit()

for i in range(1,10):
    q.append(i)

counta = 9
while K > counta:
    x = q.popleft()
    
    if x % 10 != 0:
        q.append(10 * x + (x % 10) - 1)
        counta += 1
        if K == counta:
            break
    if True:
        q.append(10 * x + (x%10))
        counta += 1
        if K == counta:
            break
    if x % 10 != 9:
        q.append(10 * x + (x%10) + 1)
        counta += 1
        if K == counta:
            break
print(q.pop())

Measured memory_bytes: 6216
#include<stdio.h>
#include<math.h>
 
int main(void)
{
   int n, i, f, s, x=0, r;
 
   scanf("%d",&n);
 
   for(i=1;i<=n;i=i+2){
      s=0;
      r=sqrt(i);
      for(f=1;f<=r;f++)
         if(i%f==0)
            s++;
      if((s==4)&&(i!=r*r)){
         x++;
      }
   }
 
   printf("%d\n",x);
   return 0;
}

Measured memory_bytes: 2112
H, W, M = map(int, input().split())
row = [0] * (H + 1)
col = [0] * (W + 1)

bom = []
for i in range(M):
    h, w = map(int, input().split())
    bom.append([h, w])
    row[h] += 1
    col[w] += 1
 
rmax = max(row)
cmax = max(col)
cnt = row.count(rmax) * col.count(cmax)

for h, w in bom:
    if rmax == row[h] and cmax == col[w]:
        cnt -= 1

print(rmax + cmax - (cnt == 0))


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

int main() {
    int64_t n;
    cin >> n;
    int64_t throughput = INT64_MAX;
    for (int i = 0; i < 5; i++) {
        int64_t people;
        cin >> people;
        throughput = min(people, throughput);
    }
    cout << 4 + n / throughput + (n % throughput == 0 ? 0 : 1) << endl;
}

Measured memory_bytes: 256
/* AOJ 0056
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0056
 *
 */

#include <stdio.h>
#define true 1
#define false 0

int table[51000];

int isprime(int n){
    int i;
    for(i=2;i*i<=n;i++){
        if(table[i] && !(n%i)){
            return false;
        }
    }
    return true;
}

void build(void){
    int i;
    table[0]=1;
    table[1]=1;
    table[2]=1;
    for(i=2;i<51000;i++){
        table[i]=isprime(i);
    }
}


int goldbach(int n){
    int i;
    int count;
    count = 0;
    for(i=2;i<=n/2; i++){
        if (table[i] && table[n-i]){
            count += 1;
        }
    }
    return count;
}


int main(){
    int n, largest, smallest;
    build();
    while(scanf("%d", &n) == 1 && n){
        printf("%d\n", goldbach(n));
    }

    return 0;
}

Measured memory_bytes: 604
import sys
input = sys.stdin.readline

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    abs_a = list(map(abs, A))
    min_a = min(abs_a)
    for i in range(N-1):
        if A[i] < 0:
            A[i] = -A[i]
            A[i+1] = -A[i+1]
    if A[N-1] < 0:
        return sum(abs_a) - min_a * 2
    else:
        return sum(abs_a)


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


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

using namespace std;

typedef long long ll;

ll arr[100100];

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

    ll awal = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            awal += arr[i];
        } else {
            awal -= arr[i];
        }
    }
    awal /= 2;

    printf("%lld", awal * 2);

    for (int i = 0; i < n - 1; i++) {
        printf(" %lld", 2 * (arr[i] - awal));
        awal = arr[i] - awal;
    }
}


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

using namespace std;

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

const int INF = 1e9+7;

int n;

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

  cin>>n;
  int m = sqrt(10+n);
  vector<int> out(n+1,0);
  
  rep(x,1,m+1)
    rep(y,1,m+1)
      rep(z,1,m+1)
        if(x*x + y*y + z*z +x*y+y*z+z*x <= n){
          out[x*x + y*y + z*z +x*y+y*z+z*x]++;
        }
  rep(i,1,n+1)cout<<out[i]<<"\n";

}


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

using namespace std;

long long k;

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

    cin >> k;

    long long ans = -1;
    long long re = 0;
    for(long long i = 1; i <= 1e6; i++){
        long long calc = (re * 10 + 7) % k;
        re = calc;
        if(re == 0){
            ans = i;
            break;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<time.h>
#include<cstdlib>
typedef long long ll;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mm(a) memset(a,0,sizeof(a))
#define lr rt<<1
#define rr rt<<1|1
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0);
#define inf 0x3f3f3f3f
#define eqs 1e-8
#define lb(x) (x&(-x))
#define ch(a) (int(a-'a')+1)
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
const double pi=acos(-1);
const int maxn=1100;
const ll Mod=1000000007;


char ans3[12][12] = {"aa.",
                     "..a",
                     "..a"};
char ans4[12][12] = {"aacd",
                     "bbcd",
                     "dcaa",
                     "dcbb"};
char ans5[12][12] = {"aabc.",
                     "..bcd",
                     "iij.d",
                     "n.jaa",
                     "nkkbb"};
 
char ans7[12][12] = {"aade...",
                     "bbde...",
                     "ccffg..",
                     "..i.gee",
                     "..ihhdd",
                     "....cba",
                     "....cba"};
 
int n;
char a[maxn][maxn];

void add(int st,int len,char (*T)[12])
{
    int x,y;
    for(int i=0;i<len;i++)
    {
        for(int j=0;j<len;j++)
        {
            x=st+i;
            y=st+j;
            a[x][y]=T[i][j];
        }
    }
}

int main()
{
    sync;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            a[i][j]='.';
    }
    if(n<=2)
    {
        cout<<-1<<endl;
        return 0;
    }
    if(n==3)
        add(0,3,ans3);
    else if(n==4)
        add(0,4,ans4);
    else if(n==5)
        add(0,5,ans5);
    else if(n==7)
        add(0,7,ans7);
    else if(n==11)
    {
        add(0,4,ans4);
        add(4,7,ans7);
    }
    else if(n%3==0)
    {
        for(int i=0;i<=n;i+=3)
            add(i,3,ans3);
    }
    else
    {
        if(n%5==0)
        {
            for(int i=0;i<=n;i+=5)
                add(i,5,ans5);
        }
        else if(n%5==1)
        {
            add(0,4,ans4);
            add(4,7,ans7);
            for(int i=11;i<=n;i+=5)
            add(i,5,ans5);
        }
        else if(n%5==2)
        {
            add(0,7,ans7);
            for(int i=7;i<=n;i+=5)
            add(i,5,ans5);
        }
        else if(n%5==3)
        {
            add(0,4,ans4);
            add(4,4,ans4);
            for(int i=8;i<=n;i+=5)
            add(i,5,ans5);
        }
        else if(n%5==4)
        {
            add(0,4,ans4);
            for(int i=4;i<=n;i+=5)
            add(i,5,ans5);
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            cout<<a[i][j];
        cout<<endl;
    }
    return 0;
    
}


Measured memory_bytes: 2304