akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  int N, K; cin >> N >> K;
  vector<char> D(K);
  rep(i, K) cin >> D[i];
  for(int n=N;;++n) {
    int cnt = 0;
    string s = to_string(n);
    for(char c:s) {
      rep(i, K) {
        if(c == D[i]) ++cnt;
      }
    }
    if(cnt == 0) {
      cout << n << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
N,M = map(int,input().split())
switch = {}
for i in range(M):
    box = list(map(int,input().split()))
    switch[i] = box[1:]
P = list(map(int,input().split()))

c = 0
for i in range(2**N):
    num = format(i, 'b')
    num = num.rjust(N, '0')
    for m_switch in range(M):
        box = 0
        for j in switch[m_switch]:
            box += int(num[j-1])
        if box%2 != P[m_switch]:
            break
        elif m_switch == M-1:
            c += 1
print(c)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
  int N; cin>>N;
  int A[2][100];
  for(int i=0;i<2;i++){
    for(int j=0;j<N;j++)
      cin>>A[i][j];
  }
  int Max=0;
  for(int i=0;i<N;i++){
    int sum=0;
    for(int j=0;j<=i;j++) sum+=A[0][j];
    for(int j=i;j<N;j++) sum+=A[1][j];
    Max=max(Max,sum);
  }
  cout<<Max<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  string N;
  cin >> N;
  i64 cnt = 0;
  for (char i : N)
    cnt += (i - '0');
  if (cnt % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

using namespace std;

const int MAXN = 1e5 + 5;

int n, w, val, mas;
long long DP[MAXN];

int main()
{
	cin >> n >> w;
	for(int i = 0; i < n; i++)
	{
	    cin >> mas >> val;
	    for(int j = w; j >= mas; j--)
	    {
	    	DP[j] = max(DP[j - mas] + val, DP[j]);
		}
  	}
  	cout << DP[w];
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

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

	int ans = 1;
	while (1)
	{
		if (ans*2 > n) {
			break;
		}
		ans = ans * 2;
	}
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <string.h>

int main()
{
    char s[201], p[201];
    scanf("%s", s);
    scanf("%s", p);
    int len = strlen(s);
    for (int i = 0; i < len; i++)
    {

        if (strstr(s, p) != NULL)
        {

            printf("Yes\n");
            break;
        }
        s[len + i] = s[i];
        if (i == len - 1)
        {
            printf("No\n");
        }
    }
}


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

int main() {
  char a;
  cin >> a;
  
  if(a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o') {
  	cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
r = list()
r.append((1, 399))
r.append((400, 799))
r.append((800, 1199))
r.append((1200, 1599))
r.append((1600, 1999))
r.append((2000, 2399))
r.append((2400, 2799))
r.append((2800, 3199))

n = int(input())
a = map(int, input().split(" "))

count = [0 for i in range(0, len(r) + 1)]
for ai in a:
    add = False
    for i in range(0, len(r)):
        if r[i][0] <= ai <= r[i][1]:
            count[i] += 1
            add = True
    if not add:
        count[len(count) - 1] += 1

ans_min = 0
for c in range(0, len(count) - 1):
    if count[c] > 0:
        ans_min += 1

if ans_min > 0:
    ans_max = ans_min + count[len(count) - 1]
elif count[len(count) - 1] > 0:
    ans_min = 1
    ans_max = count[len(count) - 1]
else:
    ans_max = 0

print("%d %d" % (ans_min, ans_max))


Measured memory_bytes: 3064
n, m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x: x[0])
num = 0
ansum = 0
for i in range(n):
    if num + l[i][1] < m:
        ansum += l[i][0] * l[i][1]
        num += l[i][1]
    else:
        ansum += l[i][0] * (m - num)
        break
print(ansum)

Measured memory_bytes: 29024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string s;
  cin >> n>>s;
int min=0;
for(int i=1;i<s.size();i++){
 if(s.at(i)=='E'){
  min++;
 }
}
int memo=min;
for(int i=1;i<s.size();i++){
   int sum=memo;
   if(s.at(i-1)=='W'){
     sum++;
   }
  if(s.at(i)=='E'){
  sum--;
   }
   if(sum<min){min=sum;}
memo=sum;
}

cout << min << endl;


}

Measured memory_bytes: 900
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int result = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				for (int c = 1; c <= K; c++) {
					result += gcd(gcd(a, b), c);
				}
			}
		}
		System.out.println(result);
	}

	public static int gcd(int a, int b){
		return b > 0 ? gcd(b,a%b) : a;
		}

}


Measured memory_bytes: 35644
N=gets.to_i
A=gets.chomp.split.map(&:to_i)

def gcd(a,b)
  return a if b == 0
  gcd(b,a%b)
end


ans=A[0]
1.upto(N-1) {|i| ans = gcd(ans,A[i])}
puts ans

Measured memory_bytes: 9476
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]

