akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 55;
 
int toChild[1000000][3];
int Buffer[99999];
vector< int > Dwill;
int N, M;
 
int MakeTree(){
  queue< int > que;
  for(int i = 0; i < N; i++){
    que.push(i);
    toChild[i][0] = -1;
    toChild[i][1] = -1;
    toChild[i][2] = -1;
  }
  int nextIndex = N;
  while(que.size() > 1){
    toChild[nextIndex][0] = que.front(); que.pop();
    toChild[nextIndex][1] = que.front(); que.pop();
    toChild[nextIndex][2] = que.front(); que.pop();
    que.push(nextIndex);
    ++nextIndex;
  }
  return(que.front());
}
 
int64 getDP(const int64& Value, int index) {
  if(toChild[index][0] == -1){
    if(Buffer[index] == 0) return(1);
    else if(Buffer[index] >= Value) return(0);
    else return(INF);
  } else {
    int64 array[] = { getDP(Value, toChild[index][0]), getDP(Value, toChild[index][1]), getDP(Value, toChild[index][2])};
    sort( array, array + 3);
    return(min(INF - 1, array[0] + array[1]));
  }
}
 
bool Calclation(int64 Value, const int& root){
  int High = Dwill.end() - lower_bound( Dwill.begin(), Dwill.end(), Value);
  return(getDP(Value, root) <= High);
}
 
int main() {
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int D, P;
    cin >> D >> P;
    --P;
    Buffer[P] = D;
  }
  Dwill.resize(N - M);
  for(int i = 0; i < N - M; i++){
    cin >> Dwill[i];
  }
  sort( Dwill.begin(), Dwill.end());
  int root = MakeTree();
  int64 low = 0, high = INF;
  while(high - low > 0){
    int64 mid = (low + high + 1) / 2;
    if(Calclation(mid, root)) low = mid;
    else high = mid - 1;
  }
  cout << low << endl;
}

Measured memory_bytes: 5892
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

# 逆元事前処理ver
# nが小さい場合に
lim = 10 ** 6 + 1
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, lim + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    # 累計
    factinv.append((factinv[-1] * inv[-1]) % mod)

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % mod

N, K = getNM()

# 部屋がn個
# 重複組み合わせ？

# つまり数え上げ
# 人数が0人の部屋がいくつあるか
# 0 ~ N - 1人
# 0人の部屋が0個の場合
# kが偶数ならいける kが1の場合はダメ
# kの回数は何か関係あるか

# k >= 2の時0人の部屋0人ができる
# 0人の部屋1人ができるのは？　k >= 1の時

if K >= 2:
    ans = 1 # 0人の部屋0人
else:
    ans = 0

for k in range(1, min(K + 1, N)):
    # 0の場所を決める *
    # 球があるN - kの部屋の仕切りN - k - 1の仕切り方について考える
    # ただし各部屋１個以上なければならないので自由に動かせる球はk個
    # kHN-k-1
    ans += cmb(N, k) * cmb(N - 1, N - k - 1)
    ans %= mod
print(ans % mod)

