akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int,input().split()))
b = [0 for _ in range(max(a) + 1)]
for x in a:
    b[x] += 1
c = sum([x * (x-1) // 2 for x in b])
for i in range(n):
    print(c -(b[a[i]]-1))

Measured memory_bytes: 88784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
int n;
cin >> n;
vector<int> b(n);
rep(i,n) cin >> b.at(i);
vector<int> a = b;
sort(a.begin(),a.end());
if(a.at(n-1)==a.at(n-2)){
  rep(i,n)cout << a.at(n-1) << endl;
}else{
  rep(i,n){
    if(b.at(i) == a.at(n-1)) cout << a.at(n-2) << endl;
    else cout << a.at(n-1) << endl;
  }
}

}


Measured memory_bytes: 4772
def main():
    n,k = map(int,input().split())
    A = list(map(int,input().split()))
    k = min(50,k)

    dp = [[0]*n for _ in range(k+1)]
    for i in range(n):
        dp[0][i] = A[i]

    flag = False
    for i in range(1,k+1):
        pos = [0]*n
        neg = [0]*n

        for j in range(n):
            pwr = dp[i-1][j]
            pos[max(0,j-pwr)]+=1
            neg[min(n-1,j+pwr)]+=1

        ac_pos = 0
        ac_neg = 0
        for j in range(n):
            ac_pos += pos[j]
            ac_neg += neg[j]
            pos[j] = ac_pos
            neg[j] = ac_neg

        if pos[0]==n and neg[n-2]==0:
            flag = True
            break

        dp[i][0] = pos[0]
        for j in range(1,n):
            dp[i][j] = pos[j] - neg[j-1]

    
    if flag:
        for j in range(n-1):
            print(n, end=" ")  
        print(n)

    else:
        for j in range(n-1):
            print(dp[i][j], end=" ")
        print(dp[i][n-1])
main()


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> s, t;
  rep(i,n) {
    cin >> a[i];
    if (a[i] < 0) t.push_back(a[i]);
    else s.push_back(a[i]);
  }

  int S = s.size();
  int T = t.size();
  bool ok = false;
  if (S > 0) {
    if (n == k) ok = (T%2==0);
    else ok = true;
  } else {
    ok = (k%2==0);
  }

  mint ans = 1;
  if (!ok) {
    sort(a.begin(), a.end(), [](int x, int y) {
      return abs(x) < abs(y);
    });
    rep(i,k) ans *= a[i];
  } else {
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if (k%2 == 1) {
      ans *= s.back();
      s.pop_back();
    }
    vector<ll> p;
    while (s.size() >= 2) {
      ll x = s.back(); s.pop_back();
      x *= s.back(); s.pop_back();
      p.push_back(x);
    }
    while (t.size() >= 2) {
      ll x = t.back(); t.pop_back();
      x *= t.back(); t.pop_back();
      p.push_back(x);
    }
    sort(p.rbegin(), p.rend());
    rep(i,k/2) ans *= p[i];
  }

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


Measured memory_bytes: 6164
#include<bits/stdc++.h>
using namespace std;
char a[1002][1002];
long long f[1002][1002];
int main()
{
	int i,j,h,w;
	scanf("%d %d",&h,&w);
	for(i=1;i<=h;i++)
	{
		getchar();
		for(j=1;j<=w;j++)
		{
			scanf("%c",&a[i][j]);
		}
	}
	for(i=1;i<=h;i++)
	{
		for(j=1;j<=w;j++)
		{
			if(a[i][j]=='#')
				f[i][j]=0;
			else if(i==1&&i==j)
				f[i][j]=1;
			else if(a[i][j]=='.')
				f[i][j]=(f[i-1][j]+f[i][j-1])%1000000007;
		}
	}
	printf("%lld",f[h][w]);
	return 0;
}

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

int main() {
  int r,g,b,num;
  int cnt = 0;
  
  cin >> r >> g >> b >> num;
  
  for(int i = 0; i <= 3000; i++){
    for(int j = 0; j <= 3000; j++){
      if(num - (r * i + g * j) < 0) continue;
      if((num - (r * i + g * j)) % b == 0)cnt++;
    }
  }
  
  cout << cnt;
}


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

long long a[200000],sum,ans;

signed main()
{
	long long n,i;
	cin >> n;
	
	for(i=1;i<=n;i++)
		cin >> a[i];

	for(i=2;i<=n;i++)
		sum=(sum+a[i])%1000000007;
		
	for(i=1;i<n;i++)
		ans=(ans+a[i]*sum)%1000000007,sum=((sum-a[i+1])%1000000007+1000000007)%1000000007;
		
		cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5168
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        int w, h;
       
        Scanner sc = new Scanner(System.in);
        while(true){
            h = sc.nextInt();
            w = sc.nextInt();
            
        if(w==0 && h==0){
        break;
        }
        else{
            for(int j = 0; j<h; j++){
        for (int i = 0; i<w; i++){
            if(i ==0 || i == w-1 ||j ==0|| j==h-1){
        System.out.print("#");
        }
        else{
                System.out.print(".");
            }}
        System.out.println();
            }
            System.out.println();
        }
        }
}}


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

