akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
int dc=100000;
#define MAX 100010

int count[3][32]={};
int d[32][32]={};
int a[3][32];
int dot_pro(int* a,int* b,int len);
int main(){
  if(df)printf("*** debug mode ***\n");
  int n,c,i,j;
  scanf("%d%d",&n,&c);
  for(i=0;i<c;i++){
    for(j=0;j<c;j++){
      scanf("%d",&d[j][i]);  // transposed
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      int x;
      scanf("%d",&x);
      count[(i+j)%3][x-1]++;
    }
  }
  if(df){
    printf("change cost\n");
    for(i=0;i<c;i++){
      for(j=0;j<c;j++){
	printf("%d", d[i][j]);
      }
      printf("\n");
    }
    printf("-----\n");
  }

  if(df){
    printf("count\n");
    for(i=0;i<3;i++){
      for(j=0;j<c;j++){
	printf("%d", count[i][j]);
      }
      printf("\n");
    }
    printf("-----\n");
  }

  

  for(i=0;i<3;i++){
    for(j=0;j<c;j++){
      a[i][j]=dot_pro(count[i],d[j],c);
    }
  }
  if(df){
    printf("a\n");
    for(i=0;i<3;i++){
      for(j=0;j<c;j++){
	printf("%d", a[i][j]);
      }
      printf("\n");
    }
      printf("-----\n");
  }
  
  int min=3e8,k;
  for(i=0;i<c;i++){
    for(j=0;j<c;j++){
      if(i==j)continue;
      for(k=0;k<c;k++){
	if(i==k || j==k)continue;
	int comp=a[0][i]+a[1][j]+a[2][k];
	min=(min<comp)?min:comp;
      }
    }
  }
  
  printf("%d",min);
  return 0;
}
int dot_pro(int* a,int* b,int len){
  int k,s=0;
  for(k=0;k<len;k++){
    s+=a[k]*b[k];
  }
  return s;
}


/// confirm df==0 ///


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

using namespace std;

int main(){
    int a,b,c,ans=0,N=0;
    cin>>a>>b;
    c=b-a;
    for(int i=1;i<c;i++){
        N+=i;
    }
    ans = N-a;

    cout<<ans<<endl;
}

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

#define F first
#define S second
#define MP make_pair
#define PB emplace_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std;

const int N = 1;

long long int a[N];

int main () {
    IOS;
    int n=0;
    string s;
    cin >> s;
    for(char c: s) {
        n += c - '0';
        n %= 9;
    }
    cout << ((n) ? "No" : "Yes") << '\n';
}


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

using namespace std;
char A[30100],B[30010];
int n,aa[30010],bb[30010],tmp[30010];
int lef[30010],rig[30010],Ans;
inline bool cmp0(const int a,const int b)
{
	return lef[a]<lef[b];
}
inline bool cmp1(const int a,const int b)
{
	return rig[a]<rig[b];
}
int main()
{
	scanf("%s%s",A,B); n=strlen(A); 
	Ans=0x3fffffff;
	for(int i=0;i<n;i++) aa[i+1]=A[i]-'0';
	for(int i=0;i<n;i++) bb[i+1]=B[i]-'0';
	for(int i=1;i<=n;i++) bb[i+n]=bb[i+n+n]=bb[i];
	for(int i=1;i<=n;i++)
	{
		lef[i]=rig[i]=-1;
		for(int j=0;j<n;j++) if(bb[i+j]==1)
		{
			rig[i]=j; break;
		}
		for(int j=0;j<n;j++) if(bb[i+n-j]==1)
		{
			lef[i]=j; break;
		}
	}
	for(int i=0;i<n;i++)
	{
		int mxr=i; tmp[0]=0;
		for(int j=1;j<=n;j++)
		{
			if(aa[j]==bb[j+i]) continue;
			if(rig[j]==-1&&lef[j]==-1)
			{
				printf("-1\n"); return 0;
			}
			tmp[++tmp[0]]=j;
		}
		sort(tmp+1,tmp+1+tmp[0],cmp0); if(!tmp[0]) Ans=min(Ans,i); 
		for(int j=tmp[0];j>=1;j--)
		{
			Ans=min(Ans,(mxr-i)*2+i+lef[tmp[j]]*2+tmp[0]);
			mxr=max(mxr,rig[tmp[j]]);
		}
		Ans=min(Ans,(mxr-i)*2+i+tmp[0]);
		//cout << Ans << endl;
	}
	for(int i=0;i<n;i++)
	{
		int mxl=i; tmp[0]=0;
		for(int j=1;j<=n;j++)
		{
			if(aa[j]==bb[j+n-i]) continue;
			tmp[++tmp[0]]=j;
			if(rig[j]==-1&&lef[j]==-1)
			{
				printf("-1\n"); return 0;
			}
		}
		sort(tmp+1,tmp+1+tmp[0],cmp1); if(!tmp[0]) Ans=min(Ans,i);
		for(int j=tmp[0];j>=1;j--)
		{
			Ans=min(Ans,(mxl-i)*2+i+rig[tmp[j]]*2+tmp[0]);
			mxl=max(mxl,lef[tmp[j]]);
		}
		Ans=min(Ans,(mxl-i)*2+i+tmp[0]);
	}
	cout << Ans << endl;
	return 0;
}

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

