akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char S[1000005], T[1000005];
int main() {
	int n;
	scanf("%d%s%s", &n, S, T);
	if (string(S) == string(T)) {
		printf("0\n");
		return 0;
	}
	int las = n;
	vector<int> A = {n}, B;
	for (int i = n - 1; i >= 0; --i) {
		if (!i || T[i - 1] != T[i]) {
			B.push_back(i);
			bool found = false;
			for (int j = min(las - 1, i); j >= 0; --j) {
				if (S[j] == T[i]) {
					las = j;
					A.push_back(j);
					found = true;
					break;
				}
			}
			if (!found) {
				printf("-1\n");
				return 0;
			}
		}
	}
	assert(A.size() == B.size() + 1);
	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());
	int ans = 0;
	int m = A.size();
	for (int i = 0; i + 1 < m; ++i) {
		int lo = 0, hi = m - 1 - i;
		while (lo < hi) {
			int j = (lo + hi) >> 1;
			if (A[i + j] - j >= B[i]) hi = j;
			else lo = j + 1;
		}
		assert(A[i + lo] - lo >= B[i]);
		ans = max(ans, lo);
	}
	printf("%d\n", ans + 1);
}


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

int main(int argc, char** argv) 
{
	long long n,a,b,c,d,e;
	cin >> n >> a >> b >> c >> d >> e;
	long long m=a;
	m = min(m,b);
	m = min(m,c);
	m = min(m,d);
	m = min(m,e);
	cout << 4+(n%m?n/m+1:n/m) << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
w = [input() for i in range(n)]
for i in w:
  if w.count(i) > 1:
    print('No')
    exit()
for i in range(n-1):
  if w[i][-1] != w[i+1][0]:
    print('No')
    exit()
print('Yes')

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

const int maxn = 1e4 + 5;
int a[maxn], dp[maxn], m, nxt[maxn];
map <int, int> mp;

int f(int n){
    if(n < 0)
        return -mod;
    if(n == 0)
        return 0;
    if(dp[n] != -1)
        return dp[n];
    int ret = -1;
    for(int i = m - 1; i >= 0; i--){
        if(1 + f(n - mp[a[i]]) > ret){
            nxt[n] = a[i];
            ret = 1 + f(n - mp[a[i]]);
        }
    }
    return dp[n] = ret;
}

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

    int n;
    cin >> n >> m;
    int h[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    for(int i = 1; i <= 9; i++)
        mp[i] = h[i - 1];
    for(int i = 0; i < m; i++){
        cin >> a[i];
    }
    memset(dp, -1, sizeof dp);
    sort(a, a + m);
    f(n);
    while(n > 0){
        cout << nxt[n];
        n -= mp[nxt[n]];
    }
}

Measured memory_bytes: 512
import fractions

A, B, C, D = [int(_) for _ in input().split()]

lcm = C*D // fractions.gcd(C, D)
n = B//C + B//D - B//lcm - (A-1)//C - (A-1)//D + (A-1)//lcm
print(B-A+1-n)


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

vector<int> par;
vector<int> sze;

void makeSets(int n) {
    par.resize(n);
    sze.resize(n);
    for(int i=0; i<n; i++) {
        par[i] = i;
        sze[i] = 1;
    }
}

int find(int x) {
    if(x != par[x]) par[x] = find(par[x]);
    return par[x];
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int size(int x) {
    return sze[find(x)];
}

void unite(int xp, int yp) {
    int x = find(xp);
    int y = find(yp);
    if(x == y) return;
    if(size(x) > size(y)) {
        sze[x] += size(y);
        par[y] = x;
    } else {
        sze[y] += size(x);
        par[x] = y;
    }
}

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

    makeSets(N + M);
    for(int i=0; i<N; ++i) {
        int K;
        cin >> K;
        for(int j=0; j<K; ++j) {
            int L;
            cin >> L;
            --L;
            unite(i, N + L);
        }
    }

    for(int i=1; i<N; ++i) {
        if(!same(0, i)) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int a,b,x;
  cin >> a >> b >> x;
  
  if(a <= x & a+b >= x)
    cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  ll f=0,s=0,t=0;
  for(ll i=0;i<n;i++) {
    ll p;
    cin >> p;
    if(p<=a) f++;
    else if(p<=b) s++;
    else t++;
  }
  cout << min({f,s,t}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  S,s1,s2,s3;
  cin >>S;
  s1=S/100;
  s2=(S-s1*100)/10;
  s3=S-s1*100-s2*10;
  cout << s1+s2+s3<< endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math/big"
)

func main() {
	var x, k, d int
	fmt.Scan(&x, &k, &d)

	fmt.Println(solve(x, k, d))
}

func solve(X, K, D int) int {
	if X < 0 {
		X = -X
	}

	if cmp(X, K, D) {
		return X - K*D
	}

	k := X / D
	x := X - D*k
	d := K - k
	if d%2 == 0 {
		return x
	} else {
		return D - x
	}
}

func cmp(X, K, D int) bool {
	x := big.NewInt(int64(X))
	k := big.NewInt(int64(K))
	d := big.NewInt(int64(D))

	return 0 < x.Cmp(k.Mul(k, d))
}


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

//Binomial Coefficients
const long long c_max = 1000003;
const long long mod = 1e9+7;
long long fac[c_max], finv[c_max], inv[c_max];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < c_max; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
// 二項係数計算
long long COM(long long comn, long long comk){
    if (comn < comk) return 0;
    if (comn < 0 || comk < 0) return 0;
    return fac[comn] * (finv[comk] * finv[comn - comk] % mod) % mod;
}

void solve_A(){
	int r;
    cin >> r;
    cout << r*r << endl;
}

void solve_B(){
	int n,i;
    char c[505];
    bool ans=true;
    cin >> n >> c;
    if(n%2==1){
        cout << "No" << endl;
        ans=false;
    } else {
        for(i=0;i<n/2;i++){
            if(c[i]!=c[n/2+i]){
                cout << "No" << endl;
                ans=false;
            }
        }
    }
    if(ans) cout << "Yes" << endl;
}

void solve_C(){
	int n,i,f=1;
    double x[15],y[15],ans=0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x[i] >> y[i];
        f*=(i+1);
    }
    vector<int> p;
    for(i=0;i<n;i++) p.push_back(i);
    do{
        double memo;
        for(i=1;i<n;i++){
            memo=(x[p[i-1]]-x[p[i]])*(x[p[i-1]]-x[p[i]])+(y[p[i-1]]-y[p[i]])*(y[p[i-1]]-y[p[i]]);
            memo=sqrt(memo);
            ans+=memo;
        }
    }while(next_permutation(p.begin(),p.end()));
    ans=ans/(double)f;
    printf("%.13lf\n",ans);
}

void solve_D(){
	long long x,y,n,i;
    bool t=true;
    cin >> x >> y;
    if((x+y)%3!=0){
        cout << "0" << endl;
    } else {
        n=(x+y)/3;
        if(x-n<0||2*n-x<0){
            cout << "0" << endl;
        } else {
            COMinit();
            cout << COM(n,x-n) << endl;
        }
    }
}

int main() {
	// your code goes here
	//solve_A();
    //solve_B();
    //solve_C();
    solve_D();
	return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    rep(i,n){
        int tmp;
        cin>>tmp;
        if(tmp%2){
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i<n; i++){
            int A = scanner.nextInt();
            int B = scanner.nextInt();
            int C = scanner.nextInt();


            if (A * A + B * B == C * C) {
                System.out.println("YES");
            } else if (A * A + C * C == B * B) {
                System.out.println("YES");
            } else if (C * C + B * B == A * A) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}


Measured memory_bytes: 33784
import operator as op
from functools import reduce

MODULUS = 10**9 + 7

if __name__ == '__main__':
    [h, w, a, b] = map(int, input().split())

    # Taken from https://atcoder.jp/contests/abc042/submissions/3178794 for learning purposes.
    factorial = [0] * (h+w)
    factorial[0] = 1
    factorial[1] = 1
    inverse = [0] * (h+w)
    inverse[0] = 1
    inverse[1] = 1
    for i in range(2, h+w):
        factorial[i] = factorial[i-1] * i % MODULUS
        # フェルマーの小定理から(x! ** mod-2 % mod == x! ** -1 % mod)
        # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
        inverse[i] = pow(factorial[i], MODULUS-2, MODULUS)
        
    # 組み合わせの数だけ返してくれる関数(自作)
    def ncr(n, r):
        # 10C7 = 10C3
        r = min(r, n-r)
        # 分子の計算
        numerator = factorial[n]
        # 分母の計算
        denominator = inverse[r] * inverse[n-r] % MODULUS
        return numerator * denominator % MODULUS

    res = 0
    for i in range(h-a):
        rights_and_downs_to_right_border_of_forbidden_area = i + (b-1)

        rights_and_downs_from_right_border_of_forbidden_area = (w - b - 1)  + (h - i - 1) 
        res = (res + ncr( rights_and_downs_to_right_border_of_forbidden_area,   b-1  ) \
            * ncr(  rights_and_downs_from_right_border_of_forbidden_area, (h - i - 1) )) % MODULUS


    print(res)

Measured memory_bytes: 44528
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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 n;
  cin >> n;
  vector<int> a[2], s[2];
  rep(i,2){
    a[i] = vector<int>(n);
    s[i] = vector<int>(n);
    rep(j,n) cin >> a[i][j];
  }
  s[0][0] = a[0][0];
  rep(j,n-1) s[0][j+1] = s[0][j] + a[0][j+1];
  s[1][n-1] = a[1][n-1];
  rep(j,n-1) s[1][n-1-j-1] = s[1][n-1-j] + a[1][n-1-j-1];

  int ans = 0;
  rep(i,n) ans = max(ans,s[0][i]+s[1][i]);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;



ll mod = 1e9 + 7;
using Matrix = vector<vector<ll>>;

Matrix matmul(const Matrix &a, const Matrix &b) {
	int n = a.size();
	Matrix ret(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		for (int k = 0; k < n; k++) {
			for (int j = 0; j < n; j++) {
				ret[i][j] += (a[i][k] * b[k][j]) % mod;
				ret[i][j] %= mod;
			}
		}
	}
	return ret;
}

Matrix matpow(Matrix a, ll p) {
	int n = a.size();
	Matrix ret(n, vector <ll>(n));
	for (int i = 0; i < n; i++) ret[i][i] = 1;
	for (ll t = p; p > 0; p /= 2) {
		if (p & 1) ret = matmul(ret, a);
		a = matmul(a, a);
	}
	return ret;
}


int main() {
	int N; ll K; cin >> N >> K;
	Matrix m(N, vector<ll>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> m[i][j];
		}
	}
	m = matpow(m, K);
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans += m[i][j];
			ans %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
# solution

data = int(input())
list = list(map(int,input().split()))
list.sort()

cnt_min = len([i for i in list if i < 0])
num_min = min([abs(i) for i in list])
sum_abs = sum([abs(i) for i in list])

if cnt_min%2 == 0:
    print(sum_abs)
else:
    print(sum_abs-2*num_min)

Measured memory_bytes: 14412
use std::cmp;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt;
use std::io::stdin;
use std::io::Error;
use std::io::ErrorKind;
use std::io::Read;

#[derive(Debug)]
struct Input {
    n: u32,
    a: HashMap<u32, u32>,
}

fn handle_input(input_str: String) -> Result<Input, Error> {
    let mut iter = input_str.split_whitespace();
    let n: u32 = iter.next().unwrap().parse().unwrap();
    let mut a = HashMap::new();
    for _ in 0..n {
        let v: u32 = iter.next().unwrap().parse().unwrap();
        let counter = a.entry(v).or_insert(0);
        *counter += 1;
    }
    let input = Input { n: n, a: a };
    Ok(input)
}

fn gcd(a: u32, b: u32) -> u32 {
    if a == 0 {
        return b;
    }
    gcd(b % a, a)
}

fn handle_output(input: Input) -> Result<String, Error> {
    let mut a = input.a.keys().clone();
    let first = *a.next().unwrap();
    let mut max_gcd = a.fold(first, |acc, &x| gcd(x, acc));
    for (&k, &v) in input.a.iter() {
        if v > 1 {
            continue;
        }
        let mut iter = input.a.keys().filter(|&&x| x != k);
        if let Some(&max) = iter.next() {
            let mut g = max;
            for &j in iter {
                g = gcd(j, g);
            }
            if g > max_gcd {
                max_gcd = g;
            }
        }
    }
    Ok(format!("{}", max_gcd))
}

fn main() {
    let mut input_str = String::new();
    let stdin = stdin();
    stdin.lock().read_to_string(&mut input_str).unwrap();
    let input = handle_input(input_str).unwrap();
    let output = handle_output(input).unwrap();
    println!("{}", output);
}

Measured memory_bytes: 6396
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, a, b) for (int i = a; i < (b); ++i)
#define FOR(i, n) for (int i = n; i >= 0; --i)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define INF (1LL << 50)
using namespace std;
struct Edge{int from, to, cost;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;

    vector<Edge> edges;

    REP(i, M){
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        Edge e1 = {a,b,c};
        edges.push_back(e1);
    }
    vector<ll> d(N, -INF);
    d[0] = 0;
    REP(i,N-1){
        //&をつけておけば値の書き換えもできる
        for(Edge& edge : edges){
            ll score = d[edge.from] + edge.cost;
            if(score > d[edge.to]){
                d[edge.to] = score;
            }
        }
    }

    ll ans = d[N-1];

    REP(i,N-1){
        for(Edge& edge : edges){
            ll score = d[edge.from] + edge.cost;
            if(score > d[edge.to]){
                d[edge.to] = score;
            }
        }
    }

    if(ans != d[N-1]) cout << "inf" << endl;
    else cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[2005][2005];
int arr1[2005];
int arr2[2005];

int mod = 1e9+7;
int main(){
  int m,n;
  cin>>m>>n;
  
  for(int i=0;i<m;++i)cin>>arr1[i];
  for(int i=0;i<n;++i)cin>>arr2[i];
  
  for(int i=0;i<2005;++i){
    dp[i][0] = 0;
    dp[0][i] = 0;
  }
  
  for(int i=0;i<m;++i){
    for(int j=0;j<n;++j){
      dp[i+1][j+1] = ((dp[i][j+1] + dp[i+1][j])%mod + mod - dp[i][j])%mod;
      
      if(arr1[i]==arr2[j]){
        dp[i+1][j+1] += 1;
        dp[i+1][j+1] += dp[i][j];
        dp[i+1][j+1] =  dp[i+1][j+1]%mod;
      }
    }
  }
  
  cout<<dp[m][n]+1<<endl;
  return 0;
}

Measured memory_bytes: 16000
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
# S=numpp.assaray(S)=="#"
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LLS(): return [list(sys.stdin.readline().rstrip()) for _ in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()



def main():
    A,B=LI()
    out=1
    num=A
    if B<=1:
        print("0")
        exit()
    while num<B:
        num+=(A-1)
        out+=1
    print(out)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14248
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
#define MOD (1000*1000*1000+7)

int t, n, m, k, a[300010], q, l, r;
int fac[500010];

int exp(int x, int e){
if(e==0){return 1;}
if(e==1){return x;}
return (( exp(x, e%2)%MOD )*(exp(x*x%MOD, e/2)   ))%MOD;
}

int inv(int x){
int fi=MOD-1;
return exp(x, fi-1);
}

int32_t main(){
INIT
cin>>n>>m;
if(m<n){cout<<0; return 0;}
fac[0]=1;
for(int i=1; i<=500000; i++){
    fac[i]=(fac[i-1]*i)%MOD;
}





int un=0;
for(int j=1; j<=n; j++){
    un+=( ( (j%2)==1)?(1):(-1)  )*( ( (( ((( (fac[m]*fac[n])%MOD   )*(fac[m-j]))%MOD )) %MOD)*((( ( (inv( (fac[m-n]*fac[m-n])%MOD ) )*(inv(fac[j])  ) ))%MOD)*(inv(fac[n-j]) )%MOD   ))%MOD );
    un%=MOD;
}
int res= ( ( (fac[m]*fac[m])%MOD )*( (inv(fac[m-n])*inv(fac[m-n]))%MOD ) )%MOD;
cout<<(res-un+MOD)%MOD<<"\n";

return 0;
}


Measured memory_bytes: 7484
N, Y = gets.split.map(&:to_i)

x = y = z = -1
x = Y / 10000
x = (x > N) ? N : x

x.downto(0) do |i|
  0.upto(N-i) do |j|
    sum = i * 10000 + j * 5000 + (N-i-j) * 1000
    if Y == sum
      x = i
      y = j
      z = N - i - j
      puts [x, y, z].join(' ')
      exit
    end
  end
end

puts [-1, -1, -1].join(' ')

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

#define INF 1000000000

using namespace std;

int main()
{
	int n;
	long long int a, b;
	long long int h[100000];
	long long int hs[100000];

	scanf("%d %lld %lld", &n, &a, &b);
	for(int i=0; i<n; i++){
		scanf("%lld", &h[i]);
	}
	sort(h, h+n);
	for(int i=n-1; i>=0; i--){
		if(i==n-1){
			hs[n-1]=h[n-1];
		}else{
			hs[i]=hs[i+1]+h[i];
		}
	}
	
	int m=0;
	while(m<n){
		if(h[m]<=(hs[m]*b)/(a-b+(n-m)*b)){
			m++;
		}else{
			break;
		}
	}

	long long int x0, x1, x2,x;
	if(hs[m]%(a-b+(n-m)*b)==0){
		x0=hs[m]/(a-b+(n-m)*b);
	}else{
		x0=hs[m]/(a-b+(n-m)*b)+1;
	}

	x1=x0;
	x2=x0+n-m+1;

	while(x1!=x2){
		long long int sum=0;
		x=(x1+x2)/2;
		for(int i=m; i<n; i++){
			if(h[i]-x*b>=0 && (h[i]-x*b)%(a-b)==0){
				sum=sum+(h[i]-x*b)/(a-b);
			}else if(h[i]-x*b>=0){
				sum=sum+(h[i]-x*b)/(a-b)+1;
			}
		}
		if(x>=sum){
			x2=x;
		}else{
			x1=x+1;
		}
	}

	long long int x3;
	if(m==0){
		x3=0;
	}else if(h[m-1]%b==0){
		x3=h[m-1]/b;
	}else{
		x3=h[m-1]/b+1;
	}

	if(x1<x3){
		x=x3;
	}else{
		x=x1;
	}

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

	return 0;

}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    long long m = min({a,b,c,d,e});
    cout << 4 + n/m + (n%m != 0) << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>
#include <sstream>

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int, int> pii;

#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)

ld EPS = (ld)1e-9L;
const double PI = 3.141592653589793238462;
const int INF = 1e9 + 7;
const li LINF = 4e18 + 7;


int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int n, k;
	cin >> n >> k;
	
	if (k == 0) {
		cout << n * 1ll * n << endl;
		return 0;
	}

	li ans = 0;
	for (int a = k; a < n; ++a) {
		ans += n - a;
	}

	for (int b = k + 1; b + k <= n; ++b) {
		int cnt = (n - b) / b;
		ans += cnt * 1ll * (b - k);
		ans += max(n - (b + k + cnt * b) + 1, 0);
	}

	cout << ans << endl;
}

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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define up(x, v) upper_bound(all(x), v)
#define low(x, v) lower_bound(all(x), v)
#define bin(x, v) binary_search(all(x), v)
#define FOR(k, a, b) for(int k = (a); k < (b); ++k)
#define ROF(k, a, b) for(int k = (a); k > (b); --k)
#define fn(k, n) for(int k = 0; k < n; ++k)

#define EPS 1.0e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

int main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n, k;
	cin >> n >> k;
	cout << int(log(n) / log(k)) + 1 << '\n';

    return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())
k = [1, 3, 5, 7, 8, 10, 12]
g = [4, 6, 9, 11]
g2 = [2]
if x in k and y in k:
    print("Yes")
elif x in g and y in g:
    print("Yes")
elif x in g2 and y in g2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <tuple>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl;

using namespace std;

int w, h, map[61][61];

bool check(int j, int k) {
	return (j >= 0 && j<h && k >= 0 && k <w && map[j][k] > 0);
}
/*
int dfs(int j, int k, int count){
	const int diff[]={-1, 0, 1, 0, -1};
	map[j][k] = 0;
	if ()
	count++;
	REP(i,4){
		if (check(j+diff[i],k+diff[i+1])) ans += dfs(j+diff[i], k+diff[i+1]);
	}
	return ans;
}
*/
void printmap() {
	REP(j, h) {
		REP(k, w) printf("%d ", map[j][k]);
		cout << endl;
	}
}

int main() {
	while (1) {
		int j, k, input, ans, count;
		const int diff[] = {-1, 0, 1, 0, -1};
		queue<tuple<int, int, int> > bfs;
		bool goal = false;
		// string input;
		
		cin >> w >> h;
		if (w==0 && h==0) break;

		h = h * 2 - 1;
		w = w * 2 - 1;
		ans = 0;

		REP(j, h) {
			REP(k, w) { map[j][k] = (j % 2 == 0 && k % 2 == 0) ? 1 : 0; }
		}

		REP(j, h) {
			// debug(j);
			// cin >> input;
			REP(k, w) {
				if ((j % 2 == 0 && k % 2 == 0) || (j % 2 == 1 && k % 2 == 1))
					continue;
				scanf("%d", &input);
				// debug(k);
				// debug(input);
				if (input == 0) map[j][k] = 1;
			}
		}

		//printmap();

		bfs.push(make_tuple(0, 0, 1));
		map[0][0] = 0;
		
		while (!bfs.empty()) {
			j = get<0>(bfs.front());
			k = get<1>(bfs.front());
			count = get<2>(bfs.front());
			bfs.pop();
			if (j >= h - 1 && k >= w - 1) {
				cout << (count/2)+1 << endl;
				goal = true;
			}
			REP(i, 4) {
				if (check(j + diff[i], k + diff[i + 1])) {
					/*debug(j+diff[i])
					debug(k+diff[i+1]);
					debug(count);*/
					bfs.push(make_tuple(j + diff[i], k + diff[i + 1], count + 1));
					map[j+diff[i]][k+diff[i+1]] = 0;
				}
			}
		}

		// printmap();
		if (!goal) cout << 0 << endl;
	}

	return 0;
}



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

int main() {
  int n, x, y;  
  cin >> n >> x >> y;
  int ml[100009];

  for (int i = 1; i < n; i++) {
    for (int j = i+1; j <= n; j++) {
      int len = min(
        abs(j - i),
        abs(x - i) + 1 + abs(j - y)
      );
      ml[len]++;
    }
  }

  for (int k = 1; k < n; k++) {
    cout << ml[k] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int cnt = 1;
  if((a == b) && (a == c)) {
    cnt = 1;
  } else if((a != b) && (a != c) && (b != c)) {
    cnt = 3;
  } else {
    cnt = 2;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
using Graph = vector< vector<int> >;

#define fprintf(...) void(0)

void add_vertex(Graph &G, vector<int> &deg, vector<int> &par, int val, int pre) {
    G.push_back(vector<int>());
    deg.push_back(val);
    par.push_back(pre);
}

void add_edge(Graph &G, vector<int> &deg, int u, int v) {
    fprintf(stderr, "add edge: u = %d, v = %d\n", u, v);
    G[u].push_back(v);
    G[v].push_back(u);
    deg[u]--;
    deg[v]--;
    fprintf(stderr, "deg of u = %d, v = %d\n", deg[u], deg[v]);
}

int main() {
    int T; cin >> T;
    while(T--) {
        int val;

        Graph G;
        vector<int> deg, par;

        int cur = 0;
        while(cin >> val, val) {
            if(G.empty()) {
                add_vertex(G, deg, par, val, -1);
            }
            else {
                if(val > 0) {
                    int nxt = (int)G.size();
                    while(deg[cur] == 0) {
                        cur = par[cur];
                    }

                    add_vertex(G, deg, par, val, cur);
                    add_edge(G, deg, cur, nxt);
                    cur = nxt;
                }
                else {
                    val = -val;
                    while(deg[cur] == 0) {
                        cur = par[cur];
                    }

                    int nxt = cur;
                    for(int i=0; i<val; i++) nxt = par[nxt];
                    add_edge(G, deg, cur, nxt);
                }
            }
        }

        for(int i=0; i<G.size(); i++) {
            sort(G[i].begin(), G[i].end());

            cout << i+1;
            for(auto to : G[i]) cout << " " << to + 1;
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3084
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	n = II()
	a = LI()
	ans = [0]*n
	for aa in a:
		ans[aa-1]+=1
	printV(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 32996
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<List<Integer>> G = new ArrayList<>();
        for(int i = 0; i < n; i++) G.add(new ArrayList<>());
        for(int i = 0; i < m; i++) {
            int a = Integer.parseInt(sc.next())-1;
            int b = Integer.parseInt(sc.next())-1;
            G.get(a).add(b);
            G.get(b).add(a);
        }

        int[] res = new int[n];
        Arrays.fill(res, -1);
        Queue<Integer> que = new ArrayDeque<>();

        res[0] = 0;
        que.offer(0);
        while(!que.isEmpty()) {
            int v = que.poll();

            for(int nv : G.get(v)) {
                if(res[nv] != -1) continue;
                res[nv] = v + 1;
                que.offer(nv);
            }
        }

        System.out.println("Yes");
        for(int i = 1; i < res.length; i++) {
            sb.append(res[i] + "\n");
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 74636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll A,B,C;
    cin >> A >> B >> C;
    ll left = A - B;
    if (C- left > 0){
        cout << C- left;
    }else{
        cout << 0;
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(map(int, input().split()))
S.sort()

ans = 0
A = [True]*(10**6+1)

for i in range(0, N):
    if not A[S[i]]:
        continue
    if 0 < i:
        if S[i-1] == S[i]:
            continue
    if i < N-1:
        if S[i] == S[i+1]:
            for j in range(1, 10**6//S[i]+1):
                A[S[i]*j] = False
            continue
    ans += 1
    for j in range(1, 10**6//S[i]+1):
        A[S[i]*j] = False

print(ans)

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

int main() {
	long long int N;
  	cin>>N;
  	long long int A[N],B[N],memo[N+10000]={};
  	long long int ans=0;
  	
  	for(int i=0;i<N;i++){
     	cin>>A[i]; 
      	B[i]=A[i];
    }
  
  	sort(B,B+N);
  
 	for(int i=0;i<N;i++){
     	memo[B[i]-1]++; 
    }
  
  	for(int i=0;i<N;i++){
     	 ans+=memo[i]*(memo[i]-1)/2;
    }
  
  	for(int i=0;i<N;i++){
        cout<<ans-memo[A[i]-1]+1<<endl;
    }
  
  	
}

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

using namespace std;

#define MAXN 1010
#define INF 0x3f3f3f3f
#define mo 1000000007
typedef long long LL;

char s[MAXN];

int main()
{
//#ifdef MYCP
//    freopen("data.in", "r", stdin);
//#endif // MYCP

    int n;
    LL sum = 0, ten[11] = {1}, two[11] = {1};
    for(int i = 1; i < 11; ++i) ten[i] = ten[i - 1] * 10, two[i] = two[i - 1] * 2;
    scanf("%s", s);
    n = strlen(s);
    if(n == 1) sum = s[0] - '0';
    else{
        for(int i = 0; i < n; ++i)
            for(int j = 0; j <= n - i - 1; ++j)
                sum += (s[i] - '0') * ten[j] * two[max(0, n - i - j - 2) + i];
    }
    printf("%lld\n", sum);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;

int main(){
  int n,x,t;
  cin>>n>>x>>t;
  int ans=n/x;
  if (n%x==0){
    cout<<ans*t;
    return 0;
  }
  else if(n%x>0){
    cout<<(ans+1)*t;
  }
  
  
  

}


Measured memory_bytes: 3632
import sys

def I(): return int(sys.stdin.readline().rstrip())

def S(): return sys.stdin.readline().rstrip()

N = I()
S = [S() for i in range(N)]

a = S.count('AC')
b = S.count('WA')
c = S.count('TLE')
d = S.count('RE')

print('AC x {}'.format(a))
print('WA x {}'.format(b))
print('TLE x {}'.format(c))
print('RE x {}'.format(d))


Measured memory_bytes: 74244
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N=int(input())
    cnt=0
    i=1
    while True:
        M=N
        M-=i
        p=M/i
        if p<=i:
            break
        else:
            if p.is_integer():
                cnt+=p
            i+=1
    print(int(cnt))



resolve()

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

#define MAX 1000000
bool isPrime[MAX+1];

int main( void )
{
    int a, d, n;
    memset( isPrime, false, sizeof( isPrime ) );

    isPrime[2] = true;
    for ( int i = 3; i <= MAX; i += 2 ) isPrime[i] = true;
    for ( int i = 3; i <= MAX; i += 2 )
    {
        if ( isPrime[i] == false ) continue;
        for ( int j = i + i; j <= MAX; j += i ) isPrime[j] = false;
    }

    while ( cin >> a >> d >> n && a && d && n )
    {
        int answer  = -1;
        int count   = 0;
        int term    = a;
        while ( count < n )
        {
            if ( isPrime[term] )
            {
                answer = term;
                count ++;
            }
            term += d;
        }

        cout << answer << endl;
    }

    return 0;
}

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

int main(){
    int fibo[45];
    fibo[0] = 1;
    fibo[1] = 1;
    int n;
    cin >> n;
    int i;
    for(i = 2; i <= n; i++){
        fibo[i] = fibo[i-1] + fibo[i-2];
    }
    cout << fibo[n] << endl;
    return 0;
}


Measured memory_bytes: 3084
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
	public static void main (String[] args){
		Scanner sc=new Scanner(new InputStreamReader(System.in));
		int n=sc.nextInt();
		int[] a=new int[n];
		a[0]=sc.nextInt();
		int min=a[0],max=a[0];
                long sum=a[0];
		for(int i=1;i<n;i++){
			a[i]=sc.nextInt();
			if(min>a[i]) min=a[i];
			if(max<a[i]) max=a[i];
			sum+=a[i];
		}
		sc.close();
		System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 42272
// in the name of Allah ;
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 2e5 + 10 ;
int main ()
{
	string s ;
	int p1= 0 , p2 = 1 , n , ans = 0 ;
	cin >> s ;
	n = (int)(s.size());
	while  ( p1 < n & p2 < n ) 
	{
		while ( p1 < n && s[p1] != 'S' ) 
			p1++;
		while ( p2 < p1 ) 
			p2++;
		while ( p2 < n &&s[p2] != 'T' ) 
			p2++;
		if ( p1 < p2 && s[p1] == 'S' && s[p2] == 'T'  ) 
			ans++;
		p1++ , p2++ ;
	}
	cout << n- ans*2 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++)
	{
		if(s[i]==s[i+1])
		{
			cout<<i+1<<" "<<i+2;
			return 0;
		}
	}
	if(s.size()>=3)
	{
		for(int i=0;i<s.size()-2;i++)
		{
			if(s[i]==s[i+2])
			{
				cout<<i+1<<" "<<i+3;
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define mp make_pair
#define rep(a,b,c) for(int a=1;a<=b;a+=c)
#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)

const double PI=acos(-1);
const double EPS=1e-12;
const int MOD=1e9+7;
const int INF=1<<30;


using namespace std;

int dat[100005][5];
int maxx[100005][5];

int main(){
	int in;
	cin>>in;
	rep(i,in,1){
		rep(j,3,1){
			cin>>dat[i][j];
		}
	}
	for(int i=in;i>=1;i--){
		if(i==in){
			rep(j,3,1)maxx[i][j]=dat[i][j];
		}
		else{
			maxx[i][1]=max(maxx[i+1][2],maxx[i+1][3])+dat[i][1];
			maxx[i][2]=max(maxx[i+1][1],maxx[i+1][3])+dat[i][2];
			maxx[i][3]=max(maxx[i+1][2],maxx[i+1][1])+dat[i][3];
		}
	}
	cout<<max(maxx[1][1],max(maxx[1][2],maxx[1][3]))<<endl;;
	return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

string removeX(string s) {
    string res;
    rep(i, s.size()) {
        if (s[i] != 'x') {
            res += s[i];
        }
    }
    return res;
}

bool isPalindrome(string s) {
    rep(i, s.size()) {
        if (s[i] != s[s.size() - 1 - i])return false;
    }
    return true;
}

signed main() {
    string S;
    cin >> S;
    if (!isPalindrome(removeX(S))) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    int l = 0, r = S.size() - 1;
    while (l <= r) {
        if (l == r)break;
        if (S[l] == 'x' && S[r] == 'x') {
            l++;
            r--;
            continue;
        }
        if (S[l] == 'x') {
            ans++;
            l++;
            continue;
        }
        if (S[r] == 'x') {
            ans++;
            r--;
            continue;
        }
        l++;
        r--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
H, W = map(int, input().split())

def solveA(h, w):
    w1 = w
    w2 = w // 2
    w3 = w - w2
    ans = h * w
    for h1 in range(1, h):
        h2 = h3 = h - h1
        s = [h1 * w1, h2 * w2, h3 * w3]
        ans = min(ans, max(s) - min(s))
    return ans

def solveB(h, w):
    if h % 3 == 0:
        return 0
    else:
        return w

ans = min(solveA(H, W), solveA(W, H), solveB(H, W), solveB(W, H))
print(ans)


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

using namespace std ;

int main () {

   long long n , i, nas=0  ;

   cin >> n ;


   long long a[n+10] ;



   for(i=0;i<n;i++){
    cin >> a[i] ;
   }

    sort(a,a+n) ;

    cout << a[n/2]-a[n/2-1] ;

    return 0 ;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll vi[200],wi[200],w,n,dp[200][100100];
ll dp1(int i,ll weight)
{
    if(i>=n)
        return 0;
    if(dp[i][weight]!=-1)
        return dp[i][weight];
    ll x1=0;
    if(weight+wi[i]<=w)
    {
        x1=vi[i]+dp1(i+1,weight+wi[i]);
    }
    ll x2=dp1(i+1,weight);
    return dp[i][weight]=max(x1,x2);
}
int main()
{
    ios_base::sync_with_stdio(0);
    memset(dp,-1,sizeof(dp));
    cin>>n>>w;
    for(int i= 0 ; i<n ; i++)
    {
        cin>>wi[i]>>vi[i];
    }
    cout<<dp1(0,0);
    return 0;
}


Measured memory_bytes: 156672
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;
int main() {
	ll N;
  	cin>>N;
	ll a[N+10];
	for (ll i = 1; i <=N; i++) {
		cin >> a[i];
	}
  	ll sum=0;
  	a[0] = 0;
	a[N+1] = 0;
  	for(ll i=0; i<=N; i++){
      sum+=abs(a[i+1]-a[i]);
    }
	for (ll i = 1; i <=N; i++) {
		cout << sum+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i]-a[i+1]) << endl;
	}

}








Measured memory_bytes: 2048
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let dfs vs n =
  let d = Array.make (n + 1) 0 in
  let f = Array.make (n + 1) 0 in
  let time = ref 1 in
  let rec doit i =
    d.(i) <- !time;
    incr time;
    List.iter (fun e -> if d.(e) = 0 then doit e) vs.(i);
    f.(i) <- !time;
    incr time in
  for i = 1 to n do
    if d.(i) = 0 then doit i;
  done;
  (d, f)

let () =
  let n = read_int () in
  let vs = Array.make (n + 1) [] in
  for _ = 0 to n - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | u :: _ :: l -> vs.(u) <- l
    | _ -> assert false
  done;
  let (d, f) = dfs vs n in
  for i = 1 to n do
    Printf.printf "%d %d %d\n" i d.(i) f.(i)
  done

Measured memory_bytes: 2376
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>a>>b>>c;
    a-=c;
    Cout(a/(b+c));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  string s;
  cin>>s;
  for(int i=0;i<3;i++){
      cout<<s[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3624
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = new BigDecimal(a + b).divide(new BigDecimal(2), BigDecimal.ROUND_UP).intValue();
		
		System.out.println(c);
	}

}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define pq priority_queue
#define st first
#define nd second
#define np next_permutation

using namespace std;
typedef long long ll;
ll const inf = 1e9;
ll const mod = 1e9 + 7;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll a[n];
    fr(i, 0, n) cin >> a[i];
    ll fp = -1, ln = -1;
    fr(i, 0, n){
        if(a[i] >= 0){
            ln = i - 1;
            fp = i;
            break;
        }
    }
    ll ans = 1e9 * 2;
    fr(l, 0, n - k + 1){
        int r = l + k  - 1;
        ans = min(ans, abs(a[l]) + abs(a[l] - a[r]));
        ans = min(ans, abs(a[r]) + abs(a[l] - a[r]));
        
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split(" "))
cityList = []
preList = [0] * N

class City:
    def __init__(self, id, pre, year):
        self.id = id
        self.pre = pre
        self.year = year
        self.number = 0

for i in range(M):
    P, Y = map(int, input().split(" "))
    city = City(i+1, P, Y)
    cityList.append(city)

cityList.sort(key=lambda x:x.year)
cityList.sort(key=lambda x:x.pre)

num = cityList[0].pre
count = 1
for city in cityList:
    if(city.pre != num):
        num = city.pre
        count = 1
    city.number = str(city.pre).zfill(6) + str(count).zfill(6)
    count += 1

cityList.sort(key=lambda x:x.id)
for city in cityList:
    print(city.number)

Measured memory_bytes: 47980
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    int N;cin>>N;
    vector<ll>l(N+1);
    l[0]=2; l[1]=1;
    for(int i=2;i<N+1;i++){
        l[i]=l[i-1]+l[i-2];
    }
    cout<<l[N]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
string st1,st2;
int main()
{
	cin>>st1>>st2;
	if(st1[0]==st2[2]&&st1[1]==st2[1]&&st1[2]==st2[0]) cout<<"YES\n"; else cout<<"NO\n";
	return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}


int main(){

    ll n; cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    vll b(n, 0);
    rep2(i, 1, n){
        if(a[i]>a[i-1]){
            b[i] = 1;
        }
        else if(a[i]<a[i-1]){
            b[i] = -1;
        }
    }

    ll ans = 1000;
    ll kabu = 0;
    rep(i, n-1){
        if(b[i]<b[i+1]){
            if(a[i]<=ans){
                kabu = ans/a[i];
                ans -= kabu*a[i];
            }
        }
        else if(b[i]>b[i+1]){
            ans += kabu*a[i];
            kabu = 0;
        }
    }

    if(kabu){
        ans += kabu*a[n-1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <ctype.h>

#define SIZE 26

int main(void) {
  int histgram[SIZE] = {0};
  int c = 0;
  int position = 0;
  int i = 0;

  while ((c = getchar()) != EOF) {
    if (!isalpha(c)) {
      continue;
    }

    position = tolower(c) - 'a';
    histgram[position]++;
  }

  for (i = 0; i < SIZE; i++) {
    printf("%c : %d\n", i + 'a', histgram[i]);
  }

  return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//Set<Integer> set = new HashSet<Integer>();
		Scanner sc = new Scanner(System.in);
		String a = sc.nextLine();
		
		//CODEFESTIVAL2016
		System.out.println(Main.minIteration(a));
	}
	
	static int minIteration(String str) {
		int len = str.length();
		int count = 0;
		StringBuilder s = new StringBuilder("CODEFESTIVAL2016");
		
		for (int i = 0; i < len; i++) {
			if ( str.charAt(i) != s.charAt(i))
				count++;
		}
		return count;
	}

}

Measured memory_bytes: 9680
#include <algorithm>
#include <cstdio>

const int MaxN = 2999 + 5;

int N;
double P[MaxN];
double F[MaxN + MaxN], G[MaxN + MaxN];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%lf", &P[i]);
}

void solve() {
  F[N] = 1;
  for (int i = 1; i <= N; ++i) {
    std::swap(F, G);
    for (int j = 0; j <= 2 * N; ++j) {
      F[j] = 0;
      if (j > 0) F[j] += G[j - 1] * P[i];
      if (j < 2 * N) F[j] += G[j + 1] * (1 - P[i]);
    }
  }
  double ans = 0;
  for (int i = N + 1; i <= 2 * N; ++i)
    ans += F[i];
  printf("%.10lf\n", ans);
}

int main() {
  init();
  solve();
  return 0;
}

Measured memory_bytes: 384