akhauriyash/Code-Regression huggingface dataset:
n, y = map(int, input().split())
n_1000 = 0
n_5000 = 0
n_10000 = 0
key = 0
for i in range(n+1):
    for j in range(n+1-i):
        total = 1000*i + 5000*j + 10000*(n-i-j)
        if total == y:
            key = 1
            n_1000 = i
            n_5000 = j
            break
        else:
            continue
if key == 1:
    print(n-n_1000-n_5000, n_5000, n_1000, sep=' ')
else:
    print(('-1 -1 -1'))

Measured memory_bytes: 3064
from heapq import *
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-i for i in A]
heapify(A)

for i in range(M):
    a = -heappop(A)
    a //= 2
    heappush(A, -a)

print(-sum(A))


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

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> a(n - 1), b(n - 1), c(n - 1), d(n - 1);
  vector<vector<pair<int, int>>> g(n);
  vector<vector<int>> ed(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--, c[i]--;
    g[a[i]].emplace_back(b[i], d[i]);
    g[b[i]].emplace_back(a[i], d[i]);
    ed[c[i]].push_back(i);
  }

  vector<vector<int>> fa(n);
  vector<int> dep(n), tin(n), tout(n), dist(n);

  function<void(int, int)> Dfs = [&](int x, int p) {
    static int tk = 0;
    fa[x].push_back(p);
    dep[x] = ~p ? dep[p] + 1 : 0;
    tin[x] = tk++;
    for (int i = 1; (1 << i) <= dep[x]; ++i) fa[x].push_back(fa[fa[x][i - 1]][i - 1]);
    for (auto e : g[x]) {
      int u = e.first, w = e.second;
      if (u == p) continue;
      dist[u] = dist[x] + w;
      Dfs(u, x);
    }
    tout[x] = tk;
  };

  Dfs(0, -1);

  for (int i = 0; i < n - 1; ++i) {
    if (dep[a[i]] < dep[b[i]]) swap(a[i], b[i]);
  }

  auto GetLCA = [&](int u, int v) {
    if (dep[u] > dep[v]) swap(u, v);
    for (int i = 0; i < fa[v].size(); ++i) {
      if ((dep[v] - dep[u]) >> i & 1) v = fa[v][i];
    }
    if (u == v) return u;
    for (int i = min(fa[u].size(), fa[v].size()) - 1; i >= 0; --i) {
      if (i < fa[u].size() && i < fa[v].size() && fa[u][i] != fa[v][i]) {
        u = fa[u][i];
        v = fa[v][i];
      }
    }
    return fa[u][0];
  };

  vector<int> x(q), y(q), u(q), v(q);
  vector<vector<int>> qr(n - 1);
  for (int i = 0; i < q; ++i) {
    cin >> x[i] >> y[i] >> u[i] >> v[i];
    x[i]--, u[i]--, v[i]--;
    qr[x[i]].push_back(i);
  }

  vector<int> ced(n), wed(n), ans(q);
  for (int i = 0; i < n - 1; ++i) {
    vector<pair<int, int>> event;
    for (int e : ed[i]) {
      event.emplace_back(tin[a[e]], e);
      event.emplace_back(tout[a[e]], ~e);
    }
    for (int r : qr[i]) {
      int z = GetLCA(u[r], v[r]);
      event.emplace_back(tin[u[r]], u[r] + n + 1);
      event.emplace_back(tin[v[r]], v[r] + n + 1);
      event.emplace_back(tin[z], z + n + 1);
    }
    sort(event.begin(), event.end());
    int cnt = 0, sum = 0;
    for (int j = 0; j < event.size(); ++j) {
      auto &ev = event[j];
      if (ev.second >= n + 1) {
        ced[ev.second - (n + 1)] = cnt;
        wed[ev.second - (n + 1)] = sum;
      } else {
        if (ev.second >= 0) {
          cnt++;
          sum += d[ev.second];
        } else {
          cnt--;
          sum -= d[~ev.second];
        }
      }
    }
    for (int r : qr[i]) {
      int z = GetLCA(u[r], v[r]);
      ans[r] = dist[u[r]] + dist[v[r]] - 2 * dist[z];
      ans[r] -= (wed[u[r]] - wed[z]);
      ans[r] -= (wed[v[r]] - wed[z]);
      ans[r] += (ced[u[r]] - ced[z]) * y[r];
      ans[r] += (ced[v[r]] - ced[z]) * y[r];
    }
  }
  for (int i = 0; i < q; ++i) cout << ans[i] << "\n";
  return 0;
}


