akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  ll n; cin >> n;
  vvl G(n);
  vpii e_in;
  map<pair<int,int> ,int > e_out;
  rep(i,n-1){
    int a,b; cin >> a >> b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    e_in.emplace_back(a,b);
  }

  vector<set<int> > used(n);
  vb visited(n);
  int max_num = 1;
  queue<int> que;
  que.push(0);
  visited[0]=true;
  //ノードについて見ていき、隣接ノードが使っていない色を埋める
  while(!que.empty()){
    int num = 1; //辺の色は1から
    int v = que.front();
    que.pop();
    for(auto nv:G[v]){
      if(!visited[nv]){
        //vが使っている色は使えない
        if(used[v].find(num) != used[v].end()){
          num++;
        }
        int a = min(nv,1LL*v);
        int b = max(nv,1LL*v);
        e_out[{a,b}] = num;
        used[a].insert(num);
        used[b].insert(num);
        visited[nv]=true;
        que.push(nv);
        num++;
      }
    }
    max_num = max(max_num,num-1);
  }
  //出力
  out(max_num);
  for(auto e:e_in){
    out(e_out[e]);
  }
}

Measured memory_bytes: 27640
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    lli A, B, C;
    cin >> A >> B >> C;
    for(lli i=1;i<=B;i++){
    	if((i*A)%B==C){
        	cout << "YES" <<endl;
          	return 0;
        }
    }
  	cout << "NO" <<endl;
    return 0;
}

Measured memory_bytes: 256
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=9e18;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long, long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1)%mod;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

//Union-Find木
struct UnionFind{
  //メンバ変数 
  vector<long long>par; //par[i]:=頂点iの親
  vector<long long>s; //s[i]:=頂点iが属する集合の個数(iが根のとき)
  
  //コンストラクタ
  UnionFind(long long N):par(N),s(N){
    for(long long i=0;i<N;i++){
      par[i]=i; //最初はすべてが根として初期化
      s[i]=1;
    }
  }
  //メンバ関数
  //root(i):=頂点iの根
  long long root(long long i){
    if(par[i]==i) return i;
    par[i]=root(par[i]); //経路圧縮
    return root(par[i]); //再帰
  }
  //size[i]:=iが属する集合の個数
  long long size(long long i){
    return s[root(i)];
  }
  //same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか)
  bool same(long long x, long long y){
    return root(x)==root(y);
  }
  //unite(x,y) xの根をyの根に繋げる(集合を合併)
  void unite(long long x, long long y){
    if(!same(x,y)){
      long long rx=root(x);
      long long ry=root(y);
      par[rx]=par[ry];
      s[ry]=s[rx]+s[ry];
    }
  }
};

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////

//メイン関数
int main(){
  //doubleの桁数
  
  int N;
  int m = 0;
  int cnt = 0;
  cin >> N;
  rep(i, N){
    int a, b; cin >> a >> b;
    if(a == b) cnt++;
    else cnt = 0;
    m = max(m, cnt);
  }

  if(m < 3) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>

typedef struct{
  int p;
  int s;
  int deg;
  int dep;
  int h;
}data;

typedef struct{
  int id;
  int left;
  int right;;
}node;

int dep;

int getdep(data* T, int i){
  if(T[i].p == -1) return dep;
  dep++;
  return getdep(T, T[i].p);
}

int geth(data* T, node u, int i){
  int hleft=0,hright=0;
  if(u.left!=-1){
    if(T[u.left].h == -1) return -1;
    hleft = T[u.left].h;
  }
  if(u.right!=-1){
    if(T[u.right].h == -1) return -1;
    hright = T[u.right].h;
  }

  if(hleft > hright) return hleft+1;
  else return hright+1;
}

void print(data T, int i){
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T.p,T.s,T.deg,T.dep,T.h);
  if(T.p == -1) printf("root");
  else if(T.deg == 0) printf("leaf");
  else printf("internal node");
  printf("\n");
}
int main(){
  int n,i,j;
  data T[25];
  node u[25];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p = -1;
    T[i].deg = 0;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d%d",&u[i].id,&u[i].left,&u[i].right);
    
    if(u[i].right != -1){
      T[u[i].right].p = u[i].id;
      T[u[i].id].deg++;
    }
    if(u[i].left != -1){
      T[u[i].left].p = u[i].id;
      T[u[i].id].deg++;
    }

    if(T[u[i].id].deg == 0) T[u[i].id].h = 0;
    else T[u[i].id].h =-1;
  }

  for(i=0;i<n;i++){
    T[i].s = -1;
    for(j=0;j<n;j++){
      if(i != j && T[i].p == T[j].p){
        T[i].s =j;
        T[j].s =i;
      }
    }
  }

  for(i=0;i<n;i++){
    dep=0;
    T[i].dep = getdep(T,i);
  }

  i=0;
  while(1){
    if(T[i].p == -1 && T[i].h != -1) break;
    if(T[i].h != 0){
      j=0;
      while(u[j].id != i) j++;
      T[i].h = geth(T,u[j],i);
    }

    if(i == n-1) i=0;
    else i++;
  }
  for(i=0;i<n;i++) print(T[i],i);

  return 0;
}



