akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

ll powermod(ll a,ll b,ll m){
	if(b==0){
		return 1LL;
	}
	if(b%2){
		return (a*powermod(a,b-1LL,m))%m;
	}
	return powermod((a*a)%m,b/2LL,m);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N=in();
	auto D=vecin(N);
	auto Dmax = *max_element(ALL(D));

	if(D[0]!=0){
		out(0);
		return 0;
	}

	map<int,int> M;
	REP(i,N) M[D[i]]++;

	if(M[0]!=1){
		out(0);
		return 0;
	}

	ll A=1;
	REP(i,Dmax){
		A *= powermod(M[i],M[i+1],998244353);
		A %= 998244353;
	}

	out(A);
	return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>
#include <math.h>
#include<string.h>
int main(void){
    int i, len;
    char s[1001];
    for(;;){
        int ans=0;
        scanf("%s", s);
        if(s[0]=='0') break;
        
        for(i=0; s[i]!='\0'; i++)
            ans+=s[i]-'0';
            printf("%d\n", ans);
        
        
    }
    return 0;
}



Measured memory_bytes: 2048
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a, b, c, d, e, h1, m1, re;
    cin >>a >> b >> c >> d >>e ;
    h1 = (c - a)*60;
    m1 = d - b;
    re = h1 + m1;
    cout << re - e << endl;



    return 0;
}


Measured memory_bytes: 3624
n=int(input())
s=[int(input())for i in range(n)]
s.sort()
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s=groupby(s)
l=len(s)
cnt=0
for i in range(l):
    cnt+=s[i][1]%2
print(cnt)


Measured memory_bytes: 64472
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n == 25){
            System.out.println("Christmas");
        } else if(n == 24){
            System.out.println("Christmas Eve");
        } else if(n == 23){
            System.out.println("Christmas Eve Eve");
        } else if(n == 22){
            System.out.println("Christmas Eve Eve Eve");
        } 
    }
}

Measured memory_bytes: 21716
N = input()

answer = ""

for i in range(1 << 3):
    exp = N[0]
    for j in range(3):
        if i >> j & 1:
            exp += "+"
        else:
            exp += "-"
        exp += N[j + 1]
    if eval(exp) == 7:
        answer = exp
        break

print(answer + "=7")



Measured memory_bytes: 2940
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
using namespace std;

struct node{int key; node *right,*left,*parent;};
node *root,*NIL;