int main(){
    long long n;
    cin >> n;

    vector<vector<pair<long long, bool> > > a(n);

    for(long long i = 0; i < n; i++){
        long long A;
        cin >> A;

        for(long long j = 0; j < A; j++){
            long long x, y;
            cin >> x >> y;
            if(y == 1) a[i].push_back(make_pair(x-1, true));
            else a[i].push_back(make_pair(x-1, false));
        }
    }

    vector<bool> honest(n);
    long long maxv = 0;
    for(long long bit = 0; bit < (1 << n); bit++){
        long long cnt = 0;
        for(long long mask = 0; mask < n; mask++){
            if(bit & (1 << mask)) honest[mask] = true, cnt++;
            else honest[mask] = false;
        }

        bool flag = true;
        for(long long i = 0; i < n; i++){
            if(honest[i] == true){
                for(long long j = 0; j < a[i].size(); j++){
                    if(a[i][j].second != honest[a[i][j].first]){
                        flag = false;
                        break;
                    }
                }
            }
        }

        if(flag == true) maxv = max(maxv, cnt);
    }

    cout << maxv << endl;
    return 0;
}

Measured memory_bytes: 3604
awk -M '\
{
    N=$1; A=$2; B=$3;
    if(A<B){
        max = B;
        min = A;
    }else{
        max = A;
        min = B;
    }
    if((max-min)%2==0){
        print (max-min)/2
        exit;
    }
    if(N-max > min-1){
        ans += min-1
        max -= min-1;
        if((max-1)%2){
            ans++;
            max--;
        }
        ans += (max-1)/2
    }else{
        ans += N-max;
        min += N-max;
        if((N-min)%2){
            ans++;
            min++;
        }
        ans += (N-min)/2
    }
    print ans
}'

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


int main() {
    vector<int> N(5);
    rep(i, 5) cin >> N[i];
    int k;
    cin >> k;

    int last = 0;
    int mini = 10;
    rep(i, 5) if (N[i] % 10 != 0 && N[i] % 10 < mini) {
        mini = N[i] % 10;
        last = i;
    }
    
    int ans = 0;
    rep(i, 5) {
        if (N[i] % 10 == 0 || i == last) ans += N[i];
        else ans += (N[i] / 10) * 10 + 10;
    }

    cout << ans << endl;
}

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

int main(){
  long A, B;
  long max=-1000000;
  cin >> A >> B;
  if(A+B>max) max=A+B;
  if(A-B>max) max=A-B;
  if(A*B>max) max=A*B;
  cout << max << endl;
  return 0;
}

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

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
    int n,m;
    cin>>n>>m;
    Vi keycost(m);
    VVi keys(m);
    REP(i,0,m){
        int b;
        cin>>keycost[i]>>b;
        keys[i].resize(b);
        REP(j,0,b){
            cin>>keys[i][j];
            keys[i][j]--;
        }
    }
    Vi keynum(m);
    REP(i,0,m){
        int now=1;
        REP(j,0,n){
            if(binary_search(ALL(keys[i]),j)) keynum[i] += now;
            now*=2;
        }
    }
//    vout(keynum);

    const int MAXB=1<<n; 
    VVi dp(m,Vi(MAXB,INF));
    REP(i,0,m) dp[i][0]=0;
    REP(i,0,m-1){
        REP(j,0,MAXB){
            chmin(dp[i+1][j],dp[i][j]);
            chmin(dp[i+1][j|keynum[i]],dp[i][j]+keycost[i]);
        }
    }
    if(dp[m-1][MAXB-1]==INF) cout<<-1<<endl;
    else cout<<dp[m-1][MAXB-1]<<endl;
    return 0;
}


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

void fin(bool win_first){
    cout << (win_first ? "Hom" : "Tem") << endl;
    exit(0);
}

int main(){
    int A[3];
    for(int i=0; i<3; i++) cin >> A[i];
    int odd = 0;
    for(int i=0; i<3; i++) odd += A[i]%2;
    fin(odd >= 2);
    return 0;
}



Measured memory_bytes: 3072
N=int(input())
s=input().split(" ")
s1=[]
s2=[]
even=True
for z in s:
  if even:
    s1.append(z)
    even=False
  else:
    s2.append(z)
    even=True

if even:
  print(" ".join(s2[::-1]+s1))
else:
  print(" ".join(s1[::-1]+s2))