Measured memory_bytes: 2056
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] wab = scanner.nextLine().split(" ", 3);
        int w = Integer.parseInt(wab[0]);
        int a = Integer.parseInt(wab[1]);
        int b = Integer.parseInt(wab[2]);

        int left = Math.min(a, b);
        int right = Math.max(a, b);
        if (right <= left + w) {
            System.out.println(0);
            return;
        }
        System.out.println(right - (left + w));
    }
}


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

int main() {
    int a[3];
    for (int i = 0; i < 3; i++) cin >> a[i];
    sort(a, a + 3);
    int ans = 0;
    bool flag = true;
    while (flag) {
        flag = false;
        if (a[0]+1 < a[2]) {
            a[0] += 2;
            ans++;
            flag = true;
        }
        if (a[1]+1 < a[2]) {
            a[1] += 2;
            ans++;
            flag = true;
        }
    }
    flag = true;
    while (flag) {
        flag = false;
        sort(a, a + 3);
        if (a[0] < a[2]) {
            a[0]++;
            a[1]++;
            ans++;
            flag = true;
        }
        if (!flag && a[1] < a[2]) {
            a[0]++;
            a[1]++;
            ans++;
            flag = true;
        }
    }
    cout <<ans << endl;
    //cout << a[0] << " " << a[1] << " " << a[2] << endl;
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = IR(5)
    k = I()
    if max(s)-min(s) > k:
        print(":(")
    else:
        print("Yay!")
    return

#B
def B():
    s = IR(5)
    s.sort(key = lambda x:-x%10)
    ans = 0
    i = 0
    k = 0
    while 1:
        if i%10 == 0:
            ans = i+s[k]
            i += s[k]-1
            k += 1
            if k == 5:break
        i += 1
    print(ans)
    return

#C
def C():
    n = I()
    return

#D
def D():
    n = I()
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 39280
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def search_next(l, r, SC):
    ll, lc = l
    rr, rc = r
    nexts = []
    if len(ll) > len(rr):
        part = ll[::-1]
        for s,c in SC:
            if s[-len(part):] == part:
                r_n = (s[:-len(ll)], rc + c)
                l_n = ('', lc)
                nexts.append((rc+c+lc, (l_n, r_n)))
            elif s == part[-len(s):]:
                l_n =(ll[len(s):], lc)
                r_n = ('', rc + c)
                nexts.append((rc + c + lc, (l_n, r_n)))
    else:
        part = rr[::-1]
        for s, c in SC:
            if s[:len(part)] == part:
                l_n = (s[len(rr):], lc + c)
                r_n = ('', rc)
                nexts.append((lc+rc+c, (l_n, r_n)))
            elif s == part[:len(s)]:
                r_n = (rr[:-len(s)], rc)
                l_n = ('', lc + c)
                nexts.append((lc + rc + c, (l_n, r_n)))
    return nexts

def palindrome(l, r):
    if l + r == (l+r)[::-1]:
        return True
    else:
        return False



def run():
    totalL = 0
    N = int(sysread())
    SC = []
    for i in range(N):
        s,c = input().split()
        c = int(c)
        SC.append((s,c))
        totalL += len(s)

    min_val = INF
    cache = set()
    for s,c in SC:
        queue = []
        left = (s, c)
        right = ('', 0)
        heappush(queue, (c, (left, right)))
        done = False

        while queue:
            #print(queue)
            cost, (l, r) = heappop(queue)
            if (l[0], r[0]) in cache: continue
            cache.add((l[0], r[0]))
            if palindrome(l[0], r[0]):
                done = True
                #print(l, r)
                cache.remove((l[0], r[0]))
                break
            nexts = search_next(l, r, SC)
            for n in nexts:
                heappush(queue, n)
        if done:
            min_val = min(min_val, cost)
    if min_val == INF:
        print(-1)
    else:
        print(min_val)

if __name__ == "__main__":
    run()

Measured memory_bytes: 9368
N = int(input())
T = []
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

for i in range(N):
    T += [int(input())]
if len(T) == 1:
    print(T[0])
else:
    prev = T[0]
    for i in range(N-1):
        new = T[i+1]
        prev = lcm(prev, new)
    print(prev)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main
{
	static void merge(int arr[], int l, int m, int r) 
    { 
        int n1 = m - l + 1; 
        int n2 = r - m; 
        int L[] = new int [n1]; 
        int R[] = new int [n2]; 
        for (int i=0; i<n1; ++i) 
            L[i] = arr[l + i]; 
        for (int j=0; j<n2; ++j) 
            R[j] = arr[m + 1+ j]; 
        int i = 0, j = 0; 
        int k = l; 
        while (i < n1 && j < n2) 
        { 
            if (L[i] <= R[j]) 
            { 
                arr[k] = L[i]; 
                i++; 
            } 
            else
            { 
                arr[k] = R[j]; 
                j++; 
            } 
            k++; 
        } 
        while (i < n1) 
        { 
            arr[k] = L[i]; 
            i++; 
            k++; 
        } 
        while (j < n2) 
        { 
            arr[k] = R[j]; 
            j++; 
            k++; 
        } 
    } 
    static void sort(int arr[], int l, int r) 
    { 
        if (l < r) 
        { 
            int m = (l+r)/2; 
            sort(arr, l, m); 
            sort(arr , m+1, r); 
            merge(arr, l, m, r); 
        } 
    } 
    static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } 
    static long power(long n,long m)
    {
    	if(m==0)
    		return 1;
    	long ans=1;
    	while(m>0)
    	{
    		ans=ans*n;
    		m--;
    	}
    	return ans;
    }
	static int binarySearch(ArrayList<Integer> arr, int x) 
    { 
        int l = 0, r = arr.size() - 1,m=l + (r - l) / 2; 
        while (l <= r) { 
            m = l + (r - l) / 2; 
            if (arr.get(m) == x) 
                return m; 
            if (arr.get(m) < x) 
                l = m + 1; 
            else
                r = m - 1; 
        } 
        return (int)Math.max(l, m); 
    } 
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=1;//Integer.parseInt(br.readLine());
	    for(int i=1;i<=t;i++)
	    {
	        double aa,bb,cc,dd;
	        String s=br.readLine();
	        String ss[]=s.split(" ");
	        aa=Integer.parseInt(ss[0]);
	        bb=Integer.parseInt(ss[1]);
	        cc=Integer.parseInt(ss[2]);
	        dd=Integer.parseInt(ss[3]);
	        if(Math.ceil(cc/bb)<=Math.ceil(aa/dd))
	        {
	        	System.out.println("Yes");
	        	return;
	        }
	        else
	        System.out.println("No");
	    }
	}
}