int main(){
  int A,B;
  string S;
  cin >> A >> B >> S;
  if(S[A] != '-') {
    cout << "No";
    return 0;
  }
  for(int i=0;i<A;i++){
    if(S[i]<'0' || '9'<S[i]) {
      cout << "No";
      return 0;
    }
  }
  for(int i=A+1;i<A+B+1;i++){
    if(S[i]<'0' || '9'<S[i]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

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

X = sorted(X)
list = [10000]*(M-1)

if N >= M:
	print(0)
else:
	for i in range (0, M-1):
		list[i]=X[i+1]-X[i]		
	K = sorted(list)
	print(sum(K[0:M-N]))

Measured memory_bytes: 13968
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <numeric>

using namespace std;

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

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

	int key = 0;
	vector<int> B(N);
	for (int i = 1; i < N; ++i)
	{
		key = A[i - 1] + B[i - 1];
		if (key >= A[i]) B[i] = key - A[i];
		else B[i] = 0;
	}

	long long int sum = 0;
	for (int i = 0; i < N; ++i)
	{
		sum += B[i];
	}

	cout << sum;

	return 0;
}


Measured memory_bytes: 4836
use std::io;
use std::cmp;
use std::collections::HashMap;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf)
         .expect("Error");
    let n:usize = buf.trim().parse().ok().unwrap();
    
    let mut buf = String::new();
    stdin.read_line(&mut buf)
         .expect("Error");
    
    let mut a:Vec<i64> = buf.split_whitespace()
                            .map(|n| n.parse().unwrap())
                            .collect();

    let mut edges = HashMap::new();

    for x in a.iter() {
        let val = edges.get(x).unwrap_or(&0) + 1;
        edges.insert(x, val);

    }

    let mut e1 = 0i64;
    let mut e2 = 0i64;

    for(&x, &y) in edges.iter() {
        if y >= 4 {
            e1 = cmp::max(e1, *x);
            e2 = cmp::max(e2, *x);
        } else if y >= 2 {
            if e1 < *x {
                e2 = e1;
                e1 = *x;
            } else if e2 < *x {
                e2 = *x;
            }
        }
    }

    println!("{}", e1*e2);
}


Measured memory_bytes: 14588
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int a;
  cin>>a;
  cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3596
require 'tsort'
class Hash
	include TSort
	alias tsort_each_node each_key
	def tsort_each_child(node, &block)
		fetch(node).each(&block)
	end
end
V,E=gets.split.map(&:to_i)
h={}
E.times{
	k,v=gets.split.map(&:to_i)
	h[k]||=[]
	h[v]||=[]
	h[v]<<k
}
puts [*0...V]-h.keys
puts h.tsort

Measured memory_bytes: 10108
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int x1,x2,y1,y2;
  int a,b;
  cin >> x1>>y1 >>x2>>y2;
  a = x2-x1; b=y2-y1;
  cout<<x2-b<<' '<<y2+a<<' '<<x1-b<<' '<<y1+a;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import numpy as np
N, T = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
ans = 0
t = np.array(t)
t_diff = np.diff(t)
for i in t_diff:
    ans += min(i, T)
print(ans + T)

Measured memory_bytes: 34212
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] indA = new int[n];
        long[] a = new long[2000001];
        long[] res = new long[2000001];
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            a[num]++;
            indA[i] = num;
        }
        long sum = 0;
        for (int i = 0; i < 2000001; i++) {
            if (a[i] > 0) {
                res[i] = a[i] * (a[i] -1) / 2;
                sum += res[i];
            }
        }
        for (int i = 0; i < n; i++) {
            //K番目がない状態（－１して）計算しなおす
            long nv = a[indA[i]] - 1;
            long nvr = 0;
            if (nv > 0) {
                nvr = nv * (nv -1) / 2;
            }
            System.out.println(sum - res[indA[i]] + nvr);
        }
    }
}


Measured memory_bytes: 123800
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	int a;
	deque<int> b;
	rep(i, 0, n) {
		cin >> a;
		if (i % 2 == 1) {
			b.push_front(a);
		}
		else {
			b.push_back(a);
		}
	}
	if (n % 2 == 1) {
		reverse(all(b));
	}
	rep(i, 0, n) {
		cout << b[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2944
def solve():
    
    A, B, C, D, E, F = map(int, input().split())
    memo = {}
    
    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    w = (100*A)*a + (100*B)*b
                    s = C*c + D*d
                    if w ==0:
                        break
                    if w+s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            density = 100*s/(w+s)
                            memo[a,b,c,d] = density
    
    max_v = max(memo.values())
    
    for k, v in memo.items():
        if v == max_v:
            print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3], C*k[2] + D*k[3] )
            break
