akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bitset>
#define Fail puts("NO"),exit(0);
#define eps 1e-8
#define maxn 605
#define maxm 100010
#define inf 999999999999999
#define mod 1000000007
//#define inv 499122177
#define G 3
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
typedef long double ld;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int g[maxn],T;
int n,m,to[maxn],sum[maxn],f[maxn][maxn];
int query(int l,int r)
{
    if(l>r)  return 0;
    return sum[r]-sum[l-1];
}
int work(int l,int r)
{
    int res=g[query(l,r)];
    for(int i=l+1;i<r;i++)  res=(res-1ll*f[l][i]*g[query(i+1,r)]%mod+mod)%mod;
    return res;
}
bool check(int l,int r)
{
    for(int i=l;i<=r;i++)
    {
        if(to[i]&&(to[i]<l||to[i]>r))  return false;
    }
    return true;
}
int main()
{
    g[0]=1;for(int i=2;i<=600;i+=2)  g[i]=1ll*g[i-2]*(i-1)%mod;
        n=read();m=read();
        memset(to,0,sizeof(to));
        for(int i=1;i<=m;i++)
        {
            int x=read(),y=read();
            to[x]=y;to[y]=x;
        }
        for(int i=1;i<=2*n;i++)  sum[i]=sum[i-1]+(!to[i]);
        int ans=0;
        for(int l=1;l<=2*n;l++)
        {
            for(int r=l+1;r<=2*n;r+=2)
            {
                if(check(l,r))
                {
                    f[l][r]=work(l,r);
                    ans=(ans+1ll*f[l][r]*g[query(1,l-1)+query(r+1,n*2)])%mod;
                }
            }
        }
        cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1664
// 失敗するからこそ そこから立ち向かって行く強さがあって そんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/pavan/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;


int main(){
	FIO
	
	int n;cin >> n ;
	forn(i, n){
		int x;cin >> x;
		if(x % 2 == 0 && (x % 3 != 0 && x % 5 != 0)){
			puts("DENIED");
			return 0;
		}
	}
	puts("APPROVED");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

	ll k, a, b;
	cin >> k >> a >> b;

	if(a+1 >= b){
		cout << k+1 << endl;
		return 0;
	}

	ll ans = 1;
	for(ll i=1; i<=k; ++i){
		if(ans < a){
			ans = a;
			i = a-1;
		}
		else if(i == k){
			ans++;
		}
		else{
			int t = (k-i+1) / 2;
			ans += (b-a) * t;
			i += t * 2 - 1;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n, q;
    string s;

    cin >> n >> q >> s;

    vector<ll> sum(n + 1, 0);

    for (int i = 1; i < n; i++)
    {
        sum[i + 1] = sum[i];

        if (s[i - 1] == 'A' && s[i] == 'C')
        {
            sum[i + 1]++;
        }
    }

    for (int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;

        cout << sum[r] - sum[l] << endl;
    }
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        String t="None";
        for(int i=97;i<123;i++){
            if(!s.contains(String.valueOf((char)i))){
                t=String.valueOf((char)i);
                break;
            }
        }
        System.out.println(t);
    }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll gcd(ll a, ll b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
int main(){
    ll a,b;
    cin>>a>>b;
    cout<<a*b/gcd(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;

long long n,w,W[101],V[101],dp[101][N];

long long calc(int idx,int wt){
    if(wt>w) return -1e12;
    if(idx==n) return 0;
    
    if(dp[idx][wt]  != -1)
    return dp[idx][wt];
    
    return dp[idx][wt]=max(V[idx]+calc(idx+1,wt+W[idx]) , calc(idx+1,wt));
}

int main(){
cin>>n>>w;
for(int i=0;i<n;++i)
scanf("%lld%lld",&W[i],&V[i]);

memset(dp,-1,sizeof(dp));

cout<<calc(0,0);

return 0;    
}

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

using namespace std;

int main() {
    int d, g;
    cin >> d >> g;
    
    vector<int> p(d), c(d);
    
    
    int ans = 0;
    
    for (int i = 0; i < d; i++) {
        cin >> p[i] >> c[i];
    
        ans += p[i];
    }
    
    for (int i = 0; i < (1 << d); i++) {
        int score = 0;
        int cnt = 0;
        
        for (int j = 0; j < d; j++) {
            if ((i >> j) & 1) {
                score += (j + 1) * 100 * p[j] + c[j];
                cnt += p[j];
            } 
        }
        
        for (int j = d - 1; j >= 0; j--) {
            if (!((i >> j) & 1)) {
                for (int k = 1; k <= p[j] && score < g; k++) {
                    score += (j + 1) * 100;
                    cnt++;
                }
            } 
        }        
        
        if (score >= g && cnt < ans) {
            ans = cnt;
        }
    }
    
    cout << ans << endl;
}
  


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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a+b ==15)
    cout<<"+"<<endl;
    else
    if(a*b==15)
    cout<<"*"<<endl;
    else
    cout<<"x"<<endl;
	return 0;
}


Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)
G = A.each_with_object(Hash.new(0)) {|a,h| h[a] += 1 }

mem = {}
m = -> n { mem[n] ||= (n*(n-1))/2 }
total = G.inject(0) {|r,(k,v)| r + m[v] }
A.each {|a| puts total - m[G[a]] + m[G[a]-1] }


Measured memory_bytes: 28676
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ls x<<1
#define rs x<<1|1
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=3e3+100;
struct node{
	int w,c;
	bool operator < (const node&z)const {return w<z.w;}
}a[maxn];
int dp[maxn*2];
void solve()
{
	int n,t;scdd(n,t);
	int mx=0;
	rep1(i,n){
		scdd(a[i].w,a[i].c);
		mx=max(a[i].c,mx);
	}
	sort(a+1,a+n+1);
	rep1(i,n){
		for(int j=t+3000;j>=a[i].w;j--){
			if(j>t&&j-a[i].w>=t)continue;
			dp[j]=max(dp[j],dp[j-a[i].w]+a[i].c);
		}
	}
	int ans=0;
	for(int i=t+3000;~i;i--)ans=max(ans,dp[i]);
	ac;
}
int main(){
    //IOS;
    //freopen("D://data.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N;
  cin>>N;
  vector<int> a;
  rep(i,N){
    int aa;
    cin>>aa;
    a.emplace_back(aa);
  }
  SORT(a);
  cout<< a[N-1]-a[0]<<"\n";
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#include <queue>
#include <functional>
#include <sstream>
#include <climits>
#include <map>
using namespace std;

typedef pair<int,int> pii;

int main(){
	int n;
	while(scanf("%d", &n), n){
		int sr = 0, sw = 0;
		vector<pii> v(n);
		for(int i = 0; i < n; ++i){
			scanf("%d%d", &v[i].first, &v[i].second);
			sr += v[i].first;
			sw += v[i].second;
		}
		sort(v.begin(), v.end());
		
		int ans = 0;
		int sl = v.back().first;
		int st = sr - sl;

		if(st >= sl){
			ans = sr + sw;
		}
		else{
			int t = sl - st;
			vector<char> dp(t + 1);
			dp[0] = 1;
			for(int i = 0; i < n - 1; ++i){
				for(int j = t; j >= v[i].second; --j){
					dp[j] |= dp[j - v[i].second];
				}
			}
			int u;
			for(u = t; !dp[u]; --u);
			ans = 2 * sl + sw - u;
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define eps 1e-9
#define nmax 200
#define f(c,a,b) for(int c=a; c<=b; c++)
#define pi acos(-1)

using namespace std;
typedef double db;
struct P{
    db x, y;
    P operator - (P a){ return (P){x-a.x, y-a.y}; }
    db dot(P a){ return a.x*x + a.y*y; }
    P operator * (db a) { return (P){a*x, a*y}; }
    P operator + (P a){ return (P){x+a.x, y+a.y}; }
    P operator / (db a) { return (P) {x/a, y/a}; }
    db times(P a){ return x*a.y-y*a.x; }
    db le() { return sqrt( x*x+y*y ); }
    db le2() { return x*x+y*y; }
    P rot90(){ return (P){-y,x}; }
    void pri(){ printf("%.10lf %.10lf\n", x, y); }
    void swap(P& a){
        db tx = x, ty = y;
        x = a.x;  y = a.y;
        a.x = tx; a.y = ty;
    }
    bool operator < (const P a) const { return (x==a.x)?(y<a.y):(x<a.x); } 
    bool operator == (const P a) const { return (x==a.x)&&(y==a.y); }
}po[nmax];

int sign(db x) { return (x<-eps) ? -1 : x>eps; }

vector<P> tanCP(P c1, db r1, P p){
    db x = (c1-p).le2();
    db d = x - r1*r1;
    P tp = p + (c1-p)*(d/x);
    P lp = (c1-p).rot90()*( r1*sqrt(d)/x );
    return{ tp-lp,tp+lp };
}

int inC(P c1, db r1, P c2, db r2){
    db dis = (c1-c2).le2();
    int x1 = sign( (r1+r2)*(r1+r2)-dis ), x2=sign( (r1-r2)*(r1-r2)-dis );
    if(x1 == 0) return 3;
    else if(x1 == -1) return 4;
    else {
        if(x2 == 0) return 1;
        else if(x2 == 1) return 0;
        else return 2;
    }
}

vector<P> tanCC(P c1, db r1, P c2, db r2, int qx){
    vector<P> ta;
    if(!qx) return ta;
    if( sign(r1-r2)==0 ) {
        P tp = ( (c2-c1)/(c2-c1).le()*r1 ).rot90();
        ta = { c1+tp,c1-tp };
    }else{
        P tp = c1 + (c2-c1)*(r1)/(r1-r2);
        ta = tanCP(c1, r1, tp);
    }
    //cout<<qx<<endl;
    if(qx<=2) return ta;
    P tp = c1 + (c2-c1)*r1/(r1+r2);
    vector<P> tmp = tanCP(c1, r1, tp);
    ta.insert(ta.end(), tmp.begin(), tmp.end());
    return ta;
}

int main(){
    //freopen("owo.in","r",stdin);
    P c1, c2;
    db r1, r2;
    cin >> c1.x >> c1.y >> r1;
    cin >> c2.x >> c2.y >> r2;
    vector<P> ta = tanCC(c1, r1, c2, r2, inC(c1,r1,c2,r2));
    sort(ta.begin(), ta.end() );
    for(int i=0; i<ta.size(); i++) if(i && (ta[i]==ta[i-1]) ) continue; else ta[i].pri();
    return 0;
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll A,V,B,W,T;
  cin >> A >> V >> B >> W >> T;
  ll C = abs(A-B);
  if(A==B)
  {
    cout << "NO" << endl;
  }
  if(V<=W)
  {
    cout << "NO" << endl;
  }
  else
  {
    if(T*(V-W)>=C)
    {
      cout << "YES" << endl;
    }
    else
    {
      cout << "NO" << endl;
    }
    
  }
  return 0;
}


Measured memory_bytes: 3636
s = gets.chomp

N = s.count("N")
W = s.count("W")
S = s.count("S")
E = s.count("E")

if (N * S >= 1 || (N == 0 && S == 0)) && (W * E >= 1 || (W == 0 && E == 0))
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 3836
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a,b>=1&&a,b<=9)
    {
        if(a+b<10)
        {
            printf("%d",a+b);
        }
        else
        {
            printf("error");
        }
    }
}


Measured memory_bytes: 128
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = list(ns())
n = len(s)
ss = s[:(n-1)//2]
sss = s[(n+3)//2-1:]

if s == list(reversed(s)) and ss == list(reversed(ss)) and sss == list(reversed(sss)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <stdio.h>
 
 
int n, cnt;
int A[1000000];
 
 int Insertionsort(int g) {
 	int v;
 	int i,j;
 	
 	for(i=g;i < n; i++) {
 		v = A[i];
 		j = i-g;
 		while(j >= 0&& A[j] > v) {
 			A[j+g] = A[j];
 			j -= g;
 			cnt++;
 		}
 		A[j+g] = v;
 	}
 }
 
 
 
 int Shellsort() {
 	int G[100];
 	int i,m = 0,g=0;
 	while(3 * g + 1 <= n) {
 		g = 3 * g + 1;
 		G[m++]=g;
 	}
 	printf("%d\n",m);
 	
 	for(i=m-1;i>=0;i--) {
 		if(i<m-1) printf(" ");
 		printf("%d",G[i]);
 		Insertionsort(G[i]);
 	}
	puts("");
	printf("%d\n",cnt);
	
	for(i = 0; i < n; i++) {
		printf("%d\n",A[i]);
	}
}
 
 
int main(void) {
   
  int i;
   
  scanf("%d", &n);
   
  for(i = 0; i < n; i++) {
    scanf("%d", A+i);
  }
 
  Shellsort();
 
  return 0;
 
}
 


Measured memory_bytes: 5692
n=int(input())
a=list(map(int,input().split()))
a.sort()

b=a[:]
c=a[-1]

#print('c',c)


for i in range(len(a)):
    a[i]=abs(a[i]-int((c+1)/2))

#for j in range(len(a)):
#    print(a[j])


ans = b[a.index(min(a))]

#print('ans',ans)


print(b[-1],ans)


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

int main(){
    int n; string s; cin >> n >> s;
    ll r=0, g=0, b=0;

    rep(i,n){
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
        if(s[i] == 'B') b++;
    }
    ll tmp = r*g*b;

    for(int i=1; i<= ((n+1)/2) -1; i++){

        for(int j=0; (j+i*2)<=(n-1); j++){

            if((s[j] != s[j+i]) && (s[j+i] != s[j+i*2]) && (s[j] != s[j+i*2])){
                tmp--;
            }

        }
    }

    cout << tmp << endl;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x,t,a,b;
    cin>>x>>t>>a>>b;
    cout<<(x-a)*(t-b);
    return 0;
}


Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())


def calculate(a):
    s = 0
    for i in range(len(a)):
        for k in range(i+1,len(a)):
            s+=(a[i]*a[k])
    return s

n = ip()                                     #入力整数1つ
#n,x= (int(i) for i in input().split())       #入力整数横2つ以上
t = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
m  =  ip()
s = []
for i in range(m):
    a,b= (int(i) for i in input().split())
    c = copy.copy(t)
    c[a-1] = b
    s.append(sum(c))
for i in range(len(s)):
    print(s[i])

Measured memory_bytes: 13664
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>

class carr {
	int** c;
	int level;
public:
	carr(int n, int t = 0) {
		for (int i = 0; i < 30; i++) {
			if (1 << i >= n) {
				level = i + 1;
				break;
			}
		}
		c = new int*[level];
		for (int i = 0; i < level; i++) {
			c[i] = new int[1 << (level - 1 - i)];
			for (int j = 0; j < 1 << (level - 1 - i); j++) {
				if (i == 0) {
					c[0][j] = j < n ? t : 0;
				}
				else {
					c[i][j] = c[i - 1][j << 1] + c[i - 1][(j << 1) + 1];
				}
			}
		}
	}
	carr(int n, int *t) {
		for (int i = 0; i < 30; i++) {
			if (1 << i >= n) {
				level = i + 1;
				break;
			}
		}
		c = new int*[level];
		for (int i = 0; i < level; i++) {
			c[i] = new int[1 << (level - 1 - i)];
			for (int j = 0; j < 1 << (level - 1 - i); j++) {
				if (i == 0) {
					c[0][j] = j < n ? t[j] : 0;
				}
				else {
					c[i][j] = c[i - 1][j << 1] + c[i - 1][(j << 1) + 1];
				}
			}
		}
	}
	void cadd(int n, int a = 1) {
		for (int i = 0; i < level; i++) {
			c[i][n >> i] += a;
		}
	}
	void csub(int n, int a = 1) {
		for (int i = 0; i < level; i++) {
			c[i][n >> i] -= a;
		}
	}
	int prev(int n) {
		//if (c[0][n])return n;
		for (int i = 0; i < level; i++) {
			if (n&(1 << i) && c[i][(n >> i) - 1]) {
				int r = (n >> i) - 1;
				for (int j = i - 1; j >= 0; j--) {
					r <<= 1;
					if (c[j][r | 1])r |= 1;
				}
				return r;
			}
		}
		return -1;
	}
	int next(int n) {
		//if (c[0][n])return n;
		for (int i = 0; i < level; i++) {
			if ((n&(1 << i)) == 0 && c[i][(n >> i) + 1]) {
				int r = (n >> i) + 1;
				for (int j = i - 1; j >= 0; j--) {
					r <<= 1;
					if (c[j][r] == 0)r |= 1;
				}
				return r;
			}
		}
		return -1;
	}
};

const int mod = 1000000007;

int main() {
	int N;
	scanf("%d", &N);
	int *P = new int[N];
	int *w = new int[N];
	for (int i = 0; i < N; i++) {
		int p;
		scanf("%d", &p);
		P[i] = p - 1;
		w[p - 1] = i;
	}
	carr c(N);
	c.cadd(w[N - 1]);
	long long res = 0;
	for (int i = N - 2; i >= 0; i--) {
		int l = c.prev(w[i]);
		int r = c.next(w[i]);
		if (l < 0 || l>N)l = -1;
		if (r < 0 || r>N)r = N;
		long long ll = c.prev(l);
		long long rr = c.next(r);
		if (ll < 0 || ll>N)ll = -1;
		if (rr < 0 || rr>N)rr = N;
		res += ((l - ll)*(r - w[i]) + (rr - r)*(w[i] - l))*(i + 1);
		c.cadd(w[i]);
		//printf("(%lld %d %d %d,%lld)\n", ll, l, w[i], r, rr);
	}
	printf("%lld", res);
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>

using namespace std;

int h, w, sum;
int a[15][15];

int main()
{
    scanf("%d%d", &h, &w);
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    for(int k = 0; k < 10; k++)
    {
        for(int i = 0; i < 10; i++)
        {
            for(int j = 0; j < 10; j++)
            {
                if(a[i][k] + a[k][j] < a[i][j])
                {
                    a[i][j] = a[i][k] + a[k][j];
                }
            }
        }
    }
    int hw = h * w;
    while(hw--)
    {
        int t;
        scanf("%d", &t);
        if(t == -1)
        {
            t = 1;
        }
        sum += a[t][1];
    }
    printf("%d", sum);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 2000;

ll power_mod(ll a, ll power){
    ll value = 1;
    
    while(power != 0){
        if(power & 1) value = (value * a) % mod;
        a = (a * a) % mod;
        power = power >> 1;
     
    }
 
    return value % mod;
}


ll combination(ll n, ll r){
    ll numerator = 1;
    ll denomenator = 1;
 
    for(ll i = 0; i < r ; i++){
        (numerator *= ll(n - i)) %= mod;
        (denomenator *= power_mod(ll(i + 1), ll(mod - 2))) %= mod;
    }
    
    return (numerator * denomenator) % mod;
}

int main(void){
    ll N, K;
    ll answer;

    cin >> N >> K;

    rep(i, K){
        ll c1 = combination(K - 1, i);
        ll c2 = combination(N - K - 1, i - 1);
        ll c3 = combination(N - K - 1, i);
        ll c4 = combination(N - K - 1, i + 1);
        ll a1 = c1 * c2 % mod;
        ll a2 = c1 * c3 % mod * 2 % mod;
        ll a3 = c1 * c4 % mod;
        answer = ((a1 + a2) % mod + a3) % mod;
        if (i == 0) cout << answer - 1 << endl;
        else cout << answer << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;
using lli = long long int;

struct UnionFind
{
	UnionFind(int n) : par(n), rank(n, 0) {
		iota(par.begin(), par.end(), 0);
	}
	int Find(int i)
	{
		if (par[i] == i)
			return i;
		else
			return par[i] = Find(par[i]);
	}
	void Unite(int i, int j)
	{
		i = Find(i);
		j = Find(j);
		if (i == j)
			return;
		if (rank[i] < rank[j])
		{
			par[i] = j;
		}
		else
		{
			par[j] = i;
			if (rank[i] == rank[j])
				++rank[i];
		}
	}
	vector<int> par;
	vector<int> rank;
};

void ABC126E()
{
	int N, M;
	cin >> N >> M;
	vector<pair<int, int> > edge;
	for (int i = 0; i < M; ++i)
	{
		int X, Y, Z;
		cin >> X >> Y >> Z;
		edge.push_back({ X-1,Y-1 });
	}

	UnionFind uf(N);
	for (auto& x : edge)
		uf.Unite(x.first, x.second);

	set<int> parents;
	for (int i = 0; i < N; ++i)
	{
		int parent = uf.Find(i);
		parents.insert(parent);
	}
	cout << parents.size() << endl;
}

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

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

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    vector<int> a(n);
    vector<int> b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];

    ll t = 0;
    rep(i,m) t += b[i];

    int ans = 0;
    int j = m;
    rep(i,n+1){
        while(j>0 && t > k){
            t -= b[j-1];
            j--;
        }
        if(t>k) break;
        ans = max(ans, i+j);
        if(i==n) break;
        t += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4836
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;
const int maxn=10010;
int n,k;
set<int>s;
int main()
{
	scanf("%d%d",&n,&k);
	while (k--)
	{
		int num=0; scanf("%d",&num);
		for (int i=1;i<=num;i++)
		{
			int x; scanf("%d",&x);
			s.insert(x);
		}
	}
	printf("%d\n",n-(int)s.size());
return 0;
}

Measured memory_bytes: 3816
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

////////////////////////////////////////


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll q;cin>>q;
    while(q--){
        ll a,b;cin>>a>>b;
        if(a>b)swap(a,b);
        ll ans=2*(a-1);
        ll p=(ll)sqrt(a*b);
        if(a<b-1){
            if(a==p){
                ans+=1;
            }else{
                ans+=1;
                ans+=2*(p-a-1);
                if(p*(p+1)<a*b)ans+=2;
                else if(p*p<a*b)ans+=1;
                if((a*b-1)/(a+2)==b-2)ans--;
            }
        }
        
        cout<<ans<<endl;
    }
    
    return 0;
}


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

int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> h(n+10);
  rep(i,n) cin >> h[i];
  vector<ll> a(m+10);
  vector<ll> b(m+10);
  rep(i,m) cin >> a[i] >> b[i];
  vector<ll> ans(n+10);
  rep(i,n) ans[i] = 0;
  rep(i,m){
    if(h[a[i]] >= h[b[i]]) ++ans[b[i]];
    if(h[a[i]] <= h[b[i]]) ++ans[a[i]];
  }
  ll count = 0;
  rep(i,n){
    if(ans[i] == 0) ++count;
  }
  cout << count << endl;
  return 0;
}


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

using namespace std;

int rr[4] = {0, 0, 1, -1};
int cc[4] = {1, -1, 0, 0};

#define mp make_pair
#define pii pair<int, int> 

int
main(void){
	int h, w, k; cin >> h >> w >> k;
	int x1, y1, x2, y2; cin>> x1 >> y1 >> x2 >> y2;
	--x1; --x2; --y1; --y2;
	vector<string> grid(h);
	for(int i = 0; i < h; i++) cin >> grid[i];
	
	vector<vector<bool> > used(h, vector<bool> (w, false));
	vector<vector<int> > dist(h, vector<int> (w, INT_MAX));
	queue<pii> q;
	q.push(mp(x1, y1));
	dist[x1][y1] = 0;
	while(!q.empty()){
		pii cur = q.front();
		q.pop();
		int r = cur.first;
		int c = cur.second;
		int d = dist[r][c] + 1;
		for(int i = 0; i < 4; i++){
			int row = r, col = c;
			for(int j = 0; j < k; j++){
				row += rr[i]; col += cc[i];
				if(row < 0 || row >= h || col < 0 || col >= w || grid[row][col] == '@') break;
				if(dist[row][col] > d){
					q.push(mp(row, col));
					dist[row][col] = d;
				}
				else if(dist[row][col] < d) break;
			}
		} 
	
	}
	if(dist[x2][y2] == INT_MAX) cout << -1;
	else cout << dist[x2][y2];
}

Measured memory_bytes: 12424
n = gets.to_i
a = gets.split.map(&:to_i)
l = Array.new(n)
r = Array.new(n)
l[0] = a[0]
for i in 1..n-1
    l[i] = l[i-1].gcd(a[i])
end
r[-1] = a[-1]
(n-2).downto(0) do |i|
    r[i] = r[i+1].gcd(a[i])
end
ans = r[1]
for i in 1..n-2
    m = l[i-1].gcd(r[i+1])
    ans = m if m > ans
end
ans = l[-2] if ans < l[-2]
puts ans

Measured memory_bytes: 10124
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int judge(ll n, ll l, vll& a) {
  rep (i, n-1) {
    if (a[i] + a[i+1] >= l) {
      return i;
    }
  }
  return -1;
}

int main() {
  ll n, l;
  scan(n, l);
  vll a(n);
  scan(a);
  int ind = judge(n, l, a);
  if (ind == -1) {
    print("Impossible");
  } else {
    print("Possible");
    ind += 1;
    FOR (i, 1, ind) {
      print(i);
    }
    for (int i = n-1; i > ind; --i) {
      print(i);
    }
    print(ind);
  }

  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include<array>
#include<vector>
#include<string>
#include<utility>
using namespace std;

int main() {
	string str,a,b;
	cin >> str;
	int s = str.size();
	int c;
	for (int i = 1; i <= s; i++) {
		a = str[i - 1];
		c = b.size();
		if (a == "0") {
			b.push_back('0');
		}
		if (a == "1") {
			b.push_back('1');
		}
		if (c!=0 && a == "B") {

			b.pop_back();
		}
	}
		cout << b << endl;
		return 0;
	}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

string str;

int number(const int begin,const int end){
    int res=0,idx=begin;
    while(idx!=end){
        res*=10;
        res+=str[idx]-'0';
        ++idx;
    }
    return res;
}

set<int> dfs(const vector<set<int>> v,const vector<char> o){
    if(v.size()==1) return set<int>{v[0]};
    set<int> res;
    rep(i,0,o.size()){
        for(const auto &x:v[i]) for(const auto &y:v[i+1]){
            if(o[i]=='/' and y==0) continue;
            vector<set<int>> v_(v.begin(),v.begin()+i);
            vector<char> o_(o.begin(),o.begin()+i);
            if(o[i]=='+') v_.emplace_back(set<int>{x+y});
            if(o[i]=='-') v_.emplace_back(set<int>{x-y});
            if(o[i]=='*') v_.emplace_back(set<int>{x*y});
            if(o[i]=='/') v_.emplace_back(set<int>{x/y});
            v_.insert(v_.end(),v.begin()+i+2,v.end());
            o_.insert(o_.end(),o.begin()+i+1,o.end());
            set<int> tmp=dfs(v_,o_);
            res.insert(tmp.begin(),tmp.end());
        }
    }
    return res;
};

set<int> expression(const int begin,const int end){
    vector<set<int>> vals;
    vector<char> ops;
    int idx=begin;
    while(idx!=end){
        if(isdigit(str[idx])){
            int end_;
            rep(i,idx,inf) if(!isdigit(str[i])){
                end_=i;
                break;
            }
            vals.emplace_back(set<int>{number(idx,end_)});
            idx=end_;
        }else if(str[idx]=='+' or str[idx]=='-' or str[idx]=='*' or str[idx]=='/'){
            ops.emplace_back(str[idx]);
            ++idx;
        }else if(str[idx]=='('){
            ++idx;
            int cnt=1,end_;
            rep(i,idx,end){
                if(str[i]=='(') ++cnt;
                else if(str[i]==')') --cnt;
                if(!cnt){
                    end_=i;
                    break;
                }
            }
            vals.emplace_back(expression(idx,end_));
            idx=end_+1;
        }else break;
    }
    return dfs(vals,ops);
}

void solve(){
    while(true){
        cin >> str;
        if(str=="#") return;
        cout << expression(0,str.size()).size() << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 3232
#include <stdio.h>
int min(int a,int b) {return a>b?b:a;}
int main() {
	int r = 0, i = -1;
	char c[100001];
	scanf("%s", &c);
	while(c[++i])
		r += (c[i] != '0' + (i % 2));
	printf("%d", min(r, i - r));
	return 0;
}

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

int main() {
  string s,t,u;
  int a, b, c;
  cin >> c >> a >> b;
  
  if(a==b){
      if(b!=c) cout << "Yes" << endl;
      else cout <<  "No"  << endl;
  }
  else if(b==c){
      if(b!=a) cout << "Yes" << endl;
      else cout <<  "No"  << endl;
  }
  else if(c==a){
      if(c!=b) cout << "Yes" << endl;
      else cout <<  "No"  << endl;
  }
  else cout <<  "No"  << endl; 
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include "atcoder/all"
using namespace std;
using namespace atcoder;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
const long long int sMod = 998244353;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

struct S {
    ll zero,one,inversion;
};

S op(S a,S b) {
    return S{a.zero+b.zero,a.one+b.one,a.inversion+b.inversion+a.one*b.zero};
}

S e(){ return S{0,0,0}; }

using F = bool;

S mapping(F f,S a){
    if(!f) return S{a.one,a.zero,a.zero*a.one-a.inversion};
    return a;
}

F composition(F f,F g){ return !(f^g); }

F id(){ return true; }
void solve(){
    ll n,q;
    cin >> n >> q;
    Vi a(n);
    rp(i,n) cin >> a[i];
    
    lazy_segtree<S,op,e,F,mapping,composition,id> seg(n);

    rp(i,n){
        if(a[i]==0) seg.set(i,S{1,0,0});
        else seg.set(i,S{0,1,0});
    }

    while(q--){
        ll t,l,r;
        cin >> t >> l >> r;
        if(t==1){
            seg.apply(l-1,r,false);
        }else{
            print(seg.prod(l-1,r).inversion);
        }
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 21708
from fractions import gcd
def lcm(x,y):
    return x*y//gcd(x,y)
lcm_num = lcm
A, B, C, D = map(int, input().split())

lcm_num = lcm(C, D)

if A%C == 0:
    cnt_c = A//C - 1
else:
    cnt_c = A//C

if A%D == 0:
    cnt_d = A//D - 1
else:
    cnt_d = A//D

if A%(lcm_num) == 0:
    cnt_cd = A//(lcm_num) - 1
else:
    cnt_cd = A//(lcm_num)



num = (B//C)+(B//D)-(B//(lcm_num)) - (cnt_c + cnt_d - cnt_cd)
print(B-A+1-num)

Measured memory_bytes: 5076
# Tree walk

import sys
sys.setrecursionlimit(10**9)  # 再帰回数上限の向上 かなり多くしないとREになる

class Node:
    def __init__(self, parent, left, right):
        self.parent = parent #  親
        self.left = left # 左の子ノード
        self.right = right # 右の子ノード

def pre_parse(T: dict, u: int, pre_ls: list):
    # 深さ優先探索特有の即時終了条件
    if u == None:
        return
    pre_ls.append(u)
    pre_parse(T, T[u].left, pre_ls)  # より左の方から深さ優先探索
    pre_parse(T, T[u].right, pre_ls)


def in_parse(T, u, in_ls):
    if u == None:
        return
    # 左→中→右っていうちょっと気持ち悪い順番
    in_parse(T, T[u].left, in_ls)
    in_ls.append(u)
    in_parse(T, T[u].right, in_ls)


def post_parse(T, u, post_ls):
    if u == None:
        return
    post_parse(T, T[u].left, post_ls)
    post_parse(T, T[u].right, post_ls)
    post_ls.append(u)


# データの読み込み
n = int(input())
T = {key: Node(None, None, None) for key in range(n)}
for _ in range(n):
    tmp = [x if x != -1 else None for x in map(int, input().split())]
    T[tmp[0]].left = tmp[1]
    T[tmp[0]].right = tmp[2]
    if tmp[1] is not None:
        T[tmp[1]].parent = tmp[0]
    if tmp[2] is not None:
        T[tmp[2]].parent = tmp[0]

# parentがないのが特徴のROOTを探す
for id, node in T.items():
    if node.parent is None:
        ROOT = id

# リストに答えを格納していく
pre_ls, in_ls, post_ls = [], [], []
pre_parse(T, ROOT, pre_ls)
in_parse(T, ROOT, in_ls)
post_parse(T, ROOT, post_ls)

print('Preorder')
print('', *pre_ls)
print('Inorder')
print('', *in_ls)
print('Postorder')
print('', *post_ls)


Measured memory_bytes: 5624
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int v;
    cin>>v;
    vector <char> a;
    while(v)
    {
        int rem=v%26;
        if(rem==0)
        a.push_back('z');
        else
        a.push_back(96+rem);
        if(rem==0)
            v=(v-26)/26;
        else
            v=(v-rem)/26;
    }
    for(int i=a.size()-1;i>=0;i--)
        cout<<a[i];
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;scanf("%d%d",&n,&m);
	int l=n/2,r=l+1;
	if(n&1)for(int i=0;i<m;i++)printf("%d %d\n",l--,r++);
	else{
		for(int i=0;i<(m+1)/2;i++)printf("%d %d\n",l--,r++);
		l=2,r=n;
		for(int i=(m+1)/2;i<m;i++)printf("%d %d\n",l++,r--);
	}
	return 0;
}


Measured memory_bytes: 3836
#include <iostream>

 

using namespace std;

 

int main()
{
   int a, b;
   cin >> a >> b;
   
   if (a == b)
       cout << "a == b" << endl; 
   else if (a > b)
       cout << "a > b" << endl;
   else
       cout << "a < b" << endl;
   
   return 0;
}


Measured memory_bytes: 3096
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.range;
import std.numeric;

void main() {
    auto point = readln.chomp.split.map!(to!double).array;
    auto p1 = point[0..2];
    auto p2 = point[2..4];

    int q = readln.chomp.to!int;
    for (int i = 0; i < q; i++) {
        auto p = readln.chomp.split.map!(to!double).array;
        double[] p1p = new double[2];
        double[] p1p2 = new double[2];
        p1p[] = p[] - p1[];
        p1p2[] = p2[] - p1[];
        double[] ph = new double[2];
        ph[] = p1p2[] * dotProduct(p1p, p1p2) / dotProduct(p1p2, p1p2) + p1[];
        writefln("%.10f %.10f", ph[0], ph[1]);
    }
}

Measured memory_bytes: 1236
out = 0
num = int(input())
kaihukuryou = list(map(int, input().split()))
kumiawase_sum = num * (num - 1) / 2
for i in range(num - 1):
  for j in range(i,num - 1):
    out = out + kaihukuryou[i] * kaihukuryou[j + 1]
print(out)
    
    
  

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define MAX_N 1000000
#define INF 1000000

vector<ll> v;

int dfs(ll n, ll lunlun, ll keta) {

  if (n < 0 || n > 9) return false;

  keta--;
  if (keta == 0) {
    v.push_back(lunlun*10 + n);
    return true;
  }

  dfs(n - 1, lunlun*10 + n, keta);
  dfs(n,     lunlun*10 + n, keta);
  dfs(n + 1, lunlun*10 + n, keta);

  return 0;

}

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll K;
  cin >> K;

  ll keta = 1;
  
  while (v.size() < K) {
    for (ll top = 1; top <= 9; top++) {
      dfs(top, 0, keta);
    }
    keta++;
  }

  cout << v[K-1] << endl;
  
  return 0;
  
}


Measured memory_bytes: 2420
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length
    val left = s.substring(0 until (n/2))
    val right = s.substring(n/2+1)
    if (check(s) && check(left) && check(right)) {
        println("Yes")
    } else {
        println("No")
    }
}

fun check(value: String): Boolean {
    return value == value.reversed()
}


Measured memory_bytes: 33740
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=1e6+10;

int main()
{
	int sum=0;
	string s1,s2;
	cin>>s1>>s2;
	for(int i=0;i<s1.size();i++)
	{
		if(s1[i]==s2[i])
		sum++;
	}
	printf("%d\n",sum);
}


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

int main() {
  
  int n, minCount;
  cin >> n;
  
  if (n > 0) {
    int a;
    cin >> a;
    while(a % 2 == 0) {
      a /= 2;
      minCount++;
    }
  }
  
  for(int i = 1; i < n; i++) {
    int a;
    cin >> a;
    int tempCount = 0;
    
    while(a % 2 == 0) {
      a /= 2;
      tempCount++;
    }
    
    if (tempCount < minCount) {
      minCount = tempCount;
    }
  }
  
  cout << minCount << endl;
  
}

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

int parent(int i){
	return i/2;	
}
int left(int i){
	return i*2;
}
int right(int i){
	return (i*2+1);
}


int main(){
  int H,i,A[MAX+1];
  
  cin >> H;
  for(i=1;i<=H;i++){
    cin >> A[i];
  }
  
  for(i=1;i<=H;i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
    if(left(i) <= H) cout << "left key = " << A[left(i)] <<  ", ";
    if(right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }	
  
  return 0;
}



Measured memory_bytes: 3104
/**
 *
 * Contest - Problema X: Nome (link)
 *
 * Abridge version.
 *
 * Solution: text
 */
#include <iostream>

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))
#define LOGM(msg) (cerr << (msg))
#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : vec) cerr << " " << v; cerr << (sep); }
#define LOGA(arr, N, sep) { cerr << #arr << " ="; for (int i = 0; i < N; ++i) cerr << " " << (arr)[i]; cerr << (sep); }
#define LOGA2(arr, N, M, sep) { cerr << #arr << " =\n"; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) cerr << (arr)[i][j] << " "; cerr << endl; } cerr << (sep); }

ostream& operator<<(ostream& os, const ii& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

const int MAX { 2000010 };
const ll oo { 1LL << 62 };
const int MOD { 1000000007 };

void precomp()
{
}

void solve(int N)
{
    stack<char> ds;

    do {
        int d = abs(N % 2);
        ds.push('0' + d);
        N -= d;
 //       LOG(d, ' '); LOG(N, '\n');
        N /= (-2);
//        LOGM("==> "); LOG(N, '\n');
    } while (N);

    while (not ds.empty()) {
        cout << ds.top();
        ds.pop();
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    precomp();

    int N;
    cin >> N;

    solve(N);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a;
    cin >> a;
    cout << a/3 << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

# https://atcoder.jp/contests/abc108/submissions/5741604


n, k = map(int, input().split())

if k % 2 == 0:
    even = n // k
    odd = n // (k // 2) - even
    print(odd ** 3 + even ** 3)
else:
    print((n // k) ** 3)

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

bool* PrimeSieve(int n) {
  bool*s = new bool[n];
  for (int i = 0; i < n; ++i) s[i] = true;
  s[0] = s[1] = false;
  for (int i = 2; i < n; ++i)
    if (s[i]) for (int j = 2 * i; j < n; j += i) s[j] = false;
  return s;
}

int main() {

  const int N = 50022;
  auto isprime = PrimeSieve(N);

  loop {
    int n; cin >> n;
    if (!cin) break;
    int a,b;
    for (int m = n-1; m > 0; --m) {
      if (isprime[m]) {
        a = m;
        break;
      }
    }
    for (int m = n+1; m < N; ++m) {
      if (isprime[m]) {
        b = m;
        break;
      }
    }
    cout << a << ' ' << b << endl;
  }

  return 0;
}

Measured memory_bytes: 1232