Measured memory_bytes: 32636
#include <iostream>
using namespace std;
int a=0,b=0; 

int main() {
 while(1){
   cin >> a >> b;
   if(a==0 && b==0){
     break;
   }
   for(int i=0;i<a;i++){
     for(int y=0;y<b;y++){
       if(y==0 || y==b-1 || i==0 || i==a-1){
         cout << "#" ;
       }
       else{
         cout << "." ;
       }
       
     }
     cout << endl;
   }
   cout << endl;
 }
}


Measured memory_bytes: 3096
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

sumA = sum(A)
yakusu = []
yakusu2 = []
t = 1
while t <= sumA ** 0.5:
	if sumA % t == 0:
		yakusu.append(t)
		yakusu2.append(sumA // t)
	t+=1
while len(yakusu) > 0:
	yakusu2.append(yakusu.pop())

#print(yakusu2)
for num in yakusu2:
	sa = []
	for i in range(N):
		syo = A[i]//num
		sa.append(A[i]-num*syo)
	sa.sort()
	judge = 0
	wa = 0
	loc = 0
	for i in range(len(sa)):
		#print(wa + sa[i])
		if (wa + sa[i]) <= K:
			wa += sa[i]
			loc = i
		else:
			break
	if loc == len(sa) - 1:
		print(num)
		exit()
	else:
		for i in range(loc+1, len(sa)):
			sa[i] = num - sa[i]
	#print(num, sa, loc)
	if sum(sa[loc+1:]) <= K:
		print(num)
		exit()

Measured memory_bytes: 46148
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
	char s[200000];
	scanf("%s",s);
	long long int a,b,i,l=strlen(s);
	for(i=0;i<l;i++){
		if(s[i]=='A'){
			a=i;
			break;
		}
	}
	for(i=l-1;i>=0;i--){
		if(s[i]=='Z'){
			b=i;
			break;
		}
	}
	
	printf("%lld",b-a+1);
	return 0;
}

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

int main() {
  int64_t n;
  std::cin >> n;
  std::list<int64_t> l;

  for (int64_t i = 0; i < n; i++) {
    int64_t a;
    std::cin >> a;
    if (i % 2 == 0) {
      l.push_back(a);
    } else {
      l.push_front(a);
    }
  }
  std::string s("");
  if (n % 2 == 0) {
    for (auto itr = l.cbegin(); itr != l.cend(); itr++) {
      s += std::to_string(*itr);
      s += " ";
    }
  } else {
    for (auto itr = l.crbegin(); itr != l.crend(); itr++) {
      s += std::to_string(*itr);
      s += " ";
    }
  }
  s.pop_back();
  std::cout << s << std::endl;
  return 0;
}


Measured memory_bytes: 10500
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define QUEUE_SIZE 10000000	//待ち行列の大きさ

int queue[QUEUE_SIZE];
int front;	//待ち行列の先頭
int rear;	//待ち行列の末尾

#define next(a) (((a)+1)%QUEUE_SIZE)

/*待ち行列を初期化する*/
void init(){
	front = rear = 0;
}
/*待ち行列にデータを入れる*/
void enqueue(int x){
	if(next(rear)==front){
		printf("待ち行列がフルなので要素を入れられません");
		exit(1);
	}
	queue[rear] = x;
	rear = next(rear);
}
/*待ち行列からデータを取り出す*/
int dequeue(){
	int x;
	if(front==rear){
		printf("待ち行列が空なので要素を取り出せません");
		exit(1);
	}
	x = queue[front];
	front = next(front);
	return x;
}
/*待ち行列が空かどうかを調べる*/
/*空なら1、空で無ければ0を返す*/
int empty(){
	return front == rear;
}