Measured memory_bytes: 27460
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e18;
const int md=1e9+7;
const int N=200009;
vector <int> g[N];
int par[N],sz[N]={0};
int f(int a,int n=md-2){
	if(n==0)return 1;
	if(n==1)return a;
	int x=f(a,n/2);
	x=(x*x)%md;
	if(n%2)x=(x*a)%md;
	return x;
}
void dfs(int p,int v){
	par[v]=p;
	sz[v]=1;
	for(auto u:g[v]){
		if(u==p)continue;
		dfs(v,u);
		sz[v]+=sz[u];
	}
}
int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n;
	cin >> n;
	for(int i=1;i<n;i++){
		int u,v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0,1);
	int ans=0,pb[n+1];
	for(int i=1;i<=n;i++)
		pb[i]=f(f(2,sz[i]));
	for(int i=1;i<=n;i++){
		int sum=0,p=1,p1=f(f(2,n-sz[i]));
		for(auto v:g[i]){
			if(v==par[i])continue;
			p=(p*pb[v])%md;
		}
		p=(p*p1)%md;
		for(auto v:g[i]){
			if(v==par[i])continue;
			sum=(sum+((p*(md+1-pb[v]))%md*f(pb[v]))%md)%md;	
		}
		sum=(sum+(p*(md+1-p1)%md*f(p1))%md)%md;
		sum=(sum+p)%md;
		ans=(ans+1+md-sum)%md;
	}
	cout << (ans*f(2))%md << endl;
}


Measured memory_bytes: 21376
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

int ct;

void mergeSort(int *A, int left, int right);
void merge(int *A, int left, int mid, int right);

int main(int argc, char *argv[])
{
  int n, i;
  int *S;

  ct = 0;

  scanf("%d", &n);
  S = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) scanf("%d", &S[i]);

  mergeSort(S, 0, n);

  for (i = 0; i < n; i++) {
    if (i != n - 1) printf("%d ", S[i]);
    else printf("%d\n", S[i]);
  }
  printf("%d\n", ct);

  return 0;
}

