akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
			import java.io.FileReader;
			import java.io.IOException;
			import java.io.InputStreamReader;
			import java.io.PrintWriter;
			import java.math.BigInteger;
			import java.util.*;
			 
			 class Main{
					    void pre() throws Exception{}
					    void solve(int TC) throws Exception{  
					 
					    	int n=ni();
					   int a[]=new int[Math.max(2,n)];
					   int ans[]=new int[Math.max(2,n)];
					   int cost=0;
					   for(int i=0;i<n;i++) {
						   a[i]=ni();
					   }

					   ans[0]=0;
					   ans[1]=Math.abs(a[1]-a[0])+ans[0];
					   for(int i=2;i<n;i++) {
					   ans[i]=Math.min(ans[i-2] + Math.abs(a[i]-a[i-2]),ans[i-1] + Math.abs(a[i]-a[i-1]) );
					   }
					   pn(ans[n-1]);
							
							
					    }
					    
							
					     
					   
	
			
	
					     
					    static boolean multipleTC = false, memory = false;
					    FastReader in;PrintWriter out;
					    void run() throws Exception{
					        in = new FastReader();
					        out = new PrintWriter(System.out);
					        int T = (multipleTC)?ni():1;
					        pre();for(int t = 1; t<= T; t++)solve(t);
					        out.flush();
					        out.close();
					    }
					    public static void main(String[] args) throws Exception{
					        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
					        else new Main().run();
					    }
					    void p(Object o){out.print(o);}
					    void pn(Object o){out.println(o);}
					    void nd(Object o){out.println(o);}
					    void pni(Object o){out.println(o);out.flush();}
					    String n()throws Exception{return in.next();}
					    String nln()throws Exception{return in.nextLine();}
					    int ni()throws Exception{return Integer.parseInt(in.next());}
					    long nl()throws Exception{return Long.parseLong(in.next());}
					    double nd()throws Exception{return Double.parseDouble(in.next());}
					    
					    class FastReader{
					        BufferedReader br;
					        StringTokenizer st;
					        public FastReader(){
					            br = new BufferedReader(new InputStreamReader(System.in));
					        }
					
					        public FastReader(String s) throws Exception{
					            br = new BufferedReader(new FileReader(s));
					        }
					
					        String next() throws Exception{
					            while (st == null || !st.hasMoreElements()){
					                try{
					                    st = new StringTokenizer(br.readLine());
					                }catch (IOException  e){
					                    throw new Exception(e.toString());
					                }
					            }
					            return st.nextToken();
					        }
					
					        String nextLine() throws Exception{
					            String str = "";
					            try{   
						                str = br.readLine();
						            }catch (IOException e){
					                throw new Exception(e.toString());
					            }  
					            return str;
					        }
					    }
			}

Measured memory_bytes: 31728
import numpy as np
import math
N = int(input())
L = []
for _ in range(N):
    temp = list(map(int,input().split()))
    L.append(np.array(temp))
A = []
for i in range(N-1):
    for j in range(i+1,N):
        u = L[i] - L[j]
        A.append(2*math.factorial(N-1)*(np.linalg.norm(u)))
A = np.array(A)
print(np.sum(A)/math.factorial(N))

Measured memory_bytes: 12392
#include<bits/stdc++.h>
using namespace std;
# ifdef DEB
# define debug(...) fprintf(stderr, __VA_ARGS__)
# else
# define debug(...)
#endif
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LL long long
#define LD long double
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define pb pop_back
#define VI vector<int> 
#define VPI vector<PII> 
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define ALL(x) (x).begin(), (x).end()
#define siz(V) ((int)V.size())
const int M = 1024 * 128;

string s[2];
int q;
int D[2][2 * M];

void add(int ind, int v, int w)
{
  v += M;
  D[ind][v] += w;
  while (v > 1)
  {
    v /= 2;
    D[ind][v] = D[ind][2 * v] + D[ind][2 * v + 1];
  }
}

int sum(int ind, int p, int k)
{
  p += M;
  k += M;
  int res = D[ind][p];
  if (p != k)
  {
    res += D[ind][k];
  }
  while (p / 2 != k / 2)
  {
    if (p % 2 == 0)
    {
      res += D[ind][p + 1];
    }
    if (k % 2 == 1)
    {
      res += D[ind][k - 1];
    }
    p /= 2;
    k /= 2;
  }
  return res;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>> s[0] >> s[1];
  for (int ind = 0; ind < 2; ind++)
  {
    for (int i = 0; i < siz(s[ind]); i++)
    {
      if (s[ind][i] == 'A')
      {
        add(ind, i, 2);
      }
      else
      {
        add(ind, i, 1);
      }
    }
  }
  cin>> q;
  for (int i = 0; i < q; i++)
  {
    int a, b, c, d;
    cin>> a >> b >> c >> d;
    if (sum(0, a - 1, b - 1) % 3 == sum(1, c - 1, d - 1) % 3)
    {
      cout<< "YES\n";
    }
    else
    {
      cout<< "NO\n";
    }
  }
  return 0;
}