solve()

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

int main() {

	int x, y;
	cin >> x >> y;

	int tsuru, kame;
	for (tsuru = 0; tsuru <= x; tsuru++) {
		kame = x - tsuru;
		if (tsuru * 2 + kame * 4 == y) {
			cout << "Yes";
			return 0;
		}
	}

	cout << "No";
	
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,w;
	cin>>n>>w;
	ll wt[n+1],val[n+1];
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
		sum+=val[i];
	}
	vector<ll> dp(sum+2,1e9);
	dp[0]=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=sum;j>=val[i];j--)
			dp[j]=min(dp[j],wt[i]+dp[j-val[i]]);
	}
	for(ll i=sum;i>=0;i--)
	{
		if(dp[i]<=w)
		{
			cout<<i;
			break;
		}
	}
}

Measured memory_bytes: 3960
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

long long int getOneNum(long long int n, int k)
{
	// 0 ~ nまでで、 2^kの位に1がたっているような値の数を返す
	long long int tmp = (long long int)1 << (k + 1);
	long long int ans = (n + 1) / tmp * (tmp / 2);
	long long int amari = (n + 1) % tmp;
	ans += max((long long int)0, amari - tmp / 2);
	return ans;
}

int main()
{
	long long int a, b;
	cin >> a >> b;
	long long int ans = 0;
	for(int i = 40; i >= 0; i--){
		ans = (ans * 2) + ((getOneNum(b, i) - getOneNum(a - 1, i)) % 2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    string S;
    cin >> S;
    int year = atoi(S.substr(0, 4).c_str());
    int month = atoi(S.substr(5, 2).c_str());
    int day = atoi(S.substr(8, 2).c_str());
    if(year >= 2019 && month >= 5 && day > 0) {
        cout << "TBD" << endl;
        return 0;
    }
    cout << "Heisei" << endl;
}


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

int main()
{
  int H,W;  
  int flag =0;
  cin >> H >> W;
  vector<vector<char>> moji(H+2, vector<char>(W+2));
  for(int i=1;i<H+1;i++){
    for(int j=1;j<W+1;j++){
      cin >> moji.at(i).at(j);
    }
  }

//  vector<vector<int>> suu(H+2, vector<int>(W+2));
  for(int i=1;i<H+1;i++){
    for(int j=1;j<W+1;j++){
      if(moji.at(i).at(j)=='#'){
       if(moji.at(i).at(j-1)!='#' &&  moji.at(i-1).at(j)!= '#' && moji.at(i+1).at(j)!= '#' && moji.at(i).at(j+1)!= '#')flag=-1;
	   }    
      }
    }
  if(flag== -1) cout<< "No" << endl;
  else cout << "Yes" << endl;
  }
  
/*
//いったん出力してみる
  for(int i=1;i<H+1;i++){
    for(int j=1;j<W+1;j++){
      cout << suu.at(i).at(j);
    }
    cout << endl;
  }
*/





Measured memory_bytes: 256
n,m=gets.split.map &:to_i
(p (m+1)%(10**9+7);exit)if n==1
r=(0..m+1).bsearch{|i|
	m<(n-1)*i
}
r-=1
p (-~m*(r*2+1)-~-n*r*-~r)%(10**9+7)

Measured memory_bytes: 8712
import sys

while True:
    n, k, m = map(int, sys.stdin.readline().split())
    
    if n == 0:
        break
    
    stone = range(1, n + 1)
    stone.pop(m - 1)
    cur = m - 2
    for i in xrange(n - 2):
        cur = (cur + k) % len(stone)
        stone.pop(cur)
        cur -= 1
    print stone[0]

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

int main(){
    ll a , b ;
    cin >> a >> b  ;
    if(a %2 == 0 || b%2 == 0 )cout << "No" <<endl;
    else cout << "Yes" << endl ;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	//freopen("input.txt","r",stdin);
	int n;
	cin >> n;
	map <string, int>votes;
	string leader;
	int max=0;
	while(n--){
		cin >> leader;
		votes[leader]++;
		if(votes[leader]>max) max=votes[leader];
	}
	for(auto it:votes){
		if(it.second==max)cout<<it.first<<endl;
	}
	return 0;
}

Measured memory_bytes: 25216
# https://atcoder.jp/contests/keyence2019/tasks/keyence2019_b
import sys
s = input()
target = 'keyence'
for i in range(len(s)):
    for j in range(i, len(s)):
        sub = s[:i] + s[j:]
        if sub == target:
            print('YES')
            sys.exit()
print('NO')



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

using namespace std;

int main(){
    
    char s[4];
    cin >> s;
    bool ans = false;
    
    for (int i = 0; i <= 3; i++) {
        if (s[i] == s[i+1]) {
            ans = true;
        }
    }
    if (ans) {
        cout << "Bad" << endl;
    }
    else{
        cout << "Good" << endl;
    }
    
}


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

using namespace std;

string compare(string a, string b){
  
  if(a == b)return "EQUAL";
  else if(a.size() > b.size()) return "GREATER";
  else if(a.size() < b.size()) return "LESS";
  else{
    int t = a.size();
    int n = 0;
    while(a[n] == b[n] && n < t)n++;
    if(a[n]-'0' < b[n]-'0') return "LESS";
    else if(a[n]-'0' > b[n]-'0') return "GREATER";
//    else if(n == t) return "EQUAL";
    }
}

int main(){
  string a, b;
  cin >> a >> b;
  string ans;
  ans = compare(a, b);
  cout << ans;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var K, S int
	fmt.Scan(&K)
	fmt.Scan(&S)
	var cnt int
	for X := 0; X <= K; X++ {
		for Y := 0; Y <= K; Y++ {
			Z := S - X - Y
			if 0 <= Z && Z <= K {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}


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

int main(void)
{
    int cost, scost=0, num, snum=0, cnt=0;
    while(~scanf("%d,%d",&cost, &num)) {
        scost += cost * num;
        snum += num;
        cnt++;
    }
    printf("%d\n%d\n", scost, (snum + 1)/cnt);

    return 0;
}

Measured memory_bytes: 1020
N, W = map(int, input().split())
v = []
w = []
for _ in range(N):
    x, y = map(int, input().split())
    v.append(x)
    w.append(y)
dp = [-1 for _ in range(W+1)]
dp[0] = 0

for i in range(N):
    for j in range(W+1):
        if j - w[i] >= 0:
            dp[j] = max(dp[j], dp[j-w[i]] + v[i])
        # print(dp)
print(max(dp))



Measured memory_bytes: 5724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner A = new Scanner(System.in);
        int a = A.nextInt();
        int b = A.nextInt();
        A.close();
        if ((a+b)%2 == 1) {
            System.out.println(((a + b) / 2) + 1);
        } else {
            System.out.println((a + b) / 2);
        }
    }
}


Measured memory_bytes: 21972
#include<stdio.h>

int main(){
  int o,n,k,i,j;
  int kkk;
  int A[110];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);
  for(j=1;j<=n;j++)
    {   
      kkk = A[j];		
      i = j-1;
      while(i>0 && A[i]>kkk)
	{
	  A[i+1]=A[i];  
	  i = i-1;
	}
      A[i+1] = kkk;
      for(k=1;k<=n;k++){
	if(k == n)printf("%d\n",A[k]);
	else printf("%d ",A[k]);
      }
    }
  
  return 0;
}



Measured memory_bytes: 2040
#include <stdio.h>

int main() {
  int a, b, d, r;
  double f;

  scanf("%d %d", &a, &b);
  d = a / b;
  r = a % b;
  f = (double)a / b;
  printf("%d %d %lf", d, r, f);
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define until(b) while(not (b))

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}

int solve(const vector<int> &p){
    int N = p.size();
    queue<int> where;
    vector<char> used(N,false);

    where.push(0);
    for(int go=0;;go++){
        queue<int> next;
        while(not where.empty()){
            int w = where.front();
            if(w >= N-1) return go;
            where.pop();
            if(used[w]) continue;
            used[w] = true;
            for(int a=1;a<=min(6,N-1-w);a++){
                int x = w + a;
                while(not used[x] and p[x] != 0){
                    used[x] = true;
                    x += p[x];
                }
                if(not used[x] and p[x] == 0){
                    next.push(x);
                }
            }
        }
        where = next;
    }
    return -1;
}

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    cout << solve(p) << endl;
    return 0;
}

Measured memory_bytes: 1532
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  vvl TA(N, vl(2, 0));
  rep(i, N){
    cin >> TA[i][0] >> TA[i][1];
  }

  vl mul(N, 1);
  rep2(i, 1, N){
    ll m1 = 1, m2 = 1;
    
    if(TA[i][0]*mul[i]<TA[i-1][0]*mul[i-1]){
      m1 = TA[i-1][0]*mul[i-1]/TA[i][0];
      
      if(TA[i-1][0]*mul[i-1] % TA[i][0] != 0){
		m1++;
      }
    }
    if(TA[i][1]*mul[i]<TA[i-1][1]*mul[i-1]){
      m2 = TA[i-1][1]*mul[i-1]/TA[i][1];

      if(TA[i-1][1]*mul[i-1] % TA[i][1] != 0){
		m2++;
      }
    }

    mul[i] = max(m1, m2);
  }

  cout << mul[N-1]*(TA[N-1][0] + TA[N-1][1]) << endl;
  
  return 0;
}

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