int main(void){
	init();
	int dx[4]={-1,0,0,1};
	int dy[4]={0,-1,1,0};
	int i,j;
	int h,w;
	int white = 0;
	scanf("%d%d",&h,&w);
	char s[h][w+1];
	int v[h][w];
	for(i=0;i<h;i++){
		scanf("%s",s[i]);
	}
	for(i=0;i<h;i++)for(j=0;j<w;j++){
		v[i][j]=-1;
		if(s[i][j]=='.')white++;
	}
	int temp,x,y;
	enqueue(0);
	v[0][0]=0;
	while(empty()==0){
		temp = dequeue();
		x = temp/10000;
		y = temp%10000;
		for(i=0;i<4;i++){
			if( (x+dx[i]<0)||(x+dx[i]>=h)||(y+dy[i]<0)||(y+dy[i])>=w)continue;
			if(s[x+dx[i]][y+dy[i]]=='.'&&v[x+dx[i]][y+dy[i]]==-1){
				v[x+dx[i]][y+dy[i]] = v[x][y]+1;
				enqueue((x+dx[i])*10000+y+dy[i]);
			}
		}
	}
	if(v[h-1][w-1]==-1){
		printf("-1");
	}else{
		printf("%d",white - v[h-1][w-1]-1);
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;

    vector<int> res(60001);
    for (int i=1; i<=100; ++i) {
        for (int j=1; j<=100; ++j) {
            for (int k=1; k<=100; ++k) {
                ++res[i*i + j*j + k*k + i*j + j*k + k*i];
            }
        }
    }
    for (int i=1; i<=N; ++i) {
        cout << res[i] << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
namespace FastIO{const char* ln="\n";struct Reader{char buf[1<<20],*s,*t;bool EOF_FLG;Reader():s(buf),t(buf),EOF_FLG(false) {};char gt() {return s==t&&((t=(s=buf)+fread(buf,1,1<<20,stdin))==s)?EOF:(*s++);}Reader& operator>>(char* str) {if(EOF_FLG)return *str=0,*this;while((*str=gt())!=' '&&*str!='\n'&&*str!=EOF)++str;if(*str==EOF)EOF_FLG=true;*str=0;return *this;}template<typename T>Reader&operator>>(T&x) {if(EOF_FLG)return *this;char c=0,d;while(c!=EOF&&(c<'0'||c>'9'))d=c,c=gt();if(c==EOF){EOF_FLG=true;return *this;}else x=0;while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=gt();if(d=='-')x=-x;return *this;}}in;struct Writer{char buf[1<<20],*s,*t;Writer():s(buf),t(buf+(1<<20)){}~Writer(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,1<<20,stdout),*s++=c):(*s++=c);}template<typename T>Writer&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[40],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}Writer&operator<<(const char*s) {while(*s)pt(*s++);return *this;}}out;}using namespace FastIO;
namespace ZDY{
    #define ll long long
    #define db double
    #define sht short
    #define MB template <class T>
    #define Fur(i,x,y) for(int i=x;i<=y;i++)
    #define fur(i,x,y) for(i=x;i<=y;i++)
    #define Fdr(i,x,y) for(int i=x;i>=y;i--)
    #define fdr(i,x,y) for(i=x;i>=y;i--)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define inf 0x3f3f3f3f
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdout)
    #define l2(n) (int(log2(n)))
    #define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define fcin ios::sync_with_stdio(false)
    MB T ABS(T x){return x>0?x:-x;}
    MB T MAX(T x,T y){return x>=y?x:y;}
    MB T MIN(T x,T y){return x<=y?x:y;}
    MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
    void SWAP(int &x,int &y){x^=y;y^=x;x^=y;}
}using namespace ZDY;using namespace std;
#define N 1000001
int n,a[4],l[10],ans=inf;
bool v[10];
void dfs(int d,int res,int t,int f){
    if(t>=ans)return;
    if(d==3){ans=t;return;}
    if(f)dfs(d+1,a[d+1],t+res,0);
    Fur(i,1,n)
    if(!v[i]){
        v[i]=1;
        if(res>=l[i])dfs(d,res-l[i],t+f*10,1);
        else dfs(d+1,a[d+1],t+l[i]-res+f*10,0);
        v[i]=0;
    }
}
bool cmp(int x,int y){return x>y;}
int main(){
    cin>>n>>a[0]>>a[1]>>a[2];
    Fur(i,1,n)cin>>l[i];
    sort(l+1,l+n+1,cmp);
    sort(a,a+3,cmp);
    dfs(0,a[0],0,0);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict
INF = -1000000000000001

n = int(input())
l = list(map(int, input().split()))

a = int(n/2)

dpa = defaultdict(lambda: -INF)
#dpa = [[0 for j in range(a+1)] for i in range(n+1)]

dpa[(0,0)] = 0
dpa[(1,0)] = 0
dpa[(1,1)] = l[0]
j = 1
for i in range(2,n+1):
	if i == j*2:
		dpa[(i,j)] = max(dpa[(i-2,j-1)]+l[i-1],dpa[(i-1,j)])
#		print(i,j,dpa[(i,j)])
	else:
		dpa[(i,j)] = max(dpa[(i-2,j-1)]+l[i-1],dpa[(i-1,j)])
#		print(i,j,dpa[(i,j)])
		if (i != n):
			j += 1
#			print(i,j,dpa[(i,j)])
#			print("   ",i-2,j-1,dpa[(i-2,j-1)],"")
			dpa[(i,j)] = dpa[(i-2,j-1)]+l[i-1]

#print(dpa)
print(dpa[n,a])

Measured memory_bytes: 145076
#include<stdio.h>

int main(void){
	int a,b,c,max;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(a > b){
		if(a > c)
			max = a * 10 + b + c;
		else
			max = c * 10 + a + b;
	}
	else{
		if(b > c)
			max = b * 10 + a + c;
		else
			max = c * 10 + a + b;
	}
	
	printf("%d\n", max);
	
	return 0;
}

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

int main()
{
  int inputNumber = 0;
  std::cin >> inputNumber;
  int inputArr[inputNumber];
  
  int res = 0;
  
  
  for (int i = 0; i < inputNumber; i++)
  {
    std::cin >> inputArr[i];
  }
  
  for (int i = 0; i < inputNumber; i++)
  {
    if (inputArr[i] == 0)
    {
        continue;
    }
    for (int j = (i + 1); j < inputNumber; j++)
    {
        if (inputArr[j] == 0)
        {
            continue;
        }
        res += (inputArr[i] * inputArr[j]);
    }
  }
  
  std::cout << res;
  
  return 0;
}


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

#define inf 1000000000

using namespace std;

int C[101][101],T[101][101];
	int n,m;

class sint{
	public:
	int n,m;
	sint(){}
	sint(int a,int b){n=a;m=b;}
	bool operator <(const sint &a) const{
		return m>a.m;
	}
};

int dike(int st,int en,int va){
	priority_queue<sint> state;
	
	int visit[101];
	int now[101];
	for(int i=0;i<101;i++){
		visit[i]=0;
		now[i]=inf;
	}
	
	state.push(sint(st,0));
	now[st]=0;
	
	while(1){
		sint u;
		u=state.top();
		state.pop();
		visit[u.n]=1;
		/*
		printf("come %d %d\n",u.n,u.m);
		for(int i=1;i<=m;i++){
			printf("%4d",now[i]);
		}
		puts("");
		for(int i=1;i<=m;i++){
			printf("%4d",visit[i]);
		}puts("");
		*/if(u.n==en){
			return u.m;
		}
		
		
		for(int i=1;i<=m;i++){
			int cost=C[u.n][i];
			if(va==1){
				cost=T[u.n][i];
			}
			if(cost==inf||visit[i]==1){
				continue;
			}
			if(cost+u.m < now[i]){
				now[i]=cost+u.m;
				state.push(sint(i,now[i]));
			}
		}
	}
}

int main(){
	
	while(1){
		cin>>n>>m;
		if(n==0){
			break;
		}
		for(int i=0;i<101;i++){
			for(int j=0;j<101;j++){
				C[i][j]=T[i][j]=inf;
			}
		}
		
		for(int i=0;i<n;i++){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			C[a][b]=C[b][a]=c;
			T[a][b]=T[b][a]=d;
		}
		
		int l;
		cin>>l;
		
		for(int i=0;i<l;i++){
			int a,b,c;
			cin>>a>>b>>c;
			printf("%d\n",dike(a,b,c));
		}
	}
}

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

int main(){
    int N;
    cin >> N;
    
    pair<pair<string,int>,int> p[101];
    
    for(int i = 0;i < N;i++){
        string S;
        int P;
        cin >> S >> P;
        
        p[i] = make_pair(make_pair(S,-P),i);
    }
    
    sort(p,p + N);
    
    for(int i = 0;i < N;i++){
        cout <<p[i].second + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    string S;
    cin >> S;
    set<char> A;
    for (int i = 0; i < 3; i++){
        A.insert(S.at(i));
    }
    if (A.size() == 2){
      cout << "Yes" << endl;  
    }
    else{
        cout << "No" << endl;
    }
    
}


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

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

  for(int i=0;  i<19; i++){
    if(s.at(i)==','){
      cout << ' ';
    }
    else{
      cout << s.at(i);
    }
  }
  cout << endl;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int d, n;
  n = 26;
  cin >> d;
  vi c(n);
  rep(i, n) cin >> c[i];
  int ca = 0;
  rep(i, n) ca += c[i];
  dump(ca);
  vvi s(d, vi(n));
  rep(i, d) rep(j, n) cin >> s[i][j];
  ll sc = 0;
  vi l(n, -1);
  rep(i, d) {
    vl g(n);
    rep(j, n) {
      g[j] = s[i][j];
      rep(k, n) {
        if (j == k) {
        } else {
          g[j] -= (ll)c[k] * (i - l[k]);
        }
      }
    }
    int mi = 0;
    ll mx = g[0];
    rep(j, n) {
      if (mx < g[j]) {
        mx = g[j];
        mi = j;
      }
    }
    sc += mx;
    l[mi] = i;
    dump(g, mi, sc);
    cout << mi + 1 << endl;
  }
  dump(sc);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 3708
n = int(input())
a = list(map(int, input().split()))
ave = sum(a) // len(a)
ans1 = 0
ans2 = 0
for i in a:
  ans1 += (i - ave) ** 2
  ans2 += (i - ave - 1) ** 2
print(min(ans1, ans2))
  



Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
ll a[100005];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll count = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] < a[i + 1]) {
			while (i + 1 < n && a[i] <= a[i + 1]) {
				i++;
			}
			
		}
		else if (a[i] > a[i + 1]) {
			while (i + 1 < n && a[i] >= a[i + 1]) {
				i++;
			}
			
		}
		else {
			while (i + 1 < n && a[i] == a[i + 1]) {
				i++;
			}
			i--;
			continue;
		}
		count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

   rep(c, 10000) if(c*8/100==a && c*10/100==b){
      cout<<c<<endl;
      return 0;
   }
   cout<< (-1) <<endl;
   return 0;
}


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

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

	if ((a < c) && (b > c)) {
		cout << "Yes" << endl;
	}
	else if ((b < c) && (a > c)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int a, b;
    cin >> a >> b;
    if (a == b)
        cout << a * 2;
    else if (a > b)
        cout << a + (a - 1);
    else
        cout << b + (b - 1);
}