Measured memory_bytes: 2512
#include<stdio.h>

long int nC2(long int n){
    return n*(n-1)/2;
}

int main(void)
{
    long int i,j;
    long int n;
    long int a[200000];
    long int b[200000];
    long int score =0;

    scanf("%ld",&n);

    for(i=1;i<=n;i++)
        b[i]=0;

    for(i=1;i<=n;i++){
        scanf("%ld",&j);
        a[i]=j;
        b[j]++;
    }

    for(i=1;i<=n;i++){
        score += nC2(b[i]);
    }

    for(i=1;i<=n;i++)
        printf("%ld\n",score - b[a[i]] +1);
    
    return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string> w(n);
	for (int i=0;i<w.size();++i) {
		cin >> w[i];
	}
	vector<string> uni = w;
	sort(uni.begin(),uni.end());
	uni.erase(unique(uni.begin(),uni.end()),uni.end());
	if (w.size() != uni.size()) {
		cout << "No\n";
		return 0;
	}

	for (int i=0;i<n-1;++i) {
		if (w[i][w[i].size()-1]!=w[i+1][0]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 256
N, M, V, P = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)

ans = P
S = A[P-1]
for i in range(P, N):
    if A[i]+M < A[P-1]:
        continue
    if V <= P-1+N-i:
        if A[i]+M >= A[P-1]:
            ans += 1
    else:
        if S+M*(V-P+1-N+i) <= (A[i]+M)*(i-(P-1)):
            ans += 1
    S += A[i]
print(ans)

Measured memory_bytes: 62704
import sys
n, y = map(int, input().split())

for i in range(n + 1):
    for j in range(n - i + 1):
        k = n - i - j
        if 10000 * i + 5000 * j + 1000 * k == y:
            print(i, j, k)
            sys.exit()

print('-1 -1 -1')

Measured memory_bytes: 40940
exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

N, Q = gets.split.map(&:to_i)
ABCDs = (N - 1).times.map{gets.split.map(&:to_i)}
XYUVs = Q.times.map{gets.split.map(&:to_i)}

@g = Array.new(N + 1){[]}
ABCDs.each{|a, b, c, d| @g[a] << [b, c, d]; @g[b] << [a, c, d]}

def euler_tour(x, d = 0, p = nil, acc = [])
  acc << [x, d]
  @g[x].each do |y, _, _|
    next if y == p
    acc = euler_tour(y, d + 1, x, acc)
    acc << [x, d]
  end
  acc
end

vds = euler_tour(1)
@tv, @td = vds.transpose
@v2i = @tv.map.with_index.to_h
@v2d = vds.to_h
s = @tv.size
@sp = [[*0 ... s]]
(1 ... s.bit_length).each do |i|
  ps = @sp[-1]
  w = 1 << (i - 1)
  n1 = ps[0 ... -w]
  n2 = ps[w .. -1]
  @sp << n1.zip(n2).map{|l, r| @td[l] < @td[r] ? l : r}
end

def lca(x, y)
  ix = @v2i[x]
  iy = @v2i[y]
  ix, iy = iy, ix if ix > iy
  items = iy - ix + 1
  l = items.bit_length - 1
  n1 = @sp[l][ix]
  n2 = @sp[l][iy - (1 << l) + 1]
  @tv[@td[n1] < @td[n2] ? n1 : n2]
end

@ts = Array.new(N + 1){[]}
XYUVs.each_with_index do |(x, y, u, v), i|
  @ts[u] << [i, x, y, 1]
  @ts[v] << [i, x, y, 1]
  @ts[lca(u, v)] << [i, x, y, -2]
end

def dfs(x = 1, ss = [0] * (N + 1), ns = [0] * (N + 1), t = 0, p = 0, acc = [0] * Q)
  @ts[x].each{|i, c, d, f| acc[i] += f * (t - ss[c] + ns[c] * d)}
  @g[x].each do |y, c, d|
    next if y == p
    ss[c] += d
    ns[c] += 1
    t += d
    dfs(y, ss, ns, t, x, acc)
    ss[c] -= d
    ns[c] -= 1
    t -= d
  end
  acc
end

puts dfs.join("\n")

Measured memory_bytes: 336140
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;
const int dx[]={1,0};
const int dy[]={0,1};
int main()
{
  int h,w,cnt=0;
  cin>>h>>w;
  vector<string> field(h);
  for(auto&& e: field) 
  {
    cin>>e;
  }

  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      if(field[i][j]=='#') cnt++;
      if(i==h-1||j==w-1) continue;
      if(field[i+1][j]=='#'&&field[i][j+1]=='#')
      {
        cout<<"Impossible"<<endl;
        return 0;
      }
    }
  }
  queue<pair<int,int>> q;
  q.push(make_pair(0,0));
  while(!q.empty())
  {
    int i=q.front().first,j=q.front().second;
    q.pop();
    if(field[i][j]=='.') continue;
    for (int k = 0; k < 2; ++k)
    {
      int ni=dx[k]+i,nj=dy[k]+j;
      if(ni<0||ni>=h||nj<0||nj>=w) continue;
      q.push(make_pair(ni,nj));
    }
    cnt--;
  }
  if(cnt==0) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  
}

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

