akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define inf (int)(3e18)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}


signed main() {
	double L;
	cin>>L;
	printf("%.12lf\n",pow(L/3,3));
}



Measured memory_bytes: 256
def get_half_dividers(n):
    return {i for i in range(1, int(n ** 0.5) + 1) if n % i == 0}


N = int(input())

dividers = get_half_dividers(N)
print(min([max(0, d - 1) + max(0, (N // d) - 1) for d in dividers]))


Measured memory_bytes: 3316
s = input()
s_split = [s[i] for i in range(len(s))]
result = 0

for i in range(2**(len(s)-1)):
    b = bin(i)[2:]
    b = b.zfill(len(s)-1)
    tmp = s_split.copy()

    for j in range(len(b)-1, -1, -1):
        if b[j] == "1":
            tmp.insert(-j-1, "+")


    result += eval("".join(tmp))
print(result)

Measured memory_bytes: 3064
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')
  const N = Number(input[0])
  const L = input[1].split(' ').map(n => Number(n)).sort((a, b) => b - a)
  let sum = 0
  for (let i = 1; i < N; i++) {
    sum += L[i]
  }
  if (L[0] < sum) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 22076
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
  sort(a.begin(),a.end());
  if(a.at(0)==a.at(N-1)){
  if(a.at(0)==N-1 || 2*a.at(0)<=N)
    cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }else if(a.at(N-1)-a.at(0)==1){
     int A=a.at(0); int B=a.at(N-1);
    map<int,int>M; M[A]=0; M[B]=0;
    for(int i=0;i<N;i++)
      if(a.at(i)==A)
        M.at(A)++;
    else
      M.at(B)++;
    int k=M.at(A);
    if(B-k<=0)
      cout<<"No"<<endl;
    else{
     if(2*B-k<=N)
       cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
    }
  }else
    cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
	char ch = getchar(); x = 0;
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 1e5 + 10;
int n, q, sum, a[N], c[N]; 
signed main() {
	read (n);
	for (int i = 1; i <= n; ++i) read (a[i]), ++c[a[i]], sum += a[i];
	read (q);
	for (int i = 1, x, y; i <= q; ++i) {
		read (x), read (y);
		sum = sum - x * c[x] + y * c[x];
		c[y] += c[x], c[x] = 0;
		printf ("%lld\n", sum);
	}
	return 0;
}

Measured memory_bytes: 5308
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


ll gcd (ll a, ll b){ return b == 0? a : gcd(b, a % b); }
ll lcm (ll a, ll b){ return a * (b / gcd(a, b));}

ll nrPow2(ll x){
    ll cnt = 0;
    while(x%2==0 && x>0){
        cnt++;
        x/=2;
    }
    return cnt;
}

void solve(long long N, long long M, std::vector<long long> a){
    map<ll, ll> rec;
    REP(i, N) {
        rec[nrPow2(a[i])]++;
        a[i]/=2;
    }
    if(rec.size()>1){
        cout<<0<<endl; return;
    }

    ll T = a[0];
    REP(i, N-1){
        T = lcm(T, a[i+1]);
        if(T > M){
            cout<< 0<<endl; return;
        }
    }
    //cout<<"T: "<< T<<endl;
    if(T == 1){
        cout<<(M-1)/2 + 1<<endl;return;
    }
    cout<<(M/T - 1)/2 + 1<<endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, M, std::move(a));
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
    int i,n,b=0;
    double a,c,d;
    cin >> n;
    for(i=1;i<=n;i++){
        if(i%2!=0){
            b++;
        }
    }
    a = n;
    c = b;
    d = c/a;
    cout << d;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double PI=3.14159265358979323846;

int main(void){
    string n;
    cin >> n;
    for(int i = 0; i < n.size(); i++){
        if(n[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3596
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self):
		# ????????¶???
		self.dice = (2, 5), (3, 4), (1, 6) # x, y, z
		self.ax = [[0, False], [1, False], [2, False]]
		self.axmap = [0, 1, 2]
		self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (1, 0)}

	def rotate(self, dir):
		def rot(k, r):
			t = self.axmap[r]
			self.axmap[k], self.axmap[r] = t, self.axmap[k]
			self.ax[t][1] = not self.ax[t][1]

		rot(*self.mm[dir])

	def front(self): return self.value(0, True)
	def rear(self): return self.value(0, False)
	def right(self): return self.value(1, True)
	def left(self): return self.value(1, False)
	def top(self): return self.value(2, True)
	def bottom(self): return self.value(2, False)
	def value(self, ax, d):
		a = self.ax[self.axmap[ax]]
		return self.dice[a[0]][a[1] if d else not a[1]]

if __name__=="__main__":
	dice = Dice()
	labels = input().split()
	q = int(input())
	def tf(p, f, d):
		for _ in range(4):
			if p==f(): break
			dice.rotate(d)

	for _ in range(q):
		a, b = input().split()
		p = labels.index(a) + 1
		f = dice.top
		tf(p, f, "N")
		tf(p, f, "E")
		
		p = labels.index(b) + 1
		f = dice.front
		tf(p, f, "R")

		print(labels[dice.right()-1])

Measured memory_bytes: 7768
function bomb(y,x){
   var AG="ABCDEFG".split("");
   for(var i=0;i<7;i++){
      var dx,dy;
      if(i==0){dx=[0,1,0,1];dy=[0,0,1,1];}
      else if(i==1){dx=[0,0,0,0];dy=[0,1,2,3];}
      else if(i==2){dx=[0,1,2,3];dy=[0,0,0,0];}
      else if(i==3){dx=[1,0,1,0];dy=[0,1,1,2];}
      else if(i==4){dx=[0,1,1,2];dy=[0,0,1,1];}
      else if(i==5){dx=[0,0,1,1];dy=[0,1,1,2];}
      else if(i==6){dx=[1,2,0,1];dy=[0,0,1,1];}
      var cnt=0;
      for(var j=0;j<4;j++){
         var yy=y+dy[j];
         var xx=x+dx[j];
         if(yy<0 || yy>=8 || xx<0 || xx>=8)break;
         if(yx[yy][xx]=="1")cnt++;
         if(cnt==4){console.log(AG[i]);return;}
      }
   }
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=0;
var yx=[];
for(var i=0;i<Arr.length;i++){
   yx.push(Arr[i].split(""));
   n++;
   if(n!=8)continue;
   for(var y=0;y<8;y++){
      for(var x=0;x<8;x++){
         bomb(y,x);
      }
   }
   yx=[];
   n=0;
   i++;
}

Measured memory_bytes: 9936
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	string s;
	cin >> s;

	long long n = s.length(), i, j, k, MOD = 2019, x, ans;
	vector<long long> v(n + 2);
	v[n + 1] = 0;
	map<long long, long long> ct;
	ct[0]++;
	x = 1;
	for (i = n; i >= 1; i--) {
		v[i] = (v[i + 1] + (x * (s[i - 1] - '0'))) % MOD;
		ct[v[i]]++;
		x = (x * 10) % MOD;
	}

	ans = 0;
	for (auto p : ct) ans += p.second * (p.second - 1) / 2;

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 5048
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    sort(a.begin(), a.end());
    
    auto cost = [&](int p) {
        long long ret = 0;
        for (auto& e : a) {
            ret += (p-e)*(p-e);
        }
        return ret;
    };
    
    long long ans = 1e18;
    for (int i = a[0]; i <= a[n-1]; i++) {
        chmin(ans, cost(i));
    }
    
    cout << ans << endl;
    return 0;
}

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

int solve(int num)
{
  int re=0;
  while(num)
  {
    re++;
    num/=10;
  }
  return re;
}
  
int main()
{
  int N,ans=0;
  cin>>N;
  for(int i=1;i<=N;i++)
    if(solve(i)&1) ans++;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
program sample
    implicit none
  
    integer(8) :: i,j,m,n,t,x(3),y(3),z(3)
   
  
    read(*,*)x
    
    read(*,*)y
    read(*,*)z
    if(x(1)+y(2)+z(3)==x(2)+y(3)+z(1) .and. x(1)+y(2)+z(3)==x(3)+y(1)+z(2))then
        if (x(1)+y(3)+z(2)==x(2)+y(1)+z(3) .and. x(3)+y(2)+z(1)==x(2)+y(1)+z(3))then
            write(*,*)'Yes'
            stop
        end if
    end if

    write(*,*) 'No'
  
    stop
end program sample
  



Measured memory_bytes: 2832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
//typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

typedef pair<int , int> P;//<最短距離, 頂点番号>
#define MAX_V 100005
struct edge {int to; ll cost; };
ll V;//頂点数
vector<edge> G[MAX_V];
ll d[MAX_V];//頂点sからの最短距離

void dijkstra(int s) {
    //greater<P>を指定し.fsを小さい順に取り出す
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.sc;
        if(d[v] < p.fs) continue;
        rep(i,G[v].size()) {
            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 main() {
    cin >> V;
    rep(i, V - 1) {
        int a, b; ll c;
        cin >> a >> b >> c;
        a--; b--;
        edge e = {b, c};
        G[a].pub(e);
        edge f = {a, c};
        G[b].pub(f);
    }
    int Q, K; cin >> Q >> K; K--;

    dijkstra(K);

    rep(i,Q) {
        int x, y; cin >> x >> y; x--; y--;
        ll ans = d[x] + d[y];
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    int N; cin >> N;
    vector<int> nums(N);
    for (int i=0; i<N; i++){
        cin >> nums.at(i);
    }
    int temp_min=999999999;
    for (int now=-100; now<=100; now++){
        int cost=0;
        for (int n: nums){
            cost+=(n-now)*(n-now);
        }
        temp_min=min(temp_min, cost);
    }
    cout << temp_min;
    return 0;
}

Measured memory_bytes: 256
n = input()
nums = [int(num) for num in input().split()]

elems = [2 ** i for i in range(100)]

num_even = 0
cnt = 0
for i, e in enumerate(elems):
    for num in nums:
        num_even += num % e
    if num_even > 0:
        break
    else:
        cnt = i

print(cnt)


Measured memory_bytes: 2940
#include <stdio.h>
#include <algorithm>

int h, w;
int a[1401][1401];
int dp[1401][1401];

int main()
{
	scanf("%d%d", &h, &w);
	int res = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
		{
			scanf("%d", &a[i][j]);
			dp[i][j] = !a[i][j];
			res |= dp[i][j];
		}

	for (int i = 1; i < h; i++)
		for (int j = 1; j < w; j++)
		{
			if (a[i][j] == 0)
				dp[i][j] = std::min(std::min(dp[i - 1][j - 1], dp[i - 1][j]), dp[i][j - 1]) + 1;
			res = std::max(res, dp[i][j]);
		}

	printf("%d\n", res * res);

	return 0;
}



Measured memory_bytes: 17904
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

using namespace std;

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

int main(){
    int n, l;
    cin >> n >> l;
    vector<int> a(n+4);
    rep(i, n){
        cin >> a[i+2];
    }
    a[0] = 0;
    a[1] = 0;
    a[n+2] = 0;
    a[n+3] = 0;
    priority_queue< pair<int, int> > que;
    REP(i, 2, n+2){
        if(a[i-1] < a[i] && a[i] > a[i+1]){
            que.push(make_pair(a[i], i));
        }
    }
    int ans;
    while(!que.empty()){
        auto t = que.top();
        que.pop();
        ans = l - t.first;
        a[t.second] = 0;
        if(a[t.second-2] < a[t.second-1]){
            que.push(make_pair(a[t.second-1] - ans, t.second - 1));
        }
        if(a[t.second+1] > a[t.second+2]){
            que.push(make_pair(a[t.second+1] - ans, t.second + 1));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3888
n,m = gets.split(' ').map(&:to_i)
l = []
m.times do
  l << gets.split(' ').map(&:to_i)
end

ans = Array.new(n)

if l.include?([1, 0])
  if n == 1
    puts 0
  else
    puts -1
  end
else
  f = true
  l.uniq.each do |v|
    if ans[v[0]-1] != nil
      f = false
      break
    end

    ans[v[0]-1] = v[1]
  end
  
  ans.each_with_index do |v,i|
    if v.nil?
      if i == 0 and n == 1
        ans[i] = 0
      elsif i == 0 and n != 0
        ans[i] = 1
      else
        ans[i] = 0
      end
    end
  end

  if f
    puts ans.join('')
  else
    puts -1
  end
end



Measured memory_bytes: 1788
#include <stdio.h>

int main()
{
    int N; scanf("%d", &N);
    int P = 0, W = 0, G = 0, Y = 0;
    for (int i=0; i<N; i++) {
        char color;
        scanf(" %c", &color);
        if (color == 'P') P = 1;
        if (color == 'W') W = 1;
        if (color == 'G') G = 1;
        if (color == 'Y') Y = 1;
    }
    char *color_str[] = {"", "", "", "Three", "Four"};
    printf("%s\n", color_str[P + W + G + Y]);
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
class LCA:
    def __init__(self,V,edges,depth,parent,root=0):
        self.edges=edges
        self.maxLog=18
        self.parent=[[-1]*V for _ in range(self.maxLog+1)]
        self.parent[0]=parent
        self.depth=depth
        for i in range(self.maxLog):
            for j in range(V):
                if self.parent[i][j]!=-1:
                    self.parent[i+1][j]=self.parent[i][self.parent[i][j]]
    def lca(self,a,b):
        if self.depth[a]>self.depth[b]:
            a,b=b,a
        for i in range(self.maxLog):
            if (self.depth[b]-self.depth[a])&(1<<i):
                b=self.parent[i][b]
        if a==b:
            return b
        for i in reversed(range(self.maxLog-1)):
            if self.parent[i][a]!=self.parent[i][b]:
                a=self.parent[i][a]
                b=self.parent[i][b]
        return self.parent[0][a]

from collections import deque
def Eulertour(Edges,n,root=0):
    Euler=[]
    Depth=[-1]*n
    Depth[root]=0
    Parent=[-1]*n
    que=deque([root])
    que2=deque()
    Visited=[False]*n
    while que:
        fr=que.pop()
        Euler.append((Depth[fr],fr))
        if Visited[fr]:
            continue
        for to in Edges[fr]:
            if Visited[to]:
                que.append(to)
            else:
                Depth[to]=Depth[fr]+1
                Parent[to]=fr
                que2.append(to)
        que.extend(que2)
        que2=deque()
        Visited[fr]=True
    return Euler,Depth,Parent

n,q=map(int,input().split())
Edgedict=[dict() for _ in range(n)]
for _ in range(n-1):
    a,b,c,d=map(int,input().split())
    a-=1; b-=1
    Edgedict[a][b]=(c,d)
    Edgedict[b][a]=(c,d)
Queries=[tuple(map(int,input().split())) for _ in range(q)]
Euler,Depth,Parent=Eulertour(Edgedict,n)
lca=LCA(n,Edgedict,Depth,Parent)
Q=[[] for _ in range(n)]
for i,(x,y,u,v) in enumerate(Queries):
    u-=1; v-=1
    Q[u].append([i,x,y,True])
    Q[v].append([i,x,y,True])
    Q[lca.lca(u,v)].append([i,x,y,False])
Ans=[0]*q
dist=0
C_len=[0]*n
C_cnt=[0]*n
for i in range(1,len(Euler)):
    idx=Euler[i][1]
    c,l=Edgedict[Euler[i-1][1]][idx]
    if Euler[i-1][0]<Euler[i][0]:
        dist+=l
        C_len[c]+=l
        C_cnt[c]+=1
        for q_idx,x,y,flag in Q[idx]:
            if flag:
                Ans[q_idx]+=dist+C_cnt[x]*y-C_len[x]
            else:
                Ans[q_idx]-=(dist+C_cnt[x]*y-C_len[x])*2
    else:
        dist-=l
        C_len[c]-=l
        C_cnt[c]-=1
print(*Ans,sep='\n')

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

int main(){
  int n,gold;
  int res10000=-1,res5000=-1,res1000=-1;
  cin >> n >> gold;
  for(int x = 0;x <= n;x++){
    for(int y = 0;x+y <= n;y++){
      int z = n - x - y;
      int total = 10000*x + 5000*y + 1000*z;
      if(total == gold){
        res10000 = x;
        res5000 = y;
        res1000 = z;
        
      }
    }
  }
  cout << res10000 << " " << res5000 << " " << res1000 << endl;
}


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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i,1,n+1) {
    ans += to_string(i).size() % 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3748
n, m = map(int, input().split())
a = set()
for _ in range(m):
    a.add(int(input()))

dp = [0] * (n+5)
dp[0] = 1
for i in range(n):
    dp[i] %= 1000000007
    if i+1 not in a:
        dp[i+1] += dp[i]
    if i+2 not in a:
        dp[i+2] += dp[i]
print(dp[n] % 1000000007)

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

using pii = pair<int, int>;

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> v(H);
    for(int i = 0; i < H; ++i) {
        cin >> v[i];
    }

    vector<pii> now;
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(v[i][j] == '.') {
                continue;
            }
            for(int k = 0; k < 8; ++k) {
                int ny = i + dy[k];
                int nx = j + dx[k];
                if(ny < 0 || H <= ny || nx < 0 || W <= nx) {
                    continue;
                }
                v[i][j] -= v[ny][nx] == '.';
                v[i][j] = max('0', v[i][j]);
            }
        }
    }
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(v[i][j] == '0') {
                v[i][j] = '.';
                now.emplace_back(i, j);
            }
        }
    }

    int res = 0;
    while(!now.empty()) {
        vector<pii> next;
        for(auto& p : now) {
            for(int i = 0; i < 8; ++i) {
                int ny = p.first + dy[i];
                int nx = p.second + dx[i];
                if(ny < 0 || H <= ny || nx < 0 || W <= nx || v[ny][nx] == '.') {
                    continue;
                }
                v[ny][nx]--;
                v[ny][nx] = max('0', v[ny][nx]);
                if(v[ny][nx] == '0') {
                    v[ny][nx] = '.';
                    next.emplace_back(ny, nx);
                }
            }
        }
        now = move(next);
        res++;
    }

    cout << res << endl;
}


Measured memory_bytes: 3852
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	string a;
	cin >> s;
	cin >> a;
	for(int i = 0; i < s.length(); i++){
		if(s[i] != a[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 3624
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  import MapHelper._

  val n = in.readInt
  val pb = Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .toArray
  
  val map = mu.HashMap.empty[(Int,Int),Int]

  for {
    a <- pb
    b <- pb
    if (a(0) != b(0)) || (a(1) != b(1))
  } {
    val x = a(0) - b(0)
    val y = a(1) - b(1)
    map.addOrUpdate((x, y), 1)
  }


  val t = if(map.nonEmpty) map.maxBy(_._2)._2 else 0

  val ans = n - t
  println(ans)

  object MapHelper {
    implicit class AddOrUpdate[A](map:mu.HashMap[(Int,Int),Int]) {
      def addOrUpdate(key:(Int,Int), value:Int):mu.HashMap[(Int,Int),Int] =
      {
        if(map.contains(key)) map(key) += value
        else map += (key -> value)
        map
      }
    }
  }
}

Measured memory_bytes: 27720
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<endl
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
bool compare(pair<ll,ll> p1,pair<ll,ll> p2){
return p1.se>p2.se;
}
void solve(){
   ll r;
   cin>>r;
   fixd(8);
   double ans=(double)2*pi*(double)r;
   cout<<ans<<endl;
}
int main()
{   fast;
    ll t=1;
    //cin>>t;
    fr(zz,1,t+1){
solve();
    }
}


Measured memory_bytes: 3788
using System;

class Program
{
    static void Main()
    {
        string[] array = Console.ReadLine().Split(' ');
        int a = int.Parse(array[0]);
        int b = int.Parse(array[1]);
        int k = int.Parse(array[2]);
        bool order = true;

        for (int i = 0; i < k; i++)
        {
            if (order)
            {
                if (a % 2 == 1) a--;
                a /= 2;
                b += a;
            }
            else
            {
                if (b % 2 == 1) b--;
                b /= 2;
                a += b;
            }
            order = !order;
        }
        Console.WriteLine(a + " " + b);
    }
}

Measured memory_bytes: 11092
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    bool isOk = false;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if(i * j == N) {
                isOk = true;
                break;
            }
        }
    }

    string ans = isOk ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll a(n); REP(i, n) cin >> a[i];
    vll dp(k+1, 0);
    rep(i, 1, k+1) REP(j, n) if (i-a[j]>=0 && dp[i-a[j]]==0) dp[i]=1;
    if (dp[k] == 1) cout << "First\n";
    else cout << "Second\n";
    return 0;
}


Measured memory_bytes: 1024
module Main where
import Data.List
import qualified Data.Vector as V

main :: IO()
main = do    
  n <- (read <$> getLine) :: IO Int
  a <- (fmap read <$> words <$> getLine) :: IO [Int]
  let l = V.fromList $ scanl' gcd 0 a
  let r = V.fromList $ reverse $ scanl' gcd 0 (reverse a)
 
  --print $ foldl max 0 $
  --  fmap (\i-> gcd (l V.! i) (r V.! (i+1))) [0..(n-1)]
        
  --print $ maximum $
  --  zipWith gcd l r

  print $ foldl max 0 $
     [ gcd (l V.! i) (r V.! (i + 1)) | i <- [0 .. ((fromIntegral n) - 1)] ]


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

const int mod = 1e9+7;

int main() 
{
	int n, k;
	scanf("%d%d", &n, &k);
	int dp[100005];
	int a[103];
	memset(dp, 0, sizeof(dp));
	dp[0] = 1;
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		vector<int> prefix(k+1, 0);
		vector<int> tmp(k+2, 0);
		for(int j = k; j >= 0; j--) {
			tmp[j+1] += dp[j];
			tmp[j+1] %= mod;
			tmp[min(k, j+x)+1] += (-1)*dp[j];
			tmp[min(k, j+x)+1] %= mod;
			if(tmp[min(k, j+x)+1] < 0) tmp[min(k, j+x)+1] += mod;
		}
		for(int j = 1; j <= k; j++) {
			prefix[j] = prefix[j-1] + tmp[j];
			// printf("___tmp[j]___ : %d\n", tmp[j]);
			prefix[j] %= mod;
		}
		for(int j = 0; j <= k; j++) {
			dp[j] += prefix[j];
			// printf("___prefix[j]___ : %d\n", prefix[j]);
			// printf("___dp[%d]___ : %d\n", i, dp[j]);
			dp[j] %= mod;
		}
	}
	if(dp[k] < 0) dp[k] += mod;
	printf("%d\n", dp[k]%mod);
}

Measured memory_bytes: 4576
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int a,b,k;

	cin >> a >> b >> k;
	FOR(i,a,min(a+k-1,b)) println(i)
	FOR(i,max(min(a+k-1,b)+1,b-k+1),b) println(i)

	return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

x,k,d=map(int,input().split())

y=abs(x)
t=y//d
if k<t:
    print(y-d*k)
else:
    s=t-k
    if s%2==0:
        print(y-d*t)
    else:
        print(abs(y-d*(t+1)))


Measured memory_bytes: 61784
#include <bits/stdc++.h>
    using namespace std;
     
    typedef long long ll;
    #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
    #define ALL(v) (v).begin(),(v).end()
    template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
    template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
    template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
    template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}
     
     
    int nextInt() { int x; scanf("%d", &x); return x;}
     
    int main2() {
      int N = nextInt();
      ll A = nextInt();
      ll B = nextInt();
      ll C = nextInt();
      ll D = nextInt();
     
      bool ans = false;
     
      for (ll i = 0; i < N - 1; i++) {
        ll x = A + (i * C) - (N - 1 - i) * D;
        // if (N <= 10) cout << x << " " << (N-1)*(D-C) << endl;
        if (x <= B && B <= x + (N-1)*(D-C)) ans = true;
      }
      cout << (ans ? "YES": "NO") << endl;
      return 0;
    }
     
    int main() {
      for (;!cin.eof();cin>>ws) main2();
      return 0;
    }
     

Measured memory_bytes: 256
def solve(n, m, a):
    ans = 0
    r = n - 1
    for l in range(n):
        while r > l and a[l] + a[r] > m:
            r -= 1
        if r <= l:
            break
        ans = max(ans, a[l] + a[r])
    print(ans if ans > 0 else 'NONE')


if __name__ == '__main__':
    while True:
        n_imput, m_imput = map(int, input().split())
        if n_imput == 0:
            break
        a_imput = sorted(list(map(int, input().strip().split())))
        solve(n_imput, m_imput, a_imput)


Measured memory_bytes: 5644
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
 
int coin[] = {10, 50, 100, 500};
 
int main()
{
    bool first = true;
 
    while(1){
        int n;
        cin >> n;
        if(n == 0)
            return 0;
 
        if(first)
            first = false;
        else
            cout << endl;
 
        vector<int> a(4);
        int sum = 0;
        for(int i=0; i<4; ++i){
            cin >> a[i];
            sum += a[i] * coin[i];
        }
 
        sum -= n;
        vector<int> b(4);
        for(int i=3; i>=0; --i){
            b[i] = sum / coin[i];
            sum %= coin[i];
        }
 
        for(int i=0; i<4; ++i){
            int ret = max(0, a[i] - b[i]);
            if(ret > 0)
                cout << coin[i] << ' ' << ret << endl;
        }
    }
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define N 100009
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define LL long long
// ios::sync_with_stdio(false);
using namespace std;
int n, cnt;
int a[N], b[N], len[N];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++)
        b[i] = a[n - i + 1];
    len[++cnt] = b[1];
    for (int i = 2; i <= n; i++)
    {
        int p = upper_bound(len + 1, len + 1 + cnt, b[i]) - len;
        if (p > cnt)
            cnt++;
        len[p] = b[i];
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4800
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int x, y;
    int gx, gy;
    
    cin >> x >> y;
    
    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
        gx = 0;
    }else if(x==4||x==6||x==9||x==11){
        gx = 1;
    }else{
        gx = 2;
    }
    
    if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
        gy = 0;
    }else if(y==4||y==6||y==9||y==11){
        gy = 1;
    }else{
        gy = 2;
    }
    
    if (gx==gy) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 764
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B =il()
    S = iss()
    print('Yes' if S[0:A].isdecimal() and S[A:A+1] == '-' and S[A+1:].isdecimal() else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

using ll = long long;

const int N = 3005;

ll dp[N][N];
ll a[N];
int n;

void solve() {
    // dp[L][R]: the max value the first player can achieve with interval L, R
    memset(dp, 0, sizeof dp);
    for (int i = 0; i < n; ++i) scanf("%d", a + i);
    for (int L = n - 1; L >= 0; --L) {
        for (int R = L; R < n; ++R) {
            if (L == R) dp[L][R] = a[L];
            dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1]);
        }
    }
    printf("%lld\n", dp[0][n - 1]);
}

int main() {
    while (~scanf("%d", &n)) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 70784
// https://atcoder.jp/contests/abc174/tasks/abc174_c
//AtCoder Beginner Contest 174
// C - Repsept

/*
Problem.
整数Kについて、レピュニット数である1, 11, 111, ...
の最小の第何項がKの倍数となるか？
ならなければ-1
Point.
レピュニット数の一般項:(10^n - 1)/9
ユークリッドの小定理よりgcd(10, K) == 1の時
10^(K-1) = 1 (mod K)
10^(K-1) - 1 = 0
よって10と互いに素なKについては、n = K-1まで見れば必ず出てくる。
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll k;
  cin >> k;
  ll now = 0;
  ll cnt = 0;
  do{
    cnt++;
    now = (10*now + 7) % k;
    if(cnt >= k) break;
  }while(now);
  if(now) cout << -1 << endl;
  else cout << cnt << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);

/// easy access -------------
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<int,int> pi;
typedef tuple<int, int, int> tp;
///-------------------------

int main()
{
    Phuong_; /// <3333
    int n;
    cin >> n;
    int dem=0;
    while (dem<n) dem+=1e3;
    cout << dem-n;
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>

int main(void) {
	char S[128];
	if (scanf("%127s", S) != 1) return 1;
	puts(strlen(S) == 6 && S[2] == S[3] && S[4] == S[5] ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=16,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;

ll n;
ll d[MAXn][MAXn];
ll dp[(1<<MAXn)];
ll pre[(1<<MAXn)];
vector<ll> v[(1<<MAXn)];
int main(){
    IOS();
	cin >> n;
	REP (i,n) REP (j,n) cin >> d[i][j];
	
	REP (I,(1<<n)) {
		REP (i,n) if ((1<<i) & I) v[I].eb(i);
	}
	REP (I,(1<<n)) {
		ll tt = 0;
		REP (i,SZ(v[I])) {
			REP (j,i) tt += d[v[I][i]][v[I][j]];
		}
		pre[I] = tt;
	}
	
	dp[0] = 0;
	REP1 (I,(1<<n)-1) {
		ll sz = SZ(v[I]);
		REP (J,(1<<sz)) {
			ll S = 0;
			REP (i,sz) if ((1<<i) & J) S += (1<<v[I][i]);
			dp[I] = max(dp[I],dp[I-S] + pre[S]);			
		}
	}
	
	cout << dp[(1<<n)-1] << endl;
}


Measured memory_bytes: 11676
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
    ll n,k;
    cin>>n>>k;
    //this ques can also be solved with map by storing the value as the div and key as the number
    //using a diff way for the current moment
    ll a[100000+1]={0};
    for(ll i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        a[x-1]+=y;
    }
    ll sum=0;
    for(ll i=0;i<100000+1;i++){
        if(sum+a[i]>=k){
            cout<<i+1<<endl;
            break;
        }else{
            sum+=a[i];
        }
    }
}    

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

typedef struct _node {
  int right, left, parent;
} node;

node tree[25];

void preorder(int id) {
  printf(" %d", id);
  if(tree[id].left != -1) preorder(tree[id].left);
  if(tree[id].right != -1) preorder(tree[id].right);
}

void inorder(int id) {
  if(tree[id].left != -1) inorder(tree[id].left);
  printf(" %d", id);
  if(tree[id].right != -1) inorder(tree[id].right);
}

void postorder(int id) {
  if(tree[id].left != -1) postorder(tree[id].left);
  if(tree[id].right != -1) postorder(tree[id].right);
  printf(" %d", id);
}

int main() {
  int i, n, id, left, right, root;

  scanf("%d", &n);
  for(i = 0;i < n;i++) {
    tree[i].parent = -1;
    tree[i].right = -1;
    tree[i].left = -1;
  }

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

  for(i = 0;i < n;i++)
    if(tree[i].parent == -1)
      root = i;

  printf("Preorder\n");
  preorder(root);
  printf("\n");

  printf("Inorder\n");
  inorder(root);
  printf("\n");

  printf("Postorder\n");
  postorder(root);
  printf("\n");

  return 0;
}



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

int main (void)
{
    int A, B, C, day = 0, sum_coin = 0;
    cin >> A >> B >> C;
    while (sum_coin < C)
    {
        day++;
        sum_coin += A;
        if (day % 7 == 0)
        {
            sum_coin += B;
        }
    }
    cout << day << endl;
}



Measured memory_bytes: 3100
#!/usr/bin/env python3


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)

if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B;
  IN(A,B);
  OUT(6-A-B);

  return 0;
}

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

namespace contest_Csharp
{
    class Program
    {
        public static (long m,long s)[,] dp;

        static void Main(string[] args)
        {
            checked
            {
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);

                var vals = Console.ReadLine().Split(' ').
                    Select(x => long.Parse(x)).ToList();

                var N = vals[0];
                var D = vals[1];
                var ans = 0;
                for (long i = 0; i < N; i++)
                {
                    var p = Console.ReadLine().Split(' ').
                    Select(x => long.Parse(x)).ToList();
                    if (p[0] * p[0] + p[1] * p[1] <= D*D)
                        ans++;
                    
                }
                
                Console.WriteLine(ans);

                Console.Out.Flush();
            }




        }
    }
}




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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    int n, x;
    cin >> n >> x;
    int m[n];
    int minV = INF;
    int sumV = 0;
    rep(i, n) {
        cin >> m[i];
        sumV += m[i];
        minV = min(minV, m[i]);
    }

    // 処理
    int ans = 0;
    ans     = (x - sumV) / minV + n;

    // 出力
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
class ModComb {
    long long *fact, *facti;
    const int mod;
public:
    explicit ModComb(int n, int m) : mod(m) {
        fact = new long long[n+1];
        facti = new long long[n+1];
        fact[0] = 1; facti[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % m;
        // calc 1/n!
        long long &inv = facti[n], pw = fact[n];
        inv = 1;
        for (int e = mod-2; e > 0; e /= 2) {
            if (e&1) inv = inv * pw % mod;
            pw = pw * pw % mod;
        }
        for (int i = n-1; i > 0; i--) facti[i] = (facti[i+1] * (i+1)) % m;
    }

    ~ModComb() {
        if (fact) delete[] fact;
        if (facti) delete[] facti;
    }

    long long get(int n, int k) const {
        if (n < 0 || k < 0 || k > n) return 0;
        return fact[n] * facti[k] % mod * facti[n-k] % mod;
    }
};

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

int modinv(int a, int m) {
    int x = m, y = a, p = 1, q = 0, r = 0, s = 1;
    while (y != 0) {
        int u = x / y;
        int x0 = y; y = x - y * u; x = x0;
        int r0 = p - r * u, s0 = q - s * u;
        p = r; r = r0; q = s; s = s0;
    }
    return q < 0 ? q + m : q;
}

constexpr int M = 1000000007;

int main() {
    int n, a, b, c; cin >> n >> a >> b >> c;
    ModComb mc(2*n, M);
    long long ans = 0;
    for (int k = 0; k < n; k++) {
        ans += mc.get(n+k-1, k) * (n+k) % M *
            ((modexp(a, n, M) * modexp(b, k, M) +
              modexp(a, k, M) * modexp(b, n, M)) % M) % M *
            100 % M * modinv(modexp(100-c, n+k+1, M), M) % M;
        // cerr << ans%M << endl;
    }
    cout << ans%M << endl;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
	int b,num;
}q[200010];
long long a[200010];
int cmp(const node&x,const node&y)
{
	if(x.b!=y.b)
	 return x.b<y.b;
	return x.num<y.num;
}
int main()
{
	int n,i,l;
	long long k,ans=0;
	scanf("%d%lld",&n,&k);
	for(i=1;i<=n;i++)
	 {
	 	scanf("%lld",&a[i]);
	 	a[i]+=a[i-1];
	 	q[i].b=(((a[i]-i)%k)+k)%k;
	 	q[i].num=i;
	 }
	sort(q+1,q+n+1,cmp);
	l=0;
	for(i=1;i<=n;i++)
	 if(q[i].b==q[i-1].b)
	  {
	  		while(q[i].num-q[l].num>=k)
	  		 l++;
	  		ans+=i-l;
	  }
	else
	 l=i;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3328
import itertools
N,M = (int(i) for i in input().split())
K = []
for i in range(M):
    J = [int(i) for i in input().split()]
    J.sort()
    K.append(J)

#1以外の頂点リストを作成
vertex = []
for i in range(N-1):
    vertex.append(i+2)
#順列作成
X = list(itertools.permutations(vertex))

#各値ごとに有無をチェック
ans = 0
for i in X:
    start = 1
    localcount = 0
    for j in i:
        tmp = [start,j]
        tmp.sort()
        if tmp in K:            
            localcount += 1   
        start = j
            
    if localcount == N-1:
        ans += 1

print(ans) 

Measured memory_bytes: 3572