Measured memory_bytes: 3652
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    total += a[i]

tar = total / n

d = tar
ans = 0
for i in range(n):
    k = abs(tar - a[i])
    if(k < d):
        d = k
        ans = i

print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){ 
    string S;
    cin >> S;
    if(S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
        cout << "Yes" << endl;
}
else {
    cout << "No" << endl;
}
    
}


Measured memory_bytes: 3532
#include <iostream>
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  if(y&1){
  	cout << "No\n";}
  else if(2*x<=y and 4*x>=y){	cout << "Yes\n";}
  else	cout << "No\n";
  return 0;
}

Measured memory_bytes: 3584
S = input()
A = ['dream', 'dreamer', 'erase' ,'eraser' ]
A_re = []

S_re = list(reversed(S))
for i in range(0, 4):
    A_re.append(''.join(list(reversed(A[i]))))

can = True
i = 0

while i < len(S):
    can2 = False
    for j in range(0, 4):
        d = A_re[j]
        S_word = ''.join(S_re[i:(i + len(d))])
        if S_word == d:
            can2 = True
            i += len(d)
            break

    if can2 == False:
        can = False
        break

if can == True:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 2e9;

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

  vector<string> res;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= k; j++) {
      res.emplace_back(s.substr(i, j));
    }
  }
  sort(res.begin(), res.end());
  res.erase(unique(res.begin(),res.end()),res.end());
  cout << res[k-1] << endl;
  return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9+7;