using namespace std;

int main() {
#if DEBUG
    freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a;
    string s;
    cin >> a >> s;
    if (a < 3200) {
        cout << "red\n";
    } else {
        cout << s << '\n';
    }
}



Measured memory_bytes: 256
import re
import sys
from fractions import gcd
from functools import reduce
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    V = il()
    C = il()
    ans = 0
    for v, c in zip(V, C):
        k = v - c
        if k > 0:
            ans += k
    return ans


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 13560
#include<iostream>
using namespace std;
int main()
{
  int N,M;
  cin>>N>>M;
  int a[M],sum=0,ans;
  for(int i=0;i<M;i++)
  {cin>>a[i];
  sum+=a[i];
  }
  ans=N-sum;
  if(ans<0)
  cout<<"-1";
  else
  cout<<ans;
  
  
  return 0;
}

Measured memory_bytes: 3660
import math
a, b, h, m = map(int, input().split())
hrad = h * 30 + m * 0.5
mrad = m * 6
rad = hrad - mrad
if rad < 0:
    rad = -rad
else:
    if rad > 180:
        rad = 360 - rad
    else:
        pass
c = float((a**2 + b**2 - 2 * a * b * math.cos(math.radians(rad))) ** (0.5))
print(c)


Measured memory_bytes: 9456
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>



#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;


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

    vector <ll> A(N),B(N),C(N),Bget(N,0);

    REP(i,N)
    {
        cin >> A[i];
    }
    REP(i,N)
    {
        cin >> B[i];
    }
    REP(i,N)
    {
        cin >> C[i];
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());

    //メモ化
    //B[i]を選択したときに、何個のC[j]を選べるか

    ll ne = 0;
    REP(i,N)
    {
        if(B[i] >= C[N-1])break;

        for(ll j = ne; j < N; j++)
        {
            if(B[i] < C[j])
            {
                Bget[i] = N-j;
                ne = j;
                break;
            }

        }
    }

    //BgetSumの作成
    vector <ll> BgetSum(N+1,0);

    for(ll i = N-1; i >= 0; i--)
    {
        BgetSum[i] = BgetSum[i+1] + Bget[i];
    }

    ne = 0;
    //A[i]を選択したときに、何個のB[j]を選べるか B[j]を足し合わせる
    REP(i,N)
    {
        if(A[i] >= B[N-1])break;

        for(ll j = ne; j < N; j++)
        {
            //以降のBgetはすべて獲得できる
            if(A[i] < B[j])
            {
                res += BgetSum[j];
                ne = j;
                break;
            }
        }
    }

    cout << res << endl;

}



Measured memory_bytes: 4224
#include<iostream>
#include<algorithm>

using namespace std;

unsigned long long int i, fin, num[3];
int n;

int main(){

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

	if(n==2){
		fin = min(num[0], num[1]);
		for(i=1;i<=fin;i++){
			if(!(num[0]%i) && !(num[1]%i)){
				cout << i << endl;
			}
		}
	}

	if(n==3){
		fin = min(num[0], num[1]);
		fin = min(num[2], fin);
		for(i=1;i<=fin;i++){
			if(!(num[0]%i) && !(num[1]%i) && !(num[2]%i)){
				cout << i << endl;
			}
		}
	}

	return 0;
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    LL a,b,n;
    cin >> a >> b >> n;
    cout << floor((a*min(b-1,n))/b);
    return 0;
}


Measured memory_bytes: 3768
import sys

[N] = [int(x) for x in sys.stdin.readline().split(" ")]
Bs = [int(x) for x in sys.stdin.readline().split(" ")]
result = 0

prev_b = 999999
for i in range(N-1):
    b = Bs[i]
    result += min(prev_b, b)
    prev_b = b

result += prev_b

print(result)


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

using namespace std;

// Prioridade
typedef long long   ll;
typedef pair<ll,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i = a; i < (b); i++)
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (((a)/__gcd(a, b)) * b)