void insert(int k)
{
	node *y=NIL;
	node *x=root;
	node *z;
	
	z=(node *)malloc(sizeof(node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;
	
	while(x!=NIL)
	{
		y=x;
		if(z->key < x->key)
		{
			x=x->left;
		}
		else
		{
			x=x->right;
		}
	}
	
	z->parent=y;
	if(y==NIL)
	{
		root=z;
	}
	else
	{
		if(z->key < y->key)
		{
			y->left=z;
		}
		else
		{
			y->right=z;
		}
	}
}

void find(int k)
{
	node *x=root;
	while(x!=NIL)
	{
		if(x->key > k)
		{
			x=x->left;
		}
		else if(x->key < k)
		{
			x=x->right;
		}
		else
		{
			cout<<"yes"<<endl;
			return;
		}
	}
	cout<<"no"<<endl;
	return;
}

void ino(node *u)
{
	if(u==NIL)return;
	ino(u->left);
	printf(" %d",u->key);
	ino(u->right);
}

void preo(node *u)
{
	if(u==NIL)return;
	printf(" %d",u->key);
	preo(u->left);
	preo(u->right);
}

int main()
{
	int n,i,x;
	string com;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		cin>>com;
		if(com=="insert")
		{
			scanf("%d",&x);
			insert(x);
		}
		else if(com=="print")
		{
			ino(root);
			printf("\n");
			preo(root);
			printf("\n");
		}
		else if(com=="find")
		{
			scanf("%d",&x);
			find(x);
		}
	}
	
	return 0;
}

Measured memory_bytes: 21892
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
const long long mod = 1e9+7;

int main(){
  int N,M;cin >> N >> M;
  vector<int> oks(N+1,true);
  for(int i=0;i<M;i++){
    int a;cin >> a;
    oks[a]=false;
  }
  vector<Int> dp(N+1);
  dp[0]=1;
  for(int now=0;now<N;now++){
    for(int next = now+1;next<=min(N,now+2);next++){
      if(oks[next]){
        dp[next]+=dp[now];
        dp[next]%=mod;
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 1408
def comb(n,k,p):
    """power_funcを用いて(nCk) mod p を求める"""
    from math import factorial
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    a=factorial(n) %p
    b=factorial(k) %p
    c=factorial(n-k) %p
    return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
    """a^b mod p を求める"""
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p

s = int(input())
MOD = 10**9 + 7

maxlen = s//3
ans = 0

for i in range(1,maxlen+1):
    rest = s - (3 * i)
    com = comb(rest+i-1,i-1,MOD)
    
    ans = (ans + com) % MOD
    
print(ans)

Measured memory_bytes: 73360
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int INF = 1000000000;

int main() {
	int n;
	vector<int> a(3);
	cin >> n >> a[0] >> a[1] >> a[2];
	int l[n];
	for (int i = 0; i < n; i++) cin >> l[i];
	
	int p = pow(4, n);
	int ans = INF;
	for (int i = 0; i < p; i++) {
		int t[n];
		{	
			int tmp = i;
			for (int j = 0; j < n; j++) {
				t[j] = tmp % 4;
				tmp /= 4;
			}
		}

		int now = 0;
		int b[3] = {0};
		for (int i = 0; i < n; i++) {
			if (t[i] == 3) continue;
			if (b[t[i]] == 0) b[t[i]] += l[i];
			else {
				b[t[i]] += l[i];
				now += 10;
			}
		}
		if (b[0]==0 || b[1]==0 || b[2]==0) continue;
		for (int i = 0; i < 3; i++) now += abs(a[i]-b[i]);
		ans = min(ans, now);	
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
n, k = map(int, input().split())
e = 0
h = 0
for i in range(1, n + 1):
    if k % 2 == 0 and i % k == k // 2:
        h += 1
    if i % k == 0:
        e += 1
print(h * h * h + e * e * e)


Measured memory_bytes: 2940
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 100000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
const int N=305;
//Code begin....

int G[N][N], n;
bool flag[N][N];

bool solve(){
    FOR(k,1,n) FOR(i,1,n) FOR(j,1,n) {
        if (i==k||k==j) continue;
        if (G[i][j]>G[i][k]+G[k][j]) return true;
        else if (G[i][j]==G[i][k]+G[k][j]) flag[i][j]=true;
    }
    return false;
}
int main ()
{
    LL ans=0;
    scanf("%d",&n);
    FOR(i,1,n) FOR(j,1,n) scanf("%d",&G[i][j]);
    if (solve()) puts("-1");
    else {
        FOR(i,1,n) FOR(j,1,n) if (flag[i][j]==false) ans+=G[i][j];
        printf("%lld\n",ans/2);
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    long double a,b,c;
    cin >> a >> b >> c;

    long double ra = sqrt(a) , rb = sqrt(b) , rc = sqrt(c);
    long double e = 0.00000000000001;

    if((ra + rb + e) < rc){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
def dfs(r, c):
    global color, G
    S = [r]
    color[r] = c
    while (0 < len(S)):
        u = S.pop()
        for u in G[u]:
            v = color[u]
            if (v == None):
                color[u] = c
                S.append(u)
 
def assignColor():
    global color, G, n
    c = 1
    for i in range(n):
        if (color[i] == None):
            dfs(i, c)
            c += 1
 
n, m = list(map(int, input().split()))
 
G = [[] for i in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    G[s].append(t)
    G[t].append(s)
 
color = [None for i in range(n)]
 
assignColor()
 
q = int(input())

for i in range(q):
    s, t = list(map(int, input().split()))
    if (color[s] == color[t]):
        print("yes")
    else:
        print("no")

Measured memory_bytes: 23388
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,S[1000];

void push(int x){
  S[++top] = x;
}
int pop(){
 top--;
 return S[top+1];
}
int main(){
 int a,b;
 top = 0;
 char s[100];
 while( scanf("%s",s) != EOF){
    if (s[0] == '+'){
        a = pop();
        b = pop();
        push(a + b);
    }else if (s[0] == '-'){
        b = pop();
        a = pop();
        push(a - b);
    }else if (s[0] == '*'){
        a = pop();
        b = pop();
        push(a * b);
    }else {
        push(atoi(s));
    }
 }
 printf("%d\n",pop());

 return 0;
}


Measured memory_bytes: 2692
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int P, Q, R;
  cin >> P >> Q >> R;
  vector<int> v = {P+Q, Q+R, R+P};
  sort(v.begin(), v.end());
  cout << v[0] << endl;
  return 0;
}

Measured memory_bytes: 256
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

#print(combinations_count(5, 2))
def modpow(a, n, MOD):
  res = 1
  while (n > 0):
    if (n & 1):
      res = res * a % MOD
    a = a * a % MOD
    n >>= 1
  return res

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
mod = 10 ** 9 + 7
N = 2 * 10 ** 6 + 1  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

K = int(input())
S = str(input())
N = len(S)

ans = 0
p = N + K - 1
#now = combinations_count(p, N - 1) % mod

for i in range(K + 1):
  p = N + K - i - 1
  now = cmb(p, N - 1, mod)
  a = pow(25, K - i, mod)
  b = pow(26, i, mod)
  c = a * b % mod
  ans += now * c % mod
  ans = ans % mod
print(ans)
  

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

int main(){
	int n;
	cin >> n;
	
	int ans = 0;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		ans += a - 1;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
/* ex9_2
   bonbonc    */

#include <stdio.h> 
#include<stdlib.h>
#include<string.h>
#define SIZE 100000

typedef struct _entry{
    int key;//キー
    char token;//文字（0や1)
    struct _entry *next;//次の要素のポインタ
} entry;

void initialize_pool(entry *pool, int size);//プールの初期化関数
entry* insert_list(entry *head, int key, char character);//リストの先頭に要素を挿入する関数
entry* delete_head(entry *head);//リストの先頭を削除する関数

entry pool[SIZE];//メモリ確保用のentry配列
entry *freelist;//未使用のリスト

int main(void){
    entry *head;//リストの先頭を示すポインタ
    int count=0,i;//ブロックを消した回数を記録する変数とループ変数
    char string[SIZE];//入力を受け取る変数

    initialize_pool(pool,SIZE);//プールを初期化

    scanf("%s",string);//入力を受け取る
    head =NULL;//先頭のポインタをNULLで初期化
    
    for(i=0;i<strlen(string);i++){//一文字ずつ見ていく
        if(head==NULL){//先頭ポインタがNULLだったら、リストにstring[i]を挿入
            head = insert_list(head,i,string[i]);
        }else if(head->token != string[i]){
            head = delete_head(head);//リストの先頭と、string[i]が違ったら先頭を取り出す
            count++;//先頭を取り出した分のカウント
            count++;//string[i]を入れて取り出した分のカウント（実際には入れていない)
        }else{
            head = insert_list(head, i, string[i]);//リストの先頭とstring[i]が同じだったらそのまま先頭に挿入
        }
        
    }
    printf("%d\n",count);//答えを出力
    return 0;
}

void initialize_pool(entry *pool, int size){
    int i;//ループ変数
    if(size<1){//sizeが1より小さいときの例外処理
        fprintf(stderr, "Illegal pool size %d.\n",size);
        exit(1);
    }
    for(i=0;i<(size-1);i++){//pool[i]の次のポインタをpool[i+1]につなげる
        pool[i].next = &(pool[i+1]);
    }
    pool[size-1].next = NULL;//末尾の次のポインタをNULLにする
    freelist = pool;//freelistにpoolを渡す
}

entry* insert_list(entry *head, int key, char character){
    entry *new;

    if(freelist == NULL){//freelistが空いていないときの処理
        fprintf(stderr, "out of free space.\n");
        exit(1);
    }else{
        new = freelist;//freelistを一つ持ってくる
        freelist = freelist->next;//freelistを次の要素にずらす
    }
    //それぞれのメンバ変数を渡す
    new -> key = key;
    new -> token = character;
    new -> next = head;
    
    return new;//newポインタを返す
}

entry* delete_head(entry *head){
    entry *ptr;
    ptr=head;//先頭のポインタをコピー
    head = head->next;//先頭のポインタを次のポインタにずらす
    ptr->next = freelist;//元先頭のポインタをfreelistにつなげる
    freelist = ptr;//freelistの先頭のポインタを元先頭ポインタにする

    return head;//新しい先頭ポインタを返す
}

Measured memory_bytes: 3352
ans = 0
cnt = 0
for s in input():
  if s == 'g':
    if cnt > 0:
      ans += 1
      cnt -=1
    else:
      cnt += 1
  else:
    if cnt > 0:
      cnt -=1
    else:
      ans -= 1
      cnt += 1
print(ans)

Measured memory_bytes: 39664
#include<bits/stdc++.h>
using namespace std;
int n,a[2000005];
inline bool check(int k)
{
    for(int i=0;i<n-1;i++)
	{
        if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))
			return true;
        if((a[n+i]>k&&a[n+i+1]>k)||(a[n-i]>k&&a[n-i-1]>k))
			return false;
    }
    if(a[1]<=k)
    	return true;
    else
    	return false;
}
int main()
{
	scanf("%d",&n);
    for(int i=1;i<n*2;i++)
		scanf("%d",&a[i]);
    int l=1,r=n*2-1;
    while(l<r)
	{
        int mid=(l+r)/2;
        if(check(mid))
			r=mid;
        else 
			l=mid+1;
    }
    printf("%d\n",l);
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	count := 0
	for i := 0; i <= 100; i++ {
		if i >= a && i <= b && i >= c && i <= d {
			count++
		}
	}

	if count > 0 {
		count--
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
n, m = map(int, input().split())
p = list(map(int, input().split()))
g = []
for i in range(m):
    g.append(list(map(int, input().split())))
l = [[] for i in range(n+1)]
for pi in g:  
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])
x =  [0]*n
for i in range(n):
  x[p[i]-1] = i+1
ans = 0
#Union find
y = [-1] * n
for i in range(0,n):
  if y[i] == -1:
    y[i] = i
  c = l[i+1]
  while len(c) > 0:
    z = c.pop()
    y[z-1] = y[i]
    for j in range(len(l[z])):
      if y[l[z][j]-1] == -1:
        c.append(l[z][j])
    l[z] =[]
    
for i in range(n):
  c = x[i]
  if y[c-1] == y[i]:
    ans +=1
print(ans)

Measured memory_bytes: 49152
#include <algorithm>
#include <atcoder/all>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using namespace atcoder;
using ll = long long;

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

    dsu d(N);

    for (int i = 0; i < Q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 4052
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


int main(){
  string S;
  cin >> S;
  int N;
  N = S.size();
  int i=0;
  vector<int> sum(N,0);
  while(N>i){
    if(S[i] == 'R'){
      int s=i;
      int a=1,b=0;
      while(S[i+1] == 'R'){
        if((s-i)%2==0){
          b++;
        }else{
          a++;
        }
        i++;
      }
      i++;
      sum[i-1] += a;
      sum[i] += b;
    }else{
      int s=i;
      int a=0,b=1;
      while(S[i+1] == 'L' && N>=i){
        if((s-i)%2==0){
          a++;
        }else{
          b++;
        }
        i++;
      }
      i++;
      sum[s-1] += a;
      sum[s] += b;
    }
  }
  for(int i=0; i<S.size(); i++){
    cout << sum[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll a , b ;
    char c ;
    cin >> a >> c >> b;
    if(c == '+') {cout << a + b << el ;}
    else cout << a-b << el ;
    ro ;
}































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

int main() {
  int h, w, i, j, ans = 1;
  cin >> h >> w;
  string s[52];
  for (i = 0; i < h + 2; i++) {
    if (i == 0 || i == h + 1) {
      for (j = 0; j < w + 2; j++) {
        s[i] += '.';
      }
    } else {
      string tmp;
      cin >> tmp;
      s[i] += '.';
      s[i] += tmp;
      s[i] += '.';
    }
  }
  for (i = 1; i < h; i++) {
    for (j = 1; j < w; j++) {
      if (s[i][j] == '#') {
        if (!(s[i - 1][j] == '#' || s[i + 1][j] == '#' || s[i][j - 1] == '#' ||
              s[i][j + 1] == '#')) {
          ans = 0;
        }
      }
    }
  }
  if (ans) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No"
         << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD = 1e9+7;

bool comp(P &lhs, P &rhs)
{
	if(lhs.second==rhs.second)
	{
		return lhs.first>rhs.first;
	}else{
		return lhs.second<rhs.second;
	}
}

P p[200000];

int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>p[i].first>>p[i].second;
	sort(p,p+n,comp);
	ll now=0;
	bool f=true;
	for(int i=0;i<n;i++)
	{
		if(now+p[i].first<=p[i].second)
		{
			now+=p[i].first;
		}else{
			f=false;
			break;
		}
	}
	if(f)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3328
n = int(input())
nlist = [input() for i in range(n)]
m = int(input())
mlist = [input() for j in range(m)]
r = 0
for nn in nlist:
    if nlist.count(nn) > mlist.count(nn) and r < nlist.count(nn) - mlist.count(nn):
        r = nlist.count(nn) - mlist.count(nn)
print(r)


Measured memory_bytes: 3060
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
ac = list(accumulate(a))
total = ac[-1]
ans = float('inf')
for i in range(n-1):
    l, r = ac[i], total - ac[i]
    ans = min(ans, abs(l-r))
print(ans)

Measured memory_bytes: 31196
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


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

////////////////////////////////////////////////////////////////////
int n,x,y;int ans[2100];
signed main(){
  cin>>n>>x>>y;x--;y--;
  rep(i,n-1){
    repd(j,i+1,n){
      int d = min(j-i, abs(i-x)+abs(j-y)+1);
      ans[d]++;
    }
  }
  repd(i,1,n){
    cout << ans[i] << endl;
  }
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    int S[M], digit[M];
    rep(i, M){
        int s, d; cin >> s >> d;
        S[i] = s-1; digit[i] = d;
    }
    int pow10[] = {1, 10, 100, 1000};
    int dlim, ulim;
    ulim = pow10[N];
    if(N == 1) dlim = 0;
    else dlim = pow10[N-1];
    for(int i = dlim; i < ulim; i++){
        string s = to_string(i);
        bool ok = true;
        rep(j, M){
            if(s[S[j]]-'0' != digit[j]) ok = false;
        }
        if(ok){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 384
from collections import Counter

while True:
    m, n = (int(s) for s in input().split())
    if not m:
        break

    objects = [int(input(), 2) for i in range(n)]
    dp = [bytearray(1 << m) for i in range(1 << m)]
    bits = [1 << i for i in range(m)]

    for asked in reversed(range((1 << m) - 1)):
        for masked, count in Counter(obj & asked for obj in objects).items():
            if count > 1:
                dp[asked][masked] = min(max(dp[asked + b][masked],
                                            dp[asked + b][masked + b])
                                        for b in bits if not b & asked) + 1
    print(dp[0][0])

Measured memory_bytes: 15076
#include <stdio.h>
#include <iostream>
#include <limits.h>
#include <cstdlib>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;

int main(void){
  int a,b,c;
  string ans = "";
  cin >> a >> b >> c;
  if(a < c && b > c){
    ans = "Yes";
  }else if(a > c && b < c){
    ans = "Yes";
  }else{
    ans = "No";
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int sol = 1;
	for (int i = 1; i < n; ++i)
	{
		if (s[i] != s[i-1])
		sol++;
	}
	cout << sol;
}

Measured memory_bytes: 512
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class Main 
{
	static class Node
	{
		HashSet<Node> e = new HashSet<>();
		int i;
		int dis1 = -1;
		int dis2 = -1;
		
		public Node(int id)
		{
			i=id;
		}
	}

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int start1 = sc.nextInt()-1;
		int start2 = sc.nextInt()-1;
		Node[] nd = new Node[n];
		
		for(int i = 0; i < n; i++)
		{
			nd[i] = new Node(i);
		}
		
		for(int i = 0; i < n-1; i++)
		{
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			nd[a].e.add(nd[b]);
			nd[b].e.add(nd[a]);
		}
		
		Node s1 = nd[start1];
		Node s2 = nd[start2];
		LinkedList<Node> q = new LinkedList<Node>();
		q.add(s1);
		s1.dis1 = 0;
		while(!q.isEmpty())
		{
			Node pos = q.pollFirst();
			for(Node e : pos.e)
			{
				if(e.dis1 == -1)
				{
					e.dis1 = pos.dis1+1;
					q.add(e);
				}
			}
		}
		
		q = new LinkedList<Node>();
		q.add(s2);
		s2.dis2 = 0;
		while(!q.isEmpty())
		{
			Node pos = q.pollFirst();
			for(Node e : pos.e)
			{
				if(e.dis2 == -1)
				{
					e.dis2 = pos.dis2+1;
					q.add(e);
				}
			}
		}
		
		int best = 0;
		for(Node x : nd)
		{
//			System.out.println("node " + x.i + " " + x.dis1 + " " + x.dis2);
			if(x.dis2 > x.dis1)
				best = Math.max(best, x.dis2-1);
		}
		System.out.println(best);
	}

}


Measured memory_bytes: 115736
#include <stdio.h>
#include <stdlib.h>

int H,*A;

void maxHeapify(int *, int);
void buildMaxHeap(int *);

int main(){
  int i;

  scanf("%d",&H);
  A = (int *)malloc(sizeof(int)*(H+1));

  for(i=1; i<=H; i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);

  for(i=1; i<=H; i++)
    printf(" %d",A[i]);
  printf("\n");

  return 0;
}

void maxHeapify(int *A, int i){
  int l,r,largest,k;
  l = 2*i;
  r = 2*i+1;

  if((l <= H ) && (A[l] > A[i])) largest = l;
  else largest = i;

  if((r <= H) && (A[r] > A[largest])) largest = r;

  if(largest != i){
    k = A[i];
    A[i] = A[largest];
    A[largest] = k;
    maxHeapify(A, largest);
  }
} 
 

void buildMaxHeap(int *A){
  int i;
  for(i=H/2; i>=1; i--)
    maxHeapify(A,i);
}

Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0;
  cin >> N;
  vector<ll>A(N);
  rep(i,N){
    cin >> A[i];
  }
  ll ans = 0;
  ans += A[0] + A[N-2];
  rep(i,N-2){
    ans += min(A[i],A[i+1]);
  }
  cout << ans;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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

    string n;
    int k;
    cin>>n;
    cin>>k;
    int ans=0;

    rep(i,n.size()){
        if(k==1){
            string s="";
            rep(i,n.size()) s+='0';
            FOR(t,1,10){
                s[i]=t+'0';
                ans+=(s<=n);
            }
        }
        FOR(j,i+1,n.size()){
            if(k==2){
                string s="";
                rep(i,n.size()) s+='0';
                FOR(t,1,10){
                    FOR(u,1,10){
                        s[i]=t+'0';
                        s[j]=u+'0';
                        ans+=(s<=n);
                    }
                }
            }
            FOR(l,j+1,n.size()){
                if(k==3){
                    string s="";
                    rep(i,n.size()) s+='0';
                    FOR(t,1,10){
                        FOR(u,1,10){
                            FOR(r,1,10){
                                s[i]=t+'0';
                                s[j]=u+'0';
                                s[l]=r+'0';
                                ans+=(s<=n);
                            }
                        }
                    }
                }
            }
        }
    }

    cout<<ans<<endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,x=10;
int main() {
	cin>>a>>b;
    while(b/x!=0)x*=10;
    c=b+x*a;
	d=sqrt(c);
	if(d*d==c)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
const int maxn=55;

inline char gc(){
	return getchar();
	static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;
}
inline ll rd(){
    ll x=0;char c=gc();bool neg=0;
    while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();
    return neg?(~x+1):x;
}

int N,ans=1e9;
bool flag[maxn];
pa p[maxn];

inline int calc(int x,int y){
	CLR(flag,0);
	int re=0;
	for(int i=1;i<=N;i++){
		if(flag[i]) continue;
		re++;int nx=p[i].fi,ny=p[i].se;
		flag[i]=1;
		for(int j=1;j<=N;j++){
			if(flag[j]) continue;
			if(nx+x==p[j].fi&&ny+y==p[j].se){
				nx+=x,ny+=y;
				flag[j]=1;
			}
		}
	}
	return re;
}

int main(){
    //freopen("","r",stdin);
    N=rd();if(N==1){printf("1\n");return 0;}
    for(int i=1;i<=N;i++) p[i].fi=rd(),p[i].se=rd();
    sort(p+1,p+N+1);
	for(int i=1;i<=N;i++){//printf("~%d %d\n",)
		for(int j=i+1;j<=N;j++){
			int x=p[j].fi-p[i].fi,y=p[j].se-p[i].se;
			ans=min(ans,calc(x,y));
		}
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
from itertools import product

N, Y = [int(n) for n in input().split()]

ret = [-1, -1, -1]
for x in range(N + 1):
    for y in range(N + 1 - x):
        z = N - x - y
        if N - x - y < 0:
            continue
        if 10000 * x + 5000 * y + 1000 * z == Y:
            ret = [x, y, z]
            break

print(' '.join([str(r) for r in ret]))


Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }

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

// 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 = pow(10, 9) + 7;
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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= 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 {
		mint res(*this);
		return res /= a;
	}
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

void print_vec(const vector<int>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

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




	

int main(void) {
	int N, K, C;
	cin >> N >> K >> C;
	string S;
	cin >> S;

	vector<int> work_day_L(N, -1);
	int cnt = 0; //count
	for(int i=0; i<N; ){
		if(cnt >= K) break;
		if(S[i] == 'x'){
			i++;
			continue;
		}
		work_day_L[i] = cnt;
		cnt++;
		i += C+1;
	}

	vector<int> work_day_R(N, -1);
	cnt = K-1; //count
	for(int i=N-1; i>=0; ){
		if(cnt < 0) break;
		if(S[i] == 'x'){
			i--;
			continue;
		}
		work_day_R[i] = cnt;
		cnt--;
		i -= C+1;
	}
	
	//print_vec(work_day_L);
	//print_vec(work_day_R);

	for(int i=0; i<N; i++){
		//if(S[i] == 'x') continue;
		if(work_day_L[i] == -1) continue;
		if(work_day_L[i] == work_day_R[i]) cout << i+1 << endl;
	}
}




Measured memory_bytes: 3332
#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 rrep(i, n)   for(int i=(n-1); i>=0; --i)
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define int          long long
template<typename T>
using vv  = vector<vector<T>>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;
using P   = pair<int, int>;
using ll  = long long;
constexpr ll INF = 1LL << 60;

signed main(){

    int h, w, k;
    cin >> h >> w >> k; 

    vv<char> c(h, vector<char>(w));
    int cnt = 0;
    rep(i, h){
        rep(j, w){
            cin >> c[i][j];
            if(c[i][j] == '#'){
                cnt++;
            }
        }
    }

    int ans = 0;
    rep(bit, (1<<h)){
        auto v = c;
        int cnt2 = cnt;
        rep(i, h){
            if(bit & (1<<i)){
                rep(j, w){
                    if(v[i][j] == '#'){
                        cnt2--;
                    }
                    v[i][j] = 'r';
                }
            }
        }
        if(cnt2 < k){
            continue;
        }
        rep(bit2, (1 << w)){
            int cnt3 = cnt2;
            rep(i, w){
                if(bit2 & (1<<i)){
                    rep(j, h){
                        if(v[j][i] == '#'){
                            cnt3--;
                        }
                    }
                }
            }
            if(cnt3 == k){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}



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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << ' ' << x << ' ' << y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pir;

int read() {
    int x = 0, f = 1; char ch = getchar();
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}

const int Max = 2033;
int n, cnte, a[Max], fir[Max], g[Max][Max], vis[Max], deg[Max];
priority_queue<pir> que;
vector<int> ans;
struct edge {
    int to, nxt;
    edge() {}
    edge(int a, int b) {
        to = a, nxt = b;
    }
} e[Max * Max * 2];
void addedge(int u, int v) {
    deg[v]++;
    e[++cnte] = edge(v, fir[u]);
    fir[u] = cnte;
}
void dfs(int u) {
    vis[u] = 1;
    for (int i = 1; i <= n; i++)
        if (!vis[i] && g[u][i]) {
            addedge(u, i);
            dfs(i);
        }
}
int gcd(int a, int b) {
	return !b ? a : gcd(b, a % b);
}

int main() {
    n = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            g[i][j] = g[j][i] = gcd(a[i], a[j]) != 1;
    for (int i = 1; i <= n; i++)
        if (!vis[i]) dfs(i);
    for (int i = 1; i <= n; i++)
        if (!deg[i]) que.push(pir(a[i], i));
    while (!que.empty()) {
        ans.push_back(que.top().first);
        int u = que.top().second;
        que.pop();
        for (int i = fir[u]; i; i = e[i].nxt) {
            deg[e[i].to]--;
            if (!deg[e[i].to])
                que.push(pir(a[e[i].to], e[i].to));
        }
    }
    for (int i = 0; i < n; i++) printf("%d ", ans[i]);
    return 0;
}

Measured memory_bytes: 17408
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

void operator +=(vector<int>& a, vector<int>& b){
    rep(i, a.size()) a[i] += b[i];
}

template<int sigma, int a, typename T>
struct Trie{
private:
    T e;
    struct Node{
        int chi[sigma];
        T x;
        Node(T e){
            x = e;
            memset(chi, -1, sizeof(chi));
        }
    };
    vector<Node> nodes;
public:
    Trie(T _e){
        e = _e;
        nodes.push_back(Node(e));
    }
    void add_node(int n, int c){
        nodes[n].chi[c] = nodes.size();
        nodes.push_back(Node(e));
    }
    void add(string s, T y){
        int n = 0;
        nodes[n].x += y;
        for(int i=0; i<s.size(); i++){
            if(nodes[n].chi[s[i]-a] == -1) add_node(n, s[i]-a);
            n = nodes[n].chi[s[i]-a];
            nodes[n].x += y;
        }
    }
    T count_prefix(string s){
        int n = 0;
        for(int i=0; i<s.size(); i++){
            if(nodes[n].chi[s[i]-a] == -1) return e;
            n = nodes[n].chi[s[i]-a];
        }
        return nodes[n].x;
    }
};

int N;
vector<string> S[1000001];

Trie<26, 'a', vector<int>> trie(vector<int>(26, 0));
vector<pair<int, pair<int,int>>> query[1000001];

signed main(){
    cin >> N;
    rep(i, N){
        string s;
        cin >> s;
        reverse(all(s));
        S[s.size()].pb(s);
    }

    ll ans = 0;

    vector<int> v(26, 0);
    for(int i=1000000; i>=1; i--){
        rep(j, query[i-1].size()){
            v[query[i-1][j].first] = 1;
            trie.add(S[query[i-1][j].second.first][query[i-1][j].second.second], v);
            v[query[i-1][j].first] = 0;
            query[i-1][j].first = 0;
        }
        rep(j, S[i].size()){
            ans += trie.count_prefix(S[i][j].substr(0, S[i][j].size()-1))[S[i][j].back()-'a'];
            int p[26];
            memset(p, -1, sizeof(p));
            rep(l, S[i][j].size()){
                p[S[i][j][l]-'a'] = l;
            }
            rep(l, 26){
                if(p[l] == i-1){
                    v[l] = 1;
                    trie.add(S[i][j], v);
                    v[l] = 0;
                }
                else if(p[l] != -1) query[p[l]].pb({ l,{i,j } });
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 285356
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

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

bool matchACGT(char t) {
    if (t == 'A' || t == 'C' || t == 'G' || t == 'T') return true;
    return false;
}

int main() {
    char S[10];
    scanf("%s", S);
    int cnt = 0, ans = 0;
    rep(i, strlen(S)) {
        if (matchACGT(S[i])) cnt++;
        else cnt = 0;

        ans = max(ans, cnt);
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >>n;
    int i=1;
    while(++i<=n){
        int x=i;
        if(x%3==0){
            cout << " " <<i;
            continue;
        }
        while(x){
            if(x%10==3){
        cout << " " << i;
        break;
             }
             x/=10;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>

#define pll pair<ll,ll>
#define NMAX 1000006
#define eps 1e-12

using namespace std;
typedef long long ll;
typedef long double ld;

ll a[NMAX];
int main()
{
    ll k,t,ma=0,sum=0;
    cin>>k>>t;
    for(int i=1;i<=t;i++)
    {
        cin>>a[i];
        ma=max(ma,a[i]);
        sum+=a[i];
    }
    cout<<sum-(sum-max(0ll,ma*2-sum-1))<<'\n';;
    return 0;
}

Measured memory_bytes: 256
H = int(input())

nodes = list(map(int, input().split()))

for i in range(H):
    parent = (i+1) // 2 - 1
    left = 2 * (i+1) - 1
    right = 2 * (i+1)

    print('node {}: key = {}, '.format(i+1, nodes[i]), end='')
    if i != 0:
        print('parent key = {}, '.format(nodes[parent]), end='')
    if left < H:
        print('left key = {}, '.format(nodes[left]), end='')
    if right < H:
        print('right key = {}, '.format(nodes[right]), end='')

    print('')



Measured memory_bytes: 5684
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         int N=gi();
         int M=gi();
         long[] a=new long[N];
         Pair<Long, Long>[] ps=new Pair[M];

         for(int i=0; i<N;i++) {
        	 a[i]=gl();
         }

         for(int i=0; i<M;i++) {
        	 long b=gl();
        	 long c=gl();
        	 Pair<Long,Long> p=new Pair<Long,Long>(c,b);
        	 ps[i]=p;
         }

         Arrays.parallelSort(a);
         Arrays.parallelSort(ps, Collections.reverseOrder());

         int ind=0;
         long max=0;
         for(int i=0; i<M;i++) {
        	 Pair<Long,Long> p=ps[i];
        	 long b=p.getValue();
    		 long c=p.getKey();
        	 for(int j=0; j<b;j++) {
        		 if(ind>=a.length) break;
        		 if(a[ind]<=c) {
        			 ind++;
        			 max+=c;
        		 } else {
        			 break;
        		 }
        	 }
         }

         for(int i=ind; i<a.length;i++) {
        	 max+=a[i];
         }

         System.out.print(max);
     }

     public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
    		/** serialVersionUID. */
    	    private static final long serialVersionUID = 6411527075103472113L;

    	    public Pair(final K key, final V value) {
    	        super(key, value);
    	    }

    		@Override
    		public int compareTo(Pair<K, V> o) {

    			Comparable key = (Comparable)this.getKey();
    			Comparable key2 = (Comparable)o.getKey();

    			return key.compareTo(key2);
    		}

    	}

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 69004
local D=io.read"*n"

local c={}
for i=1,26 do c[i]=io.read"*n"end
local s={}
for i=1,D do s[i]={}for j=1,26 do s[i][j]=io.read"*n"end end

local function copy(t)local ret={}for i,v in ipairs(t)do ret[i]=v end return ret end

local function calc(d,t,l)
	local a=0
	l[t]=d
	for j=1,26 do
		a=a-c[j]*(d-l[j])
	end
	return a+s[d][t]
end

local t={}
for i=1,D do t[i]=io.read"*n"end

local last={}
for i=1,26 do
last[i]=0
end

local ret={}
local a=0
--score,contestid,last
local beam={{0,{},last}}
for i=1,D do
	local newbeam={}
	for k,b in ipairs(beam) do
		local lastt={}
		for j=1,26 do
			lastt[j]=copy(b[3])
		end
		for j=1,26 do
			local t=copy(b[2])
			table.insert(t,j)
			table.insert(newbeam,{b[1]+calc(i,j,lastt[j]),t,lastt[j]})
		end
	end
	table.sort(newbeam,function(a,b)return a[1]>b[1]end)
	newbeam[53]=nil
	beam=newbeam
end

for i,v in ipairs(beam[1][2])do
print(v)
end

Measured memory_bytes: 35580
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
#define pb push_back
#define N 200001
#define ll long long
#define int long long
#define pi pair<int , int>
#define pip pair<pi ,int>
#define mp make_pair
#define f first
#define s second
#define mod 998244353
int fun(int x , int y , int z){
return x*x + y*y + z*z + z*x + z*y + x*y ;
}
int32_t main(){
   ios_base::sync_with_stdio(false);
      cin.tie(NULL);
    cout.tie(NULL);


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                int php[4000] , cdc[8000], cdm[8000];
//                for(int j=0;j<5;j++){
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//                }
//
// vector<int> ab;
// vector<int> ab1(1000);
// vector<int> ab2;
// vector<int> ab3;
// vector<int> ab4;
// vector<int> ab5;
// string abcd="bdcccebcaca kjbcbsnklnslknvksn  nidcldklcnlsn";
// string abcd1="bdcccebcaca kjbcbsnklnslknvksn  nidcldklcnlsn cbcksknlsnv";
// string abcd2="bdcccebcaca kjbcbsnklnslknvksn  nidcldklcnlsn kjeaebbaekcmaekes";
//
//
// char abcde[1000];
// int mfch=0;
// int abcdefg[1000];
// int abcg[1000];
// int abcfg[1000];

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



//    ll t;
//    cin>>t;
//    while(t--)
        {
   int n;
   cin>>n;
   int dp[n+1]={0};

   int x =1 , y=1 , z=1;
   int p = fun(x , y , z);
  for(int i=1;i<sqrt(n);i++){

    for(int j=i;j<sqrt(n); j++){
 bool aage=false;
        for(int  k=j ; k<sqrt(n) ;k++){
            p = fun(i , j , k);
    if(p<=n){
            aage = true;
        if(i==j && j==k)dp[p]+=1;
        else if(i==j || i==k || j==k) dp[p]+=3;
        else dp[p]+=6;
    }
    else break;

        }
        //if(aage==false)break;
    }

  }


    for(int i=1;i<=n;i++)cout<<dp[i]<<endl;


    }

}




Measured memory_bytes: 3580
n = gets.strip.to_i
nums = gets.strip.split.map(&:to_i)
sum = nums.inject(:+)
count = 0

while true do
  flag = true
  nums.each do |n|
    if n % 2 != 0
      flag = false
    end
  end
  if flag == false
    break
  else
    nums = nums.map do |n|
      n /2
    end
    count += 1
  end
end
puts count

Measured memory_bytes: 1788