Measured memory_bytes: 39920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j) vector<vector<ll>> name(i,vector<ll>(j))
#define vec2f(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k)))
#define vec3f(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define vec4(name,i,j,k,l) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l))))
#define vec4f(name,i,j,k,l,m) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l,m))))
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
#define N 1001000
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
    ll n, aa; cin >> n;
    vector<ll> a(N,0);
    vector<ll> b(n);
    REP(i,n){
        cin >> b[i];
        a[b[i]]++;
    }
    ll ans = 0;
    REP(i,n){
        bool jud = true;
        FOR(j,1,1000){
            if (b[i]%j==0){
                ll x = b[i]/j;
                a[b[i]]--;
                if (a[x]||a[j]) jud = false;
                a[b[i]]++;
            }
        }
        if (jud) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12760
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int a, b, m, mia = 99999999, mib = 99999999, mi, x, y, c, tmp;
	vector<int> va, vb;

	cin>> a >> b >> m;
	va.resize(a);
	vb.resize(b);

	for (int i = 0;i < a;i++) {
		cin >> va[i];
		mia = min(mia, va[i]);
	}
	for (int i = 0;i < b;i++) {
		cin >> vb[i];
		mib = min(mib, vb[i]);
	}

	mi = mia + mib;

	for (int i = 0;i < m;i++) {
		cin >> x >> y >> c;
		tmp = va[x - 1] + vb[y - 1] - c;
		mi = min(mi, tmp);

	}

	cout<< mi << endl;

}


Measured memory_bytes: 1024
#include<cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#define ll long long 
using namespace std;
inline void read(ll &k)
{
	ll f=1;char c=getchar();k=0;
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	k*=f;
}
ll n;
char s1[55],s2[55];
int main()
{
	read(n);
	ll ans=1;
	int i;
	scanf("%s%s",s1,s2);
	if (s1[0]==s2[0])i=1,ans=3;
	if (s1[0]==s1[1])i=2,ans=6;
	for (;i<n;i++)
	{
		if (s1[i]==s1[i+1])if (s1[i-1]==s2[i-1])ans*=2,i++;else ans*=3,i++;else
		if (s1[i]==s2[i])
		if (s1[i-1]==s2[i-1])ans*=2;
	//	cout << i <<" "<<ans<<endl;
	}
	printf("%lld\n",ans%1000000007);
}

Measured memory_bytes: 256
import re
N=int(input())
D=input()
ans=N
match=re.compile("(.)\\1{%d,}" % 1)
while True:
    m=match.search(D)
    if not m:
        break
    ans-=(len(m.group(0))-1)*(D.count(m.group(0)))
    D=D.replace(m.group(0),m.group(0)[0])

print(ans)

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

