akhauriyash/Code-Regression huggingface dataset:
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var result = 0;

    var N = lines.shift();
    var spans = lines[0].split(" ").map(value => Number(value));

    var i = 1; var cnt = [];
    for (var span of spans) {

        cnt[i - 1] = span - i;
        i++;
    }
    cnt.sort((a, b) => a - b);

    for (var array of cnt) {
        result += Math.abs(array - cnt[Math.floor(Number(N) / 2)]);
    }

    console.log(result);
});

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

int main(void)
{
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    rep(i, n)
    {
        h -= a[i];
        if(h<=0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;

    return 0;
}

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

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

    string O, E;
    cin >> O >> E;
    int n = O.size();
    int m = E.size();

    for (int i = 0; i < n; ++i) {
        cout << O.at(i);
        if (i < m) cout << E.at(i);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
n,k,q = map(int, input().split())
nl = [k - q]*n
a = []
for i in range(q):
    a.append(int(input()))
for j in a:
    nl[j-1] += 1
for k in range(n):
    if nl[k] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 56536
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

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

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









int main() {
  int x,n;
  cin >> x >> n ;
  vector <int> p(n);
  

  rep (i,n){
    cin >> p[i];
  }
  if (n==0) {
    cout << x << endl;
    return 0;
  }
  int mini1 = INF,ans1;
  //int ans1=INF,ans2=INF,ans3;

  for (int i = x;i <= 1000+x;i++){
    bool ok1 = true;
        rep (j,n){
        if (i==p[j]){
          ok1 = false;
        }
        }
        if (ok1){ 
        ans1 = i;
        //cout << i << endl;
        break;
        }
      }
      //cout << 1 << endl;
  
  

  int mini2 = INF,ans2;
  for (int i = x;i >= x-1000;i--){
    bool ok2 = true;
        rep (j,n){
        if (i==p[j]){
          ok2=false;
        }
        }
        if (ok2) {
          ans2=i;
          break;
        }
  }
      
  
  //cout << ans1 << " " << ans2 << endl;
  

  if (abs(x-ans1)>abs(x-ans2)) {
    cout << ans2 << endl;
    }
  else if(abs(x-ans1)==abs(x-ans2)) cout << min(ans1,ans2) << endl;
  else if(abs(x-ans1)<abs(x-ans2))cout << ans1 << endl;




 }

Measured memory_bytes: 3604
/**********************************************************
* @Author: 			   Maple
* @Date:   			   2020-03-01 20:01:50
* @Last Modified by:   Maple
* @Last Modified time: 2020-03-01 20:03:33
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

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

const int maxn=1000;


int main()
{
/*	#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	#endif*/
	int n;
	cin>>n;
	if(n%2==0)
		cout<<n/2<<endl;
	else
		cout<<n/2+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;

int main() {
  int N, M, X;
  scanf("%d%d%d", &N, &M, &X);
  int A[M];
  int left=0;
  int right=0;
  for (int i=0 ; i<M ; i++) {
      scanf("%d", &A[i]);
      if (A[i] < X) left++;
      else right++;
  }
  if (left <= right) {
    printf("%d\n", left);
  } else {
    printf("%d\n", right);
  }
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n < 1200) {
            System.out.println("ABC");
        } else if (n < 2800) {
            System.out.println("ARC");
        } else {
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 23508
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b){
    int g = max(a,b); 
    int l = min(a,b);
    int res = g % l;
    if(res == 0){
        return l;
    }else{
        return gcd(l,res);
    }
    
}

int main(){
    long long A,B,C,D;
    long long cnt = 0;
    long long d;
    cin >> A >> B >> C >> D;
    d = gcd(C,D);
    long long e = C*D/d;
    long long n = B - ((B / C) + (B / D)- (B / e)) ;
    long long m = A - 1 - (((A-1) / C) + ((A-1) / D) - ((A-1) / e));
    cout << n-m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecint a(n), b(n);
  REP(i,n) cin>>a[i];
  REP(i,n) cin>>b[i];
  vecint starta(n+1, n);
  vecint enda(n+1, -1);
  REP(i,n) {
    starta[a[i]] = min(starta[a[i]], i);
    enda[a[i]] = i;
  }
  vecint ps(2*n+1);
  REP(i,n) {
    if (starta[b[i]] == n) continue;
    int from = starta[b[i]] - i;
    int to = enda[b[i]] - i;
    if (from < 0) {
      from += n;
      to += n;
    }
    ps[from] += 1;
    ps[to+1] += -1;
  }
  REP(i,2*n) ps[i+1] += ps[i];
  REP(i,n) {
    if (ps[i] == 0 && ps[i+n] == 0) {
      cout<<"Yes"<<endl;
      REP(j,n) {
        if (j)cout<<" ";
        cout<<b[(j-i+n)%n];
      }
      cout<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 7920
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut dishes: Vec<(isize, isize, isize)> = Vec::new();
    for _ in 0..n {
        let ai: isize = iterator.next().unwrap().parse().unwrap();
        let bi: isize = iterator.next().unwrap().parse().unwrap();
        dishes.push((ai + bi, ai, bi));
    }
    dishes.sort();
    dishes.reverse();

    let mut takahashi: isize = 0;
    let mut aoki: isize = 0;
    for i in 0..n {
        let dish = dishes[i];
        if i % 2 == 0 {
            takahashi += dish.1;
        } else {
            aoki += dish.2;
        }
    }
    (takahashi - aoki).to_string()
}


Measured memory_bytes: 7236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll dp[3005][3005][2],a[3005];
int n;
ll rec(int L,int R,int p){
	if(dp[L][R][p] >= -1e15) return dp[L][R][p];
	if(L > R) return 0LL;
	if(p == 0){
		ll x = -1e18;
		x = max(x,a[L]+rec(L+1,R,1-p));
		x = max(x,a[R]+rec(L,R-1,1-p));
		return dp[L][R][p] = x;
	}
	else{
		ll x = 1e18;
		x = min(x,-a[L]+rec(L+1,R,1-p));
		x = min(x,-a[R]+rec(L,R-1,1-p));return dp[L][R][p] = x;
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	rep(i,3005)rep(j,3005)rep(k,2) dp[i][j][k]=-1e18;
	cout<<rec(1,n,0)<<endl;
}

Measured memory_bytes: 141568
import java.math.BigInteger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.*;
import java.util.Map.Entry;

public class Main {
	static int mod = (int) 1e9 + 7;

	static long[][] base(int n) {
		long mat[][] = new long[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				mat[i][j] = (i == j) ? 1 : 0;
			}
		}
		return mat;
	}

	static long[][] multiply(long[][] m1, long m2[][]) {
		int n = m1.length;
		long ans[][] = new long[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
				 long temp= (m1[i][k] * m2[k][j])%mod;
				 ans[i][j]=(ans[i][j]+temp)%mod;
				 

				}
			}
		}
		return ans;

	}

	static long[][] exponentiation(long m[][], long k) {
		long ans[][] = base(m.length);
		for (int i = 0; (1L << i) <= k; i++) {
			if (((1L << i) & k)!=0) {
				ans = multiply(ans, m);
			}
			m = multiply(m, m);
		}
		return ans;
	}

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		long k = scn.nextLong();
		long mat[][] = new long[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				mat[i][j] = scn.nextLong();
			}
		}
		long an[][] = exponentiation(mat, k);
		long ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				ans = (ans + an[i][j]) % mod;
			}
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 27804
H, W = map(int, input().split())
a = []
for _ in range(H):
    a.append(input())

for i in range(H+2):
    if i == 0:
        a.insert(0, '#'*(W+2))
        print(a[i])
    elif i == H+1:
        a.append('#'*(W+2))
        print(a[i])
    else:
        a[i] = '#' + a[i] + '#'
        print(a[i])

        

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

using ll = long long;

signed main() {
  string s;
  ll k;
  cin >> s >> k;
  
  ll n = s.size();    // 元の文字列の長さ
  ll ans = 0;         // 必要な操作回数
  ll top = 0;         // 元の文字列で先頭で同じ文字が連続している数
  ll back = 0;        // 元の文字列で末尾で同じ文字が連続している数

  ll same_char_cnt;   // iから数えて連続する同じ文字の数

  // 元の文字列の中で同じ文字が連続する部分について数を数える
  for (ll i = 0; i < n; i += same_char_cnt) {
    same_char_cnt = 1;
    for (ll j = i + 1; j < n; j++) {
      if (s[i] == s[j])
        same_char_cnt++;
      else
        break;
    }

    // 先頭で連続する同じ文字数をtopに保存する. 先頭に対する操作回数はここでは数えない
    // 例えば元の文字列が、"aaabccdddaa" なら、先頭の"aaa"部分について3を格納する
    if (i == 0) {
      top = same_char_cnt;
      continue;
    }

    // 末尾で連続する同じ文字数をbackに保存する. 末尾に対する操作回数はここでは数えない
    // 例えば元の文字列が、"aaabccdddaa" なら、末尾の"aa"部分について2を格納する
    if (i + same_char_cnt >= n) {
      back = same_char_cnt;
      continue;
    }

    // 文字列の途中で連続する同じ文字に対する操作回数をansに加算する.
    // 例えば元の文字列が、"aaabccdddaa" なら、"b", "cc", "ddd" の3つの部分について計算を行う
    ans += same_char_cnt / 2;
  }

  if (top == n) {   // 元の文字列が1つの文字だけで構成される場合
    ans = (n * k) / 2;
  } else {
    // 元の文字列の途中部分に対する操作回数をk倍する
    ans *= k;

    if (s[0] == s[n - 1]) 
      // 先頭と末尾の文字が一致する場合、文字列の接点の操作回数を分けて考える必要がある
      // 先頭と末尾の文字が一致する場合の接点の操作回数は(top + back) / 2 回となる
      // "aaabccdddaa"+"aaabccdddaa"の接点は、"aaaaa"となるので、(3+2)/2 の2回操作する
      // 文字列の接点は、k-1 回あるので、接点の操作回数の和は、(top + back) / 2 * (k - 1) となる
      ans += (top + back) / 2 * (k - 1) + top / 2 + back / 2;
      
    else
      // 先頭と末尾の文字が一致しない場合は、先頭、末尾の操作回数は別々に考えればよい
      ans += k * (top / 2 + back / 2);
      
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

enum {
	CONST = 0,
	VAR,
	NEG,
	AND,
	OR
};

int NEG_TABLE[3] = { 2, 1, 0 };
int AND_TABLE[3][3] = {
	{ 0, 0, 0 },
	{ 0, 1, 1 },
	{ 0, 1, 2 }
};
int OR_TABLE[3][3] = {
	{ 0, 1, 2 },
	{ 1, 1, 2 },
	{ 2, 2, 2 }
};

struct Node {
	Node(int t, int v = 0, Node *l = NULL, Node *r = NULL) : type(t), value(v), left(l), right(r) { }
	int type, value;
	Node *left, *right;
};

Node *makeTree(const char **ptr){
	if('0' <= **ptr && **ptr <= '2'){
		Node *node = new Node(CONST, **ptr - '0');
		++*ptr;
		return node;
	}
	if('P' <= **ptr && **ptr <= 'R'){
		Node *node = new Node(VAR, **ptr - 'P');
		++*ptr;
		return node;
	}
	if(**ptr == '-'){
		++*ptr;
		return new Node(NEG, 0, makeTree(ptr));
	}
	++*ptr;
	Node *left = makeTree(ptr);
	Node *node = new Node(**ptr == '*' ? AND : OR, 0, left);
	++*ptr;
	node->right = makeTree(ptr);
	++*ptr;
	return node;
}
void deleteTree(Node *node){
	if(node->left != NULL){ deleteTree(node->left); }
	if(node->right != NULL){ deleteTree(node->right); }
	delete node;
}
int calculate(Node *node, int p, int q, int r){
	if(node->type == CONST){ return node->value; }
	if(node->type == VAR){
		switch(node->value){
			case 0: return p;
			case 1: return q;
			case 2: return r;
		}
	}
	if(node->type == NEG){ return NEG_TABLE[calculate(node->left, p, q, r)]; }
	if(node->type == AND){
		return AND_TABLE[calculate(node->left, p, q, r)][calculate(node->right, p, q, r)];
	}
	if(node->type == OR){
		return OR_TABLE[calculate(node->left, p, q, r)][calculate(node->right, p, q, r)];
	}
	return 0;
}

int main(){
	while(true){
		string query;
		cin >> query;
		if(query == "."){ break; }
		const char *ptr = query.c_str();
		Node *root = makeTree(&ptr);
		int answer = 0;
		for(int p = 0; p < 3; ++p){
			for(int q = 0; q < 3; ++q){
				for(int r = 0; r < 3; ++r){
					if(calculate(root, p, q, r) == 2){ ++answer; }
				}
			}
		}
		deleteTree(root);
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
# include <bits/stdc++.h>
using namespace std;
namespace fastio{
	template<typename tn> void read(tn &a){
	    tn x=0,f=1;char c=' ';
	    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	    for(;isdigit(c);c=getchar() ) x=x*10+c-'0';
	    a=x*f;
	}
	template<typename tn> void print(tn a){
	    if(a<0) putchar('-'),a=-a;
	    if(a>9) print(a/10);
	    putchar(a%10+'0');
	}
};
using namespace fastio;
const int N=1e5+5;
struct Edge{
	int nex,to;
}e[N*2];
int head[N],cnt;
void add(int x,int y){
	e[++cnt].nex=head[x];
	head[x]=cnt;
	e[cnt].to=y;
}
int n,m,h[N];
int ans;
int main(){
	read(n);
	read(m);
	for(int i=1;i<=n;i++) read(h[i]);
	for(int i=1;i<=m;i++){
		int x,y;
		read(x);
		read(y);
		add(x,y);
		add(y,x);
	}
	for(int i=1;i<=n;i++){
		int tot=0;
		for(int j=head[i];j;j=e[j].nex)
			tot=max(tot,h[e[j].to]);
		if(tot<h[i]) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6088
N,A,B = map(int,input().split())
V = [int(x) for x in input().split()]

V.sort(reverse = True) # desc order

x = V[A-1]
large = V.index(x) # xより大きなものの個数
cnt = V.count(x)

import numpy as np
comb = np.zeros((N+1,N+1),dtype=np.int64)
comb[:,0] = 1
for n in range(1,N+1):
  comb[n,1:] = comb[n-1,1:] + comb[n-1,:-1]

max_avg = sum(V[:A]) / A
pattern = 0
if V[0] == V[A-1]:
  for choose in range(A-large, B-large+1):
    pattern += comb[cnt,choose]
else:
  pattern = comb[cnt,A-large]
  
print(max_avg)
print(pattern)

Measured memory_bytes: 22008
import java.util.Scanner;

public class Main{

	public static void main (String [] args) {

		Scanner sc = new Scanner (System.in);

		int N = sc.nextInt();
		long amari = 0;

		for (int index=1; index<N; index++) {
			amari += index;
		}

		System.out.println(amari);
	}
}

Measured memory_bytes: 23764
n = int(input())
a = list(map(int, input().split()))
c = [0] * 8
monster = 0
for i in range(n):
    if a[i] < 400:
        c[0] = 1
    elif a[i] < 800:
        c[1] = 1
    elif a[i] < 1200:
        c[2] = 1
    elif a[i] < 1600:
        c[3] = 1
    elif a[i] < 2000:
        c[4] = 1
    elif a[i] < 2400:
        c[5] = 1
    elif a[i] < 2800:
        c[6] = 1
    elif a[i] < 3200:
        c[7] = 1
    else:
        monster += 1
print(max(sum(c), 1), sum(c) + monster)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int s = sc.nextInt();
        int palceHolder = s == 1000000000 ? 1 : s + 1;
        
        for(int i = 0; i < n; i++) {
        	if(i != n-1) {
        		if(i < k) System.out.print(s + " ");
        		else System.out.print(palceHolder + " ");
        	} else {
        		if(i < k) System.out.println(s);
        		else System.out.println(palceHolder);
        	}
        }
    }
}


Measured memory_bytes: 42508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
ll a[1010];

int main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	rep(i, n) {
		FOR(j, i + 1, n) {
			if ((a[j] - a[i]) % (n - 1) == 0) {
				cout << a[j] << " " << a[i] << endl;
				return 0;
			}
		}
	}
}


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

vector<pair<int, int> > graph[100010];

int visited[100010] = {};
int color[100010] = {};

int dfs(int idx, int c){
    visited[idx] = 1;
    color[idx] = c;

    for(int i = 0;i < graph[idx].size();i++){
        if(visited[graph[idx][i].first] == 0){
            dfs(graph[idx][i].first,(c + graph[idx][i].second) % 2);
        }
    }

    return 0;
}

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

    int a, b, c;
    for(int i = 0;i < n-1;i++){
        cin >> a >> b >> c;
        a--; b--;
        graph[a].push_back(make_pair(b, c % 2));
        graph[b].push_back(make_pair(a, c % 2));
    }

    dfs(0, 0);

    for(int i = 0;i < n;i++){
        cout << color[i] << endl;
    }

    return 0;
}




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

int main() {
	int n, x;
	int all_gram = 0, do_num = 0, min = 0;
	
	std::cin >> n >> x;
	std::vector<int> m(n);
	int tmp_gram = x;
	
	for (int i = 0; i < n; i++) {
		std::cin >> m[i];
		tmp_gram -= m[i];
	}
	min = *std::min_element(m.begin(), m.end());
	do_num = (int)(tmp_gram/min) + n;
	 
	printf("%d", do_num);
	
	return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
kisu = 1

for i, a in enumerate(A):
    if a % 2 == 0:
        kisu *= 2
    else:
        kisu *= 1
print(3 ** N - kisu)


Measured memory_bytes: 5504
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <stdio.h>
#include <queue>
#define pb push_back
#define ppb pop_back
#define nd second
#define st first
#define ll long long
#define pi 3.1415926535897932384626433832795028841971
using namespace std;

int a, b;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> a >> b;
	a = a <= b ? a : a - 1;
	cout << a << endl; 
	
	return 0;
}

Measured memory_bytes: 256
import math

n = int(input())

p1, p2 = (0, 0), (100, 0)

def koch(d, p1, p2):
    
    if d == n:
        return

    th = math.radians(60)
    
    s = (2/3 * p1[0] + 1/3 * p2[0], 2/3 * p1[1] + 1/3 * p2[1])
    t = (1/3 * p1[0] + 2/3 * p2[0], 1/3 * p1[1] + 2/3 * p2[1])
    u = ((t[0]-s[0])* math.cos(th) - (t[1]-s[1])*math.sin(th) + s[0], \
    (t[0]-s[0])*math.sin(th) + (t[1]-s[1])*math.cos(th)+s[1])

    koch(d+1, p1, s)
    print(*s)
    koch(d+1, s, u)
    print(*u)
    koch(d+1, u, t)
    print(*t)
    koch(d+1, t, p2)

print(*p1)
koch(0, p1, p2)
print(*p2)


Measured memory_bytes: 5780
from collections import defaultdict
n=int(input())
d={}
for _ in range(n):
    n=input()
    if n in d:
        d[n]+=1
    else:
        d[n]=1
l=[]
mm=0
for y in d.values():
    if y>mm:
        mm=y
for x,y in d.items():
    if y==mm:
        l.append(x)
l=sorted(l)
for i in l:
    print(i)
    

Measured memory_bytes: 33372
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
int g[33],h[3003];
int main()
{
	int a=io::F(),b=io::F(),c=io::F(),d=io::F(),e=io::F(),f=io::F();
	for(register int i=0;i<=f/100;i+=a)g[i]=1;
	for(register int i=0;i<=f;i+=c)h[i]=1;
	for(register int i=0;i+b<=f/100;++i)if(g[i])g[i+b]=1;
	for(register int i=0;i+d<=f;++i)if(h[i])h[i+d]=1;
	double max=0;
	int mi=a,mj=0;
	for(register int i=1;i<=f/100;++i)
		for(register int j=1;j<=f;++j)
			if(g[i]&&h[j]&&i*100+j<=f&&i*e>=j)
				if(cmax(max,(double)j/(i*100+j)))mi=i,mj=j;
	printf("%d %d\n",mi*100+mj,mj);
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
ll n;
const int max_n = 1e6;
int main(){
  cin >> n;
  vector<ll> a(n),b(n),c(n);
  for(int i=0 ; i<n ; i++){
    cin >> a[i];
  }
  for(int i=0 ; i<n ; i++){
    cin >> b[i];
  }
  for(int i=0 ; i<n ; i++){
    cin >> c[i];
  }
  sort(a.begin(),a.end());  sort(b.begin(),b.end());  sort(c.begin(),c.end());
  ll sum = 0;
  for(int i=0 ; i<n ; i++){
    ll aite = lower_bound(a.begin(),a.end(), b[i]) - a.begin();
    ll bite = c.end() - upper_bound(c.begin(),c.end(),b[i]);
    sum += aite * bite;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(void){
   int n, N, a, b, s, count2, count5;
   scanf("%d", &n);
   while ( n ) {
      count2 = count5 = 0;
      while ( n ) {
         N = n;
         a = b = 1;
         while ( a ) {
            if ( N % 2 == 0 ) { count2++; N /= 2; }
            else if ( N % 2 != 0 ) a = 0;
/*printf("N:%d count2:%d\n", N, count2);*/
         }
         while ( b ) {
            if ( N % 5 == 0 ) { count5++; N /= 5; }
            else if ( N % 5 != 0 ) b = 0;
/*printf("N:%d count5:%d\n", N, count5);*/
         }
         n--;
/*printf("n:%d\n", n);*/
      }
      if ( count2 > count5 ) printf("%d\n", count5);
      else printf("%d\n", count2);
      scanf("%d", &n);
   }
   return 0;
}

Measured memory_bytes: 1748
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,0,N)cin >> A[i];
    int cnt = 0;
    rep(i,0,N){
        while(A[i] % 2 == 0){
            A[i] /= 2;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 384
import fractions as fr
a,b,c,d=map(int,input().split())

def div(x,y):
  return y//x

def div2(x):
  return div(x,b)-div(x,a-1)
  
print(b-a+1-div2(c)-div2(d)+div2(c*d//fr.gcd(c,d)))

Measured memory_bytes: 5052
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int a, b; cin >> a >> b;
  if(a <= 8 && b <= 8) cout << "Yay!\n";
  else cout << ":(\n";
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize
    }
    println!("{}", if n == m {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;

  int cnt_right = 0;
  int cnt_left = 0;

  //( < ) 
  for(int i = 0;i < s.size();i++){
    if(s[i] == ')'){
      if(cnt_left > 0)cnt_left--;

      else cnt_right++;
    }else{
      cnt_left++;
    }
  }

  for(int i = 0;i < cnt_right;i++)cout << '(';
  cout << s;
  for(int i = 0;i < cnt_left;i++)cout << ')';
  cout << endl;
} 

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N, X, x, ans;
	cin >> N >> X;
	rep(i, N) {
		cin >> x;
		if (!i)ans = abs(X - x);
		else ans = gcd(ans, abs(X - x));
	}
	cout << ans;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    string s;
    cin >> s;
    if (s == "SUN") cout << 7 << endl;
    if (s == "MON") cout << 6 << endl;
    if (s == "TUE") cout << 5 << endl;
    if (s == "WED") cout << 4 << endl;
    if (s == "THU") cout << 3 << endl;
    if (s == "FRI") cout << 2 << endl;
    if (s == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

ll n; 
ll a[3030];
ll dp[3030][3030];
ll vis[3030][3030];

ll f(ll x, ll y){
	ll &r=dp[x][y];
	if(vis[x][y])return r;
	vis[x][y]=1;
	if(y==x+1){
		r=a[x]; return r;
	}
	r=max(a[y-1]-f(x,y-1),a[x]-f(x+1,y));
	return r;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n)cin>>a[i];
	cout<<f(0,n);	
	return 0;
}

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

using namespace std;

bool chkString(string str) {
	int n = (int)str.size();
	if (str.substr(0, n / 2) == str.substr(n / 2, n / 2)) return true;
	else return false;
}

int main() {
	string S;
	cin >> S;
	int n = (int)S.size();
	for (int i = 0; i < n; i++) {
		S.pop_back();
		S.pop_back();

		if (chkString(S)) break;
	}

	cout << S.size() << endl;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    for(int i = a; i < 1e6; i += a){
        if(i % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0; 
}

Measured memory_bytes: 764
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  x = int(input())
  ans = 1
  for i in range(1,x):
    for j in range(2,x):
      if i**j <= x:
        ans = max(ans, i**j)
      else:
        break
  print(ans)
  
if __name__ == '__main__':
  main()

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

int main() {
	int t, h, s;
	while (cin >> t >> h >> s, ~t) {
		int cnt = t * 3600 + h * 60 + s;
		cnt = 7200 - cnt;
		int cnt3 = cnt * 3;
		int a = cnt / 3600; cnt %= 3600;
		int b = cnt / 60; cnt %= 60;
		int c = cnt3 / 3600; cnt3 %= 3600;
		int d = cnt3 / 60; cnt3 %= 60;
		printf("%02d:%02d:%02d\n%02d:%02d:%02d\n", a, b, cnt, c, d, cnt3);
	}
	return 0;
}

Measured memory_bytes: 3152
// B - Count Balls
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    long long ans = 0, x, r;
    if(a == 0){
        cout << 0 << endl;
    }else if(n <= a){
        cout << n << endl;
    }else if(n <= a+b){
        cout << a << endl;
    }else{    
        x = n/(a+b);
        r = n%(a+b);
        ans = a*x;
        // cout << x << " " << r << " " << ans << endl;
        if(r >= a){
            while(r >= a){
                ans += a;
                r -= (a+b);
            }
        }else{
            ans += r;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
S = list(input())
K = int(input())

S1 = list(S)
cnt1 = 0
for i in range(1, len(S1)):
    if S1[i] == S1[i - 1]:
        S1[i] = '*'
        cnt1 += 1

S2 = list(S) * 2
cnt2 = 0
for i in range(1, len(S2)):
    if S2[i] == S2[i - 1]:
        S2[i] = '*'
        cnt2 += 1
        
S3 = list(S) * 3
cnt3 = 0
for i in range(1, len(S3)):
    if S3[i] == S3[i - 1]:
        S3[i] = '*'
        cnt3 += 1

# print("#", S1, S2, S3)
# print("#", cnt1, cnt2, cnt3)
ans = cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>
#include <deque>
#include <string>
#include <map>
#include <utility>
using namespace std;

#define INF 1000000000

int N, M, cap;
string cityfrom, cityto;
string cityname[3000][2];
string citystat[300];
int d[3000];

typedef pair<int,int> pii;
typedef priority_queue<pii,deque<pii>,greater<pii> > pq_t;

int solve(){
	map<string,int> m_city;
	
	for( int i = 0; i < N; ++i ){
		m_city.insert( make_pair( cityname[i][0], m_city.size() ) );
		m_city.insert( make_pair( cityname[i][1], m_city.size() ) );
	}
	
	int n = m_city.size();
	vector< vector<pii> > road( n );
	
	for( int i = 0; i < N; ++i ){
		int a = m_city[ cityname[i][0] ];
		int b = m_city[ cityname[i][1] ];
		road[a].push_back( pii( b, d[i] ) );
		road[b].push_back( pii( a, d[i] ) );
	}
	
	
	vector<int> nstat( M + 2 );
		//スタンドの番号。
		//ただし最初2つは出発地と目的地の番号としておく。
	
	nstat[0] = m_city[ cityfrom ];
	nstat[1] = m_city[ cityto ];
	for( int i = 0; i < M; ++i ){
		nstat[i + 2] = m_city[ citystat[i] ];
	}

	cap *= 10;

	vector< vector<int> > dist( nstat.size(), vector<int>( n, INF ) );
	for( int first = 0; first < nstat.size(); ++first ){
		int n_first = nstat[first];
		dist[first][n_first] = 0;
		pq_t pq;
		pq.push( pii( 0, n_first ) );
		while( !pq.empty() ){
			pii p = pq.top();
			pq.pop();

			int n_from = p.second;
			if( dist[first][n_from] != p.first ){
				continue;
			}

			for( int i = 0; i < road[n_from].size(); ++i ){
				int n_to = road[n_from][i].first;
				int ds = p.first + road[n_from][i].second;
				
				if( ds <= cap && dist[first][n_to] > ds ){
					dist[first][n_to] = ds;
					pq.push( pii( ds, n_to ) );
				}
			}
		}
	}


	vector<int> dp( nstat.size(), INF );
	dp[0] = 0;
	
	pq_t pq;

	pq.push( make_pair( 0, 0 ) );
	while( !pq.empty() ){
		pii p = pq.top();
		pq.pop();

		int from = p.second;
		if( dp[from] != p.first ){
			continue;
		}
		
		int n_from = nstat[from];
		for( int to = 0; to < nstat.size(); ++to ){
			int n_to = nstat[to];
			if( dist[from][n_to] <= cap && dp[to] > dp[from] + dist[from][n_to] ){
				dp[to] = dp[from] + dist[from][n_to];
				pq.push( make_pair( dp[to], to ) );
			}
		}
	}
	
	if( dp[1] == INF ){
		return -1;
	}
	return dp[1];
}

int main(){
	for( ; cin >> N >> M >> cap >> cityfrom >> cityto; ){
		for( int i = 0; i < N; ++i ){
			cin >> cityname[i][0] >> cityname[i][1] >> d[i];
		}
		for( int i = 0; i < M; ++i ){
			cin >> citystat[i];
		}
		
		cout << solve() << endl;
	}
}

Measured memory_bytes: 5056
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,a,b,c,d;
    while(~scanf("%d %d %d",&a,&b,&c))
    {
        if(c>a&&a+b>c)
            {
                printf("YES\n");
            }
            else if(c==a)
            {
                printf("YES\n");
            }
            else
            {
                printf("NO\n");
            }
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    unsigned short int usi_inputData;

    scanf("%d", &usi_inputData);

    if (usi_inputData % 2 == 0)
    {
        printf("%d", usi_inputData / 2);
    }
    else
    {
        printf("%d", usi_inputData / 2 + 1);
    }

}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<iostream>
#include<set>
#include<queue>
#include<stack>
using namespace std;
long long n,a,b;
long long ans;
int main()
{
	cin>>n>>a>>b;
	ans=n/(a+b)*a+min(n%(a+b),a);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
using namespace std;

#define lint long long int

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


Measured memory_bytes: 3580
#include <iostream>
#include <string.h>
using namespace std;

int dp[50][50];
int k,n,l[50];

int dfs(int a,int b){
    int sum;
    if (dp[a][b]>=0)
        return dp[a][b];
    if (a==n || b==0) sum = 0;
    else
        sum = max(dfs(a+1,b),dfs(a+1,b-1)+l[a]);
    return dp[a][b]=sum;
}

int main(void){
    cin >> n >> k;
    for (int i=0;i<n;i++)
        cin >> l[i];
    memset(dp,~0,sizeof(dp));
    cout << dfs(0,k) << endl;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
G = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
C = [0 for i in range(n)]
for j in range(q):
    p, x = map(int, input().split())
    C[p-1] += x
s = 0
Q = [s]
V = [False for i in range(n)]
while Q:
    x = Q.pop()
    V[x] = True
    for y in G[x]:
        if not V[y]:
            Q.append(y)
            C[y] += C[x]
print(*C)


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

using namespace std;

#define int long long

const int N = 2e3 + 5;
int n, x, y;
vector <int> ad[N];
int f[N], cnt[N];
void c(int u) {
  memset(f, 0, sizeof(f));
  f[u] = 1;
  queue <int> q;
  q.push(u);
  while(q.size()) {
    int a = q.front();
    q.pop();
    for(int v : ad[a]) {
      if(!f[v]) {
        f[v] = f[a] + 1;
        q.push(v);
      }
    }
  }
}
main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> x >> y;
  ad[x].push_back(y);
  ad[y].push_back(x);
  for(int i = 1; i < n; ++i) ad[i].push_back(i + 1), ad[i + 1].push_back(i);
  for(int i = 1; i <= n; ++i) {
    c(i);
    for(int j = 1; j <= n; ++j) cnt[f[j] - 1]++;
  }
  for(int i = 1; i < n; ++i) cout << cnt[i] / 2 << '\n';
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);dfm
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// 参考: https://atcoder.jp/contests/abc147/submissions/8886712

ll n,x,d;

ll F(ll y){
  ll mx=(n-y+n-1)*y/2;
  ll mn=y*(y-1)/2;
  return mx-mn+1;
}

ll G(ll y){
  ll l1=((n-y)+(n-1))*y/2,
  l2=y*(y-1)/2,
  r1=((n-y-d)+(n-1))*(y+d)/2+x,
  r2=(y+d)*(y+d-1)/2+x;
  return max(min(l1,r1)-max(l2,r2)+1,0LL);
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>n>>x>>d;
  if(d==0){
    cout<<(x!=0 ? n+1 : 1)<<endl;
    return 0;
  }
  if(x==0) {
    cout<<(n*(n-1)/2+1)<<endl;
    return 0;
  }
  
  if(x<0) x*=-1,d*=-1;
  
  // x,dを互いに素にする
  int g=__gcd(x,d);
  x/=g;
  d/=g;
  
  ll ans=0;
  for(int i=0;i<=n;i++){
    ans+=F(i);
  }
  
  for(int i=0;i<=n;i++){
    if(0<=i+d&&i+d<=n) ans-=G(i);
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const int N = 5005;

namespace Modop {
    ll modAdd(ll a, ll b) {
        return (a + b) % MOD;
    }
    
    ll modSub(ll a, ll b) {
        return (((a - b) % MOD) + MOD) % MOD;
    }
    
    ll modMul(ll a, ll b) {
        return ((a % MOD) * (b % MOD)) % MOD;
    }

    ll modExp(ll base, ll power) {
        if (power == 0) {
            return 1;
        } else {
            ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
            if (power % 2 == 1) cur = cur * base;
            cur = cur % MOD;
            return cur;
        }
    }
    
    ll modInv(ll a) {
        return modExp(a, MOD - 2);
    }
    
    ll modDiv(ll a, ll b) {
        return modMul(a, modInv(b));
    }
}

using namespace Modop;

int n, k;

ll fac[N], inv[N];

void pre() {
    fac[1] = inv[1] = 1;
    for (int i = 2; i < N; i++) {
        fac[i] = modMul(fac[i - 1], i);
        inv[i] = modInv(fac[i]);
    }
}

ll combo(int n, int k) {
    ll t = fac[n + k - 1];
    ll b = modMul(inv[k], inv[n - 1]);
    return max(modMul(t, b), 1ll);
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    pre();
    cin >> n >> k;

    for (int i = 1; i <= k; i++) {
        if (n - k - (i - 1) < 0) cout << 0 << '\n';
        else cout << modMul(combo(i, k - i), combo(i + 1, n - k - (i - 1))) << '\n';
    }
}
    


Measured memory_bytes: 384
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, H = in.next().toInt
  val _a = new Array[Int](N)
  val _b = new Array[Int](N)

  for(i <- 0 until N) {
    val a, b = in.next().toInt
    _a(i) = a
    _b(i) = b
  }

  val a = _a.sorted.reverse
  val b = _b.filter(_ > a(0)).sorted.reverse

  var ans = 0
  var hp = H
  breakable {
    
    for (e <- b) {
      hp -= e
      ans += 1
      if(hp <= 0)
        break
    }
  }

  if(hp <= 0)
    println(ans)
  else {
    ans += hp / a(0)
    if (hp % a(0) != 0) {
      ans += 1
    }
    println(ans)
  }

}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1);

int main(){
	rep1(i,50) pw2[i]=2*pw2[i-1];
	ll N; cin>>N;
	vector<ll> Xin(N);
	vector<ll> Yin(N);

	ll num;
	rep(i,N){	
		cin>>Xin[i]>>Yin[i];
		if(i!=0 && ((num%2)!=(abs(Xin[i]+Yin[i]))%2)){
			cout<<-1;
			return 0;
		}
		num=abs(Xin[i]+Yin[i]);
	}
	bool even=false;
	if(num%2==0) even=true;

	if(even) cout<<32<<endl;
	else cout<<31<<endl;//m

	if(even) cout<<1<<" ";
	rep(i,31) cout<<pw2[i]<<" ";
	cout<<endl;//d

	rep(i,N){
		ll x=Xin[i],y=Yin[i];
      	bool xx=false,yy=false;
      if(x<0){
       x*=-1;
        xx=true;
      }
      if(y<0){
       y*=-1;
        yy=true;
      }
		if(even) x--;
	
		ll tmp=(pw2[31]-1-x-y)/2;
		ll tmpx=tmp;
		vector<ll> bit(31,0);
		rrep(i,31){
			bit[i]=tmp/pw2[i];
			tmp%=pw2[i];
		}
		//bit立っているところがマイナス
		vector<ll> X(31,0);
		vector<ll> bitX(31,0);

		ll tmp2=x+tmpx;
		rrep(i,31){
			bitX[i]=tmp2/pw2[i];
			tmp2%=pw2[i];
		}

		tmpx=x;
		rep(i,31){
			if(bit[i]==1 && bitX[i]==0) tmpx+=pw2[i+1];
		}

		rrep(i,31){
			X[i]=tmpx/pw2[i];
			tmpx%=pw2[i];
		}

		if(even){
         if(!xx) cout<<"R";
          else cout<<"L";
        }
      	vector<ll>ans(31);//0:L 1:D 2:R 3:U
		rep(i,31){
			if(bit[i]==1){
				if(X[i]==1) ans[i]=0;//cout<<"L";
				else ans[i]=1;//cout<<"D";
			}
			else{
				if(X[i]==1) ans[i]=2;//cout<<"R";
				else ans[i]=3;//cout<<"U";
			}
		}
      	rep(i,31){
         if(ans[i]==0){
          if(xx) cout<<"R"; 
           else cout<<"L";
         }
          else if(ans[i]==1){
          if(yy) cout<<"U"; 
           else cout<<"D";
         }
          else if(ans[i]==2){
          if(xx) cout<<"L"; 
           else cout<<"R";
         }
          else if(ans[i]==3){
          if(yy) cout<<"D"; 
           else cout<<"U";
         }
        }
		cout<<endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char s[3][11];
    int i;
    for (i = 0; i < 3; i++) {
        scanf("%s", s[i]);
    }
    for (i = 0; i < 3; i++) {
        printf("%c", s[i][0]-32);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll A, V, B, W, T;

    cin >> A >> V >> B >> W >> T;
    if (A <= B) {
        if (A + V * T >= B + W * T)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    else {
        if (A - V * T <= B - W * T)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3648