// fim da Prioridade
double dp[3002][3002];
double v[3002];
int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	REP(i,0,n){
		cin >> v[i];
	}
	dp[0][1] = v[0];
	dp[0][0] = 1-v[0];
	REP(i,1,n){
		dp[i][0] = dp[i-1][0] * (1-v[i]);
		REP(j,1,n+1){
			dp[i][j] = dp[i-1][j-1] * v[i] + dp[i-1][j] * (1-v[i]);
		}
	}
	double ans = 0;
	
	REP(i,n/2 + 1, n+1){
		ans += dp[n-1][i];
	}
	cout << setprecision(10) << fixed <<  ans << endl;
	return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,d;
    cin >> n >> d;
    int cnt;
    if(n%(2*d+1))
        cout << n/(2*d+1)+1  << endl;
    else
        cout << n/(2*d+1)  << endl;
    return 0;
}


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

int main() {
  int64_t n;
  cin >> n;
  int64_t ans = (n/11)*2, tmp = 0;
  n %= 11;
  while (tmp < n) {
    ans++;
    if (ans%2 == 1) {
      tmp += 6;
    } else {
      tmp += 5;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4000200, mod = 998244353;
int mul(long long a, long long b){
	return a * b % mod;
}
int xp(long long a, long long b){
	int r = 1;
	for(; b; b >>= 1, a = mul(a, a)) if(b&1) r = mul(r, a);
	return r;
}
int fat[maxn], ifat[maxn];
void init(){
	fat[0] = 1;
	for(int i = 1; i < maxn; i++) fat[i] = mul(i, fat[i - 1]);
	ifat[maxn - 1] = xp(fat[maxn - 1], mod - 2);
	for(int i = maxn - 2; i >= 0; i--) ifat[i] = mul(i + 1, ifat[i + 1]);
	for(int i = 0; i < maxn; i++) assert(mul(fat[i], ifat[i]) == 1);
}
int ncr(int n, int r){
	if(r > n) return 0;
	return mul(fat[n], mul(ifat[r], ifat[n - r]));
}
int distribution(int n, int m, int lim, int r2){
	int ans = 0;
	for(int i = r2; i <= min(n, lim); i += 2){
		int miss = (m - i) / 2;
		ans += mul(ncr(n, i), ncr(n + miss - 1, miss));
		if(ans >= mod)
			ans -= mod;
	}
	return ans;
}
int main(){
	init();
	int n, m; cin >> n >> m;
	int res = distribution(n, 3 * m, m, m % 2);
	res += mod - mul(n, distribution(n, m, m, m % 2));
	if(res >= mod)
		res -= mod;
	res += mul(n, distribution(n - 1, m, m, m % 2));
	if(res >= mod)
		res -= mod;
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 31488
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

#define MOD 1000000007
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	vi dp(m+1);
	int out=0;
	for(int i=m;i>0;i--){
		dp[i]=powmod(m/i,n,MOD);
		for(int j=i*2;j<=m;j+=i)(dp[i]+=MOD-dp[j])%=MOD;
		(out+=i*dp[i]%MOD)%=MOD;
	}
	cout<<out<<endl;
}












Measured memory_bytes: 3988
from pprint import pprint
from collections import deque, defaultdict

n, q = map(int, input().strip().split(" "))
edges = [[] for _ in range(n)]
for _ in range(n-1):
    a_i, b_i = map(int, input().strip().split(" "))
    edges[a_i-1].append(b_i-1)
    edges[b_i-1].append(a_i-1)

counter = [0] * n
p = [0] * n
for _ in range(q):
    p_i, x_i = map(int, input().strip().split(" "))
    counter[p_i-1] += x_i


parents = deque()
parents.append(0)
visited = set()
while parents:
    parent = parents.popleft()
    if parent in visited:
        continue
    visited.add(parent)
    for child in edges[parent]:
        if child in visited:
            continue
        counter[child] += counter[parent]
        # print("child")
        # print(child, counter[child])
        parents.append(child)

print(" ".join(list(map(str, counter))))

Measured memory_bytes: 129392
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <math.h> // sqrt()
#include <iomanip>
#define rep(i , n) for (int i = 1; i <= (int)(n); i++)
#define repz(i , n) for (int i = 0; i < (int) n; i++)
#define repi(i , r, n) for (int i = r; i <= (int)(n); i++)
#define repd(i , r, n) for (int i = r; i >= (int)(n); i--)


using namespace std;
int main(){
    int c[10000];
    int n ,t , a , b;
    cin >> n >> t;
    rep(i , n){
        cin >> a >> b;
        c[a] = b;
    }
    rep(i , 1001){
        if ( c[i] <= t && c[i] > 0) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "TLE" << endl;
    
    
    
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

class Schedular {
public:
    int D;
    vi c;
    vvi s;
    vvi hist;
    vi t;
    Schedular(int d) : D(d), c(26), s(D, vi(26)), t(D), hist(26) {
        cin >> c;
        REP(i, D)
        REP(j, 26) {
            cin >> s[i][j];
        }
    }

    void out() {
        REP(i, D) {
            cout << t[i] + 1 << endl;
        }
    }

    void init() {
        vi last(26, -1);
        int score = 0;
        REP(d, D) {
            REP(j, 26) {
                score -= c[j] * (d - last[j]);
            }
            int mx = 0;
            int ind = 0;
            REP(j, 26) {
                int diff = s[d][j] + c[j] * (d - last[j]);
                if (diff > mx) {
                    mx = diff;
                    ind = j;
                }
            }
            score += s[d][ind] + c[ind] * (d - last[ind]);
            last[ind] = d;
            t[d] = ind;
        }
    }

    int calcScore(int dN) {
        vi last(26, -1);
        int score = 0;
        REP(d, dN) {
            score += s[d][t[d]];
            last[t[d]] = d;
            REP(j, 26) {
                score -= c[j] * (d - last[j]);
            }
        }
        return score;
    }

    int replace(int d, int q) {
        assert(0 <= d && d <= D);
        assert(0 <= q && q <= 26);
    }

    void build() {
        REP(i, 26)
        hist[i].push_back(-1);
    }
};

signed main() {
    cin >> D;
    Schedular s(D);
    s.init();
    s.out();
}

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

using namespace std;

#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 All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int n;
   string s;
   cin >> n >> s;
   int cnt = 0;
   for(int i=0;i<n;i++){
      if(s[i] == '.')cnt++;
   }
   int ans = cnt;
   for(int i=0;i<n;i++){
      if(s[i] == '.')cnt--;
      else cnt++;
      ans = min(ans,cnt);
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n, y = map(int, input().split())
    y //= 1000

    for noguchi in range(n + 1):
        for higuchi in range(n + 1 - noguchi):
            yukichi = n - noguchi - higuchi
            if noguchi + higuchi * 5 + yukichi * 10 == y:
                print(yukichi, higuchi, noguchi)
                return
    
    print("-1 -1 -1")

if __name__=="__main__":
    solve()


Measured memory_bytes: 39920
#include<bits/stdc++.h>
using namespace std;
int n,m;
char c[25][25];
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
int vis[23][23];
int mx=0;
void bfs(int x,int y){
	queue<pair<pair<int,int>,int> > q;
	q.push(make_pair(make_pair(x,y),0));
	while(!q.empty()){
		pair<pair<int,int>,int> p;
		p=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int ax=p.first.first+dx[i];
			int ay=p.first.second+dy[i];
			if(ax==x&&ay==y)continue;
			if(ax>=0&&ax<n&&ay>=0&&ay<m&&c[ax][ay]=='.'&&!vis[ax][ay]){
				vis[ax][ay]=p.second+1;
				mx=max(mx,vis[ax][ay]);
				q.push(make_pair(make_pair(ax,ay),vis[ax][ay]));
			}
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>c[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(c[i][j]=='#')continue;
			bfs(i,j);
			memset(vis,0,sizeof(vis));
		}
	}
	cout<<mx<<endl;
	return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize,
    }

    let mut r = a%b;
    for i in 0..b {
        if r==c {
            println!("YES");
            return;
        }
        r = (r+a)%b;
    }
    println!("NO");
}


Measured memory_bytes: 2120
using System;
using System.Collections;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        public class TupleList<T1, T2, T3> : List<Tuple<int, int, string>>
        {
            public void Add(int item1, int item2, string s)
            {
                Add(new Tuple<int, int, string>(item1, item2, s));
            }
        }
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            List<string> input_list = new List<string>();
            for(int i = 0; i< n; i++)
            {
                input_list.Add(Console.ReadLine());
            }
            input_list.Sort();
            foreach (string s in input_list) Console.Write(s);
            Console.WriteLine();
        }
    }
}


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

P headsTail(int x) {
  int tail = x % 10;
  int heads = tail;
  while ((x / 10) != 0) {
    x /= 10;
  }
  heads = x;
  P ans(heads, tail);
  return ans;
}

int main() {
  int N;
  cin >> N;
  ll sum = 0;
  map<P, int> freq;
  for (int i = 1; i <= N; i++) {
    P p = headsTail(i);
    // 整数iにおいてのpair = {heads, tail}
    freq[p]++;
    // 例えば(1, 9)みたいなペアがあったら，その集計を1増やす
    // 存在しないキー値にアクセスすると勝手にゼロ値を代入してくれる
  }

  for (int i = 1; i<= N; i++){
    P p = headsTail(i);
    P q(p.second, p.first);
    sum += freq[q];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  S=to_string(N);
  M=S.size();
  lli DP[10][10];//DP[i][j]:=[先頭がi][末尾がj]
  rep(i,0,10)rep(j,0,10)DP[i][j]=0;
  rep(i,0,N){
    int n=i+1;
    int b=n%10;
    while(n>9)n/=10;
    int a=n;
    DP[a][b]++;
  }
  rep(i,0,10)rep(j,0,10)sum+=DP[i][j]*DP[j][i];
  Out(sum);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int n;
bool is_prime[1000000];
int prime[1000000];

int main(int argc, char const* argv[])
{
	fill(is_prime, is_prime+1000000, true);
	is_prime[0] = false;
	is_prime[1] = false;
	int res = 0;
	for(int i = 2; i < 1000000; i++){
			if(is_prime[i]){
					res++;
					for(int j = 2; j * i < 1000000; j++){
							is_prime[j * i] = false;
					}
			}
			prime[i] = res;
	}
	while(cin >> n){
			cout << prime[n] << endl;
	}
	return 0;
}



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

int main(){
vector<int> a(2);
int max = 0, sum = 0;
for (int i = 0; i < 3; i++){
cin >> a[i];
if (a[i] > max){
max = a[i];
}
sum += a[i];
}
cout << sum - max << "\n";
return 0;
}


Measured memory_bytes: 256
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define INF 1e9
#define MOD 1000000007;//1e9+7

void solve() {
    int N, ans = 0;
    cin >> N;
    vector<int>P(N+1), Min(N+1, INF);
    for (int i = 1; i <= N; i++) {
        cin >> P[i];
        Min[i] = min(P[i], Min[i - 1]);
        if (P[i] < Min[i - 1])ans++;
    }
    cout << ans;
}

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

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

int main(){
  ll N;
  cin >> N;
  cout << N*N*N << endl;
  
  return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;


void solve(long long N, long long Y){
    rep(i,N+1){
        for(int j=0;j<N+1;j++){
            if(Y==i*10000+5000*j+(N-i-j)*1000 and N-i-j>=0 ){
                cout<<i<<" "<<j<<" "<<N-i-j<<endl;
                return;
            }
        }
    }
     cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long Y;
    scanf("%lld",&Y);
    solve(N, Y);
    return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,ans=0;
    ll h,w;
    cin >> n >> h >> w;
    for(int i = 0;i < n;i ++){
        ll a,b;
        cin >> a >> b;
        if(a>=h&&b>=w) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, i, tmp;   
    while(1){
      	double devsq = 0, mean = 0, sum = 0;
        vector<int> a(0);
        scanf("%d", &n);
        if(n == 0) break;
        for(i = 0; i < n; i++){
            scanf("%d", &tmp);
            a.push_back(tmp);
            sum += tmp;
        }
        mean = sum / n;
        for(i = 0; i < n; i++){
            devsq += pow(a.at(i) - mean, 2);
        }
        printf("%.8lf\n", sqrt(devsq / n));
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

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

    if(s[2]==s[3] && s[4]==s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;

}


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

class state{
public:
  int n;
  string str;
  state():n(0),str(""){}
};

bool word(char n, char c){
  return (n == '2' && (c == 'a' || c == 'b' || c == 'c')
	  || n == '3' && (c == 'd' || c == 'e' || c == 'f') 
	  || n == '4' && (c == 'g' || c == 'h' || c == 'i') 
	  || n == '5' && (c == 'j' || c == 'k' || c == 'l')
	  || n == '6' && (c == 'm' || c == 'n' || c == 'o')
	  || n == '7' && (c == 'p' || c == 'q' || c == 'r' || c == 's')
	  || n == '8' && (c == 't' || c == 'u' || c == 'v')
	  || n == '9' && (c == 'w' || c == 'x' || c == 'y' || c == 'z'));
}

int main(){
  int n;
  while(cin >> n && n){
    vector<string> v;
    string str;
    for(int i=0;i<n;i++){
      cin >> str;
      v.push_back(str);
    }
    cin >> str;

    queue<state> Q;
    state u,s;
    Q.push(u);
    while(!Q.empty()){
      u = Q.front();
      Q.pop();

      for(int i=0;i<v.size();i++){
	int j;
	for(j=0;j<v[i].size();j++) if(j + u.n >= str.size() || !word(str[j+u.n],v[i][j])) break;
	if(j == v[i].size()){
	  s = u;
	  s.str += v[i];
	  s.n += v[i].size();
	  if(s.n == str.size()) cout << s.str << "." << endl;
	  else{
	    s.str += " ";
	    Q.push(s);
	  }
	}
      }
    }
    cout << "--" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <climits>
using namespace std;

int main(){
    int32_t N, M;
    std::cin >> N >> M;
    string S;
    cin >> S;
    constexpr int32_t INV = (1 << 20);
    vector<int> from(N+1, 0);
    vector<int> dp(N+1, INV);

    struct segment_tree {
      int NV;
      vector<pair<int,int>> dat;
      segment_tree(int N) {
        NV = 1;
        while (NV < N) NV = NV << 1;
        dat.resize(NV*2 -1);
        //cout << "sg init: NV = " << NV << endl; 
        for (int i = 0; i < NV; i++) {
          dat[i+NV-1] = make_pair(INV, i);
        }
        for (int i = NV - 2; i >=0; i--) {
          dat[i] = min(dat[i*2+1], dat[i*2+2]);
        }
      }

      void update(int idx, int val) {
        //cout << "update called: " << idx << "," << val << endl;
        if (idx < 0) return;
        idx += NV - 1;
        dat[idx] = make_pair(val, idx - NV + 1);
        //cout << idx << ":" << dat[idx].first << "," << dat[idx].second << endl;
        while (idx > 0) {
          idx = (idx - 1) / 2;
          dat[idx] = min(dat[idx*2 + 1], dat[idx*2 + 2]);
          //cout << idx << ":" << dat[idx].first << "," << dat[idx].second << endl;
        }
        return;
      }

      pair<int,int> query(int a, int b) {
        return _query(a, b, 0, 0, NV);
      }
      pair<int,int> _query(int a, int b, int k, int l, int r) {
        //cout << "query called :" << a << "," << b << "," << k << "," << l << "," << r << endl;
        if (r <= a || b <= l) return make_pair(INV, INV);
        if (a <= l && r <= b) return dat[k];
        else {
          pair<int,int> vl = _query(a, b, k*2 + 1, l, (l + r) / 2);
          pair<int,int> vr = _query(a, b, k*2 + 2, (l + r) / 2, r);
          //cout << "querry return val: " << min(vr,vl).first << "," << min(vr,vl).second << endl;
          return min(vr, vl);
        }
      }
    };

    segment_tree sg(N);
    dp[N] = 0;
    sg.update(N-1, 0);
    for (int i = N - 1; i >= 0; i--) {
      if (S[i] == '1') continue;
      //pair<int,int> q = sg.query(i, min(i+M, N) , 0, 0, N);
      pair<int,int> q = sg.query(i, min(i+M, N));
      //cout << "query res: " << q.first << "," << q.second << endl;
      dp[i] = q.first + 1;
      sg.update(i-1, q.first + 1);
      from[i] = q.second + 1;
      //for (int j = i + 1; j <= N && j - i <= M; j++) {
      //  if (dp[i] > dp[j] + 1) {
      //    dp[i] = dp[j] + 1;
      //    from[i] = j;
      //  }
      //}
    }

    if (dp[0] >= INV) {
        cout << "-1" << endl;
        return 0;
    }
    int cur = 0;
    while (cur < N) {
      cout << from[cur] - cur << " ";
      cur = from[cur];
    }
    cout << endl;
                   
    return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
int op[maxn],a[maxn],str[30];
int dp[1<<26];
#define inf  999999
int main()
{
    string s;
    int n;
    cin>>s;
    n=s.size();
    memset(str,0,sizeof(str));
    for(int i=0;i<n;i++){
        int bit=0;
        str[s[i]-'a']++;
        for(int j=0;j<26;j++){
             if(str[j]%2){
                 bit+=(1<<j);
             }
        }
        a[i+1]=bit;//表示前i个长度的字串，都有哪些字母是奇数个;
    }
   for(int i=0;i<1<<26;i++){
		dp[i] = inf;//表示在i状态下，能够满足题意得最少分解数目
	}
	for(int i=0;i<=n;i++) op[i] = inf;
    dp[0]=0;
    for(int i=1;i<=n;i++){
        op[i]=min(op[i],dp[a[i]]+1);//最差的情况是前i-1的最佳结果加上1
        for(int j=0;j<26;j++){
            op[i]=min(op[i],dp[a[i]^(1<<j)]+1);//转移到（异或上任意一个字符再加上当前字符就最小）的那个状态
        }
        dp[a[i]]=min(dp[a[i]],op[i]);//更新当前状态
    }
    cout<<op[n]<<endl;
    return 0;
}


Measured memory_bytes: 264324
/*
Author : N_o_o_B
Created : March 22 2020 17:36:17 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;


    ll l;
    cin >> l;
    ld ans  = 0;
    ld len = l*1.00/3;
    ans = len*len*len;
    cout << ans << endl;


    time_taken();
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int A = stoi(s.substr(0, 2));
    int B = stoi(s.substr(2, 2));
    if (1 <= A && A <= 12 && 1 <= B && B <= 12) {
        cout << "AMBIGUOUS" << endl;
    } else if (1 <= A && A <= 12) {
        cout << "MMYY" << endl;
    } else if (1 <= B && B <= 12) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

int main()
{
	char b,ret;
	cin >> b;

	switch (b)
	{
	case 'A':ret = 'T'; break;
	case 'C':ret = 'G'; break;
	case 'G':ret = 'C'; break;
	default:ret = 'A'; break;
	}

	cout << ret << endl;

	return 0;
}

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

int main(void)
{
  int n;
  cin >> n;
  double cnt = 0;
  for(int i = 1; i <= n; i++)
  {
    if(i % 2 == 1)
      cnt++;
  }
  cout << fixed << setprecision(15);
  cout << cnt / n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#define lop(i,n) for(int i=0;i<n;i++)
#define lop1(i,n) for(int i=1;i<=n;i++)
#define lopr(i,n) for(int i=n-1;i>=0;i--)
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second    
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define sz(x) (ll)x.size()
#define M1 1000000007
#define M2 998244353
#define I1 1000000001
#define I2 1000000000000000001
#define pb push_back
#define asort(v) sort(v.begin(),v.end())
#define dsort(v) sort(v.begin(),v.end(),greater<int>())
using namespace std;
int main()
{
    IOS;
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
   string s;
   cin>>s;
   if(s[sz(s)-1]=='s'){cout<<s<<"es";}
   else{cout<<s<<"s";}


}
    

   
  

     




       
     


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

using namespace std;

#define endl '\n'
#define MAX 1500

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

char board[MAX][MAX];
int dp[MAX][MAX];
int L[MAX][MAX];
int R[MAX][MAX];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
		
    int n,m;
    cin >> n >> m;

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> board[i][j];

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
            if(board[i][j] == '1')
                dp[i][j] = 0;
            else
                dp[i][j] = 1 + dp[i - 1][j];
        }

    for(int i = 1; i <= n; i++){
        stack<int> st;
        for(int j = 1; j <= m; j++){
            while(!st.empty() && dp[i][st.top()] >= dp[i][j])
                st.pop();
            if(st.empty())
                L[i][j] = 1;
            else
                L[i][j] = st.top() + 1;
            st.push(j);
        }
    }

    for(int i = 1; i <= n; i++){
        stack<int> st;
        for(int j = m; j >= 1; j--){
            while(!st.empty() && dp[i][st.top()] >= dp[i][j])
                st.pop();
            if(st.empty())
                R[i][j] = m;
            else
                R[i][j] = st.top() - 1;
            st.push(j);
        }
    }

    int solve = 0;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
            if(dp[i][j] == 0)
                continue;
            int size = R[i][j] - L[i][j] + 1;
            int rectangle_size = size * dp[i][j];

            solve = max(solve,rectangle_size);
        }

    cout << solve << endl;

	return 0;
}


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

int main(){
  int N,X;cin>>N>>X;
  vector<int> m(N);
  int cnt=0;
  rep(i,N){
    cin>>m[i];
    cnt+=m[i];
  }
  int ans=N;
  X-=cnt;
  sort(m.begin(),m.end());
  ans+=X/m[0];
  cout<<ans<<endl;
}
  

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

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

void solve_abc_c() {
	ll n, t;
	ll ans = 0;

	cin >> n;

	rep(i, n)rep2(j, i, n)rep2(k, j, n) {
		t = gcd(i + 1, j + 1);
		t = gcd(t, k + 1);

		if (i == j && j == k) {
			ans += t;
		}
		else if (i == j || j == k) {
			ans += 3 * t;
		}
		else {
			ans += 6 * t;
		}
	}

	cout << ans << "\n";
}

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

	solve_abc_c();

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
#define NIL -1
using namespace std;

typedef struct{
    int key;
    int right;
    int left;
    int parent;
}node;

void insert(vector<node> &T, int i, int *root) {
    int x=*root, y = NIL;
    while(x != NIL){
        y = x;
        T[i].key<T[x].key?x=T[x].left:x=T[x].right;
    }
    T[i].parent = y;
    if(y == NIL) *root = i;
    else if(T[i].key < T[y].key) T[y].left = i;
    else T[y].right = i;
}

void inorder(vector<node> &T, int i){
    if(T[i].left != NIL) 
        inorder(T,T[i].left);
    cout << " " << T[i].key;
    if(T[i].right != NIL)
        inorder(T,T[i].right);
}

void preorder(vector<node> &T, int i){
    cout << " " << T[i].key;
    if(T[i].left != NIL)
        preorder(T,T[i].left);
    if(T[i].right != NIL)
        preorder(T,T[i].right);
}

bool find(vector<node> &T, int i, int k) {
    bool result = false;
    if(T[i].key == k) return true;
    else if(T[i].key > k) {
        if(T[i].left != NIL)
            result = find(T,T[i].left,k);
    } else if(T[i].key < k) {
        if(T[i].right != NIL)
            result = find(T,T[i].right,k);
    }
    return result;
}

int main(void) {
    int n,i,x,root=NIL;
    string od;
    bool judge;
    vector<node> T;
    cin >> n;
    T.resize(n);
    rep(i,n) {
        T[i].key = 0;
        T[i].right = NIL;
        T[i].left = NIL;
        T[i].parent = NIL;
    }
    rep(i,n){
        cin >> od;
        if(od == "insert"){
            cin >> T[i].key;
            insert(T,i,&root);
        } else if(od == "print") {
            inorder(T,root);
            cout << endl;
            preorder(T,root);
            cout << endl;
        } else if(od == "find") {
            cin >> x;
            judge = find(T,root,x);
            if(judge) cout << "yes";
            else cout << "no";
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8984