int main(){
    int n;
    cin>>n;
    ll h[n];
    bool flag=true;
    int cnt=0;
    for(int i=0;i<n;i++)cin>>h[i];
    if(h[0]>=h[1])h[0]--;
    for(int i=0;i<n-1;i++){
        if(h[i]>=h[i+1]&&h[i]-1>=h[i-1])h[i]--;
    }
    for(int i=0;i<n-1;i++){
        if(h[i]<=h[i+1])cnt++;
    }
    
    // for(int i=0;i<n;i++){
    //     cout<<h[i]<<" ";
    // }
    if(cnt==n-1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=1e5+10,MOD=1e9+7;
int n,x,res[MAXN];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		int rk=(n-1+x)/2;
		if(!res[rk+1]) res[rk+1]=i;
		else if(!res[n-rk]) res[n-rk]=i;
		else return puts("0"),0;
	}
	int res=1;
	for(int i=1;i<=n/2;i++) (res*=2)%=MOD;
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

   int x,y;
   cin >> x >> y;
   cout << x+y/2 << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
T = input().split()
M = int(input())

for i in range(N):
   T[i] = int(T[i])

S = sum(T)

for i in range(M):
   l = input().split()
   print(S - (T[int(l[0]) - 1] - int(l[1])))

Measured memory_bytes: 9136
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int edge[N][N];
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      edge[i][j] = false;
    }
  } 
  for(int i=0;i<M;i++){
    int a, b;
    cin >> a >> b;
    edge[a-1][b-1] = true;
    edge[b-1][a-1] = true;
  }

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

  int ans = 0;
  do{
    /*for(int i=0;i<N;i++) cout << vertex[i] << " ";
    cout <<endl;*/
    bool judge = true;
    for(int i=0;i<N-1;i++){
      if(!edge[vertex[i]][vertex[i+1]]){
        judge = false;
        break;
      }
    }
    if(judge){
      ans++;
    }
  }while(next_permutation(vertex+1,vertex+N));

  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
// 5/30
// 2-6-1. 線分状の格子点の個数
// 類題
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;

ll gcd(ll a, ll b) {  // bが常にワル役
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;  // 先に割ることでオーバーフローを防げる
}