Q = []
heapq.heappush(Q, [-(A[0]+B[0]+C[0]),0,0,0])
for _ in range(K):
  p, i, j, k = heapq.heappop(Q)
  print(-p)
  if i+1<X and [-(A[i+1]+B[j]+C[k]),i+1,j,k] not in Q: heapq.heappush(Q, [-(A[i+1]+B[j]+C[k]),i+1,j,k])
  if j+1<Y and [-(A[i]+B[j+1]+C[k]),i,j+1,k] not in Q: heapq.heappush(Q, [-(A[i]+B[j+1]+C[k]),i,j+1,k])
  if k+1<Z and [-(A[i]+B[j]+C[k+1]),i,j,k+1] not in Q: heapq.heappush(Q, [-(A[i]+B[j]+C[k+1]),i,j,k+1])

Measured memory_bytes: 3956
#include <cstdio>
#include <set>
#include <utility>
#include <algorithm>

using namespace std;

const int N = 59;

int x[N];
int y[N];

int main() {
  int n;
  scanf("%d", &n);
  set<pair<int, int>> s;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", x + i, y + i);
    s.emplace(x[i], y[i]);
  }
  int ans = n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (j == i) {
        continue;
      }
      int dx = x[i] - x[j];
      int dy = y[i] - y[j];
      int cnt = 0;
      for (int k = 0; k < n; ++k) {
        if (s.count({x[k] - dx, y[k] - dy}) != 0) {
          ++cnt;
        }
      }
      ans = min(ans, n - cnt);
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a, b, c[5], d;
	d = 0;

	do{
		scanf("%d", &a);
		scanf("%d", &b);
	}while(a > b);

	for (int i = a; i < b+1; i++)
	{
		int j;
		j = i;

		for (int k = 0; k < 5; k++)
		{
			c[k] = j % 10;
			j /= 10;
		}


		if (c[0] == c[4])
		{
			if (c[1] == c[3])
			{
				d++;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 128
n=int(input())
w=[input() for i in range(n) ]
if len(w)==len(set(w)): 
    for i in range(len(w)-1):
        if w[i][-1]==w[i+1][0]:
            a=True
        else:
            a=False
            break
else:
    a=False
if a:
    print("Yes")
else:
    print("No")

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

int64_t ceil_div(int64_t a, int64_t b) {
    return (a + b - 1) / b;
}

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

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    // int t;cin>>t;

    // while(t--){
    // }

    ll n;
    cin>>n;
    vector<ll> a(n);
    ll s=0;

    for(int i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    ll ans=1e18,s1=0;
    for(int i=0;i<n-1;i++){
        s1+=a[i];
        ll y=s-s1;
        ans=min(ans,abs(s1-y));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4756
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n),b(n),c(n);
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<n;i++) cin >> b[i];
  for(int i=0;i<n;i++) cin >> c[i];

  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());

  ll ans = 0;
  for(int i=0;i<n;i++){
    ll ax;
    ax = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
    ll cx;
    cx = lower_bound(c.begin(),c.end(),b[i]+1) - c.begin();

    ans += ax*(n-cx);
  }

  cout << ans << endl;
}


Measured memory_bytes: 2560
<?php
list($s) = strs();
for ($i = strlen($s) - 2; $i >= 2; $i -= 2) {
    if (isGumoji(substr($s, 0, $i))) {
        echo $i;
        exit;
    }
}

function isGumoji($s)
{
    $l = strlen($s);
    if ($l % 2) return false;
    for ($i = 0; $i < intdiv($l, 2); ++$i) {
        if ($s[$i] !== $s[$i + intdiv($l, 2)]) return false;
    }
    return true;
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 4604
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void swap_int(int *x, int *y) {int temp;temp = *x;*x = *y;*y = temp;}
void swap_char(char *x, char *y) {char temp;temp = *x;*x = *y;*y = temp;}
int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x > y ? y : x; }
int fsum(int x){
    char str[1000];
    sprintf(str,"%d",x);
    int sum=0;
    for(int i=0;str[i]!='\0';i++)sum+=str[i]-0x30;
    return sum;
}
int main(){
    int N;
    int a,b;
    int i,j,k;
    int min=999999;

    scanf("%d",&N);

    for(i=1;i<=N/2;i++){
        a=i;
        b=N-a;
        if(min>fsum(a)+fsum(b))min=fsum(a)+fsum(b);
    }
    printf("%d\n",min);
    return 0;
}


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

int main() {
	int T[101][101], r, c;

	cin >> r >> c;
	for (int i = 0; i < r; i++)
		for (int j = 0; j < c; j++)cin >> T[i][j];

	for (int i = 0; i <= r; i++)T[i][c] = 0;
	for (int j = 0; j <= c; j++)T[r][j] = 0;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			T[i][c] += T[i][j];
			T[r][j] += T[i][j];
			T[r][c] += T[i][j];
		}
	}
	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			if (j)cout << " ";
			cout << T[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

const int mod = 1e9+7;
struct mint {
    ll x;
    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;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

int main() {
    int n; cin >> n;
    vll a(n);
    rep(i,n) cin >> a[i];
    mint ans = 0;
    rep(i,60) {
        ll x = 0;
        vint sum(n+1,0);
        rep(j,n) {
            sum[j+1] = sum[j] + (a[j]>>i&1);
        }
        rep(j,n) {
            if (a[j]>>i&1) x += (n-j-1) - (sum[n]-sum[j+1]);
            else x += sum[n]-sum[j+1];
        }
        ans += mint(2).pow(i)*x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3840
#include<cstdio>
#include<cassert>
#include<cstring>
#include<algorithm>

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

using namespace std;

int n,star;
int cnt[12]; // 数字 i が書かれた牌はあと i 個
int rem[12]; // * が i に成れるのは rem[i] 個まで

bool dfs(int i){
	if(i==12) return star==0;

	if(cnt[i]==0){
		if(dfs(i+1)) return true;
	}

	// i, i, i
	if(cnt[i]+min(star,rem[i])>=3){
		int tmp=min(cnt[i],3);
		cnt[i]-=tmp;
		star-=3-tmp;
		rem[i]-=3-tmp;
		assert(cnt[i]>=0);
		assert(star>=0);
		assert(rem[i]>=0);
		bool res=dfs(i);
		cnt[i]+=tmp;
		star+=3-tmp;
		rem[i]+=3-tmp;
		if(res) return true;
	}

	// i, i+1, i+2
	if(i<=9){
		bool b=true; // i, i+1, i+2 の割り当てが可能かどうか
		int minus=0;
		rep(j,3){
			if(cnt[i+j]==0 && min(star-minus,rem[i+j])==0) b=false;
			if(cnt[i+j]==0) minus++;
		}
		if(b){
			bool used[3]={};
			rep(j,3){
				if(cnt[i+j]>0) cnt[i+j]--, used[j]=true;
				else           star--, rem[i+j]--;
				assert(cnt[i+j]>=0);
				assert(star>=0);
				assert(rem[i+j]>=0);
			}
			bool res=dfs(i);
			rep(j,3){
				if(used[j]) cnt[i+j]++;
				else        star++, rem[i+j]++;
			}
			if(res) return true;
		}
	}

	return false;
}

int main(){
	scanf("%d",&n);
	int hai[47],star=0;
	rep(i,3*n+1){
		char s[4]; scanf("%s",s);
		if(s[0]=='*'){
			hai[i]=-1;
			star++;
		}
		else{
			hai[i]=atoi(s)-1;
			cnt[hai[i]]++;
		}
	}

	bool none=true;
	rep(a,12) if(cnt[a]<4) { // 3*n+2 枚目の牌
		hai[3*n+1]=a;
		cnt[a]++;

		rep(i,12) rem[i]=4-cnt[i];

		bool ok=false;
		rep(b,12) if(cnt[b]+star>=2) { // 最後の二つの牌
			int tmp1[47],tmp2[12],tmp3[12];
			memcpy(tmp1,hai,sizeof hai);
			memcpy(tmp2,cnt,sizeof cnt);
			memcpy(tmp3,rem,sizeof rem);

			::star=star;
			int m=3*n+2,two=2;
			rep(i,m) if(two>0 && hai[i]== b) swap(hai[i],hai[m-1]), i--, m--, two--, cnt[b]--;
			rep(i,m) if(two>0 && hai[i]==-1) swap(hai[i],hai[m-1]), i--, m--, two--, rem[b]--, ::star--;
			assert(two==0);
			ok=dfs(0);

			memcpy(hai,tmp1,sizeof hai);
			memcpy(cnt,tmp2,sizeof cnt);
			memcpy(rem,tmp3,sizeof rem);

			if(ok) break;
		}

		if(ok) printf("%d\n",a+1), none=false;

		cnt[a]--;
	}
	if(none) puts("-1");

	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
using namespace std;
int main(){
long n,h,m,i,y;
char c;
cin>>n;
for(i=0;i<n;i++){
cin>>h>>c>>m;
y=m*11-h*60;
if(y<0)y=-y;
if(y>360)y=720-y;
if(y<60)cout<<"alert"<<endl;
else if(y>=180)cout<<"safe"<<endl;
else cout<<"warning"<<endl;
}
return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.LinkedList;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long W =sc.nextLong();
        long a=Math.min(patern1(H,W),patern2(H,W));
        long b=Math.min(a,patern1(W,H));
        long ans=Math.min(b,patern2(W,H));
        System.out.println(ans);
    }
    long patern1(long h,long w){
        long ans=Long.MAX_VALUE;
        for(int i=1;i<h;i++){
            long tmp=Math.max(i*w,(h-i)/2*w);
            long tnp=Math.max(tmp,((h-i)-(h-i)/2)*w);
            long tlp=Math.min(i*w,(h-i)/2*w);
            long top=Math.min(tlp,((h-i)-(h-i)/2)*w);
            ans=Math.min(ans,tnp-top);
        }
        return ans;
    }
    long patern2(long h,long w){
        long ans=Long.MAX_VALUE;
        for(int i=0;i<h;i++){
            long tmp=Math.max(i*w,(h-i)*(w/2));
            long tnp=Math.max(tmp,(h-i)*(w-w/2));
            long tlp=Math.min(i*w,(h-i)*(w/2));
            long top=Math.min(tlp,(h-i)*(w-w/2));
            ans=Math.min(ans,tnp-top);
        }
        return ans; 
    }
}

Measured memory_bytes: 22868
N = int(input())
A = [int(s) for s in input().split()]

mod_number = 10**9 + 7
sum_A = sum(A)
total = 0
for i in range(0, N - 1):
    sum_A = sum_A - A[i]
    total += A[i] * sum_A

ans = total % mod_number

print(ans)

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

int main()
{
    ll k, a, b, c;
    cin >> a >> b >> c >> k;
    ll ans;
    if(k<=b){
        ans = k;
    }else{
        ans = a - (k - a - b);
    }

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

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

ll sumN(int n) {
    return (ll)n * (n + 1) / 2;
}

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

    int N = S.size();

    // <, >, <, > ... <, > の個数
    vector<int> v;
    char c = '<';
    int cnt = 0;
    rep(i, N) {
        if (S[i] == c) {
            cnt++;
        } else {
            v.push_back(cnt);
            c = S[i];
            cnt = 1;
        }
    }
    v.push_back(cnt);
    if (S.back() == '<') v.push_back(0);


    ll ans = 0;
    int l = 0;
    rep(i, v.size()) {
        if (i % 2 == 0) {   // <
            int r = l + v[i] - 1;
            ans += sumN(r) - sumN(l - 1);
            l = r + 1;
        } else {            // >
            if (l < v[i]) {
                ans += sumN(v[i]);
                l = 0;
            } else {
                ans += sumN(v[i] - 1);
                ans += l;
                l = 0;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2048
#include <stdio.h>

int main(void) {
    char str[6];
    int i;

    scanf("%s", str);

    for (i = 0; str[i + 1] != '\0'; i++) {
        if (str[i] == 'A') {
            if (str[i+1] == 'C') {
                puts("Yes");
                return 0;
            }
        }
    }

    puts("No");

    return 0;
}

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

const int nil=-1;
struct node{
	int parent;
	int degree;
	int left;
	int right;
	int depth;
	int height;
};
node *nodes;int n;

int height_setd(int id, int d) //????????????height, ????????¨??¨??????depth????¨????
{
	int res;
	if( id==nil ){
		res=-1;
	}else{
		nodes[id].depth=d;
		res= nodes[id].height=max(
			1 +height_setd(nodes[id].left, d+1),
		 	1 +height_setd(nodes[id].right, d+1)
		);
	}
	return res;

}
int trackRoot(int start){
	int prt=nodes[start].parent;
	if( prt==nil )
		return start;
	else
		return trackRoot(prt);
}
int getSib(int id)
{
	int p=nodes[id].parent;
	if( p==nil ){
		return nil;
	}else{
		return nodes[p].left+nodes[p].right-id;
	}
}

void show()
{
	for( int i=0; i<n; i++ ){
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
			i,
			nodes[i].parent,
			getSib(i),
			nodes[i].degree,
			nodes[i].depth,
			nodes[i].height
		);

		if( nodes[i].parent==nil ){
			printf("root\n");
		}else if( nodes[i].degree==0 ){
			printf("leaf\n");
		}else{
			printf("internal node\n");
		}
	}
}


	
	

int main()
{
	scanf("%d",&n);nodes=new node[n];

	for(int i=0;i<n;i++)
		nodes[i].parent=nodes[i].left=nodes[i].right=nil;
	

	for(int i=0,id,l,r; i<n; i++){
		scanf("%d %d %d",&id,&l,&r);
		if( l!=nil ){
			nodes[id].left=l;
			nodes[l].parent=id;
		}
		if( r!=nil ){
			nodes[id].right=r;
			nodes[r].parent=id;
		}
		if( r!=nil && l!=nil ){
			nodes[id].degree=2;
		}else if( r==nil && l==nil ){
			nodes[id].degree=0;
		}else{
			nodes[id].degree=1;
		}
		l=r=nil;
	}
	height_setd(trackRoot(0), 0);
	show();
	
}

Measured memory_bytes: 1040
#include <stdio.h>

#define len 100005


typedef struct q{

    char name[100];

    int time;

}q;


q pro[len];
int head,tail,n;


q enqueue(q x){

    pro[tail]=x;

    tail=(tail+1)%len;

}


q dequeue(void){

    q x=pro[head];

    head=(head+1)%len;

    return x;

}


int main(void){

    int n,max,total=0,i;

    q x;

    scanf("%d %d",&n,&max);

    for(i=0;i<n;i++)

        scanf("%s %d",pro[i].name,&pro[i].time);


    head=0,tail=n;

    while(head != tail){

        x=dequeue();

        if(x.time <= max){

            total+=x.time;

            printf("%s %d\n",x.name,total);

        }

        else{

            total+=max;

            x.time-=max;

            enqueue(x);

        }

    }

    return 0;

}



Measured memory_bytes: 11880
import scala.io.StdIn

object Main extends App {

  val Array(a,b,c,d) = StdIn.readLine.toCharArray.map(_.toString.toInt)

  val ans = {
    val sign = Array("+","-")
    var ret = Array(0, 0, 0)
    for {
      i <- 0 to 1
      j <- 0 to 1
      k <- 0 to 1
    } {
      val x = if(i == 0) a + b else a - b
      val y = if(j == 0) x + c else x - c
      val z = if(k == 0) y + d else y - d
      if(z == 7) ret = Array(i, j, k)
    }
    (sign(ret(0)), sign(ret(1)), sign(ret(2)))
  }

  println(a + ans._1 + b + ans._2 + c + ans._3 + d + "=7")
}

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

int N;
int A[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }  
  sort(A, A + N);
  ll sum = A[0];
  int ans = 1;
  for (int i = 1; i < N; i++) {
    if (sum * 2 < A[i]) {
      ans = 1;
    } else {
      ans++;
    }
    sum += A[i];
  }
  cout << ans << endl;
  
  return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;

    if(b%2)
        cout << "No\n";
    else
    {
        if((a * 2) <= b && (a * 4) >= b)
            cout << "Yes\n";
        else
            cout << "No\n";
    }

    return 0;
}


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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define REP(i, n) FOR(i, 0, n)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 2e9;
const ll MOD = 1e9+7;
//const ll MOD 998244353;

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

	vector<int> l(n);
	REP(i, n) cin >> l[i];
	sort(all(l));

	ll ans = 0;
	REP(i, n-2){
		FOR(j, i+1, n-1){
			int num = lower_bound(all(l), l[i]+l[j])-l.begin();
			ans += num-j-1;
		}
	}

	co(ans);

	return 0;
}


Measured memory_bytes: 256
import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A)
count=0
for i in range(1,N+1):
  a=B[i]
  count+=(a*(a-1))/2
for i in A:
  a=B[i]
  print(int((count-(a*(a-1))/2)+(a-1)*(a-2)/2))

Measured memory_bytes: 26780
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int ans=3;
	if(a==b&&b==c) ans=1;
	else if(a==b) ans=2;
	else if(b==c) ans=2;
	else if(c==a) ans=2;
	cout<<ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll a,b,c,n;
  cin>>a>>b>>c>>n;
  ll ans = 0;
  rep(i,0,3001){
    rep(j,0,3001){
      ll p = n-a*i-b*j;
      if(p<0)continue;
      if(p%c==0)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>

using ll = long long;

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

    std::unordered_map<int,int> tasu, hiku;
    for (int i = 0; i < N; i++)
    {
        int a;
        std::cin >> a;
        tasu[i + 1 + a]++;
        hiku[i + 1 - a]++;
    }

    ll ans = 0;
    for (auto [k, v] : hiku)
        ans += (ll)hiku[k] * tasu[k];
    std::cout << ans << std::endl;
}


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

int main(){
	string s;
	cin>>s;
	rep(i,s.size()){
		s[i]='x';
	}
	cout<<s<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
bitset<5005> dp;
int a[5005],b[5005];
bool can[5005];
int N,k,n;
bool check(int T)
{
	if(a[T]>=k) return 0;
	n=0;
	for(int i=0;i<N;i++)
	{
		if(i==T) continue;
		b[n++]=a[i];
	}
	dp.reset();
	dp.set(0);
	if(b[0]<k)dp.set(b[0]);
	bool flag=1;
	for(int i=1;i<n;i++)
	{
		if(b[i]>=k) break;
		dp|=(dp<<b[i]);
//		cout<<dp<<endl;
	}
//	cout<<T<<"em\n";
	for(int i=k-a[T];i<k;i++)
	{
		if(dp[i])
		{
			flag=0;
//			cout<<i<<endl;
		}
	}
	return flag;
}
int main()
{
	cin>>N>>k;
	for(int i=0;i<N;i++) cin>>a[i];
	sort(a,a+N);
	int cnt=-1;
	int l=0,r=N-1,mid;
	while(l<=r)
	{
		mid=(l+r)/2;
		bool flag=check(mid);
		if(flag)
		{
			cnt=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	cout<<cnt+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  vector<string> s(n);
  vl t(n);
  rep(i,n){
    cin >> s[i] >> t[i];
  }
  string x;
  cin >> x;
  rep(i,n){
    if(s[i]==x){
      ans = 0 ;
    }
    else{
      ans += t[i];
    }
  }
  print(ans);
}

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

void SelectionSort(int *,int);
void output(int *,int,int);

int main(void){

  int datanum;
  int* databuff;

  cin >> datanum;
  databuff = new int[datanum];

  for(int i = 0 ; i < datanum ; i++ ){
    cin >> databuff[i];
  }

  SelectionSort(databuff,datanum);

  return 0;

}

void SelectionSort(int* databuff,int datanum){

  int min;
  int temp;
  int exchangetimes;

  exchangetimes = 0;

  for ( int i = 0 ; i < datanum ; i++){
    min = i;

    for ( int j = i  ; j < datanum ; j++){
      if ( databuff[j] < databuff[min]){
        min = j;
      }
    }

    if(databuff[i] != databuff[min]){
      temp = databuff[i];
      databuff[i] = databuff[min];
      databuff[min] = temp;
      exchangetimes++;
    }
  }
  output(databuff,datanum,exchangetimes);
}


void output(int *databuff,int datanum,int exchangetimes){
  for ( int i = 0 ; i < datanum ; i++){
    cout << databuff[i];

    if ( i < datanum - 1){
      cout << " ";
    }else{
      cout << endl;
    }
  }
  cout << exchangetimes << endl;
}

Measured memory_bytes: 3068
N=int(input())
x=list()
u=list()
for i in range(N):
    a,b=map(str,input().split())
    x.append(float(a))
    u.append(b)
sum=0
for i in range(N):
    if u[i]=='BTC':
        sum+=x[i]*380000
    else:
        sum+=x[i]
print(sum)

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n, m;
  cin >> n >> m;
  int  l = 1, r = n;

  REP(i, 0, m){
    int x, y;
    cin >> x >> y;
    l = max (l, x);
    r = min (r, y);
  }
  cout << max(r - l + 1, 0) << endl;
  

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    ll ans = 0;
    for(int i = 1; i < n;i++){
        if(a.at(i-1) > a.at(i)){
            int d = a.at(i-1) - a.at(i);
            ans += d;
            a.at(i)+=d;
        }
    }
    cout << ans << endl;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            long total = 0;
            Dictionary<int, int> numdict = new Dictionary<int, int> { };

            for (int i = 0; i < n; i++)
            {
                int thisnum = input[i];
                total += thisnum;
                if (numdict.ContainsKey(thisnum))
                    numdict[thisnum]++;
                else
                    numdict.Add(thisnum, 1);
            }

            int q = int.Parse(Console.ReadLine());

            var b = new int[q];
            var c = new int[q];

            for (int i = 0; i < q; i++)
            {
                var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
                b[i] = input1[0];
                c[i] = input1[1];
            }

            for (int i = 0; i < q; i++)
            {
                if (numdict.ContainsKey(b[i]))
                {
                    if (numdict.ContainsKey(c[i]))
                    {
                        total += numdict[b[i]] * (c[i] - b[i]);
                        numdict[c[i]] += numdict[b[i]];
                        numdict.Remove(b[i]);
                    }
                    else
                    {
                        total += numdict[b[i]] * (c[i] - b[i]);
                        numdict.Add(c[i], numdict[b[i]]);
                        numdict.Remove(b[i]);
                    }
                }
                Console.WriteLine(total);
            }

        }

    }
}


Measured memory_bytes: 47120
#include <stdio.h>

int main(void)
{
   int N;
   int F[100][11];
   int P[100][12];
      int C[11];
      C[0]=11;
   scanf("%d",&N);
   int n;
   for(n=0;n<N;n++){
   	int x;
   	for(x=1;x<=10;x++){
   		scanf("%d",&F[n][x]);
   		if(F[n][x]==1){
   			C[x]++;
   		}
   	}
   }

   for(n=0;n<N;n++){
   	int x;
   	for(x=0;x<11;x++){
   		scanf("%d",&P[n][x]);
//printf("%d\n",C[x]);
   	}

   }
   
   int a,b,c,d,e,f,g,h,i,j,flag=0;
   int max=-1000000000;
   for(a=0;a<2;a++){
   	for(b=0;b<3;b+=2){
   		for(c=0;c<4;c+=3){
   			for(d=0;d<5;d+=4){
   				for(e=0;e<6;e+=5){
   					for(f=0;f<7;f+=6){
   						for(g=0;g<8;g+=7){
   							for(h=0;h<9;h+=8){
   								for(i=0;i<10;i+=9){
   									for(j=0;j<11;j+=10){
   										if(flag==0){flag=1;continue;}
   										int min=0;								for(n=0;n<N;n++){
   											
int p=F[n][a]+F[n][b]+F[n][c]+F[n][d]+F[n][e]+F[n][f]+F[n][g]+F[n][h]+F[n][i]+F[n][j];
   											min+=P[n][p];
   										}
   									if(min>max){max=min;}
   									}
   								}
   							}
   						}
   					}
   				}
   			}
   		}
   	}
   }
   
   printf("%d\n",max);
	return 0;
}


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

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

  vector<int> p(N);
  for(int i = 0; i < N; ++i){
    cin >> p.at(i);
  }


  int max = 0;
  vector<int> sums(N);
  for(int i = 0; i < K; ++i){
      sums.at(0) += p.at(i);
  }
  max = sums.at(0);

  for(int i = 1; i < N - K + 1; ++i){
    int sum = sums.at(i-1) - p.at(i-1) + p.at(i+K-1);
    
    sums.at(i) = sum;
    if(max < sum) max = sum;
  }

  double ans = (max + K) / 2.0;

  cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>

int main() {
    long long a,b,c,d;
    std::cin >> a >> b >> c >> d;
      if ( abs(a-c) <= d )
          std::cout << "Yes";
      else if( abs(b-a) <= d && abs(c-b) <= d)
       std::cout << "Yes";
      else
       std::cout << "No";
  return 0;
}


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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define MP make_pair
#define PB push_back
#define X first
#define Y second

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    cin >> s;

    int sum = accumulate(s.begin(), s.end(), 0, [](int val, char &b) {
        return val + b - '0';
    });

    if (sum % 9) {
        cout << "No" << '\n';
    } else {
        cout << "Yes" << '\n';
    }

    return 0;
}

// g++ sol.cpp -o sol.out -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17

Measured memory_bytes: 3704
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
char op[2] = {'+', '-'};

int calc(int x, int y, char op) {
  if (op == '+')
    return x + y;
  else
    return x - y;
}

int main() {
  string exp;
  cin >> exp;
  int A = exp[0] - '0', B = exp[1] - '0', C = exp[2] - '0', D = exp[3] - '0';
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        if (calc(calc(calc(A, B, op[i]), C, op[j]), D, op[k]) == 7) {
          cout << A << op[i] << B << op[j] << C << op[k] << D << "=7" << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<endl;
using namespace std;

int n,m;
string s;
char a,b;
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>a>>b;
  if(a>b)cout<<">"<<endl;
  else if(a==b)cout<<"="<<endl;
  else cout<<"<"<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<int> c(n);
        for (int i = 0; i < n; ++i) c[i] = n-i;
        for (int i = 0; i < m; ++i) {
            int p, r; cin >> p >> r;
            rotate(c.begin(), c.begin()+p-1, c.begin()+p+r-1);
        }
        cout << c[0] << endl;
    }
}

Measured memory_bytes: 3084
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n,m = map(int, input().split())
    dp = [0]*(n+1)
    dp[0] = 1
    a = [int(input()) for _ in range(m)]
    b = [1]*(n+1)

    for i in range(m):
        b[a[i]] = 0
    for i in range(n):
        if i - 1 >= 0:
            dp[i+1] = dp[i]*b[i]+dp[i-1]*b[i-1]
        else:
            dp[i+1] = dp[i]*b[i]
        dp[i+1] %= 10**9+7
    print(dp[n])

if __name__=="__main__":
    main()


Measured memory_bytes: 78880
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int k;
  cin>>k;
  string s;
  cin>>s;
  if(k>=(int)s.size()) out(s);
  else{
    string t="";
    rep(i,k) t+=s[i];
    rep(i,3) t+='.';
    out(t);
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>
#include<stdio.h>

using namespace std;

using ll = long long;

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

const ll INF = 1LL << 60;

typedef pair<ll, double> P;

bool pairCompare(const P& firstElof, const P& secondElof)
{
	return firstElof.second < secondElof.second;
}

bool IsPrime(ll num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

signed main() {

	ll n, q;

	cin >> n >> q;

	vector<vector<ll>>G(n + 1);

	rep(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<ll>ans(n + 1, 0);
	vector<bool>done(n + 1, false);
	rep(i, q) {
		ll p, x;
		cin >> p >> x;
		p--;
		ans[p] += x;
	}

	queue<ll>que;
	que.push(0);
	while (!que.empty()) {
		ll a = que.front();
		done[a] = true;
		que.pop();
		for (ll i : G[a]) {
			if (done[i] == true)continue;
			que.push(i);
			ans[i] += ans[a];
		}
	}
	


	rep(i, n)cout << ans[i] << endl;
}


Measured memory_bytes: 18672
from scipy.sparse.csgraph import floyd_warshall

n,m,l=map(int,input().split())
g=[[float('inf')]*(n+1) for _ in range(n+1)]
for _ in range(m):
  a,b,c=map(int,input().split())
  g[a][b]=c 
  g[b][a]=c
d=floyd_warshall(g)
g2=[[float('inf')]*(n+1) for _ in range(n+1)]
for i in range(1,n+1):
  for j in range(1,n+1):
    if d[i][j]<=l:
      g2[i][j]=1
d2=floyd_warshall(g2)
q=int(input())
for _ in range(q):
  a,b=map(int,input().split())
  tmp=d2[a][b]
  if tmp==float('inf'):
    print(-1)
  else:
    print(int(tmp-1))

Measured memory_bytes: 28212
#include<iostream>
#include<map>
#include<vector>
using namespace std;

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

  map<char, vector<int>> chars_s, chars_t;
  for (int i = 0; i < s.size(); i++)
    chars_s[s[i]].push_back(i);

  for (int i = 0; i < t.size(); i++)
    chars_t[t[i]].push_back(i);

  //if t has a char that we can't find in s, there is no solution
  for (auto it : chars_t) {
    if (chars_s.find(it.first) == chars_s.end()) {
      cout << "-1 \n";
      return 0;
    }
  }

  //if s has all chars from t, then there is a solution; we go through every char from t and see how many chars from s we have to add until we reach that char
  int64_t count = 0;
  int pos = -1;
  for (int i = 0; i < t.size(); i++) {
    int new_pos;
    auto find = lower_bound(chars_s[t[i]].begin(), chars_s[t[i]].end(), pos + 1);
    if (find != chars_s[t[i]].end()) {
      new_pos =  find - chars_s[t[i]].begin();
      count += chars_s[t[i]][new_pos] - pos;
    } else {
      new_pos = lower_bound(chars_s[t[i]].begin(), chars_s[t[i]].end(), 0) - chars_s[t[i]].begin();
      count += s.size() - pos + chars_s[t[i]][new_pos];
    }

    pos = chars_s[t[i]][new_pos];
  }

  cout << count << "\n";
  return 0;
}


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
	int n;
	scanf("%d", &n);
	bool ans = false;
	rep(i, 10) {
		rep(j, 10) {
			if(i * j == n) ans = true;
		}
	}
	if(ans) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	string s;
	cin >> s;
	if (s == "AAA") {
		cout << "No";
	}
	else if (s == "BBB") {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
}

Measured memory_bytes: 256
<?php
  $input=explode(' ',trim(fgets(STDIN)));
  $a=intval($input[0]);
//A,B,Cそれぞれを$a,$b,$cに格納
  if(($a >= 1)&&($a <= 100000)){
    if($a == 100000){
      $result = 90909;
      echo $result;
    }else if(($a >=10000)&&($a <= 99999)){
      $b = $a - 9999;
      $c = 900;
      $d = 9;
      $result = $b + $c + $d;
      echo $result;
    }else if(($a >=1000)&&($a <= 9999)){
      $b = 0;
      $c = 900;
      $d = 9;
      $result = $b + $c + $d;
      echo $result;
    }else if(($a >=100)&&($a <= 999)){
      $b = 0;
      $c = $a - 99;
      $d = 9;
      $result = $b + $c + $d;
      echo $result;
    }else if(($a >=10)&&($a <= 99)){
      $b = 0;
      $c = 0;
      $d = 9;
      $result = $b + $c + $d;
      echo $result;
    }else if(($a >=0)&&($a <= 9)){
      $b = 0;
      $c = 0;
      $d = $a;
      $result = $b + $c + $d;
      echo $result;
    }
  }
?>


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

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

  int num = pow(2, M);
  int time = M * 1900 + (N - M) * 100;
  int ans = num * time;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll n;
    cin >> n;
    if (65<=n && n<=90) {
        cout << 1 << endl;
    } else if (97<=n && n<=122) {
        cout << 2 << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 3108
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int N, M, C;
  sc.scan(N, M, C);
  int[]B = new int[M];

  foreach (i; 0 .. M) {
    sc.scan(B[i]);
  }

  int res = 0;
  foreach (i; 0 .. N) {
    int tmp = 0;
    int A;
    foreach (j; 0 .. M) {
      sc.scan(A);
      tmp += A * B[j];
    }
    tmp += C;
    if (tmp > 0)
      res++;
  }

  writeln(res);
}


Measured memory_bytes: 256
#encoding:utf-8

import math

N,P = map(int,input().split())

def factorint(N):
    table = {}
    while(N > 1):
        for i in range(2,N+1):
            if N%i == 0:
                while N%i == 0:
                    N = N//i
                    if i in table.keys():
                        table[i] += 1
                    else:
                        table[i] = 1
                break
    return table

ans = 1
if N == 1:
    ans = P
elif 1 < N < 40:
    for i in range(2,round(P**(1/N))+1):
        if P % i**N == 0:
            ans = i

else:
    pass

print(int(ans))
# print(type(ans))


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	int ans = 0;
	int d[100];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> d[i];
	sort(d, d + n);
	for (int i = 0; i < n; i++) {
		if (d[i] != d[i + 1])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256