void mergeSort(int *A, int left, int right)
{
  int mid;

  if (left + 1 < right) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

void merge(int *A, int left, int mid, int right)
{
  int n1 = mid - left, n2 = right - mid;
  int *L, *R;
  int i, j, k;

  L = (int *)malloc(sizeof(int) * (n1 + 1));
  R = (int *)malloc(sizeof(int) * (n2 + 1));

  for (i = 0; i < n1; i++) L[i] = A[left+i];
  for (i = 0; i < n2; i++) R[i] = A[mid+i];

  L[n1] = INT_MAX;
  R[n2] = INT_MAX;
  i = 0;
  j = 0;

  for (k = left; k < right; k++) {
    ct++;
    if (L[i] <= R[j]) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

Measured memory_bytes: 63344
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;

const int MAXN = 5e5 + 10;
const int MAXM = 1e6 + 10;
int N, K;
int P[MAXN], A[MAXN];
int cnt = 1, Head[MAXN], Next[MAXM], To[MAXM];
int deg[MAXN];
int tr[MAXN << 2];

inline void add_edge(int x, int y) {
	Next[++cnt] = Head[x], To[cnt] = y, Head[x] = cnt; ++deg[y];
}

inline void build(int rt, int l, int r) {
	tr[rt] = N + 1;
	if(l == r)
		return;
	int mid = (l + r) >> 1;
	build(rt << 1, l, mid), build(rt << 1 | 1, mid + 1, r);
}

inline void upd(int rt, int l, int r, int x, int d) {
	if(l == r)
		return tr[rt] = d, void();
	int mid = (l + r) >> 1;
	if(x <= mid) upd(rt << 1, l, mid, x, d);
	else upd(rt << 1 | 1, mid + 1, r, x, d);
	tr[rt] = min(tr[rt << 1], tr[rt << 1 | 1]);
}

inline int qry(int rt, int l, int r, int x, int y) {
	if(x <= l && r <= y)
		return tr[rt];
	if(y < l || r < x)
		return N + 1;
	int mid = (l + r) >> 1, res = N + 1;
	if(x <= mid) res = min(res, qry(rt << 1, l, mid, x, y));
	if(mid < y) res = min(res, qry(rt << 1 | 1, mid + 1, r, x, y));
	return res;
}

int main() {
	register int i;
	scanf("%d%d", &N, &K);
	for(i = 1; i <= N; ++i)
		scanf("%d", P + i), A[P[i]] = i;
	build(1, 1, N);
	for(i = N; i; --i) {
		int tp1 = qry(1, 1, N, max(A[i] - K + 1, 1), A[i]);
		int tp2 = qry(1, 1, N, A[i], min(A[i] + K - 1, N));
		if(tp1 <= N) add_edge(A[i], A[tp1]);
		if(tp2 <= N) add_edge(A[i], A[tp2]);
		upd(1, 1, N, A[i], i);
	}
	priority_queue<int> q;
	for(i = 1; i <= N; ++i)
		if(!deg[i])
			q.push(-i);
	int t = 0;
	while(!q.empty()) {
		int x = -q.top(); q.pop();
		P[x] = ++t;
		for(i = Head[x]; i; i = Next[i])
			if(!(--deg[To[i]]))
				q.push(-To[i]);
	}
	for(i = 1; i <= N; ++i)
		printf("%d\n", P[i]);
	return 0;
}

Measured memory_bytes: 27764
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
	int a;
	int b;
	int x;
	cin >> a >> b >> x;
	const double pi= acos(-1);
// constであらかじめ定義しておくと、間違えて定義してもエラーになる
	double S=a*a*b/2.0;
	if(S<x){
		int hoge=a*a*a;
		int chage=2*a*a*b-2*x;
		double rad = atan((double)hoge/chage);
		double drg = rad*180/pi;
		
		cout << fixed << setprecision(9) << 90.0-drg << endl;
		return 0;
	} else {
		int hoge=2*x;
		int chage=a*b*b;
		double rad = atan((double)hoge/chage);
		double drg = rad*180/pi;
		
		cout << fixed << setprecision(9) << 90.0-drg << endl;
		return 0;
	}
}

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

int main() {
  string A, B;
  cin >> A >> B;
  if (A.size()>B.size())
    cout << "GREATER" << endl;
  else if (A.size()<B.size())
    cout << "LESS" << endl;
  else{
    bool eq = true;
    int i=0;
    while (eq){
      if (A.at(i) > B.at(i)){
        eq = false;
        cout << "GREATER" << endl;
      }
      else if (A.at(i) < B.at(i)){
        eq = false;
        cout << "LESS" << endl;
      }
      else if (A.at(i) == B.at(i) && i==A.size()-1){
        eq = false;
        cout << "EQUAL" << endl;
      }
      i++;
    }
  }
}

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

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

    rep(i, s.size()){
        if(i%2==0){
            if(!(s[i]=='R'||s[i]=='U'||s[i]=='D')){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(!(s[i]=='L'||s[i]=='U'||s[i]=='D')){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	vector<pair<P,ll>> t(m);
	REP(i,m) cin >> t[i].first.second >> t[i].first.first;
	REP(i,m) t[i].second = i;
	sort(ALL(t));
	vector<vector<ll>> cit(n);
	REP(i,m) {
		cit[t[i].first.second - 1].pb(t[i].second);
	}
	vector<string> ans(m);
	REP(i,n) REP(j,cit[i].size()) {
		string zen = to_string(i + 1);
		while(zen.size() < 6) zen = "0" + zen;
		string kou = to_string(j + 1);
		while(kou.size() < 6) kou = "0" + kou;
		ans[cit[i][j]] = zen + kou;
	}
	REP(i,m) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 14848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

// if a >= b
bool compare(string a, string b) {
    if (a.size() > b.size()) return true;
    else if (a.size() < b.size()) return false;
    else {
        for (long long i = 0; i < a.size(); i++) {
            if (a[i] > b[i]) return true;
            else if (a[i] < b[i]) return false;
        }
    }
    return true;
}


string add(string a, string b) {
    bool x = false, y = false;
    if (a[0] == '-') x = true;
    if (b[0] == '-') y = true;

    if (x && y) return '-' + add(a.substr(1, a.size()-1), b.substr(1, b.size()-1));
    else if (x) return add(b, a);
    // 'a - b' or 'a + b'

    if (y) b = b.substr(1, b.size()-1);
    if (y && !compare(a, b)) {
        return '-' + add(b, '-' + a);
    }

    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    string res = "";
    long long up = 0;

    for (long long i = 0; i < max(a.size(), b.size()); i++) {
        long long tmp = up;
        if (i < a.size()) {
            tmp += (a[i] - '0');
        }
        if (i < b.size() && b[i] != '-') {
            if (y) tmp -= (b[i] - '0');
            else tmp += (b[i] - '0');
        }

        if (tmp < 0) {
            res.push_back((10 + tmp) + '0');
            up = -1;
        }
        else if (tmp > 9) {
            res.push_back((tmp - 10) + '0');
            up = 1;
        }
        else {
            res.push_back(tmp + '0');
            up = 0;
        }
    }

    if (up > 0) res.push_back(up + '0');

    reverse(res.begin(), res.end());

    long long begin = 0;
    while (res[begin] == '0') begin++;
    
    if (res.size() == begin) return "0";
    else return res.substr(begin, res.size() - begin);
}


int main(){
    string a, b;
    cin >> a >> b;
    cout << add(a, b) << endl;
    return 0;
}


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

int main() {
    vector<int> vec(3);
    for (int i = 0; i < vec.size(); i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    cout << vec[2] - vec[0] << endl;
    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Digit Sum Replace
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

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

  ll d = 0, s = 0;
  for (int i = 0; i < m; i++) {
    int di;
    ll ci;
    scanf("%d%lld", &di, &ci);

    d += ci;
    s += di * ci;
  }
  //printf("%lld %lld\n", d, s);

  printf("%lld\n", (d - 1) + (s - 1) / 9);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k, a, b;

	cin >> k >> a >> b;

	for ( int i = a; i <= b; i++ )
	{
		if ( i % k == 0 )
		{
			cout << "OK" << endl;
			return 0;
		}
	}

	cout << "NG" << endl;
}

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

int main()
{
    int i,j,k,x,sp,ep;
    cin>>k>>x;
    sp=max(-1000000,x-k+1);
    ep=min(1000000,k+x-1);
    for(i=sp;i<=ep;i++)
        cout<<i<<" ";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string s;
int size;
int r[7][7];
int now;
int flag;

int main(void){
  
  for( int i = 0 ; i < 7 ; i++ ){
    for( int j = 0 ; j < 7 ; j++ ){
      r[i][j] = -1;
    }
  }
  r[1][2] = r[4][2] = r[6][4] = r[3][5] = r[5][6] = 0;
  r[1][4] = r[2][3] = r[6][2] = r[3][6] = r[5][4] = 1;
  
  // A = 1, B = 6, X = 2, Y = 4, W = 5, Z = 3
  
  while( cin >> s , s[0] != '#' ){
    
    int now = 1;
    size = s.size();
    
    for( int i = 0 ; i < size ; i++ ){
      
      int S = s[i] - '0';
      flag = 0;
      for( int j = 1 ; j < 7 ; j++ ){
	
	if( r[now][j] == S ){
	  now = j;
	  // cout << j << endl;	  
	  break;
	}
	else flag++;
      }
      if( flag == 6 ) goto end;
    }
    if( now == 6 ) cout << "Yes" << endl;
    else {
    end:
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1180
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    ll N; cin >> N;
    
    ll ans = 0;
    ll i = 0;
    ll q = 0;
    while (q * q < N) {
        i++;
        ll m = N / i - 1;
        if (m <= 0) break;
        q = N / m;
        ll r =  N % m;
        if (q == r) ans += m;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
main(){
  int a[8],b,h,i,j;
  for(;;){
    for(i=0;i<8;i++)
      if(scanf("%d",&a[i])==-1)
	break;
    if(i!=8)
      break;
    b=0;
    h=0;
    for(i=0;i<4;i++)
      for(j=0;j<4;j++)
	if(a[i+4]==a[j])
	  if(i==j)
	    h++;
	  else
	    b++;
    printf("%d %d\n",h,b);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<vector<ll>> dp;
vector<ll> a;

ll dfs(ll l,ll r){
    if(l>r){return E;}
    if(l==r){return dp[l][r]=0;}
    if(dp[l][r]!=E){return dp[l][r];}
    for(ll i=l;i<r;i++){
        dp[l][r]=min(dp[l][r],dfs(l,i)+dfs(i+1,r)+a[r]-(l==0?0LL:a[l-1]));
    }
    return dp[l][r];
}


int main(){
    ll n;
    cin>>n;
    a.resize(n);
    for(auto &i:a){cin>>i;}
    for(int i=1;i<n;i++){a[i]+=a[i-1];}
    dp.resize(n,vector<ll>(n,E));
    cout<<dfs(0,n-1)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1536
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val d = cin.nextInt()
    val k = 2*d + 1

    if (n%k == 0) {
        println(n/k)
    } else {
        println(n/k + 1)
    }
}

Measured memory_bytes: 31136
N = int(input())
S = input()


W = [[] for _ in range(N)]
E = [[] for _ in range(N)]

prev_w = 0
prev_e = 0
for i, s in enumerate(S):
    if s == 'W':
        W[i] = prev_w + 1
    else:
        W[i] = prev_w
    prev_w = W[i]

for i, s in enumerate(S[::-1]):
    if s == 'E':
        E[-i] = prev_e + 1
    else:
        E[-i] = prev_e
    prev_e = E[-i]
        
ans = len(S)
for i in range(N):
    if i == 0:
        cost = E[i+1]
    elif i == N-1:
        cost = W[i-1]
    else:
        cost = W[i-1] + E[i+1]
    ans = min([cost, ans])
print(ans)

Measured memory_bytes: 82912
#include <iostream>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rep1(i,n) for(int i = 1 ; i < n ; i++)
const int MAX_N = 101;
const int MAX_T = 21;

//total 0 <= x <= 20 テ」ツ?敕」ツつ古、ツサツ・テ・ツ、ツ姪」ツ?ッテ」ツ?ァテ」ツ?催」ツ?ェテ」ツ??」ツ?ョ
//dp[n][total]

int main(){
  int n,a[MAX_N],ans;
  long long dp[MAX_N][MAX_T];
 
  cin >> n;
  rep(i,n-1) cin >> a[i];

  rep(i,MAX_N) rep(j,MAX_T) dp[i][j] = 0;
  dp[0][a[0]] = 1;

  rep1(i,n-1){
    rep(j,MAX_T){
      if(j+a[i] < MAX_T) dp[i][j+a[i]] += dp[i-1][j]; 
      if(j-a[i] >= 0) dp[i][j-a[i]] += dp[i-1][j];
    }
  }

  cin >> ans;
  cout << dp[n-2][ans] << endl;

  return 0;
}

Measured memory_bytes: 1172
N,K = map(int,input().split())
sum_ans = 0
 #get "ruisekiwa"
c_sum = [0]*(N+2)
for i in range(N+1):
    c_sum[i+1]+=c_sum[i]+i

for i in range(K,N+2):
    sum_ans+= ((c_sum[N+1]-c_sum[N+1-i])-(c_sum[i]-c_sum[0])+1)
print(sum_ans%(10**9+7))


Measured memory_bytes: 19252
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
#include<math.h>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    if(n*a > b) cout << b;
    else cout << n*a;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
char b[256];
int a[256];
int main(void)
{
    int i, n, m;
    while (1) {
        for (i=0; i<256; ++i) a[i] = 0;
        n = atoi(fgets(b, 256, stdin));
        if (n == 0) break;
        for (i=0; i<n; ++i) {
            fgets(b, 256, stdin);
            a[b[0]] = b[2];
        }
        m = atoi(fgets(b, 256, stdin));
        for (i=0; i<m; ++i) {
            char t = fgets(b, 256, stdin)[0];
            if (a[t]) putchar(a[t]);
            else putchar(t);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int h = S / 3600;
    int m = (S % 3600) / 60;
    int s = ((S % 3600) % 60);
    System.out.println(h + ":" + m + ":" + s);
  }
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += mp[i - a];
    mp[i + a] += 1;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 20556
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <cstring>

using namespace std;
typedef pair<int, int> pii;

string field[1000];
int passed[1000][1000];

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

int main(){
	int H, W, N, answer = 0;
	cin >> H >> W >> N;
	pii from = pii(0, 0);
	for(int i = 0; i < H; ++i){
		cin >> field[i];
		char *pos = strchr(field[i].c_str(), 'S');
		if(pos != NULL){ from = pii(pos - field[i].c_str(), i); }
	}
	for(int i = 1; i <= N; ++i){
		for(int j = 0; j < H; ++j){ memset(passed[j], 0, sizeof(int) * W); }
		char goal = '0' + i;
		queue<pii> q;
		q.push(from);
		while(!q.empty()){
			pii pt = q.front();
			if(field[pt.second][pt.first] == goal){ break; }
			q.pop();
			int dist = passed[pt.second][pt.first];
			for(int j = 0; j < 4; ++j){
				pii next = pii(pt.first + dx[j], pt.second + dy[j]);
				if(
					0 <= next.first && next.first < W &&
					0 <= next.second && next.second < H &&
					field[next.second][next.first] != 'X' &&
					passed[next.second][next.first] == 0
				){
					passed[next.second][next.first] = dist + 1;
					q.push(next);
				}
			}
		}
		answer += passed[q.front().second][q.front().first];
		from = q.front();
	}
	cout << answer << endl;
	return 0;
}

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

int main() {
  int a, b;
  std::cin >> a >> b;
  int max = a + b;
  max = std::max(max, a*b);
  max = std::max(max, a-b);
  std::cout << max << std::endl;
  
  return 0;
}

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

void func(int,int);
char ans[12];
int d[12],flag,w;

int main(){
  cin>>w;
  d[0]=1,d[1]=3;
  for(int i=2;i<12;i++) d[i]=d[i-1]*3;
  func(0,0);
  return 0;
}

void func(int x,int n){
  if(flag) return ;
  if(x==12){
    if(n==w){
      flag=1;
      int f=0;
      for(int i=11;i>=0;i--){
	if(!f&&ans[i]!='0') f=1;
	if(f) cout<<ans[i];
      }
      cout<<endl;
    }
  }else{
    ans[x]='-';
    func(x+1,n-d[x]);
    ans[x]='0';
    func(x+1,n);
    ans[x]='+';
    func(x+1,n+d[x]);
  }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
 
using namespace std;
 
const int inf=1e9+10;
int main(){
        int p1,p2,p12,n1,n2;
        cin>>p1>>p2>>p12>>n1>>n2;
        int ans=inf;
        for(int i=0;i<=n2;i++){
                int cans=i*p12*2;
                cans+=max(0,n1-i)*p1;
                cans+=max(0,n2-i)*p2;
                ans=min(ans,cans);
        }
        cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int N, T, A;
  cin >> N;
  cin >> T >> A;
  double minimum = 10000000.;
  int H;
  double diff;
  int ans;
  for (int i = 0; i < N; ++i) {
    cin >> H;
    diff = abs(A - (T - (H * 0.006)));
    if (diff < minimum) {
      minimum = diff;
      ans = i + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  cout << "ABC" << N << endl;

  return 0;
}



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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    List<int> A;

    public void Do()
    {
        cin = new Scanner();
        string S = cin.nextString();
        int N = S.Length;
        A = new List<int>();

        int mod = 0;
        int tmp = 1;
        for (int i = 0; i < N; i++)
        {
            if (S[N - 1 - i] == '?')
            {
                A.Add(tmp);
            }
            else
            {
                int v = S[N - 1 - i] - '0';
                mod = (mod + v * tmp) % 13;
            }
            tmp = (10 * tmp) % 13;
        }


        int M = A.Count;
        int[,] DP = new int[M + 1, 13];

        DP[0, mod] = 1;

        for (int i = 1; i <= M; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                int tmp2 = (j * A[i - 1]) % 13;
                for (int k = 0; k < 13; k++)
                {
                    DP[i, (k + tmp2) % 13] = (DP[i, (k + tmp2) % 13] + DP[i - 1, k]) % 1000000007;
                }
            }
        }

        Console.WriteLine(DP[M, 5]);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 17888
// v3
// ref: https://img.atcoder.jp/arc096/editorial.pdf
// ref: https://atcoder.jp/contests/abc095/submissions/12788641

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

vector<int64> v_max(const vector<int64>& v){
    vector<int64> ret;
    int64 maxKCal=INT_MIN;
    for(uint i=0; i<v.size(); ++i){
        maxKCal = max(maxKCal, v[i]);
        ret.push_back( maxKCal );
    }
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    // R: clockwise
    // L: counterclockwise
    
    int64 N, C; cin >> N >> C;
    vector<int64> vDistR(N+1), vKCal(N+1); // distance, kcal
    for(int i=1; i<=N; ++i){ cin >> vDistR[i] >> vKCal[i]; }
    
    vector<int64> vR(N+1); vR[0]=0ll; for(int i=1; i<=N; ++i){ vR[i] = vR[i-1] + vKCal[i]; }
    vector<int64> vL(N+1); vL[0]=0ll; for(int i=1; i<=N; ++i){ vL[i] = vL[i-1] + vKCal[N+1-i]; }
    vector<int64> vR_max(N+1); vR_max[0]=0ll; for(int i=1; i<=N; ++i){ vR_max[i]=max(vR_max[i-1], vR[i]-vDistR[i]); } // kcal - dist
    vector<int64> vL_max(N+1); vL_max[0]=0ll; for(int i=1; i<=N; ++i){ vL_max[i]=max(vL_max[i-1], vL[i]-(C-vDistR[N+1-i])); } // kcal - dist
    
    int64 sum=0ll;
    // R: clockwise
    for(int i=1; i<=N; ++i){
        sum = max(sum, vR[i] -   vDistR[i]              );
        sum = max(sum, vR[i] - 2*vDistR[i] + vL_max[N-i]);
    }
    // L: counterclockwise
    for(int i=1; i<=N; ++i){
        sum = max(sum, vL[i] -   (C-vDistR[N+1-i])              );
        sum = max(sum, vL[i] - 2*(C-vDistR[N+1-i]) + vR_max[N-i]);
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

#define N 100000

typedef struct{
  int p;
  int l;
  int r;
}Node;

void preorder(Node*,int);
void inorder(Node*,int);
void postorder(Node*,int);

int main(){

   int i;
   int n;
   int id;
  Node T[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p = -1;
    T[i].l = -1;
    T[i].r = -1;
  }

   for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d%d",&T[id].l,&T[id].r);
    T[T[id].l].p = id;
    T[T[id].r].p = id;
   }

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

    printf("Preorder\n");
    preorder(T ,i);
    printf("\n");
    printf("Inorder\n");
    inorder(T ,i);
    printf("\n");
    printf("Postorder\n");
    postorder(T ,i);
    printf("\n");

  return 0;
}


void preorder(Node *T ,int i){
  if(i == -1) return;
  printf(" %d",i);
  preorder(T ,T[i].l);
  preorder(T ,T[i].r);
}

void inorder(Node *T ,int i){
  if(i == -1) return;
  inorder(T ,T[i].l);
  printf(" %d",i);
  inorder(T ,T[i].r);
}

void postorder(Node *T ,int i){
  if(i == -1) return;
  postorder(T ,T[i].l);
  postorder(T ,T[i].r);
  printf(" %d",i);
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, K;
int A[100010], B[100010];
int tmp = 0;
ll sum = 0, ans = 0;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    tmp |= A[i];
    sum += B[i];
  }
  if (tmp <= K) {
    cout << sum << endl;
    return 0;
  }

  sum = 0;
  for (int j = 0; j < N; j++) {
    if ((K | A[j]) == K) {
      sum += B[j];
    }
  }
  ans = max(ans, sum);
  

  for (int i = 0; i < 30; i++) {
    if (!(K >> i & 1)) continue;
    int nK = (1 << i) - 1;
    for (int j = i+1; j < 30; j++) {
      nK |= ((K >> j & 1) << j);
    }
    sum = 0;
    for (int j = 0; j < N; j++) {
      if ((nK | A[j]) == nK) {
        sum += B[j];
      }
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1152
<?php
$a = trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
$count = 0;
for ($i = 0; $i < $a-1; $i++) {

if($i>0 && $i<$a-1) {
    if (($input[$i-1] < $input[$i] && $input[$i] < $input[$i+1])or($input[$i-1] > $input[$i] && $input[$i] > $input[$i+1])) {
        $count++;
    }
}
}
echo $count;
?>

Measured memory_bytes: 4728
#### import ####
import sys
import math
from collections import defaultdict

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

#### 定数 ####
mod = 10**9 + 7

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

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

N,D = II()

X = []
for i in range(N):
    X.append(III())

ans = 0
for i in range(N):
    for j in range(i+1,N):
        l = 0
        for k in range(D):
            l += (X[i][k]-X[j][k])**2
        if math.sqrt(l) == int(math.sqrt(l)):
            ans += 1

print(ans)

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define no cout << "NO" << endl;
#define yes cout << "YES" << endl;
#define tc int t; cin >> t; while (t--)
#define sz(c) (int) (c).size()
#define trav(x,c) for(auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define _for(i,a,n) for(int i = a ; i < n; ++i)
#define _rfor(i,n,a) for(int i = n-1 ; i >= a; --i)
#define db(x) cout << #x << ": " << x << endl;
#define _db(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);
template<typename... T> void read(T&... x) {((cin >> x),...);}

const ld PI = acos(-1);
int main() {
    godspeed;
    int a, b, h, m;
    read(a,b,h,m);

    ld rad = PI * 2 * ((ld)h / 12.0 + ((ld)m / 60.0) / 12.0 - (ld)m / 60.0);
    ld rsq = (ld)(a * a + b * b) - (ld)(2 * a *b) * cosl(rad);
    cout << setprecision(20) << fixed << sqrt(rsq);
}


Measured memory_bytes: 4152
n,x,y = map(int, input().split())

ans = [0]*(n-1)
for j in range(1, n+1):
    for i in range(1, j):
        dis = min(j-i, abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        ans[dis-1] += 1

for i in ans:
    print(i)


Measured memory_bytes: 46940
#include <iostream>
#include <algorithm>
#include <vector>
#include <map> 
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define pb push_back

int main(int argc, char** argv) {
	int n,a,b;
	cin>>n>>a>>b;
	int p=(n-b);
	if(n<b+a-1)
	{
		cout<<-1;
		return 0;
	}
	if((n/b+((n%b)?1:0))>a||(n/a+((n%a)?1:0))>b)
	{
		cout<<-1;
		return 0;
	}
	vector<int>ans;
	;
	ans.pb(b);
	a--;
	while(a)
	{
		int u=min(b,p-(a-1));
		p-=u;
	//	cout<<u<<endl;
		a--;
		ans.pb(u);
	}
	int low=0,hig=0;
	rep(i,0,ans.size()-1)
	{
		low=hig;
		hig=hig+ans[i];
		//cout<<hig<<endl;
		rep2(j,hig,low+1)printf("%d ",j);
	}
	return 0;
}

Measured memory_bytes: 3184
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    
    const win  = S.filter(n=>n==="o").length;
    const rest = 15 - S.length;
    
    console.log((rest + win) >= 8 ? "YES" : "NO");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<stdio.h>
#include<vector>
using namespace std;
vector<int> graph[100];
int n_node,n_edge;
bool visited[100];
int ans;

void depth(int at,int node_visited)
{
    if(node_visited==n_node)
    {
        ans++;
        return;
    }
    for(vector<int>::iterator it=graph[at].begin();it!=graph[at].end();++it)
    {
        if(visited[*it]==false)
        {
            visited[*it]=true;
            depth(*it,node_visited+1);
            visited[*it]=false;
        }
    }
}

main()
{
    scanf("%d %d",&n_node,&n_edge);
    for(int i=1;i<=n_edge;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    visited[1]=true;
    depth(1,1);
    printf("%d",ans);
}


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

int main(){

  int m,n;
  int a;
  int ans = 0;
  int k;
  cin >> m >> n;

  for(int i=0;i<m;i++){

    k = 0;
    for(int j=0;j<n;j++){
      cin >> a; 
      if(a == 1) k++;
    }

    ans = max(ans,k);
  }

  cout << ans << endl;

}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n,ans=0;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	rep(i, n) {
		while (a[i] % 2 == 0)a[i] /= 2,ans++;
	}
	cout << ans << endl;
}




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chkmax(T& a,T b){return a<b?a=b,1:0;}
template<class T> inline bool chkmin(T& a,T b){return a>b?a=b,1:0;}
template<typename T> inline T& read(T& x){
    static char c; bool flag=0;
    while(!isdigit(c=getchar())) if(c=='-') flag=1;
    for(x=c-'0';isdigit(c=getchar());(x*=10)+=c-'0');
    if(flag) x=-x;
    return x;
}
const int maxn=3010,mo=1e9+7;
int n,m,f[maxn][maxn][2],ans;
int main(){
    read(n); read(m);
    f[0][0][1]=1;
    for(int i=1;i<=n;i++) f[0][i][0]=1;
	for(int i=1;i<=m;i++){
		f[i][0][1]=((f[i-1][1][0]+f[i-1][1][1])%mo+f[i-1][0][1])%mo;
		if(n==1){
			f[i][1][1]=((f[i-1][0][1]+f[i-1][1][1])%mo+f[i-1][1][0])%mo;
			continue;
		}
		f[i][1][0]=(f[i-1][1][0]+f[i-1][2][0])%mo;
		f[i][1][1]=(((f[i-1][0][1]+f[i-1][1][1]*2%mo)%mo+f[i-1][1][0])%mo+f[i-1][2][1])%mo;
		for(int j=2;j<n;j++) for(int k=0;k<=1;k++)
			f[i][j][k]=((f[i-1][j][k]*2%mo+f[i-1][j-1][k])%mo+f[i-1][j+1][k])%mo;
		f[i][n][0]=(f[i-1][n][0]+f[i-1][n-1][0])%mo;
		f[i][n][1]=(f[i-1][n][1]+f[i-1][n-1][1])%mo;
	}
	for(int i=0;i<=n;i++) (ans+=f[m][i][1])%=mo;
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 70784