using namespace std;

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int count = 0;
  for(int k = 0; k < 1000; k++){
    int key = k;
    int d = 100;
    for(int i = 0; i < N; i++){
      if((int)(S[i] - '0') == key / d){
        key -= (key / d) * d;
        d /= 10;
      }
      if(d == 0){
        count++;
        break;
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();
  
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll x,y;
        cin>>x>>y;
        if(y-2*x>=0 && (y-2*x)%2==0 && x-(y-2*x)/2>=0)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
using ll = long long;
using namespace std;
int main(){
    ll d,g;
    cin >> d >> g;
    vector<ll> a(d),b(d);
    for(ll i=0;i<d;i++)    cin >> a[i] >> b[i];
    ll res = 101010;
    for(int bit=0;bit<(1<<d);bit++){
        ll sum=0,num=0;
        for(int i=0;i<d;i++){
            if(bit&(1<<i))  sum+=b[i]+a[i]*100*(i+1) , num+=a[i];
        }
        if(sum>=g)   res=min(res,num);
        else{
            for(int i=d-1;i>=0;i--){
                if(bit&(1<<i))  continue;
                for(int j=0;j<a[i];j++){
                    if(sum>=g)  break;
                    sum+=100*(i+1);
                    num++;
                }
            }
            res=min(res,num);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<vector>
#include<algorithm>


#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;
typedef long long LL;
const int MAXN=1005;


int main(){
	#ifdef L_JUDGE
		freopen("in.txt","r",stdin);
//		freopen("out.txt","w",stdout);
	#endif
    LL X;
    cin>>X;
    X*=2;
    LL l=0,r=1e9;
    while((l+1)<r){
        LL mid=(l+r)/2;
        LL tmp=(mid+1)*mid;
        if(tmp>=X){
            r=mid;
        }else{
             l=mid;
        }
    }
    printf("%lld\n",r);

	#ifdef L_JUDGE
		fclose(stdin);
		fclose(stdout);
//		system("out.txt");
	#endif

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <cctype>
#include <climits> // INT_MAX ...
#include <cstring> // 

using namespace std;

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

    string s;
    cin >> s;
    for (char &c : s) c = 'x';
    cout << s << endl;


	return 0;
}

Measured memory_bytes: 256
MOD = 1000000007
s = [int(x) if x!="?" else -1 for x in input()]
dp = [[0] *  13 for _ in range(len(s))] 

if s[0] == -1:
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(s[0])] = 1
 
table = [ s % 13 for s in range(130)]
for index in range(1, len(s)):
    if not s[index] == -1:
        value = int(s[index])
 
        for old_amari in range(13):
            new_amari = (table[old_amari * 10] + value) % 13
            dp[index][new_amari] += dp[index-1][old_amari]
    else:
        for value in range(10):
            for old_amari in range(13):
                new_amari = (table[old_amari * 10] + value) % 13
                dp[index][new_amari] += dp[index - 1][old_amari]
 
    for i in range(len(dp[index])):
        dp[index][i] %= MOD

print(dp[len(s)-1][5])


Measured memory_bytes: 63776
#include<iostream>
#include<algorithm>
#define N 100000

using namespace std;

int main(){
  int n, k, data[N];
  while(1){
    cin >> n >> k;
    if(!n && !k) break;
    int x=0;
    for(int i=0; i<n; ++i){
      cin >> data[i];
      if(i<k) x += data[i];
    }
    int max_=x;
    for(int i=k; i<n; ++i){
      x -= data[i-k];
      x += data[i];
      max_ = max(max_, x);
    }
    cout << max_ << endl;
  }
  return 0;
}

Measured memory_bytes: 1548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

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

Measured memory_bytes: 256
/*input
1000000000000000000
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
#define DEC(N)	cout << std::fixed; cout << setprecision(N);
void solve()
{
	lld x=100;
	lld t;
	cin >> t;
	rep(i,0,100000){
		x+=x/100;
		if(x>=t){
			cout << i+1 << endl;
			return ;
 		}
	} 

}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 3644
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,cnt[27];
string s;
int32_t main(){
CODE_START;
cin >> s;
n=s.size();
for(ll i=0;i<n-1;i++){
if(s[i]==s[i+1]){
    cout << i+1 << ' ' << i+2;
    return 0;
}
if(i!=n-2){
    if(s[i]==s[i+2]){
        cout << i+1 << ' ' << i+3;
        return 0;
    }
}
}
cout << "-1" << ' ' <<"-1";
return 0;}



Measured memory_bytes: 512
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int max = n*2-1;
		if(x==1 || x==2*n-1) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
			final String sep = System.lineSeparator();
			String ans = IntStream.range(x+n-1, x+n+max-1)
					.mapToObj(e -> (e % max + 1) + sep)
					.collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 47524
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int r;
  cin >> r;
  cout << r * r << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	ll K;
	cin>>K;
	ll a[50];
	rep(i,50)a[i]=49+K/50;
	ll r=K%50;
	rep(i,r)a[i]+=51-r;
	for(int i=r;i<50;i++)a[i]-=r;
	
	cout<<50<<endl;
	rep(i,50)cout<<a[i]<<" ";
	cout<<endl;
}

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

int main()
{
    long long n;
    cin >> n;
    long long i = 0, j = 0;
    vector<long long> ans;
    double sqrtn = sqrt(n);
    for (int i = 1; i <= sqrtn; i++)
    {
        if (n % i == 0)
            ans.push_back(i);
    }
    cout << ans.back() + n / ans.back() - 2 << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        while(tan.hasNext()){
            char ch=tan.next().charAt(0);
            if(ch>='A' && ch<='Z')
                System.out.println("A");
            else
                System.out.println("a");
        }
    }
}


Measured memory_bytes: 35564
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)
count = [0]*N
answer = 0
z = 0
for i in range(N):
    if B[N-1] >= C[i]:
        break
    z += 1
count[N-1] = z
for i in range(1, N):
    k=z
    for j in range(k):
        if B[N-1-i] < C[k-1-j]:
            break
        else:
            z -= 1      
    count[N-1-i] = z
sum_matrix = [0]*(N+1)
y = 0
for i in range(N):
    sum_matrix[i+1] = sum_matrix[i] + count[i]
for i in range(N):
    if A[N-1] >= B[i]:
        break
    answer += count[i]
    y += 1
for i in range(1, N):
    x = y
    for j in range(x):
        if A[N-1-i] < B[x-1-j]:
            break        
        y -= 1
    answer += sum_matrix[y]
print(answer)

Measured memory_bytes: 103956
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define ALLA(a) a,a+a.size();
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;


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

const int NIL = -1;

Node T[100005];
int D[100005];
int H[100005];
int deep = 0;

void preorder(int u){
  if (u == NIL)return;
  //根節点
  cout << " " << u;
  //左部分木
  preorder(T[u].l);
  //右部分木
  preorder(T[u].r);
}
void inorder(int ln){
  if (ln == NIL)return;
  //左部分木
  inorder(T[ln].l);
  //根節点
  cout << " " << ln;
  //右部分木
  inorder(T[ln].r);
}
void postorder(int ln){
  if(ln == NIL) return;

  postorder(T[ln].l);
  postorder(T[ln].r);
  cout << " " << ln;
}

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

    //配列初期化
    REP(i,n) T[i].p = T[i].l = T[i].r = NIL;

    int id, l , r;
    REP(i,n){
      cin >> id >>  l >> r;
      if(l != NIL){
	T[id].l = l;
	T[T[id].l].p = id;
      }
      if(r != NIL){
	T[id].r = r;
	T[T[id].r].p = id;
      }
    }

    int ln;
    REP(i,n){
      //親を持っていない(最上位のノード)
      if(T[i].p == NIL) ln = i;
    }

    cout << "Preorder" << endl;
    preorder(ln);
    cout << endl << "Inorder" << endl;
    inorder(ln);
    cout << endl << "Postorder" << endl;
    postorder(ln);
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3068
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
// ll mod(long long val) {
//     long long res = val % MOD;
//     if (res < 0) res += MOD;
//     return res;
// }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     fac[0] = fac[1] = 1;
//     finv[0] = finv[1] = 1;
//     inv[1] = 1;
//     for (int i = 2; i < MAX; i++){
//         fac[i] = fac[i - 1] * i % MOD;
//         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
//         finv[i] = finv[i - 1] * inv[i] % MOD;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }


int main() {
    int s, w;
    cin >> s >> w;
    if (s <= w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}


Measured memory_bytes: 3596
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=list(S())
  
  l1=[]
  l2=[]

  _s=s[::-1]

  st=0
  l1.append(st)
  a=0
  for x in s:
    if x=='<':
      a+=1
    else:
      a=0
    l1.append(a)

  st=0
  l2.append(st)
  a=0
  for x in _s:
    if x=='>':
      a+=1
    else:
      a=0
    l2.append(a)
  l2.reverse()

  # print(l1)
  # print(l2)

  sm=0
  for i in range(len(s)+1):
    sm+=max(l1[i],l2[i])

  return sm

# main()
print(main())


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,x,y; cin>>k>>x>>y;
    int sx = (x<0)?-1:1; x*=sx;
    int sy = (y<0)?-1:1; y*=sy;
    int cntx = x/k; x%=k;
    int cnty = y/k; y%=k;
    if (x+y<k){
        if (cntx>0) cntx--, x+=k;
        else if (cnty>0) cnty--, y+=k;
    }
    int m = cntx+cnty;
    int nx=0,ny=0;
    if (x+y!=0){
        if (x+y==k){
            cout<<m+1<<"\n";
        }else if((x+y)%2==0){
            cout<<m+2<<"\n";
            int l = (2*k-x-y)/2;
            if (x<=y){
                nx+=sx*(x+l), ny+=sy*(k-x-l);
            }else{
                nx+=sx*(k-y-l), ny+=sy*(y+l);
            }
            cout<<nx<<" "<<ny<<"\n";
        }else if(k%2==1){
            cout<<m+3<<"\n";
            nx+=sx*k;
            cout<<nx<<" "<<ny<<"\n";
            x-=k;
            bool flg=false;
            if (x<0) sx=-sx, x=-x, flg=true;
            int l = (2*k-x-y)/2;
            if (x<=y){
                nx+=sx*(x+l), ny+=sy*(k-x-l);
            }else{
                nx+=sx*(k-y-l), ny+=sy*(y+l);
            }
            cout<<nx<<" "<<ny<<"\n";
            if (flg) sx=-sx, x=-x;
            x+=k;
        }else{
            cout<<"-1\n";
            return 0;
        }
        nx=sx*x, ny=sy*y;
        cout<<nx<<" "<<ny<<"\n";
    }
    rep(i,cntx){
        nx+=sx*k;
        cout<<nx<<" "<<ny<<"\n";
    }
    rep(i,cnty){
        ny+=sy*k;
        cout<<nx<<" "<<ny<<"\n";
    }
    return 0;
}


Measured memory_bytes: 2304
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var S = lines[0].split("")
    var T = lines[1].split("")

    var len = S.length;
    var strategy_S = {};
    var strategy_T = {};

    // chokudai
    // redcoder

    // c <--> r  h <--> e  o <--> d  k <--> c  u <--> o  u <--> d
    // rhokudai  reokudai  redkuoai  redcuoai  redcouai  reucodai


    for (var i = 0; i < len; i++) {
        if (strategy_S[S[i]] !== undefined || strategy_T[T[i]] !== undefined) {
            if (strategy_S[S[i]] !== T[i] || strategy_T[T[i]] !== S[i]){
                console.log("No");
                return(0);
            }
        }
        else {
            strategy_S[S[i]] =T[i];
            strategy_T[T[i]] =S[i];
        }
    }
    console.log("Yes");
});

Measured memory_bytes: 18496
#include<stdio.h>
#define N 1000001
char add[N];
int solve(int a, int b, int n) {
  int i, m;
  m = 0;
  add[0] = 1;
  for (i = 1; i < N; i ++) {
    if (i >= a && i < b) {
      add[i] = add[i - a];
    } else if (i < a && i >= b) {
      add[i] = add[i - b];
    } else if (i >= a && i >= b) {
      add[i] = add[i - a] || add[i - b];
    } else {
      add[i] = 0;
    }
  }
  for (i = 0; i <= n; i ++) m += !add[i];
  return m;
}
int main() {
  int a, b, n;
  while (1) {
    scanf("%d %d %d", &n, &a, &b);
    if(! (a||b||n)) break;
    printf("%d\n", solve(a, b, n));
  }
  return 0;
}

Measured memory_bytes: 1576
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////
int n,a;
int main(){
    cin >> n;
    
    ll m = 0;
    rep(i,0,n){
	cin >> a;
	m += a-1;
    }
    
    P(m);
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a[100005],b[100005];
const ll mod=998244353;
ll quick_m(ll x,ll y)
{
    if(x==0)
        return 0;
    ll ans=1;
    while(y)
    {
        if(y&1)
            ans=(ans*x)%mod;
        y=y>>1;
        x=(x*x)%mod;
    }
    return ans;
}
int main()
{
    ll ans1=1;
    ll n,num,maxx=-1;
    memset(a,0,sizeof(a));
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&num);
        a[num]++;
        b[i]=num;
        maxx=max(maxx,num);
    }
    if(a[0]!=1||b[1]!=0)
        cout<<0;
    else
    {
        ll x=a[1];
        for(int i=2; i<=maxx; i++)
        {
            ll k=a[i];
            ans1=(ans1*quick_m(x,k))%mod;
            x=k;
        }
        cout<<ans1;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
    static const double pi = 3.141592653589793;
    double a, b, h, m, c, ans;
    double l, s, kakudo;
    cin >> a >> b >> h >> m;
    l = (30*h)+(m/2);
    s = 6*m;
    if(l-s>0){
        kakudo = l-s;
    }else{
        kakudo = s-l;
    }
    if(kakudo>180){
        kakudo = 360-kakudo;
    }

    c = a*a+b*b-2*a*b*cos(kakudo*pi/180);
    ans = sqrt(c);

    cout << fixed << setprecision(11) << ans << endl;

    return 0;
}

Measured memory_bytes: 4164
import java.util.Scanner; 
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String line = in.nextLine();
		String[] Array = line.split(" ");
		int a = Integer.parseInt(Array[0]);
		int b = Integer.parseInt(Array[1]);
		if(a<b){
			System.out.println("a < b");
		} else if(a>b){
			System.out.println("a > b");
		}else {
			System.out.println("a == b");
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int>P(N);
  for(int i=0; i<N; i++)cin >> P.at(i);
  
  int mini =P.at(0);
  int count =0;
  
  for(int i=0; i<N; i++){
    if(P.at(i)<=mini){
      mini=P.at(i);
      count ++;
    }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 3972
#include "bits/stdc++.h"

using namespace std;

#define cerr if(true)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;
# define M_PI 3.14159265358979323846


double toRad(double ang){
	return ang * M_PI / 180.0;
}




int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	double angHoras = (360.000 / 12) * c + 30.00 / 60.00 * d ;
	double angMinutos = (360.00 / 60) * d;

	double ang = min(abs(angHoras - angMinutos), 360.00 - abs(angMinutos - angHoras));
	
	ang = toRad(ang);
	cout << setprecision(15) << fixed << sqrt(a*a + b*b - (2*a*b*cos(ang))) << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    ll Q;
    cin >> Q;

    vector<vector<ll>> dp(min(N + 1, (1LL << 10) + 1), vector<ll>(100001, 0));
    rep2(i, 1, min(N + 1, (1LL << 10) + 1)) {
        rep(j, 100001) {
            ll par = i / 2;
            dp[i][j] = dp[par][j];
            if (j - items[i - 1].second >= 0) {
                dp[i][j] = max(dp[i][j], dp[par][j - items[i - 1].second] + items[i - 1].first);
            }
        }
    }
    vector<ll> ans(Q);
    vector<P> query(Q);
    rep(q, Q) cin >> query[q].first >> query[q].second;
    rep(q, Q) {
        ll v = query[q].first;
        ll L = query[q].second;
        vector<ll> use;
        v--;
        ll u = v;
        use.push_back(u);
        while (u != 0) {
            u = (u - 1) / 2;
            use.push_back(u);
        }
        if (v < (1LL << 10)) {
            ans[q] = dp[v + 1][L];
            continue;
        }
        sort(use.begin(), use.end());
        ll n = use.size();
        vector<ll> use_p;
        ll last = -1;
        rep(i, n) {
            if (use[i] >= (1LL << 10)) {
                use_p.push_back(use[i]);
            } else {
                last = max(last, use[i]);
            }
        }
        ll a = 0;
        rep(i, 1LL << (ll) use_p.size()) {
            ll value = 0;
            ll weight = 0;
            rep(j, use_p.size()) {
                if (i & (1 << j)) {
                    value += items[use_p[j]].first;
                    weight += items[use_p[j]].second;
                    if (weight > L) break;
                }
            }
            if (L - weight < 0) continue;
            a = max(a, dp[last + 1][L - weight] + value);
        }
        ans[q] = a;
    }
    rep(q, Q) {
        cout << ans[q] << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main() {
    vector<int> a(5);
    int ans = 0;
    rep(i,5) cin >> a[i];
    rep(i,5) {
        if (a[i] == 0) ans = i;
    }
    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3596
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    void solve(InputReader in, PrintWriter out) {
        String s = in.next();
        String[] ss = { "KIHBR", "KIHBRA", "KIHBAR", "KIHBARA", "KIHABR", "KIHABRA", "KIHABAR", "KIHABARA", "AKIHBR",
                "AKIHBRA", "AKIHBAR", "AKIHBARA", "AKIHABR", "AKIHABRA", "AKIHABAR", "AKIHABARA", };

        for (String target : ss) {
            if (s.equals(target)) {
                out.println("YES");
                return;
            }
        }

        out.println("NO");
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

    int nextInt() {
        return Integer.parseInt(this.sc.next());
    }

    long nextLong() {
        return Long.parseLong(this.sc.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[100010], B[100010];
    cin >> N;
    rep(i,0,N) cin >> A[i] >> B[i];
    ll ans = 0;
    rrep(i,N-1,0){
        A[i] += ans;
        if(A[i] % B[i] == 0) continue;
        ans += (B[i] - A[i] % B[i]);
    } 
    print(ans);

}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

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

    bool can = false;
    for (int i = 1; i < 10 ; ++i) {
        for (int j = 1; j < 10 ; ++j) {
            if (i * j == n) {
                can = true;
                break;
            }
        }
    }

    cout << (can ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int a, p;
    cin >> a >> p;
    p += a * 3;
    int ans = p / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

int main() {
	ll N, K;
	cin >> N >> K;
	ll ans = 0;

	rep(i, N) {
		ll h; cin >> h;
		if (h >= K) {
			ans++;
		}
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <stack>
#include <cstdio>
#include <complex>
#include <iomanip>
#include <cctype>
#include <cassert>
#include <numeric>
#define rep(i,n) for(int i=0;i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define show(x) cout << #x << " = " << x << endl;

int main(){
        int n;
        cin >> n;
        vector<int>a(n);
        vector<int>b(n,0);
        rep(i,n){
                cin >> a[i];
                if(a[i]%2==0){
                        b[i] = 2;
                }else{
                        b[i] = 1;
                }
        }
        int ans = 1;
        rep(i,n){
                ans *= 3;
        }
        int temp = 1;
        rep(i,n){
                temp *= b[i];
        }
        cout << ans - temp << endl;
        return 0;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
m = 1e+10
suma = W[0]
sumb = sum(W[1:])
for i in range(1, N):
  suma += W[i]
  sumb -= W[i]
  m = min(m, abs(suma - sumb))
print(m)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
  cin >> n;
  vector <bool> m(100);
  for(int i = 1; i <= 9; i++){
  
  	for(int j = 1; j <= 9; j++){
    	m[i*j] = 1;
    }
    
  } 
  if(m[n] == 1)
    	cout << "Yes\n";
  else
    cout << "No\n";
}

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

int main(){
    ll n, m;
    ll sum=0;
    cin >> n >> m;
    for(ll i=0; i<m; i++) {
        ll a;
        cin >> a;
        sum += a;
    }
    if(sum <= n) {
        cout << n - sum <<endl;
    }
    else {
        cout << "-1" <<endl;
    }
}


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

int main()
{
	int N, M;
	while (cin >> N >> M, N | M) {
		vector<int> a(N);
		for (int i = 0; i < N; i++) {
			int d, v;
			cin >> d >> v; --d;
			a[d] = max(a[d], v);
		}
		cout << accumulate(a.begin(), a.end(), 0) << endl;
	}
	return 0;
}



Measured memory_bytes: 3040
d, g = map(int, input().split())
p_c = [list(map(int, input().split())) for _ in range(d)]

ans = 10 ** 9
for i in range(2 ** d):
    score = 0
    count = 0
    for j in range(d):
        if (i >> j) & 1: 
            score += p_c[j][1] + p_c[j][0] * 100 * (j + 1)
            count += p_c[j][0]
    for k in range(d - 1, -1, -1):
        if (i >> k) & 1: 
            continue
        if score >= g:
            break
        for l in range(p_c[k][0] + 1):
            score += 100 * (k + 1)
            count += 1
            if score >= g:
                break
    if ans > count:
        ans = count
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int N,M;
cin >> N >> M;

map <int,int> mp;

rep(i,N) {
    int K;
    cin >> K;
    rep(i,K) {
        int A;
        cin >> A;
        mp[A]++;
    }
}

int cnt = 0;

for(auto x : mp){
    if(x.second == N) cnt++;
}

cout << cnt << endl;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<stack>
int main ()
{
	stack<char>s;
	string str;
	int flag=0;
	cin>>str;
	for(int i=0;i<str.length();i++)
	{
		if(str[i]=='C')
		s.push(str[i]);
	 	if(str[i]=='F')
	 	{
	 		if(!s.empty())
	 		{
	 			flag=1;
	 			break;
			}
		}
	}
	if(flag==1)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/
struct conn_info{
  int d;
  int l;
};

int main(){
  int64_t n;
  cin >> n;
  vector<vector<conn_info>> conn(n);
  rep(i,n-1){
    int64_t a,b,c;
    cin >> a >> b >> c;
    conn_info ci;
    ci.l = c;
    ci.d = b-1;
    conn.at(a-1).push_back(ci);
    ci.d = a-1;
    conn.at(b-1).push_back(ci);
  }
  
  int64_t q;
  int64_t k;
  cin >> q >> k;
  vector<int64_t> x(q),y(q);
  rep(i,q){
    cin >> x.at(i) >> y.at(i);
  }
  vector<int64_t> distance(n);
  rep(i,n){
    distance.at(i) = -1;
  }
  queue<int64_t> que;
  distance.at(k-1) = 0;
  que.push(k-1);
  while(!que.empty()){
    int64_t ww = que.front();
    rep(i,conn.at(ww).size()){
      conn_info  ci = conn.at(ww).at(i);
      if(distance.at(ci.d) == -1){
        distance.at(ci.d) = distance.at(ww) + ci.l;
        que.push(ci.d);
      }
    }
    que.pop();
  }
  /*rep(i,n){
    cout << distance.at(i) << ",";
  }*/
  rep(i,q){
    cout << distance.at(x.at(i)-1) + distance.at(y.at(i)-1) << endl;
  }
            
    
  
    
    
  
        
    
    
    
  
  
    
}

Measured memory_bytes: 10740