Measured memory_bytes: 220860
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {

	string k;
	char a;

	while(cin >> k) {
		int mae = 0;
		int number;
		int sum = 0;
		int b;
		b = k.size();
		for (int i = 0; i < b; i++) {
			a = k[i];
			 if (a == 'I') {
				number = 1;
			} else if (a == 'V') {
				number = 5;
			} else if (a == 'X') {
				number = 10;
			} else if (a == 'L') {
				number = 50;
			} else if (a == 'C') {
				number = 100;
			} else if (a == 'D') {
				number = 500;
			} else if (a == 'M') {
				number = 1000;
			}

			if (number <= mae || sum == 0) {
				sum += number;
				mae = number;
			} else {
				sum = sum - (mae * 2) + number;
				mae = number;
			}
		}

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

Measured memory_bytes: 1180
while True:
    n,x=map(int,input().split())
    if(n==0 and x==0):
        break
    ans=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k==x :
                    ans=ans+1
    print(ans)



Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

ll lcm(ll x, ll y){
	return x*y/gcd(x,y);
}

int main(void) {
	int n; cin >> n;
	ll m; cin >> m;
	vll a(n); rep(i,n) cin >> a[i];
	vll b(n); rep(i,n) b[i] = a[i]/2;
	ll lcm_b;
	if(n==1) lcm_b = b[0];
	else{
		lcm_b=lcm(b[0],b[1]);
		rep2(i,2,n){
			if(lcm_b>m){ out(0); return 0; } 			
			lcm_b=lcm(lcm_b,b[i]);
		}
	}
	rep(i,n){
		if((lcm_b/b[i])%2==0){ out(0); return 0; }
	}
	ll ans = m/(lcm_b*2);
	if(m%(lcm_b*2)>=lcm_b) ans++;
	out(ans);
	
}




Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string> 
#include<map>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<utility>
#include<cstdio>
#include<cstring>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qui queue<int>
#define vit vector<int>
#define ll long long
#define pb push_back
using namespace std;
int main()
{int a,b,c,k;cin>>a>>b>>c>>k;
int n=1<<k,m=max(max(a,b),c);
cout<<a+b+c+m*n-m;
system("pause");
return 0;
}

Measured memory_bytes: 504
#!/usr/bin/env python3
import sys


def solve(s: str):
    z = ""
    for c in s:
        if c == "B":
            z = z[:-1]
        else:
            z += c
    print(z)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
ans = A[0]
i = 1
j = 1
while i < N-1:
    ans += A[j]
    i += 1
    if i < N-1:
        ans += A[j]
    i += 1
    j += 1
print(ans)


Measured memory_bytes: 31756
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

#define ll long long
const int maxN = 100005;
const ll INF = 1000000000000000000LL;

class TaskA {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int x;
		cin >> x;
		if (x <= 599) {
			cout << 8 << endl;
			return;
		}
		if (x <= 799) {
			cout << 7 << endl;
			return;
		}
		if (x <= 999) {
			cout << 6 << endl;
			return;
		}
		if (x <= 1199) {
			cout << 5 << endl;
			return;
		}
		if (x <= 1399) {
			cout << 4 << endl;
			return;
		}
		if (x <= 1599) {
			cout << 3 << endl;
			return;
		}
		if (x <= 1799) {
			cout << 2 << endl;
			return;
		}
		cout << 1 << endl;

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskA solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
 string a;
  cin >> a;
  int b = a.size();
  if(a.at(b-1)=='s'){
    rep(i,b){
      cout << a.at(i);
    }
    cout << "es";
  }
  else {
    cout << a << "s" << endl;
  }
}


Measured memory_bytes: 3596
import java.util.*;public class Main{public static void main(String[]a){Scanner sc=new Scanner(System.in);String S=sc.next();int s=S.length();Set<Character>t=new HashSet<>();for(int i=0;i<s;i++){t.add(S.charAt(i));}System.out.println(t.size()==s?"yes":"no");}}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<tuple<string,int,int>>a;
  for(int i=1;i<=n;i++){
    string s;
    int p;
    cin>>s>>p;
    p=-p;
    a.push_back(tie(s,p,i));
  }
  sort(a.begin(),a.end());
    rep(i,n)
  cout << get<2>(a[i]) <<endl;
}

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

int main() {
	string s[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	string a;
	cin>>a;
	for(int i=0;i<7;i++)if(s[i]==a)cout<<7-i;
	return 0;
}


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

const int INF =1e9+7;
int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int n = max(x,y);
    ll ans = INF;
    rep(i,n+1){
        ll cost = 2*i*c+(max(0,x-i))*a + (max(0,y-i))*b;
        ans = min(cost,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using _TYPE = int;
typedef tree< _TYPE, null_type, less< _TYPE >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main() {
    IO;
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    #endif
    int n;
    cin >> n;
    int rem = n - (n / 1000) * 1000;
    rem = rem % 1000;
    if(!rem)
        cout << 0;
    else cout << 1000 - rem;
    return 0;
}


Measured memory_bytes: 3660
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

R, C, K = getNM()
point = [[0] * C for i in range(R)]
for i in range(K):
    r, c, v = getNM()
    point[r - 1][c - 1] = v

# dp[j][n] j列目にn個まで取った時の最大値
prev = [[0] * 4 for _ in range(C + 1)]

for i in range(R):
    next = [[0] * 4 for _ in range(C + 1)]
    for j in range(C):
        # 取った時
        for n in range(2, -1, -1):
            prev[j][n + 1] = max(prev[j][n + 1], prev[j][n] + point[i][j])

        # 下段に降りた時
        next[j][0] = max(prev[j])

        # 取らない時
        for n in range(4):
            prev[j + 1][n] = max(prev[j + 1][n], prev[j][n])
    prev = next

print(max(prev[C - 1]))

Measured memory_bytes: 231332
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    rep(i, n) sort(all(s[i]));
    sort(all(s));

    ll sum = 0;
    ll cnt = 1;
 //   rep(i, n) put(s[i]);
    rep(i, n-1) {
        if (s[i] == s[i+1]) {
            cnt++;
        }
        else {
            if (cnt >= 2) {
                sum += cnt * (cnt - 1) / 2;
            }
            cnt = 1;
        }
    }
    if (cnt >= 2) {
        sum += cnt * (cnt - 1) / 2;
    }
    cnt = 1;

    put(sum);

    return 0;
}

Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}

struct edge
{
    long long to, cost;
};
using P = pair<int, int>;
int V;
const int MAX_V = 2e5 + 1;

vector<edge> G[MAX_V], newG[MAX_V]; //G[i]={j,c} ⇔ iからjへの辺の重みがc
vector<long long> d(MAX_V, INF / 2);

void dijkstra(int start)
{
    priority_queue<P, vector<P>, greater<P>> que;
    d[start] = 0;
    que.push(P(0, start));
    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        long long v = p.second;
        if (d[v] < p.first)
        {
            continue;
        }
        for (int i = 0; i < G[v].size(); i++)
        {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
int toInt(pair<int, int> p) //点とコインのペア
{
    return p.first * 2500 + p.second;
}
ll toInt(ll point, ll coin)
{
    return point * 2500 + coin;
}
int main()
{
    int N, M, S;
    cin >> N >> M >> S;
    vint U(M), V(M), A(M), B(M);
    for (size_t i = 0; i < M; i++)
    {
        cin >> U[i] >> V[i] >> A[i] >> B[i];
        U[i]--;
        V[i]--;
        for (size_t j = A[i]; j < 2500; j++)
        {
            G[toInt(U[i], j)].push_back({toInt(V[i], j - A[i]), B[i]});
            G[toInt(V[i], j)].push_back({toInt(U[i], j - A[i]), B[i]});
        }
    }
    vint C(N), D(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> C[i] >> D[i];
        for (ll j = 0; j + C[i] < 2500; j++)
        {
            G[toInt(i, j)].push_back({toInt(i, j + C[i]), D[i]});
        }
    }
    dijkstra(toInt(0, min(S, 2499)));
    for (size_t i = 1; i < N; i++)
    {
        ll ans = INF;
        for (size_t j = 0; j < 2500; j++)
        {
            chmin(ans, d[toInt(i, j)]);
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 33000
n = int(input())
l = []
for i in range(n):
    x, y, h = map(int, input().split())
    l.append([x, y, h])
l.sort(reverse=True, key=lambda x: x[2])
for x in range(101):
    for y in range(101):
        height = l[0][2] + abs(x - l[0][0]) + abs(y - l[0][1])
        for pyx, pyy, pyh in l:
            if pyh != max(height - abs(x - pyx) - abs(y - pyy), 0):
                break
        else:
            print(x, y, height)
            exit()


Measured memory_bytes: 3064
n,m = map(int, input().split())
temp=[0]*n
h = list(map(int, input().split()))
for j in range(0,m):
    a,b = map(int, input().split())
    if h[a-1]>h[b-1]:
        temp[b-1]=1
    elif h[a-1]<h[b-1]:
        temp[a-1]=1
    elif h[a-1]==h[b-1]:
        temp[a-1]=1
        temp[b-1]=1
num=0
for i in range(0,n):
    if temp[i]==0:
        num=num+1
print(num)

Measured memory_bytes: 20912
s = input()
ans = False
for i in range(len(s)):
    if i%2==0:
        if s[i]=="L":
            ans =True
            break
    if i%2==1:
        if s[i]=="R":
            ans=True
            break

if ans==False:
    print('Yes')
else:
    print('No')

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----

すごい

----解説ここまで---- */



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

	int N; cin >> N;
	VVI a(N, VI(N));
	FOR(i, 0, N) {
		FOR(j, 0, N) {
			cin >> a[i][j];
		}
	}
	VL cost(1 << N, 0);
	FOR(state, 0, 1 << N) {
		FOR(i, 0, N) {
			FOR(j, i + 1, N) {
				if (state & 1 << i && state & 1 << j) {
					cost[state] += a[i][j];
				}
			}
		}
	}
	VL dp(1 << N, 0);
	FOR(nx, 0, 1 << N) {
		for (int state = nx; ; state = (state - 1)&nx) {
			dp[nx] = max(dp[nx], dp[nx^state] + cost[state]);

			if (state == 0)break;
		}
	}
	cout << dp[(1<<N) - 1] << endl;

	return 0;
}


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

 
int main(void)
{
    int n,ans;

    cin >> n;

    ans = 1000 - (n%1000);

    if(n%1000 == 0)ans = 0;

    cout << ans << endl;
}

Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

//scanf("%d",&x);
//printf("%d",x);
//for(i=0;i<N;i++){  }
//if( == ){  }else{  }
//while( ){  }

/*
int N, i;
int H[100];
scanf("%d", &N);
for (i = 0; i < N; i++) scanf("%s", &H[i]);
*/

int main()
{
	int x;
	scanf("%d", &x);

	printf("%d", x*x*x);


}


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

#define ll long long
#define MOD 1000000007

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> Q[i];
  }

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

  int count = 0;
  int a, b;
  do {
    bool flag = true;
    count++;
    for (int i = 0; i < N; i++) {
      if (V[i] != P[i]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      a = count;
    }

    flag = true;
    for (int i = 0; i < N; i++) {
      if (V[i] != Q[i]) {
        flag = false;
        break;
      }
    }

    if (flag) {
      b = count;
    }
  } while (std::next_permutation(V.begin(), V.end()));

  cout << abs(b - a) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

vector<ll> res;

void prime_factorize(long long N) {
    
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back(ex);
    }

    // 最後に残った数について
    if (N != 1) res.push_back(1);
}

//ここから。
int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    prime_factorize(N);
    rep(i,res.size()){
        ll memo=1;
        while(true){
            if(res[i] - memo >= 0){
                ans++;
                res[i] -= memo;
            }else{
                break;
            }
            memo++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
from fractions import Fraction

n, m = map(int, input().split())
a = list(map(int, input().split()))

condition1 = Fraction(1,4 * m)

count = 0

condition2 = sum(a) * condition1
for A in a:
    if A >= condition2:
        count +=1

if count >= m:
    print("Yes")
else:
    print("No")


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int a[200009],b[200009];
ll pref[200009];

void solve()
{
	int n,m,i,k;
	cin>>n>>m>>k;
	for(i=1;i<=n;i++) cin>>a[i];
	for(i=1;i<=m;i++) cin>>b[i];
	for(i=1;i<=m;i++) pref[i]=pref[i-1]+b[i];
	ll sum=0;
	int maxx=0;
	for(i=0;i<=n;i++)
	{
		sum += a[i];
		if(sum>k)
		{
			//maxx=max(maxx,i);
			break;
		}
		auto it = upper_bound(pref,pref+1+m,k-sum);
		it--;
		//if(it==pref) continue;
		int ind = it - pref;
		maxx=max(maxx,ind+i);
	}
	cout<<maxx<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 6736
#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(){
    string S,ans;
    cin >> S;
    for(auto c:S){
        if(c == 'B'){if(ans.size()){ans.pop_back();}}
        else ans.push_back(c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC126D
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = CIN.Long();
            Dictionary<long, List<Point>> pool = new Dictionary<long, List<Point>>();
            for (int i = 0; i < N - 1; i++)
            {
                long[] UVR = CIN.LongArray();
                if (pool.ContainsKey(UVR[0]-1))
                {
                    pool[UVR[0] - 1].Add(new Point(UVR[1] - 1, UVR[2]));
                }

                if (pool.ContainsKey(UVR[1]-1))
                {
                    pool[UVR[1] - 1].Add(new Point(UVR[0] - 1, UVR[2]));
                }

                if (!pool.ContainsKey(UVR[0]-1))
                {
                    pool.Add(UVR[0] - 1, new List<Point>() {new Point(UVR[1] - 1, UVR[2])});
                }

                if (!pool.ContainsKey(UVR[1]-1))
                {
                    pool.Add(UVR[1] - 1, new List<Point>() {new Point(UVR[0] - 1, UVR[2])});
                }
            }

            Queue<Point> queue = new Queue<Point>();
            bool[] ans = new bool[N];
            bool[] memo = new bool[N];
            for (int i = 0; i < N; i++)
            {
                ans[i] = false;
                memo[i] = false;
            }

            queue.Enqueue(new Point(0, 0));
            memo[0] = true;
            while (queue.Count > 0)
            {
                var pop = queue.Dequeue();

                foreach (var a in pool[pop.P])
                {
                    if (memo[a.P])
                    {
                        continue;
                    }
                    queue.Enqueue(a);
                    ans[a.P] = ans[pop.P] ^ (a.W % 2 == 1);
                    memo[a.P] = true;
                }
            }

            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(ans[i] ? 1 : 0);
            }
        }
    }

    class Point
    {
        public long P;
        public long W;

        public Point(long p, long w)
        {
            P = p;
            W = w;
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 39992
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    int K; cin >> K;
    cout << K / 2 * ((K + 1)/ 2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int N;
vector<string> strings;
void dfs(string s,char mx){
    if(s.length()==N){
        cout<<s<<endl;
    }else{
        for(char c='a'; c<=mx; c++){
            if(c==mx){
                dfs(s+c,(char)(mx+1));
            }else{
                dfs(s+c,mx);
            }

        }
    }

}

void solve(){
    
    
    cin >> N;
    dfs("",'a');
    
}

int main(){
    solve();
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map < int , int > mp;
    int x, n, p,b,a;
    while(cin>>x>>n){
        while(n--) cin>>p, mp[p]=1;
        b=x;
        a=x;

        if(mp[x]==0) {
            cout<<x<<endl;
            continue;
        }
        while(1){
            b--;
            a++;
            if(mp[a]==0 || mp[b]==0) break;
        }
        if(mp[a]==0 && mp[b]==0) cout<<min(a,b)<<endl;
        else if(mp[a]==0) cout<<a<<endl;
        else cout<<b<<endl;
        mp.clear();
    }
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include<math.h>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define INF 1000000007;

int main(){
  ll A,B,ans=0;
  ll X[100000];
  int N;

  cin >> N >> A >> B;
  rep(i,N){
    cin >> X[i];
  }

  rep(i,N-1){
    ans+=min(A*(X[i+1]-X[i]),B);
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 1024
using System;

namespace Volume0_0019
{
	class Program
	{
		static void Main(string[] args)
		{
			ulong n = ulong.Parse(Console.ReadLine());
			ulong a = 1UL;

			for(ulong i = 2; i <= n; i++) {
				a *= i;
			}

			Console.WriteLine(a);
		}
	}
}



Measured memory_bytes: 15936
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  int ren=0;
  int count=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=1;i<n;i++){
    if(a[i]==a[i-1]){
      ren++;
    }else{
      if(ren>0){
        if(ren%2==1){
          count+=ren/2+1;
        }else{
          count+=ren/2;
        }
        ren=0;
      }
    }
  }

      if(ren>0){
        if(ren%2==1){
          count+=ren/2+1;
        }else{
          count+=ren/2;
        }
        ren=0;
      }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
//BUGSBUNNY
//IIT ROORKEE

#include<bits/stdc++.h>
using namespace std; 
#define int long long
#define ll long long
#define double long double
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define gcd __gcd
#define mp make_pair
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
// #define mod 1000000007
#define mod 1000000000 
// #define mod 998244353
#define rep(i,n) for (ll i = 0; i < n; i++)
#define repp(i,a,b) for(ll i = a ; i<b ; i++)
#define reppr(i,a,b) for(ll i = a-1 ; i>=b ; i--)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " << 
#define setprec(x) cout << fixed << setprecision(x);
#define reve(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()

//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }

//modInverse
    int modInverse(int a) 
    { 
       return powmod(a,mod-2); 
    }

//Binomial Coefficients
    // int fact[200010], factinv[200010];
    // int nCr(int n , int r)
    // {
    //     return ((fact[n] * modInverse(fact[n-r]) % mod * modInverse(fact[r]))%mod) ;
    // }


void solve();

signed main()
{
    //-------------------------------------------------------------------------------
        
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        clock_t clk = clock();

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

        // fact[0] = 1 , factinv[0] = 1;
        // repp(i,1,200010)
        // {
        //     fact[i] = (fact[i-1] * i)%mod;
        //     factinv[i] = (factinv[i-1] * modInverse(i))%mod;
        // }
        
    //-------------------------------------------------------------------------------
        int t = 1;
        // cin >> t;
        while(t--)
            solve();
        clk = clock() - clk;
        cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
    //-------------------------------------------------------------------------------
}

void solve()
{
    int a , b , c;
    cin >> a >> b >> c;
    swap(a,b);
    swap(a,c);
    cout << a sp b sp c ;
}

Measured memory_bytes: 256
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  string s = readln.chomp;
  int c;

  foreach (i; 0..s.length-1) {
    if (s[i] != s[i + 1]) {
      c++;
    }
  }

  writeln(c);
}


Measured memory_bytes: 508
def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()
        L = max(A).bit_length()
        s = [0]*L
        ID = A.index(max(A))

        def check(x):
            for i in range(L-1, -1, -1):
                if (x >> i) % 2:
                    x ^= s[i]
            return(x == 0)

        def update(x):
            flag = False
            if x.bit_length() == 60:
                flag = True
            for i in range(L-1, -1, -1):
                if (x >> i) % 2:
                    x ^= s[i]
            id = x.bit_length() - 1
            if id >= 0:
                s[id] = x

        res = 0
        L2 = 0
        for i in range(N-1, -1, -1):
            k = int(S[i])
            if k:
                if check(A[i]):
                    continue
                else:
                    res = 1
                    break
            else:
                L2 = max(L2, A[i].bit_length())
                update(A[i])
        print(res)



main()


Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  ll sum = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"

//文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal){ 
    decimal.erase(1, 1); //小数点削除
    int n_decimal = atoi(decimal.c_str()); //c_strでchar*に変換後、atoiでintに変換
    return n_decimal;
}

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

//素数判定(True/Falseを返却)
int IsPrime_tf(ll num){
    if (num < 2) return false; //0、1は素数でない
    else if (num == 2) return true; //2は素数
    else if (num%2==0) return false; // 偶数はあらかじめ除く
    for (ll i = 3; i*i <= num; i += 2){ //チェックは2～√nで十分
        if (num % i == 0) return false; //素数でない
    }
    return true; //素数である
}

//素数判定(割れる値を返却)
ll IsPrime_value(ll num){
    if (num < 2) return -1; //0、1は素数でない
    else if (num == 2) return 2; //2は素数
    for (ll i = 2; i*i <= num; i += 1){ //チェックは2～√nで十分
        if (num % i == 0) return i; //素数でない
    }
    return num; //素数である
}

int main(){
   int n;
   cin >> n;
   vector<int> l(n);
   int ans=0;
   rep(i,n) cin >> l[i];
   for(int i=0; i<n; i++){
       for(int j=i+1; j<n; j++){
           for(int k=j+1; k<n; k++){
               if(i!=j && j!=k && i!=k){
                   if(l[i]!=l[j] && l[j]!=l[k] && l[i]!=l[k]){
                       if(l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j]){
                        ans++;
                        //cout << i << " " << j << " " << k << endl;
                       }
                   }
               }
           }
       }
   }
   cout << ans << endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char c[100007];
int main(){
    scanf("%s",c);int l=strlen(c),g=0;
    for(int i=0;i<l;++i)if(c[i]=='g')g++;
    printf("%d\n",min(l/2,g)-min(l-l/2,l-g));
    return 0;
}

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

int main() {
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n), x(q);
    rep(i, n) cin >> a[i];
    rep(i, q) cin >> x[i];

    a.push_back(1e18);

    for (long long i = 0; i < q; i++) {
        ll left = 0;
        ll right = 0;
        ll ans = 0, cnt = 0;
        for (; right <= n;) {
            if (cnt + a[right] <= x[i]) {
                cnt += a[right++];
            } else {
                ans += right - left;
                cnt -= a[left++];
            }
            //cout << "cnt:" << cnt << endl;
        }
        put(ans);
    }
}


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

int main() {
  long long N; cin >> N;
  long long res = 0;
  for (long long i = 1; i <= N; i++) {
    long long v = N / i;
    res += (i*(v+1)*v)/2;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3632
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)


function main()
    ans = 0
    N = parseInt(readline())
    A = parseMap(split(readline()))
    for i in 1:2:N
        if A[i] % 2 == 1
            ans += 1 
        end
    end

    println(ans)
end

main()

Measured memory_bytes: 164332
#include <cmath>
#include <iostream>

int main()
{
  double n, a, b, x;
  int ans;
  std::cin >> a >> b >> n;
  x = b - 1;
  if (x > n)
    x = n;
  ans = static_cast<int>(std::floor(a * x / b) - a * std::floor(x / b));
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3712
def main():
	A, B, C, X, Y = map(int, input().split())
	lst = [0] * (10 ** 5 + 1)

	for i in range(10 ** 5 + 1):
		lst[i] = 2 * C * i + max(X - i, 0) * A + max(Y - i, 0) * B

	print(min(lst))


  
if __name__ == "__main__":
  	main()

Measured memory_bytes: 12748
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1 << 30, mod=1e9+7;

int n;
char s[500005];

int fac(int x){
	int r=1;
	for(int i=1;i<=x;i++)r = 1ll*r*i%mod;
	return r;
}

int main(){
	scanf("%d",&n); int m = n<<1;
	scanf("%s",s+1);
	int state=0, cur=0, ans=1;
	for(int i=1;i<=m;i++){
		if(s[i] == 'B'){
			if(state%2 == 0){
				++ state;	// 1
				++ cur;
			}else{	// -1
				ans = 1ll*ans*cur%mod;
				-- cur;
				-- state;
			}
		}else{
			if(state%2 == 1){
				++ state;
				++ cur;
			}else{
				ans = 1ll*ans*cur%mod;
				-- cur;
				-- state;
			}
		}
		if(state > n)return puts("0"),0;
//		printf("%d %d %d\n",ans,cur,state);
	}	
	if(state)puts("0");
	else printf("%d\n",1ll * ans * fac(n) % mod);

	return 0;
}


Measured memory_bytes: 384
from sys import exit

divisor = 1000000007

N, M = map(int, input().split())

if abs(N - M) > 1:
    print(0)
    exit()

k = min(N, M)
t = 1
for i in range(2, k + 1):
    t = t * i % divisor
t = t * t % divisor

if N == M:
    print(2 * t % divisor)
else:
    print(t * (k + 1) % divisor)


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int>> ans(n, vector<int>(n, -1));

  vector<int> group(n, 0);
  for (int level = 1;; level++) {
    vector<int> grcnt(n*3), sgcnt(n*3);
    for (int i = 0; i < n; i++) { grcnt[group[i]]++; }
    for (int i = 0; i < n; i++) {
      int thres = grcnt[group[i]] / 2;
      if (sgcnt[group[i]]++ < thres) {
        group[i] = group[i] * 2 + 1;
      } else {
        group[i] = group[i] * 2;
      }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < i; j++) {
        if (ans[i][j] > 0) continue;
        if (group[i] != group[j]) {
          ans[i][j] = level;
          ans[j][i] = level;
          cnt++;
        }
      }
    }
    if (cnt == 0) break;
  }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      printf("%d%c", ans[i][j], " \n"[(j + 1 == n) ? 1 : 0]);
    }
  }
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    string ins = "insert";
    string fi = "find";
    cin >> n;
    map<string,int> m;
    while(n--) {
        string t,s;
        cin >> t >> s;
        if(t == ins) {
            m[s]++;
        }
        else if(t == fi) {
            if(m.find(s) == m.end()) cout << "no" << endl;
            else cout << "yes" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 36360
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

A,B = II()

ans = 0
temp = 1
while temp<B:
    temp += A-1
    ans += 1
print(ans)

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

int main(){
  int a,b,c,z;
  cin >> a >> b >> c >> z;
  int an=0,bn=0,cn=0;
  int ans=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(i*500+j*100+k*50==z)
          ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3588
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::cmp::Ordering;
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

impl<T: Copy> Copy for Rev<T> {}

fn main() {
    input! {
        n: usize, k: usize,
        s: chars
    }

    let (left_char, right_char) = if s[0] == 'L' { ('L', 'R') } else { ('R', 'L') };

    let mut left = Vec::new();
    let mut right = Vec::new();

    let mut idx = 0;
    while idx < s.len() {
        let mut i = 0;
        while idx + i < s.len() && s[idx + i] == left_char {
            i += 1;
        }
        left.push(i);
        idx += i;

        let mut j = 0;
        while idx + j < s.len() && s[idx + j] == right_char {
            j += 1;
        }
        right.push(j);
        idx += j;
    }

    for i in 0..k {
        if i >= right.len() {
            break;
        }
        left[i] += right[i];
        right[i] = 0;
    }

    let mut tmp = Vec::new();
    for i in 0..left.len() {
        for _ in 0..left[i] {
            tmp.push(left_char);
        }
        for _ in 0..right[i] {
            tmp.push(right_char);
        }
    }

    let l = tmp.len();
    tmp.dedup();
    let d = tmp.len();

    println!("{}", l - d);
}


Measured memory_bytes: 6396
#include <stdio.h>
#include <math.h>

int main(void)
{

	int N;
	
	scanf("%d",&N);
	
	int a[N];

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

	int loop = 0;
	int k,j = 0;

	for (k=0; k < 10000; k++){
		j=0;
		for (j=0; j<N; j++){
			if ( a[j]%2==0) {
				loop = loop + 1;
				a[j] = a[j]/2;
			}
		}
	}

	printf("%d",loop);

	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#define _for(i,n) for(ll i = 0; i < n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

using namespace std;

int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for(ll a = 1; a*(a+1)<n;a++) {
    if(n%a==0&&n/a-1>a) sum+=n/a-1;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256