// ll tri(ll a, ll b) {
//     int x = a / b;
//     int y = a & b;

    


//     // if (b == 0) return a;

//     // return tri(b, a % b) + b;
// }

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

    ll ans = N;

    ll a = max(N - X, X);
    ll b = min(N - X, X);  // 本当はたぶんa, bはどちらでも良さそう。

    while (true) {
        // cout << ans << endl;
        ll x = a / b;
        ll y = a % b;

        if (y != 0) {
            ans += x * b * 2;  // 一回削るごとにカンカン、と２回bが通る。
            a = b;
            b = y;
        } else {
            ans += (x - 1) * b * 2 + b;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define fast ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int N=3002;
int dp[N][N];
int main()
{
    fast
    string a,b;
    cin>>a>>b;
    for(int i=1;i<=a.size();i++)
        for(int j=1;j<=b.size();j++){
            if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
        //length of lcs is now stored in dp (a 2d array)
    
    string ans="";
    int i=a.size(),j=b.size();
    while(1){
        if(dp[i][j]==0)break;
        while(i>0&&dp[i-1][j]==dp[i][j])i--;
        while(j>0&&dp[i][j-1]==dp[i][j])j--;
        ans+=a[i-1];
        i--;j--;
    }
    reverse(ans.begin(),ans.end());
cout<<ans;

return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define PI acos(-1)
typedef long long ll;
using namespace std;
//  Table is the complete reverse of dp

int main()
{
    cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif
    int x, y, a, b, c, z;
    priority_queue<pair<int, char> > p;
    cin >> x >> y >> a >> b >> c;
    for(int i = 0; i < a; i++)
    {
        cin >> z;
        p.push(pair<int, char>(z, 1));
    }
    for(int i = 0; i < b; i++)
    {
        cin >> z;
        p.push(pair<int, char>(z, 2));
    }
    for(int i = 0; i < c; i++)
    {
        cin >> z;
        p.push(pair<int, char>(z, 0));
    }
    z = 0;
    ll ans = 0;
    while(x + y > z)
    {
        if(!p.top().second || (p.top().second == 1 && x) || (p.top().second == 2 && y))
        {
            ans = ans + p.top().first;
            if(!p.top().second)
                z++;
            else if(p.top().second == 1)
                x--;
            else
                y--;
        }
        p.pop();
    }
    cout << ans;
}

Measured memory_bytes: 6512
import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().trim.toInt
  var root: Node = _
  val buff = ListBuffer.empty[String]
  case class Node(key: Int, var parent: Node, var left: Node, var right: Node){
    private def getDefaultKey(p: Node) = if(p == null) -1 else p.key
    override def toString: String = s"Node($key, ${getDefaultKey(parent)} ${getDefaultKey(left)} ${getDefaultKey(right)})"
  }
  
  (0 until n).foreach { _ =>
    val command = StdIn.readLine()
    command.split(' ') match {
      case Array("insert", key) => insert(Node(key.toInt, null, null, null))
      case Array("find"  , key) => 
        buff += (if(find(root, key.toInt) == null) f"no%n" else f"yes%n")
      case _ => 
        // print
        inorder(root)
        buff += f"%n"
        preorder(root)
        buff += f"%n"
    }
  }
  
  
  def insert(z: Node): Unit = {
    var y:Node = null
    var x:Node = root
    while(x != null){
      y = x
      if(z.key < x.key){
        x = x.left
      } else {
        x = x.right
      }
    }
    z.parent = y
    
    if(y == null){
      root = z
    } else if(z.key < y.key){
      y.left = z
    } else {
      y.right = z
    }
  }
  
  def preorder(n: Node): Unit = {
    buff += " " + n.key
    if(n.left != null) preorder(n.left)
    if(n.right != null) preorder(n.right)
  }

  def inorder(n: Node): Unit = {
    if(n.left != null) inorder(n.left)
    buff += " " + n.key
    if(n.right != null) inorder(n.right)
  }
  
  def find(x: Node, key: Int) = {
    var temp = x
    while(temp != null && key != temp.key){
      if(key < temp.key){
        temp = temp.left
      } else {
        temp = temp.right
      }
    }
    temp
  }
  
  print(buff.mkString(""))
}



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

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
void solve(void)
{
    int n;
    cin >> n;
    if (n < 1000)
        cout << "ABC" << endl;
    else
        cout << "ABD" << endl;
}
int main(void)
{
    solve();
}

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

int main() {
  int A,B,H,M;
  cin>>A>>B>>H>>M;
  double a,ans,PI;
  PI=3.141592653589793;
  a =30*H+0.5*M-6*M;
  ans = sqrt(A*A+B*B-2*A*B*cos(a*PI/180.0));
  cout << fixed << setprecision(20);
  cout<<ans<<endl;
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int a[N], b[N];
    rep(i, N) cin >> a[i] >> b[i];
    int c[M], d[M];
    rep(i, M) cin >> c[i] >> d[i];
    int minimum = INF2;
    int min_ID = 0;
    rep(i, N) {
        minimum = INF2;
        min_ID = 0;
        rep(j, M) {
            int distance = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (minimum > distance) {
                minimum = distance;
                min_ID = j;
            }
        }
        cout << min_ID + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll N,K;
vec d;
vec m;

ll Solve(ll a,ll T){
    //cout<<a+1<<' '<<T<<endl;
    if(!T) return a;
    if(m[a]<0) {
        m[a]=T;
        return Solve(d[a],T-1);
    }
    ll F=m[a]-T;
    if(T>F) return Solve(a,T%F);
    return Solve(d[a],T-1);
}
int main(){
    cin>>N>>K;
    rep(i,N){
        ll x; cin>>x; x--;
        d.pb(x);
    }
    rep(i,N) m.pb(-1);
    cout<<Solve(0,K)+1<<endl;

}

Measured memory_bytes: 7952
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const long long INF = 1LL << 60;
const int MOD = 1000000007;
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
template <class T> inline bool chmin(T &a, T b) { if ( a > b ) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T &a, T b) { if ( a < b ) { a = b; return 1; } return 0; }
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int N;
ll dp[100100][3];
int S[100100][3];


int main(int argc, char *argv[]){
    cin >> N;
    rep(i, N) cin >> S[i][0] >> S[i][1] >> S[i][2];
    rep(i, N){
        rep(j, 3){
            rep(k, 3){
                if(j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + S[i][k]);
            }
        }
    }
    ll res = 0;
    rep(i, 3) chmax(res, dp[N][i]);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
int main(void){
    int d;
    scanf("%d",&d);
    switch (d){
        case 25:
            printf("Christmas\n");
            break;
        case 24:
            printf("Christmas Eve\n");
            break;
        case 23:
            printf("Christmas Eve Eve\n");
            break;
        case 22:
            printf("Christmas Eve Eve Eve\n");
            break;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int a, b, m;
	scanf("%d %d %d", &a, &b, &m);
	V A(a), B(b);
	ll mina = 1e9, minb = 1e9;
	REP(i, 0, a){
		scanf("%ld", &A[i]);
		mina = std::min(mina, A[i]);
	}
	REP(i, 0, b){
		scanf("%ld", &B[i]);
		minb = std::min(minb, B[i]);
	}
	ll ans = mina + minb;
	REP(i, 0, m){
		int x, y, c;
		scanf("%d %d %d", &x, &y, &c);
		ans = std::min(ans, A[x-1]+B[y-1]-c);
	}
	printf("%ld\n", ans);
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  int p[n];
  for(int i=0; i<n; i++)
    cin >> p[i];
  int ans=0;
  sort(p,p+n);
  for(int i=0; i<k; i++)
    ans += p[i];
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
pair<ll,ll> a[2005];
ll d[2005][2005];
int main(){
    ll n,ans=0;
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a+1,a+1+n);
    reverse(a+1,a+1+n);
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<=i;j++){
            ll x=n+1-(i-j),p=a[i].second,v=a[i].first;
            if(j==0&&x<n+1) d[j][x]=d[j][x+1]+abs(x-p)*v;
            else if(x==n+1&&j>0) d[j][x]=d[j-1][x]+abs(j-p)*v;
            else d[j][x]=max(d[j][x+1]+abs(x-p)*v,d[j-1][x]+abs(j-p)*v);
            ans=max(ans,d[j][x]);
        }
    }
    cout<<ans<<endl;
}   

Measured memory_bytes: 26276
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const ll MOD = 1e9 + 7;

ll pw(ll a, ll b) {
	ll ans = 1;
	while (b) {
		while (!(b & 1))
			b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD;
		--b;
	}
	return ans;
}

ll fc[10000];
ll bfc[10000];

void init() {
	fc[0] = 1;
	for (int i = 1; i < 10000; ++i)
		fc[i] = (fc[i - 1] * i) % MOD;
	for (int i = 0; i < 10000; ++i)
		bfc[i] = pw(fc[i], MOD - 2);
}

ll cnk(int n, int k) {
	return fc[n] * bfc[k] % MOD * bfc[n - k] % MOD;
}
const int MX = 2100;
int n;
ll arr[MX * 2][MX * 2];


int main() {
	init();
	scanf("%d", &n);
	ll ans = 0;
	vector<pair<int, int> > vv;
	for (int i = 0; i < n; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		++arr[MX - a][MX - b];
		vv.push_back(make_pair(a, b));
		ans = (ans + MOD - cnk(2 * a + 2 * b, 2 * b)) % MOD;
	}
	for (int i = 1; i < MX * 2; ++i)
		for (int j = 1; j < MX * 2; ++j)
			arr[i][j] = (arr[i][j] + arr[i - 1][j] + arr[i][j - 1]) % MOD;
	for (int i = 0; i < (int)vv.size(); ++i) {
		ans = (ans + arr[vv[i].first + MX][vv[i].second + MX]) % MOD;
	}
	ans = (ans * pw(2, MOD - 2)) % MOD;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 139888
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b,i,x=0;
    cin>>k>>a>>b;
    for(i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK"<<endl;
            x=0;
            break;
        }
        else
        {
            x=1;
        }

    }
    if(x==1)
        cout<<"NG"<<endl;
}


Measured memory_bytes: 3628