typedef long long unsigned ll;

//map<int,int> mmap;

char A[51][51];
char B[51][51];
int main(){

    //freopen("test.in","r",stdin);

    int M,N;
    cin>>N>>M;

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++) cin>>A[i][j];
    }

    for(int i=0;i<M;i++){
        for(int j=0;j<M;j++) cin>>B[i][j];
    }

    bool got = false;
    bool inner = false;

    for(int i=0;i<=N-M;i++){
        for(int j=0;j<=N-M;j++){


            inner=true;
            for(int x=0;x<M;x++){
                for(int y=0;y<M;y++){
                    if(A[i+x][j+y]!=B[x][y]){
                        inner = false;
                        break;
                    }
                }
                if(!inner) break;
            }

            if(inner) {
                got=true;
                cout<<"Yes\n";
                return 0;
            }
        }


    }

    cout<<"No\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int main(){
  double N;
  double D;
  cin >> N >> D;
  cout << ceil(N/(2*D+1)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ar array
#define pb push_back
#define input(arr,n) for(int i = 0; i<n; i++) cin>>arr[i]
const int mod = 1e9+7;
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	input(a,n);
	sort(a,a+n,greater<int>());
	priority_queue<ar<int,2>> pq;
	pq.push({a[0],1});
	ll ans = 0;
	for(int i = 1; i<n; i++)
	{
		ar<int,2> y = pq.top();
		pq.pop();
		ans += y[0];
		y[1]--;
		if(y[1]) pq.push(y);
		y[0] = a[i];
		y[1] = 2;
		pq.push(y);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6100
/*
 * ALDS1_11_A.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>

using namespace std;

int main() {
	int n;
	bool adj[101][101] = {0};
	cin >> n;

	int u, k, v;
	for(int i=0; i<n; i++) {
		cin >> u >> k;
		while(k--) {
			cin >> v;
			adj[u][v] = 1;
		}
	}

	for(int i=1; i<=n; i++) {
		cout << adj[i][1];
		for(int j=2; j<=n; j++) {
			cout << " " << adj[i][j];
		}
		cout << endl;
	}
}





Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  int ans = 0;
  rep(i, k + 1) {
    ans += max(0, k + 1 - abs(s - i - k));
  }
  cout << ans << endl;
  


  
  return 0;
}

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

int main()
{
    int a,b,c,k,max;
    cin >> a >> b >> c;
    cin >> k;
    if(a>b){
        if(a>c)
            max=b+c+pow(2,k)*a;
        else   
            max=a+b+pow(2,k)*c;
    }
    else{
        if(b>c)
            max=a+c+pow(2,k)*b;
        else   
            max=a+b+pow(2,k)*c;
    }
    cout << max << '\n';

    return 0;
}

Measured memory_bytes: 256
program main;
var
    n, i : int64;
begin
    readln(n);
    writeln(((1 + n) * n div 2) - (((3 * (n div 3)) + 3) * (n div 3) div 2) -(((5 * (n div 5)) + 5) * (n div 5) div 2) + (((15 * (n div 15)) + 15) * (n div 15) div 2))
end.

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

using namespace std;
typedef long long ll;

int H,W,D,A;
int Q,L,R;
map<int, pair<int, int> > pos;
int d[90001];

int  main() {
  cin >> H >> W >> D;

  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      cin >> A;
      pos[A] = make_pair(i, j);
    }
  }

  memset(d, 0, sizeof(d));
  for(int i=D+1; i<=H*W; i++) {
    d[i] = d[i - D]
      + abs(pos[i].first - pos[i - D].first)
      + abs(pos[i].second - pos[i-D].second);
  }

  cin >> Q;
  while(Q--) {
    cin >> L >> R;
    cout << d[R] - d[L] << endl;
  }
  return 0;
}

Measured memory_bytes: 7040
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n = II()
    print("ABC"+str(n))
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39024
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define yes cout << "YES\n"
#define no cout << "NO\n" 
#define pi 3.1415926536
#define mod  1000003
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int f=0;
    while(1){
        if(f==0) {c=c-b;f=1;}
        else {a=a-d;f=0;}
        if(c<=0||a<=0) break;
    }
    if(f) cout<<"Yes";
    else cout<<"No";
    
    
    
    
    return 0;
  
}

Measured memory_bytes: 3616
#include<iostream>
#include <stdlib.h>
using namespace std;

int main(void) {
	int n, alice = 0, bob = 0;
	int a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] < a[j])swap(a[i], a[j]);
		}
	}
	for (int i = 0; i < n; i += 2) {
		alice += a[i];
	}
	for (int i = 1; i < n; i += 2) {
		bob += a[i];
	}
	cout << alice - bob << endl;
	return 0;
}

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

using namespace std;

void fill(vector<vector<char> >& vec,int i, int j, char c){
    if(vec[i][j] == c) {
        vec[i][j] = '^';
    } else {
        return;
    }
    fill(vec,i+1,j,c);
    fill(vec,i-1,j,c);
    fill(vec,i,j+1,c);
    fill(vec,i,j-1,c);
}

int main(){
    while (1) {
        int h,w;
        cin >> h;
        cin >> w;
        if(!h&&!w) break;
        vector< vector<char> > vec(h+2,vector<char>(w+2));
        for(int i = 0; i <= h+1; ++i){
            for (int j = 0; j <= w+1; j++) {
                if(i == 0 || j == 0 || i == h+1 || j == w+1)
                    vec[i][j] = '^';
                else
                    cin >> vec[i][j];
            }
        }
        int persons = 0;
        for(int i = 1; i <= h; ++i){
            for (int j = 1; j <= w; j++) {
                char c = vec[i][j];
                if(c == '^')
                    continue;
                else {
                    persons++;
                    fill(vec,i,j,c);
                }
            }
        }
        cout << persons << endl;
    }
    return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LLINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	REP(i, n - 2) {
		if (s[i] == 'A' && s[i + 1] == 'B'&& s[i + 2] == 'C')
			ans++;
	}
	cout << ans << endl;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n;
   cin >> n;
   int S[5] = {0};
   string march = "MARCH";
   rep (i, n) {
      string s;
      cin >> s;
      auto p = march.find(s[0]);
      if (p == string::npos) continue;
      S[p]++;
   }

   ll sum = 0;
   rep (i, 5) {
      repp (j, i+1, 5) {
         repp (k, j+1, 5) {
            sum += 1LL * S[i] * S[j] * S[k];
         }
      }
   }
   cout << sum << endl;

   return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<ctype.h>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<stdio.h>
#include<stdlib.h>
#include<streambuf>
#include<string.h>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#define x first
#define y second
#define m_p make_pair
using namespace std;
const int sz=262143;
inline int mini(int a,int b){
	return (a>b)?b:a;
}
inline void gtmn(int &a,int b){
	if (a>b) a=b;
}
int odd[524299],eve[524299];
void upd(int *a,int i){
	a[i]=mini(a[i<<1],a[i<<1|1]);
}
void update(int *a,int i){
	i>>=1;
	while(i){
		upd(a,i);
		i>>=1;
	}
}
int query(int *a,int l,int r){
	int res=100000000;
	while(l<=r){
		if (l&1){
			gtmn(res,a[l++]);
		}
		if (!(r&1)){
			gtmn(res,a[r--]);
		}
		l>>=1;
		r>>=1;
	}
	return res;
}
set<pair<int,pair<int,int> > > s;
int inv[200010],init[200010];
int main(void){
	memset(odd,55,sizeof(odd));
	memset(eve,55,sizeof(eve));
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&init[i]);
		inv[init[i]]=i;
		if (i&1){
			odd[i+sz]=init[i];
		}
		else{
			eve[i+sz]=init[i];
		}
	}
	for (int i=sz;i;i--){
		upd(odd,i);
		upd(eve,i);
	}
	s.insert(m_p(query(odd,1+sz,n+sz),m_p(1,n)));
	for (int _=1;_<=(n>>1);_++){
		int mn=s.begin()->x,hd=s.begin()->y.x,tl=s.begin()->y.y;
		s.erase(s.begin());
		if (hd&1){
			int t1=inv[mn];
			int t2=inv[query(eve,t1+sz,tl+sz)];
			printf("%d %d ",init[t1],init[t2]);
			if (t1>hd){
				s.insert(m_p(query(odd,hd+sz,t1-1+sz),m_p(hd,t1-1)));
			}
			if (t2>t1+1){
				s.insert(m_p(query(eve,t1+1+sz,t2-1+sz),m_p(t1+1,t2-1)));
			}
			if (t2<tl){
				s.insert(m_p(query(odd,t2+1+sz,tl+sz),m_p(t2+1,tl)));
			}
		}
		else{
			int t1=inv[mn];
			int t2=inv[query(odd,t1+sz,tl+sz)];
			printf("%d %d ",init[t1],init[t2]);
			if (t1>hd){
				s.insert(m_p(query(eve,hd+sz,t1-1+sz),m_p(hd,t1-1)));
			}
			if (t2>t1+1){
				s.insert(m_p(query(odd,t1+1+sz,t2-1+sz),m_p(t1+1,t2-1)));
			}
			if (t2<tl){
				s.insert(m_p(query(eve,t2+1+sz,tl+sz),m_p(t2+1,tl)));
			}
		}
	}
	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;


lli INF=1e18;

lli memo[101][100001];
lli N,W;
vector< lli >w;
vector< lli >v;

lli max_profit(lli index,lli tot_weight){
	if(tot_weight>W)return -INF;
	if(index==N)
		return 0;

	if(memo[index][tot_weight]!=-1)return memo[index][tot_weight];
	return memo[index][tot_weight] = max( max_profit(index+1,tot_weight) , max_profit(index+1,tot_weight+w[index])+v[index] );
}


int main()
{
	lli i,j;
	for(i=0;i<100;i++)
	{
		for(j=0;j<100001;j++)
			memo[i][j]=-1;
	}


	cin>>N>>W;
	lli temp1,temp2;
	for(i=0;i<N;i++)
	{
		cin>>temp1>>temp2;
		w.emplace_back(temp1);
		v.emplace_back(temp2);
	}
	cout<<max_profit(0,0);

	return 0;

}



Measured memory_bytes: 78336
import itertools,math
def isOverlapped(x1,y1,x2,y2,r1,r2):        
    return ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))**0.5<=r1+r2+0.000009
while True:
    n=input()
    if n==0:
        break
    li=[]
    for i in xrange(n):
        li.append(map(float,raw_input().split(",")))
    ma=1
    for i,j in itertools.combinations(xrange(n),2):
        x1,y1,x2,y2=li[i][0],li[i][1],li[j][0],li[j][1]
        if isOverlapped(x1,y1,x2,y2,1,1):
            L=((x1-x2)**2+(y1-y2)**2)**0.5
            t=math.atan2(y2-y1,x2-x1)
            al=math.acos(L/2)
            node=[[x1+math.cos(t+al),y1+math.sin(t+al)],
                  [x1+math.cos(t-al),y1+math.sin(t-al)]]
            for p in xrange(2):
                c=0
                for q in xrange(n):
                    if isOverlapped(node[p][0],node[p][1],li[q][0],li[q][1],0,1):
                        c+=1
                ma=max(c,ma)
    print ma

Measured memory_bytes: 4732
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


bool dp1[3101];
bool dp2[3101];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;

	dp1[0]=true;
	rep(i,3000){
		if (dp1[i]){
			dp1[i+a]=true;
			dp1[i + b] = true;
		}
	}
	dp2[0] = true;
	rep(i, 3000){
		if (dp2[i]){
			dp2[i + c] = true;
			dp2[i + d] = true;
		}
	}
	int x = a*100, y = 0;
	for (int i = 0; i * 100 <= f; i++)if (dp1[i]){
		for (int j = 0; j + i * 100 <= f; j++)if (dp2[j]){
			if (j > i*e)continue;
			if (y*(i*100 + j) < j*(x)){
				x = i * 100 + j;
				y = j;
			}
		}
	}
	cout << x << ' ' << y << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

vector<ll> v;
ll a[334334];
int b[334334];

int f(int i){
	int p,q;
	p = (int)(lower_bound(v.begin(),v.end(),a[i])-v.begin());
	q = (int)(upper_bound(v.begin(),v.end(),a[i])-v.begin());
	if(i<p){
		return -1;
	}else if(i>=q){
		return 1;
	}else{
		return 0;
	}

}

int main(void){
	int n,i,s=0,t=0,q,x,y;
	bool flag = false;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
		v.push_back(a[i]);
	}
	sort(v.begin(),v.end());
	for(i=0; i<n; ++i){
		b[i] = f(i);
		if(b[i]>0){
			++s;
		}else if(b[i]<0){
			++t;
		}
	}
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> x >> y;
		--x; --y;
		if(flag){
			continue;
		}else if(s==0 && t==0){
			cout << i << endl;
			flag = true;
			continue;
		}
		if(b[x]>0){
			--s;
		}else if(b[x]<0){
			--t;
		}
		if(b[y]>0){
			--s;
		}else if(b[y]<0){
			--t;
		}
		swap(a[x],a[y]);
		b[x] = f(x);
		b[y] = f(y);
		if(b[x]>0){
			++s;
		}else if(b[x]<0){
			++t;
		}
		if(b[y]>0){
			++s;
		}else if(b[y]<0){
			++t;
		}
	}
	if(!flag){
		if(s==0 && t==0){
			cout << q << endl;
		}else{
			cout << "-1" << endl;
		}
	}
	return 0;
}



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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

void solve(){
    int n;
    cin >> n;
    vi h(n);
    for(auto &it: h) cin >> it;

    vi dp(n, 1e9+5);
    dp[0] = 0;
    for(int i = 1; i < n; ++i){
        for(int j = max(i-2, 0); j < i; ++j){
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));
        }
    }
    cout << dp[n-1] << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}

Measured memory_bytes: 4788
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

struct BIT{
    int n;
    VL bit;

    BIT(){}
    BIT(int x){
        n = x;
        bit.assign(n+1, 0);
    }

    void init(int x){
        n = x;
        bit.assign(n+1, 0);
    }

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

    // [0, i]
    ll sum(int i){
        i++;
        ll ret = 0;
        while (i > 0){
            ret += bit[i];
            i -= i & -i;
        }
        return ret;
    }

    // [l, r)
    ll sum(int l, int r){
        if (l >= r) return 0;
        return sum(r-1) - sum(l-1);
    }
};

int main() {
    ll n, t;
    cin >> n >> t;
    VL h(n);
    REP(i,n) cin >> h[i];

    ll sum = 0;
    REP(i,n) sum += h[i];

    VL ans(n, 1);
    ll ma = 0;

    REP(i,n){
        ma = max(ma, h[i]);

        ans[i] = (t + ma - 1) / ma;
        if (t % ma == 0 || t % ma >= h[i]) ans[i]++;

        t -= h[i];
        if (t < 0) break;
    }

    REP(i,n) cout << ans[i] << endl;

    return 0;
}

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

using ll = long long;

int main(){
  int N,ans=0;
  cin >> N;
  vector<ll> A(N),B(N),diff;
  ll sum=0;
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  for(int i=0; i<N; i++){
    cin >> B[i];
    if(A[i] >= B[i]) diff.push_back(A[i]-B[i]);
    else{
      sum += B[i] - A[i];
      ans++;
    }
  }
  sort(diff.begin(), diff.end());
  reverse(diff.begin(), diff.end());
  int flag=0;
  if(sum == 0) ans = 0;
  else{
    for(int i=0; i<diff.size(); i++){
      sum -= diff[i];
      ans++;
      if(sum <= 0) {flag = 1; break;}
    }
    if(flag == 0) ans = -1;
  }  
  cout << ans;
  return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,K;
    cin >> N >> K;
    if(N>K){
        N%=K;
    }
    cout << min(N,abs(N-K)) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <vector>
using namespace std;
int main(){
  string s;
  cin>>s;
  int a,b;
  a=count(s.cbegin(), s.cend(), '0');
  b=count(s.cbegin(), s.cend(), '1');
  if(a>b)
    cout<<b*2<<endl;
  else
    cout<<a*2<<endl;
}

Measured memory_bytes: 512
// CONTEST

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

// Utility
#define ALL(X) (X).begin(), (X).end()
#define RANGE(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T>            istream& operator>>(istream& i, vector<T>& x)    { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#define DD(X) std::cout << #X ": " << (X) << std::endl << std::flush
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T>            ostream& operator<<(ostream& o, const vector<T>& x)    { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const set<T1, T2>& x)  { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& x)  { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  string s;
  cin >> s;
  ll res = 0;
  if (s == "RRR") {
    res = 3;
  } else if (s == "RRS" || s == "SRR") {
    res = 2;
  } else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
    res = 1;
  }
  cout << res << endl;
}

int main() {
  mainCase();
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	int s=0;
	int m = n;
	while(m>0){
		s += m%10;
		m = m/10;
	}
	if(n%s == 0) cout << "Yes" << endl;
	else cout <<"No" << endl;
}

Measured memory_bytes: 256
#"memo roiti 875674"
d={"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}

while 1:
    try:
        n=raw_input()
        t=0
        value=1000
        for i in n:
            if value>=d[i]:
                value=d[i]
                t=t+value
            else:
                t=t-value*2
                value=d[i]
                t=t+value
        print t
    except:
        break

Measured memory_bytes: 6428
#!/usr/bin/python3
import bisect

n = int(input())
s = input()
q = int(input())

idxs = [ [] for i in range(26) ]
sl = [ s[i] for i in range(n) ]

for i in range(n):
    idxs[ord(s[i]) - ord('a')].append(i + 1)

#print(idxs)

qs = []
for i in range(q):
    qs.append(input())

for qi in qs:
    (op, x, y) = qi.split()
    if op == '1':
        j = int(x)
        c = y
        oc = sl[j - 1]
        if oc != c:
            sl[j - 1] = c
            idx = bisect.bisect_left(idxs[ord(oc) - ord('a')], j)
            del idxs[ord(oc) - ord('a')][idx]
            idx = bisect.bisect_left(idxs[ord(c) - ord('a')], j)
            idxs[ord(c) - ord('a')].insert(idx, j)
        
    elif op == '2':
        l = int(x)
        r = int(y)
        c = 0
        for i in range(26):
            il = bisect.bisect_left(idxs[i], l)
            ir = bisect.bisect_right(idxs[i], r)
            if il < ir:
                c += 1
        print(c)


Measured memory_bytes: 102372
#include<iostream>
#include<string>
using namespace std;
int main()
{
    long long n,i,w,r,p;
    string s;
    cin>>n;
    cin>>s;
    w=r=p=0;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='W')
        {
            w++;
        }
        else if(s[i]=='R')
        {
            r++;
        }
    }
    for(i=0;i<r;i++)
    {
        if(s[i]=='W')
        {
            p++;
        }
    }
    cout<<p<<endl;
    return 0;
}

Measured memory_bytes: 3716
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let q = io.read::<usize>();
    for _ in 0..q {
        let (a, b) = (io.read::<i64>(), io.read::<i64>());
        if a == b {
            io.writeln((a - 1) * 2);
            continue;
        }
        let mut ok = 1i64;
        let mut ng = 1 << 33 as i64;
        while (ng - ok).abs() > 1 {
            let mid = (ng + ok) / 2;
            let mul = (mid + 1) / 2 * (mid + 1 - (mid + 1) / 2);
            if mul > a * b - 1 {
                ng = mid;
            } else {
                ok = mid;
            }
        }
        io.writeln(ok - 1);
    }
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 2136