akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/floor.hpp
#ifndef FLOOR_HPP
#define FLOOR_HPP


/*
usage:

tools::floor(5, 3) // => 1 (i.e., floor(5 / 3))
*/

#endif

// main.cpp

int main() {
  i64 A, B, N;
  std::cin >> A >> B >> N;
  std::cout << tools::floor(A * std::min(N, B - 1), B) << std::endl;
  return 0;
}

Measured memory_bytes: 3644
dic = {}
h, w, d = map(int, input().split())
lis = [list(input().split()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        dic[int(lis[i][j])] = (i, j)
n = h * w
su = [0] * (n + 1)
for k in range(1, n - d + 1):
    x = dic[k + d][0] - dic[k][0]
    y = dic[k + d][1] - dic[k][1]
    su[k + d] = su[k] + abs(x) + abs(y)

q = int(input())
for i in range(q):
    s, g = map(int, input().split())
    print(su[g] - su[s])


Measured memory_bytes: 28380
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> g;

int main(){
  int n, m;
  cin >> n >> m;
  g.resize(n);
  for(int i = 0; i < m; ++i){
  	int a, b;
  	cin >> a >> b;
  	--a;
  	--b;
  	g[a].push_back(b);
  	g[b].push_back(a);
  }

  // vector<int> dist(n, -1); 
  vector<int> p(n, -1);
  p[0] = 0;
  queue<int> que;

  // dist[0] = 0;
  que.push(0);

  while(!que.empty()){
    int v = que.front(); 
    que.pop();

    for(auto nv : g[v]){
      // if(dist[nv] != -1)continue;
      if(p[nv] != -1)continue;

      // dist[nv] = dist[v] + 1;
      p[nv] = v;
      que.push(nv);
    }
  }

  for(int i = 1; i < n; ++i){
  	if(p[i] == -1){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for(int i = 1; i < n; ++i){
  	cout << p[i] + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 10240
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		int c = 0;
		for (int a = 1; a < 10; a++) {
			for (int b = 1; b < 10; b++) {

				if (a * b == n)
					c = 1;

			}
		}
		if (c == 1)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

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

int main()
{
	int N;
	scanf("%d", &N);
	int count[3]{}, sum{};
	for (int i{}; i < N; i++)
	{
		std::string s;
		std::cin >> s;
		for (int j{}; j + 1 < (int)s.size(); j++)
			if (s[j] == 'A' && s[j + 1] == 'B')
				sum++;
		if (s.front() == 'B' && s.back() == 'A')
			count[0]++;
		else if (s.front() == 'B')
			count[1]++;
		else if (s.back() == 'A')
			count[2]++;
	}
	if (count[1] || count[2])
		sum += count[0];
	else if (count[0])
		sum += count[0] - 1;
	
	sum += std::min(count[1], count[2]);
	printf("%d\n", sum);

	return 0;
}

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

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


Measured memory_bytes: 3100
n = int(input())
*an, = map(int,input().split())
*bn, = map(int,input().split())
*cn, = map(int,input().split())
befi = -1
ans = sum(bn)
for i in an:
  if i - befi == 1:
    ans += cn[befi-1]
  befi = i
print(ans)

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

int main(){
  int n,a,b;
  bool flg=false;
  a=0;
  b=0;
  cin >> n;
  for(int i=0;i<=n/4;i++){
    for(int j=0;j<=n/7;j++){
      if(4*i+7*j==n){
        flg=true;
      }
    }
  }
  if(flg){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    #ifdef TarekHasan
        freopen("input.txt","r",stdin);
    #endif // TarekHasan

    string str; cin >> str;
    str[2]==str[3] && str[4]==str[5] ? cout << "Yes\n" : cout << "No\n";

    return 0;
}


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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

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

int main()
{
	int n, k; scanf("%d%d", &n, &k);
	char s[100005]; scanf("%s", s);
	int count = 0;
	for(int i = 1; s[i]; i++) {
		if(s[i] == s[i - 1])
			count++;
	}
	count += k * 2;
	if(count > n -1)
		count = n - 1;
	printf("%d", count);
}










Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scan(&S)
	if S[0] != 'A' {
		fmt.Println("WA")
		return
	}

	cnt := 0
	for i := 1; i < len(S); i++ {
		s := S[i]
		if s < 'a' || 'z' < s {
			if 2 <= i && i <= len(S)-2 && s == 'C' {
				cnt++
			} else {
				fmt.Println("WA")
				return
			}
		}
	}

	if cnt != 1 {
		fmt.Println("WA")
		return
	}

	fmt.Println("AC")
}


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

int main() {
    int N, M, ans = 0;
    cin >> N >> M;
    vector<long long>H(N+1);
    vector<bool>check(N+1);
    vector<int>A(M), B(M);
    for (int i = 1; i <= N; i++) {
        cin >> H.at(i);
        check.at(i) = true;
    }
    for (int i = 0; i < M; i++) {
        cin >> A.at(i) >> B.at(i);
    }
    for (int j = 0; j < M; j++) {
        if (H.at(A.at(j)) == H.at(B.at(j))) {
            check.at(A.at(j)) = false;
            check.at(B.at(j)) = false;
        }
        else if (H.at(A.at(j)) < H.at(B.at(j))) {
            check.at(A.at(j)) = false;
        }
        else {
            check.at(B.at(j)) = false;
        }
    }
    for (int i = 1; i <= N; i++) {
        if (check.at(i)) {
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 4840
from itertools import zip_longest

s = input()
s = list(s)
cnt_pos = len(s) - 1#記号の入り得る位置の数
formula_cnt = 2 ** (cnt_pos)#式数

ans = 0
for i in range(formula_cnt):
    sgns = ['+' if (i & (2 ** x) != 0) else '' for x in range(cnt_pos)]
    formula = ''
    for c, sgn in zip_longest(s, sgns, fillvalue=''):
        formula += c + sgn
    #print(i, s, sgns, formula)
    ans += eval(formula)
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

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

	int sum = 0;
	for(int i=0; i<N; i++) sum += A[i];

	int cnt = 0;
	for(int i=0; i<N; i++) if(A[i]*4*M >= sum) cnt++;

	if(cnt>=M) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

using namespace std;

int main(void){

    int a, b, c;
    cin >> a >> b >> c;

    int max = std::max({a,b,c});
    int delta = (max - a) + (max - b) + (max - c);

    if(delta%2==0) {
        cout << delta/2 << endl;
    }
    else {
        cout << (delta+1)/2 + 1 << endl;    
    }

    return 0;
    
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val used = mutableSetOf<String>()
    var pre = ""
    repeat(n) {
        val s = sc.next()
        if (pre != "" && pre.last() != s.first() ||
                used.contains(s)) {
            println("No")
            return
        }
        used.add(s)
        pre = s
    }
    println("Yes")
}

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

int n,k,M,x,y;
vector<int> v[2000];

int dfs(int now,int from,int step)
{
    int ret=1;
    if(step<(int)(k/2)) for(int i=0;i<v[now].size();++i) if(v[now][i]!=from) ret+=dfs(v[now][i],now,step+1);
    return ret;
}

void maxExistNodes()
{
    if(k%2==0) for(int i=0;i<n;++i) M=max(M,dfs(i,-1,0));
    else       for(int i=0;i<n;++i) for(int j=0;j<v[i].size();++j) if(i<v[i][j]) M=max(M,dfs(i,v[i][j],0)+dfs(v[i][j],i,0));
}

void prepare()
{
    scanf("%i%i",&n,&k);
    for(int i=0;i<n-1;++i) {scanf("%i%i",&x,&y); --x; --y; v[x].push_back(y); v[y].push_back(x);}
}

int main()
{
    prepare();
    maxExistNodes();
    printf("%i\n",n-M);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(num,init,name) vector<int> name((num),(init));
#define op(i) cout<<(i)<<endl;

int main(){
    int n;
    int sum=0;
    cin>>n;
    vec(n+2,0,a);
    vec(n+1,0,b);
    vec(n+1,0,c);
    repf(i,1,n+1){
        cin>>a[i];
    }
    repf(i,1,n+1){
        b[i]=abs(a[i+1]-a[i-1]);
    }
    repf(i,0,n+1){
        sum+=(c[i]=abs(a[i+1]-a[i]));
    }
    repf(i,1,n+1){
        cout<<sum+b[i]-(c[i-1]+c[i])<<endl;
    }
    return 0;

}

Measured memory_bytes: 2432
n = input()
h = [list(map(int, input().split()))]

cnt = 0

while 1 == 1:
  split0, temp = [], []

  # リストリストhを、0以外の塊に分け、split0に入れる
  for i_ in h:
    for i in i_:
      if i == 0:
        if len(temp) >= 1:
          split0.append(temp)
        temp = []

      else:
        temp.append(i)
        
    if len(temp) >= 1:
      split0.append(temp)
    temp = []
        
  if len(temp) >= 1:
    split0.append(temp)

  # リストリストsplit0の各リストから1を引き、リストリストhに格納
  # ただし、すべて要素0の場合はhに格納しない
  h = []
  for i_ in split0:
    i_ = list(map(lambda x: x - 1, i_))
    cnt += 1
    
    if sum(i_) != 0:
      h.append(i_)
      
  if len(h) == 0:
    print(cnt)
    break
      

    


Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        String S = sc.next();

        if(N%2==0){
            for(int i=0; i<N/2; i++){
                if(S.charAt(i)!=S.charAt(N/2+i)){
                    System.out.println("No");
                    break;
                }
                else if(i<N/2-1){
                    continue;
                }
                System.out.println("Yes");
            }
        }
        else if(N%2!=0){
            System.out.println("No");
        }
    }
}

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

const int MAXH = 13;
const int MAXW = 13;
int H, W;
char S[MAXH][MAXW];

int P[MAXH][2];
bool used[MAXW];

bool isGood() {
	for (int i = 0; i < W; i++) {
		used[i] = false;
	}
	bool mid = false;
	for (int i = 0; i < W; i++) {
		if (used[i]) continue;

		int j = i+1;
		for (; j < W; j++) {
			if (used[j]) continue;
			for (int z = 0; z < H/2; z++) {
				if (S[P[z][0]][i] != S[P[z][1]][j] || S[P[z][1]][i] != S[P[z][0]][j]) {
					goto failed;
				}
			}
			break;
failed:;
		}

		if (j != W) {
			assert(j < W);
			used[j] = true;
		} else {
			for (int z = 0; z < H/2; z++) {
				if (S[P[z][0]][i] != S[P[z][1]][i]) {
					return false;
				}
			}
			if (W % 2 == 0 || mid) {
				return false;
			}
			mid = true;
		}
	}
	return true;
}

bool go(int m, int cur, bool mid) {
	if (m == 0) {
		assert(cur == H/2);
		return isGood();
	}
	if (mid && go(m & (m-1), cur, false)) {
		return true;
	}
	
	if (m != (m & -m)) {
		int i = 0;
		while (!(m & (1 << i))) i++;
		for (int j = i+1; j < H; j++) {
			if (m & (1 << j)) {
				P[cur][0] = i;
				P[cur][1] = j;
				if (go(m & ~(1<<i) & ~(1<<j), cur+1, mid)) {
					return true;
				}
			}
		}
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	puts(go((1<<H) - 1, 0, H%2 == 1) ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#define x3(i) ((i)*(i)*(i))
#define x2(i) ((i)*(i))
using namespace std;

int main(){
  int e;
  while(cin>>e,e){
    int min=1<<30;
    for(int z=0;x3(z)<=e;z++){
      for(int y=0;x2(y)<=e;y++){
	int x=e-x3(z)-x2(y);
	if(x<0) continue;
	if(x+y+z < min) min = x+y+z;
      }
    }
    cout<<min<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};

ll N,L,T;

ll collision(ll x1,ll w1,ll x2,ll w2){
  // 蟻1と2が何回衝突するか
  // 向きが同じなら衝突しない
  if (w1 == w2) return 0;
  // 簡単のため、1が時計回り、2が反時計回りに移動するとする
  if (w1 == -1){ swap(x1, x2); swap(w1, w2);}
  // 2が原点に来るように各々の座標を調整。1が負なら正にしとく
  x1 -= x2; x2 -= x2;
  if (x1 < 0) x1 += L;
  // 結局、x1が時計回りに2Tだけ動いた時に何回原点を通るかという問題に帰着できる
  ll res = (x1 + 2*T) / L;
  return res;
}

int main() {
  cin >>N >>L >>T;
  vector<ll> x(N),w(N); rep(i, N) cin >>x[i] >>w[i];
  rep(i, N) if (w[i] == 2) w[i] = -1;
  
  // 座標自体は衝突を無視して計算すればいい
  // 各々がどの蟻かについては、x[0]の蟻についてT秒で衝突する蟻の個数を求める
  // それをそのまま足すか引くかすればその座標の蟻がどの蟻か決定する
  ll ant0 = 0;
  // x[0]にいた蟻について調査
  for (int i=1; i<N; i++){
    ant0 += w[0] * collision(x[0], w[0], x[i], w[i]);
  }
  ll colli = abs(ant0);
  if (ant0 >= 0) ant0 %= N;
  else{ ant0 *= -1; ant0 %= N; ant0 = (N-ant0) % N; }

  // 座標を再計算
  for (int i=0; i<N; i++){
    x[i] += T * w[i];
    if (x[i] >= 0) x[i] %= L;
    else{ x[i] *= -1; x[i] %= L; x[i] = (L - x[i]) % L; }
  }
  // ant0 : x[0]の蟻が実際にはどの蟻か
  int index = ant0;
  int indexco = x[0];
  // 現在、蟻index は indexco にいる
  sort(all(x));
  // 各々の蟻は座標順に存在すると考えられる
  // colli : 何回衝突したか。
  // ただし、同じ座標の蟻が存在しうる。
  // この場合、w[0] = 1なら若い方、w[0] = -1なら若くない方。
  vector<ll> res(N);
  res[index] = indexco;
  for (int j=0; j<N; j++){
    if (x[j] == indexco){
      if (x[(j+1)%N] == indexco) if (w[0] == 1) j = (j+1+N)%N;
      for (int i=0; i<N; i++){
        res[(i+index)%N] = x[(j+i)%N];
      }
      break;
    }
  }

  // たとえば1であれば、蟻0から蟻N-1の座標は各々x[N-1], x[0], x[1], ..., x[N-2] となる
  for (int i=0; i<N; i++){
    cout <<res[i] <<endl;
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int sai[]={0,0,0,0,0,0,4,3,2,1};

int main(){
	string n;
	int ans=0;
	cin >> n;
	reverse(all(n));
	int ku=0;
	FOR(i,(int)n.size()){
		int v=sai[((n[i]-'0')+ku)%10];
		if(((n[i]-'0')+ku)%10==5){
			if(i==(int)n.size()-1 || (n[i+1]-'0')<=4){

			}else{
				v=5;
			}
		}
		ans+=((n[i]-'0')+v+ku)%10+v;
		if((n[i]-'0')+v+ku>=10){
			ku=1;
		}else{
			ku=0;
		}
		
	}
	if(ku)ans++;

	
	cout << ans << endl;

}

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

int solve (int n, int k) {
    while (n%k != 0 && n > k) {
        int r = n % k;
        int delta = n/k + 1;
        int tmp = r / delta;
        if (r % delta != 0) tmp++;
        n -= tmp*delta;
    }
    return n/k;
}

int main() {
//    freopen("test.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, a, b, ret = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        ret ^= solve (a, b);
    }
    if (ret == 0) {
        cout << "Aoki" << endl;
    }
    else cout << "Takahashi" << endl;
}

Measured memory_bytes: 256
def main():
    s = input()
    dream = 0
    erase = 1
    work = []
    temp1 = 0
    temp2 = 0
    kind = -1
    append = work.append
    for c in s:
        if c == 'd':
            if kind != -1:
                append([kind, temp2-temp1])
            kind = dream
            temp1 = temp2
        elif c == 's':
            if kind != -1:
                append([kind, temp2-temp1-3])
            kind = erase
            temp1 = temp2-3
        temp2 += 1
    append([kind, len(s)-temp1])
    result = []
    append = result.append
    for i, j in work:
        if i == dream:
            if j <= 5:
                append("dream")
            else:
                append("dreamer")
        else:
            if j <= 5:
                append("erase")
            else:
                append("eraser")
    result = "YES" if "".join(result)==s else "NO"
    print(result)
main()

Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	deque<int> v;
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		if(i&1) v.push_front(x);
		else v.push_back(x);
	}
	if(n&1) reverse(v.begin(),v.end());
	for(int x:v) cout<<x<<' ';
	cout<<'\n';
}



Measured memory_bytes: 4488
import java.util.*;

class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();

    char[] ch = new char[s.length()];
    char c;

    for(int i=0; i<s.length(); i++){
       c = s.charAt(i);

       for(int j=0; j<n; j++){

          if(c == 'Z'){
             c = 'A';
          }else{
             c++;
          }
   
       }
       ch[i] = c;
       System.out.print(String.valueOf(ch[i]));
    }
  }
}



Measured memory_bytes: 26104
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

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


int n;
string s;

int main(){
	cin >> n >> s;
	
	bool b = 1;
	if(n % 2) b = 0;
	for(int i = 0; i < n/2; i++){
		if(s[i] != s[n/2+i]) b = 0;
	}
	if(b) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
a=0
i=0
while i<N:
    if i==N-1:
        if A[-1]==N:
            a+=1
            i+=1
        else:
            i+=1
    elif i+1==A[i]:
        if i+2==A[i+1]:
            i+=2
            a+=1
        else:
            i+=1
            a+=1
    else:
        i+=1
print(a)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("input.txt", "r", stdin);
    string str;
    string newStr = "";
    cin >> str;
    for(int i = 0; i < 3; i++){
        if(str[i] == '1'){
            newStr += "9";
        }else{
            newStr += "1";
        }
    }
    cout << newStr;
    return 0;
}


Measured memory_bytes: 256
def ceil(a,b): return (a+b-1)//b
K=int(input())
print(50)
Y = ceil(K,50)*50
A=[49 + Y//50]*50
for _ in range(Y-K):
    for i in range(49):
        A[i]+=1
    A[-1]-=50
    A.sort()
print(*A)

Measured memory_bytes: 38512
import java.util.*;
import java.util.ArrayList;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int ans = 0;
        
        ArrayList<Integer> list = new ArrayList<>();
        list.add(s);
        int n = 0;
       
        while(true){
          n++;
          int next;
          if(s % 2 == 0){
            next = s / 2 ;
          }else{
            next = 3*s + 1;
          }
          
           list.add(n,next);
           s = next;
           
          
         for(int i = 0 ; i < list.size()-1; i++){
           if(list.get(i)==list.get(n)){
             ans = n;
             System.out.println(ans+1);
             return;
           }else{
             continue;
           }
         }
        }
      
       
	}
}

Measured memory_bytes: 35712
#ABC073C
import sys

n=int(raw_input())
dic={}
for i in xrange(n):
 a=int(raw_input())
 if a in dic:
  dic[a]^=1
 else:
  dic[a]=1

res=0
for i in dic:
 if dic[i]==1:
  res+=1
print res


Measured memory_bytes: 13884
#include <bits/stdc++.h>
#define bear ryan
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define ends ' '
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll inf = 1e9;

int k;

int main(void) {
    fastio;
    cin >> k;
    ll ans = 0;
    for(int a = 1; a <= k; ++a) for(int b = 1; b <= k; ++b) for(int c = 1; c <= k; ++c) {
        ans += __gcd(a, __gcd(b, c));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1e9+5;
const int N=2e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector<int> ans(n);
	for(int i=0;i<n-1;++i){
		int x;
		cin>>x;
		--x;
		++ans[x];
	}
	for(int i=0;i<n;++i) cout<<ans[i]<<" ";
	return 0;
}


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

int main() {
	int n;
	cin>>n;
	long long int a[n+1];
	for(int i=0;i<n+1;i++)
		a[i]=1;
		
	a[0] = 0;
	
	for(int i=2;i<n+1;i++) {
		for(int j=i;j<n+1;j+=i) {
			a[j]+=1;
		}
	}
	
	long long int res=0;
	
	for(int i=1;i<n+1;i++) {
		res+= i*a[i];
	}
	
	cout<<res<<endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int res = 0;
    rep(i, 0, N-2) {
        if (S.substr(i, 3) == "ABC") res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
long long dp[100010];
long long h[100010];
const int MOD = 1000000007;

int main()
{
    string s; cin >> s;
    int a[10];
    int len = s.size();
    rep(i, len) a[i] = s[i] - '0';

    ll ans = 0;
    //cout << len << endl;
    rep(i, 1 << len - 1)
    {
        //cout << 1 << endl;
        ll tmp = a[0];
        rep(j, len - 1)
        {
            //tmp = tmp*10 + a[j + 1];
            if (i >> j & 1)
            {
                //cout << i << endl;
                ans += tmp;
                tmp = a[j + 1];
                //cout << ans << endl;
                continue;
            }
            else
            {
                tmp = tmp*10 + a[j + 1];
            }

        }
        ans += tmp;
        // cout << "tmp: " << tmp << endl;
        // cout <<"ans: " << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.readInt;
object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt();
        var ret = 0;
        for (i <- (0 until n)) {
            ret += isPrime(readInt());
        }
        println(ret);
    }
    
    def isPrime(num: Int): Int = {
        if (num < 2) return 0;
        if (num == 2) return 1;
        if (num % 2 == 0) return 0;
        var i = 3;
        while (i * i <= num) {
            if (num % i == 0) return 0;
            i += 2;
        }
        return 1;
    }
}


Measured memory_bytes: 49856
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll n, sum[1010], x;
bool jud = false;
vector<ll> ans[1010];
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < 1000; i++) sum[i + 1] = sum[i] + i + 1;
    for (ll i = 1; i <= 1000; i++){
        if (sum[i] == n){
            jud = true;
            x = i;
            break;
        }
    }
    if (jud){
        cout << "Yes" << endl;
        cout << x + 1 << endl;
        for (ll i = 2; i <= x + 1; i++){
            for (ll j = 1; j < i; j++){
                ans[i].push_back(sum[i - 2] + j);
                ans[j].push_back(sum[i - 2] + j);
            }
        }
        for (ll i = 1; i <= x + 1; i++){
            cout << x << ' ';
            for (ll j = 0; j < x - 1; j++){
                cout << ans[i][j] << ' ';
            }
            cout << ans[i][x - 1] << endl;
        }
    } else {
        cout << "No" << endl;
    }
}


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

// 
int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long maxNum;
    maxNum = a * c;
    maxNum = max(a * d, maxNum);
    maxNum = max(b * c, maxNum);
    maxNum = max(b * d, maxNum);
    cout << maxNum;
}


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

using namespace std;

int main(int argc, char** argv) {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  int r[n];
  // for (int i = 0; i < n; ++i) {
  //   r[i] = -1;  // Sentinel
  // }

  for (int i = n - 1; i >= 0; --i) {
    int s = 0;
    // Check right
    int k = 2;
    while (((i + 1) * k - 1) < n) {
      s += r[((i + 1) * k - 1)];
      ++k;
    }
    if ((s % 2) == a[i]) {
      r[i] = 0;
    } else {
      r[i] = 1;
    }
  }

  // For debug
  // for (int i = 0; i < n; ++i) {
  //   cout << r[i] << endl;
  // }

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (r[i] == 1) {
      ++cnt;
    }
  }

  int acm = 0;
  cout << cnt << endl;
  if (cnt > 0) {
    for (int i = 0; i < n; ++i) {
      if (r[i] == 1) {
        cout << (i + 1);
        ++acm;

        if (cnt != acm) {
          cout << " ";
        }
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 2432
/**
       ������������    ������������
		Author : Avi J Patel
		University : DA-IICT
       ������������    ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define large 10000000000000001

#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int a[2005][2005];
void calc()
{
	for(int i=0;i<2005;i++)
	{
		a[i][0]=1;
		a[i][i]=1;
		for(int j=1;j<i;j++)
		{
			a[i][j]=(a[i-1][j-1]+a[i-1][j])%MOD;	
		}
	}
}
int main()
{
	int n,k;
	cin>>n>>k;
	calc();
	for(int i=1;i<=k;i++)
	{
		cout<<(1LL*a[n-k+1][i]*a[k-1][i-1])%MOD<<endl;
	}
	return 0;
}








Measured memory_bytes: 15104
import sys
import random

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
#t = [int(input()) for i in range(D)]
#M = int(input())
#Q = [list(map(int,input().split())) for i in range(M)]

def content(t):
    cont = 0
    last = [0]*26
    for i in range(D):
        cont += s[i][t[i]-1]
        last[t[i]-1] = i+1
        for j in range(26):
            cont -= c[j]*(i+1-last[j])
    return cont

def main():
    t = [random.randint(1,26) for i in range(D)]
    prev = content(t)
    for i in range(5000):
        d,q = random.randint(0,D-1), random.randint(1,26)
        prev_t = t[d]
        t[d] = q
        now = content(t)
        if prev>content(t):
            t[d] = prev_t
        else:
            prev=now
    for a in t:
        print(a)


if __name__ == '__main__':
    main()





Measured memory_bytes: 85664
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N) {
		VVI A(2, VI(N));
		REP(y, 2) REP(i, N) cin>>A[y][i];
		VI S(2),SUM(2);
		REP(j, 2) SUM[j]=accumulate(ALL(A[j]), 0LL);
		ll ans=0;
		REP(sx, N) {
			maxUpdate(ans, S[0]+A[0][sx]+SUM[1]-S[1]);
			REP(j, 2) S[j]+=A[j][sx];
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <functional>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
    int h,w;
    std::cin >> h >> w;
    do {
        for (int i=0; i<h; ++i){
            for (int j=0; j<w; ++j){
                if(i%2==0){
                    if(j%2==0){printf("#");}
                    else {printf(".");}
                }
                else {
                    if(j%2==1){printf("#");}
                    else {printf(".");}
                }
            }
            std::cout << endl;
        }
        std::cin >> h >> w;
        std::cout << endl;
    }
    while (h!=0 && w!=0);
}




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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    vector<char> t(N+1);

    vector<string> ani = {"SS", "SW", "WS", "WW"};
    rep(i, 0, 4){
        t[0] = ani[i][0];
        t[1] = ani[i][1];
        rep(j, 1, N){
            // もしj番目の動物が羊だったら
            if(t[j] == 'S'){
                if(S[j] == 'o'){
                    if(t[j-1] == 'S') t[j+1] = 'S';
                    else t[j+1] = 'W';
                }else{
                    if(t[j-1] == 'S') t[j+1] = 'W';
                    else t[j+1] = 'S';
                }
            }else{
                if(S[j] == 'o'){
                    if(t[j-1] == 'S') t[j+1] = 'W';
                    else t[j+1] = 'S';
                }else{
                    if(t[j-1] == 'S') t[j+1] = 'S';
                    else t[j+1] = 'W';
                }
            }
        }
        if(t[0] == 'S'){
            if(S[0] == 'o'){
                if(t[1] != t[N - 1]) continue;
            }else{
                if(t[1] == t[N-1]) continue;
            }
        }else{
            if(S[0] == 'o'){
                if(t[1] == t[N-1]) continue;
            }else{
                if(t[1] != t[N-1]) continue;
            }
        }
        if(t[N] == t[0]){
            rep(i, 0, N){
                cout << t[i];
            }
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    
}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
using namespace std;
typedef long long ll;
template<typename T>
T GCD(T a, T b) {
	while (max(a, b) % min(a, b)) {
		if (a > b)a = a % b;
		else b = b % a;
	}
	return min(a, b);
}
template<typename T>
T LCM(T a, T b) {
	return a / GCD(a, b)*b;
}
int main() {
	ll a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	c = min(a * 4,min( b * 2, c));
	if (c * 2 < d) cout << e * c << endl;
	else cout << e % 2 * c + e / 2 * d << endl;
	return 0;
}

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

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

    cout << 6-a-b << endl; 
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll>a(n), b(n), c(n);
    rep(i, 0, n)cin >> a[i] >> b[i] >> c[i];
    ll ans = -1;
    for(int bit=0; bit<(1<<3); bit++){
        vector<ll>tempa=a,tempb=b,tempc=c,sum(n);
        ll temp = 0;
        if(bit&(1<<0)){
            rep(i, 0, n)tempa[i]*=-1;
        }
        if(bit&(1<<1)){
            rep(i, 0, n)tempb[i]*=-1;
        }
        if(bit&(1<<2)){
            rep(i, 0, n)tempc[i]*=-1;
        }
        rep(i, 0, n)sum[i]=tempa[i]+tempb[i]+tempc[i];
        sort(sum.begin(),sum.end(),greater<ll>());
        rep(i, 0, m)temp += sum[i];
        ans = max(ans, temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<bool>>;
const int MOD = 1e9 + 7;

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

    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; ++i)
        cin >> w[i] >> v[i];
    int ma = W / w[0];

    static int dp[103][103][303];
    for (int i = 0; i < N; ++i) {
        int tmp = w[i] - w[0];
        for (int j = 0; j <= min(i, ma); ++j) {
            for (int k = 0; k <= 300; ++k) {
                if (k - tmp >= 0) {
                    dp[i + 1][j + 1][k] = max(dp[i][j][k - tmp] + v[i], dp[i][j][k]);
                    dp[i + 1][j + 1][k] = max(dp[i + 1][j + 1][k], dp[i][j + 1][k]);
                } else
                    dp[i + 1][j + 1][k] = dp[i][j + 1][k];
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= ma; ++i)
        ans = max(ans, dp[N][i][min(W - w[0] * i, 300)]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10752
def prime(n):
    primes = [True] * (n+1)
    primes[0] = False
    primes[1] = False

    for i in range(2, int(n**0.5)+1):
        if not primes[i]:
            continue

        for j in range(i*2, n+1, i):
            primes[j] = False

    return [i for i in range(n+1) if primes[i]]


while True:
    N, P = map(int, input().split())  # Nより大きい素数, 和の小さな方がP番目

    if N == -1:
        break

    prime_numbers = [i for i in prime(120000) if i > N]

    hoge = []
    for i in range(P+1):
        for j in range(i, P+1):
            hoge.append(prime_numbers[i] + prime_numbers[j])

    hoge.sort()

    print(hoge[P-1])



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int dp[20][2];

int main() {
  string s;
  cin >> s;

  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;

  rep(i, s.size()) rep(ls, 2) if (dp[i][ls] != -1) {
    int v = (int)(s[i] - '0');
    int lim = ls ? 9 : v;
    rep(k, lim + 1) {
      int nls = ls || (k < lim);
      dp[i + 1][nls] = max(dp[i + 1][nls], dp[i][ls] + k);
    }
  }

  cout << max(dp[s.size()][0], dp[s.size()][1]) << endl;
}


Measured memory_bytes: 256
import scala.math.{min,max}

object Main {
  val sc = new java.util.Scanner(System.in)
  def sec(a: List[Int]) = {
    a(0) * 3600 + a(1) * 60 + a(2)
  }
  def hms(s: Int) = {
    List(s/3600, (s%3600)/60, s%60)
  }
  def calc(a: List[Int]) = {
    hms(sec(a.drop(3)) - sec(a.take(3)))
  }
  def main(args: Array[String]) {
    for(i <- 1 to 3) {
      println(calc(sc.nextLine.split(" ").map(_.toInt).toList).mkString(" "))
    }
  }
}

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

using namespace std;
#define ll long long 
int main() {
    unordered_map<string,int> m1;
    string s1,s2;
    cin>>s1>>s2;
    int a,b;
    cin>>a>>b;
    m1[s1]=a;
    m1[s2]=b;
    string s3;
    cin>>s3;
    if(m1[s3]>0){
        m1[s3]--;
    }
    
    cout<<m1[s1]<<" "<<m1[s2];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    for (ll i = 2; (i * i) <= n; i++) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while((n % i) == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll sum = 0;
    rep(i, n) sum += a[i];
    vector<pair<ll, int>> fact = factorize(sum);
    set<ll> z;
    ll ans = a[0];
    rep(i, n) {
        ans = gcd(ans, a[i]);
    }
    rep(i, sz(fact)) {
        rep(ii, fact[i].second) {
            set<ll> add;
            add.insert(fact[i].first);
            for (auto x : z) add.insert(x * fact[i].first);
            for (auto x : add) z.insert(x);
        }
    }
    map<ll, vector<ll>> surplus, dp;
    for (auto x : z) {
        surplus[x].resize(n);
        rep(i, n) surplus[x][i] = a[i] % x;
        sort(all(surplus[x]));
        dp[x].resize(n + 1, 0);
        rep(i, n) dp[x][i + 1] = dp[x][i] + surplus[x][i];
    }
    reps(i, 1, n) {
        for (auto x : z) {
            ll minus = 0, plus = 0;
            minus = dp[x][i];
            plus = (n - i) * x - (dp[x][n] - dp[x][i]);
            if (abs(minus - plus) % x != 0) continue;
            if (max(minus, plus) <= k) ans = max(ans, x);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9472
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = -1
	}

	m := stdin.ReadInt()
	for i := 0; i < m; i++ {
		s := stdin.ReadInt() - 1
		c := stdin.ReadInt()
		if a[s] == -1 || a[s] == c {
			a[s] = c
		} else {
			stdout.Println(-1)
			return
		}
	}

	if n == 1 {
		if a[0] == -1 {
			stdout.Println(0)
		} else {
			stdout.Println(a[0])
		}
		return
	}

	if a[0] == 0 {
		stdout.Println(-1)
		return
	}

	for i := 0; i < n; i++ {
		if a[i] == -1 {
			if i == 0 {
				a[i] = 1
			} else {
				a[i] = 0
			}
		}
	}

	ans := 0
	d := 1
	for i := n - 1; i >= 0; i-- {
		ans += a[i] * d
		d *= 10
	}
	stdout.Println(ans)
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t = 0;
	while (cin >> t&&t) {
		int n = 0;
		int fa[10] = {};
		int fb[10] = {};
		cin >> n;
		int ts = 0;
		for (int i = 0; i < n; i++) {
			cin >> fa[i] >> fb[i];
			ts += (fb[i] - fa[i]);
		}
		if (ts >= t) {
			cout << "OK" << endl;
		}
		else{
			cout << t - ts << endl;
		}
	}

	return 0;
	
}

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

int main() {
  int L, R, d, cnt=0;
  cin >> L >> R >> d;
  for(int i=L;i<=R;i++) {
    if(i%d==0)cnt++;
  }
  cout << cnt <<endl;
  return 0;
}


Measured memory_bytes: 3620