akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc126/tasks/abc126_d

#include "algorithm"
#include "iostream"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

// f: node, s: length
V<VPL> edges;
VL colors;

void rec(ll u) {
  ll c = colors[u];

  for (auto edge : edges[u]) {
    ll v = edge.first;
    ll l = edge.second;
    if (colors[v] != -1) continue;

    colors[v] = l % 2 == 0 ? c : 1 - c;
    rec(v);
  }
}

void solve() {
  ll N;
  cin >> N;

  edges.resize(N, VPL());

  rep(i, N - 1) {
    ll u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    edges[u].emplace_back(v, w);
    edges[v].emplace_back(u, w);
  }

  colors.resize(N, -1);
  colors[0] = 1;

  rec(0);

  rep(i, N) { cout << colors[i] << endl; }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 9984
#include <stdio.h>

int main(void){
    int N,M;
    scanf("%d %d",&N,&M);
    int A[N][M];
    for(int i=0;i<N;i++)for(int j=0;j<M;j++){
        scanf("%d",&A[i][j]);
    }
    int kibousya[M];
    int nozoki[M];
    for(int i=0;i<M;i++){kibousya[i]=0;nozoki[i]=0;}
    int ans=114514;
    for(int i=0;i<M;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<M;k++){
                if(nozoki[A[j][k]-1]==0){kibousya[A[j][k]-1]++;break;}
            }
        }
        int maxkibou=0;
        for(int j=0;j<M;j++)if(nozoki[j]==0&&kibousya[j]>=kibousya[maxkibou])maxkibou=j;
        if(ans>kibousya[maxkibou])ans=kibousya[maxkibou];
        nozoki[maxkibou]=1;
        for(int i=0;i<M;i++)kibousya[i]=0;
    }
    printf("%d",ans);
    return 0;
}


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

using namespace std;
int tot[105];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int t;
        scanf("%d",&t);
        tot[i]=tot[i-1]+t;
    }
    int mi=1<<30,al=tot[n];
    for(int i=1;i<=n;i++)
    {
        mi=min(mi,abs(tot[i]-(tot[n]-tot[i])));
    }
    printf("%d\n",mi);
    return 0;
}


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

int main(){
	
	int n;
	double x1,y1,x2,y2,x3,y3;
	
	cin>>n;
	while(n>0){
		double px,py,r;
		double A,B,C,a,b,c;
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		A=2*(x2-x1);
		B=2*(y2-y1);
		C=(pow(x1,2)-pow(x2,2))+(pow(y1,2)-pow(y2,2));
		a=2*(x3-x1);
		b=2*(y3-y1);
		c=(pow(x1,2)-pow(x3,2))+(pow(y1,2)-pow(y3,2));
		
		px=(B*c-b*C)/(A*b-a*B);
		py=(C*a-c*A)/(A*b-a*B);
		r=sqrt(pow(x1-px,2)+pow(y1-py,2));
				
		printf("%.3f %.3f %.3f\n",px,py,r);
		n--;
		
	}
}

Measured memory_bytes: 1244
#include <iostream>
#include <array>
#include <fstream>

int main(){
    const int max_sum = 20;
    const int min_sum = 0;
    const int max_number = 100;
    int N;
    //std::ifstream ifs("517.txt");
    
    while(std::cin >> N){
        std::array<int, max_number> numbers;
        std::array<std::array<long long int, max_sum + 1>, max_number> count;
        for(int i = 0; i < max_number; ++i){
            count[i].fill(0);
        }
        for(int i = 0; i < N; ++i){
            std::cin /*ifs*/ >> numbers[i];
        }
        
        count[0][numbers[0]] = 1;
        for(int i = 1; i < N; ++i){
            for(int j = 0; j <= max_sum; ++j){
                if(j + numbers[i] <= max_sum){
                    count[i][j + numbers[i]] += count[i - 1][j];
                }
                if(j - numbers[i] >= min_sum){
                    count[i][j - numbers[i]] += count[i - 1][j];
                }
            }
        }
        std::cout << count[N - 2][numbers[N - 1]] << std::endl;
    }
    
    //ifs.close();
    return 0;
}

Measured memory_bytes: 1172
#include <stdio.h>
int n, m, x, y;
int a[50];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &x, &y);
		x--; y--;
		a[x]++; a[y]++;
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", a[i]);
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define lli long long int
#define pb push_back
#define loop(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000007
#define mem(x,a) memset(x,a,sizeof(x))

int main()
{
	long long int a,b,s;
	cin>>a>>b>>s;
	long long int arr[11];
	arr[0]=s;
	for(long long int i=1;i<11;i++)
		arr[i]=a*arr[i-1]-b;
	for(long long int i=1;i<11;i++)
		cout << arr[i] << endl;
	return 0;
}

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


int main(){
  string s;
  cin >>s;
  if(s=="ARC"){cout << "ABC" << endl;}else{cout << "ARC" << endl;}
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;

    vector<P> p(n);
    rep(i, n) {
        ll t, d;
        cin >> t >> d;
        p[i] = make_pair(d, t);
    }
    sort(rall(p));

    map<ll, ll> mp;
    priority_queue<P, vector<P>, greater<P>> prQ;
    ll ans = 0;
    rep(i, k) {
        ll d = p[i].first;
        ll t = p[i].second;
        ans += d;
        mp[t]++;
        if(mp[t] >= 2) {
            prQ.push(make_pair(d, t));
        }
    }
    ll x = mp.size();
    ans += x*x;

    ll now = ans;
    exrep(i, k, n-1) {
        if(prQ.empty()) {
            break;
        }
        ll d = p[i].first;
        ll t = p[i].second;
        if(mp[t] > 0) {
            continue;
        }
        auto z = prQ.top();
        prQ.pop();
        now += d - z.first;
        now += 2*x + 1;
        mp[t]++;
        x++;
        chmax(ans, now);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 6648
import copy
N=int(input())
b=[int(i) for i in input().split()]
 
c = copy.copy(b) #コピーを行う
a = [0]*N
a_n = N-1
 
for n in range(N)[::-1]:#N桁
  for i in range(len(c))[::-1]:#大きい数字からcheck
    if c[i]==i+1:#iが9を超えても成立する
      a[a_n] = c.pop(i)
      #print(c,len(c))
      a_n = a_n-1
      break#このbreakに気づかなかったので、2を取り除いたあとに1も取り除いてしまった
 
if n-1 != a_n:
  print(-1)
  exit()
else:
  for i in range(N):
    print(a[i])

Measured memory_bytes: 3444
#include <iostream>
    #include<vector>
    #include<algorithm>
    using namespace std;
 
    int main() {
        int a; cin>>a;
        bool ok=false;
        vector <int> v(a);
        for(int i=0; i<a; i++){
            cin>>v[i];
        }
        sort(v.begin(), v.end());
        for(int i=0; i<a; i++){
                if(v[i]==v[i+1]){cout<<"NO"; ok=true; break;}
        }
        if(ok==false)cout<<"YES";
    }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	vector<ll> a(N);
	FOR(i,0,N)cin >> a[i];
	SORT(a);
	if( a[N-1]-a[0] > 1 ){
		cout << "No" << endl;
		return 0;
	}
	ll B = a[N-1];
	ll S = a[0];
	ll BN = 0;
	FOR(i,0,N){
		if(a[i]==B)BN++;
	}
	if(BN==1){
		cout << "No" << endl;
		return 0;
	}
	ll SN = N - BN;
	if(SN != 0){
		ll ans = B;
		if((SN+1)<=ans && ans <= (SN+BN/2)){
			cout << "Yes" << endl;
			return 0;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}else{
		if(B==N-1){
			cout << "Yes" << endl;
		}else if(1<=B && B<=N/2){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[200009],c[200009],ans=0;
void add(int x,int d)
{
    while(x<=n)
    {
        c[x]+=d;
        x+=x&-x;
    }
}
int query(int x)
{
    int res=0;
    while(x)
    {
        res+=c[x];
        x-=x&-x;
    }
    return res;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        int tmp=query(a[i]-1);
        if(!tmp)
            ans++;
        add(a[i],1);
    }
    printf("%d",ans);
    return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct unionFind{
    vector<int> par;
    int siz;

    void init(int N){
        par.resize(N);
        fill(par.begin(), par.end(), -1);
        siz = N;
        return;
    }

    unionFind(int N){
        init(N);
    }

    int root(int X){
        if(par[X] < 0){
            return X;
        }
        return par[X] = root(par[X]);
    }

    bool unite(int X, int Y){
        X = root(X);
        Y = root(Y);

        if(X == Y){
            return false;
        }

        if(par[X] < par[Y]){
            swap(X, Y);
        }

        par[Y] += par[X];
        par[X] = Y;
        --siz;

        return true;
    }

    bool same(int X, int Y){
        return root(X) == root(Y);
    }

    int size(int X){
        return -par[root(X)];
    }
};

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

    int n, m;
    cin >> n >> m;

    unionFind uf(n);

    vector<int> x(m), y(m), z(m);
    rep(i, m){
        cin >> x[i] >> y[i] >> z[i];
        uf.unite(x[i] - 1, y[i] - 1);
    }

    cout << uf.siz << endl;

    return 0;
}

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

int main(){
  
  int a;
  cin >> a;
  
  if( a == 7 || a == 5 || a == 3 ){
    
    cout << "YES" << endl;
    
  }
  
  else{
    
    cout << "NO" << endl;
    
  }
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
  int a,b,c;
  scanf ("%d %d %d",&a,&b,&c);
  int x;
  int n;
  for (n=0;n<100;n++) {
  if (a > b) {
    x = b;
    b = a;
    a = x;
  }
  if (b > c) {
    x = b;
    b = c;
    c = x;
  }
  if (a > c) {
    x = a;
    a = c;
    c = x;
  }
  }
  printf ("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
using namespace std;
int N;
void dfs(string s, char mx){
if(s.length() == N){
printf("%s\n", s.c_str());
} else {
for(char c='a';c<=mx;c++){
 dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
} }}
int main(void){
 cin >> N;
 dfs("", 'a');
 return 0;
 }

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int a[100000];
int b[100000];
int o[100000];

int main()
{
	int N, H;
	int ans = 0;
	int damage = 0;
	int max_a = 0, sum_b = 0, cnt = 0;

	cin >> N >> H;
	rep(i, N) {
		cin >> a[i] >> b[i];
		max_a = max(max_a, a[i]);
		o[i] = b[i];
	}
	sort(o, o + N);
	rrep(i, N) {
		if (o[i] > max_a) {
			sum_b += o[i];
			cnt++;
		}
	}

	if (H > sum_b) {
		ans = cnt + (H - sum_b + max_a - 1) / max_a;
	}
	else {
		while (damage < H) {
			ans++;
			damage += o[N - ans];
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='?')s[i]='D';
    }
    cout << s << endl;
}

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


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC099C()
{
	int N;
	cin >> N;
	++N;
	vector<int> num(N, N);
	num[0] = 0;

	int x = 6;
	while (x < N)
	{
		num[x] = 1;
		x *= 6;
	}
	int y = 9;
	while (y < N)
	{
		num[y] = 1;
		y *= 9;
	}

	for (int i = 1; i < N; ++i)
	{
		num[i] = min(num[i], num[i - 1] + 1);
		int x = 6;
		while (i > x)
		{
			num[i] = min(num[i], num[i - x] + 1);
			x *= 6;
		}
		int y = 9;
		while (i > y)
		{
			num[i] = min(num[i], num[i - y] + 1);
			y *= 9;
		}
	}
	cout << num[N - 1] << endl;
}
int main()
{
	ABC099C();
	return 0;
}


Measured memory_bytes: 640
import math

def Is(x):
  flag = False
  i = 2
  while i < math.sqrt(x):
    if x % i==0:
      flag = True
      break
    i += 1
  return flag

a = int(input())
ans = 0
flag2 = True
i = 0
while flag2:
  flag2 = Is( a + i )
  ans = a + i
  i += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <sstream>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int main(){
    int glid[8];
    while(cin >> glid[0]){
        for(int i=1; i<8; i++) cin >> glid[i];
        for(int i=0; i<8; i++){
            if(glid[i] != 0){
                if(glid[i+1]==glid[i] && glid[i]%11==0) cout << "A";
                else if(glid[i]==glid[i+1] && glid[i+1]==glid[i+2]) cout << "B";
                else if(glid[i]%1111==0) cout << "C";
                else if(glid[i+1]==glid[i]*10+glid[i]) cout << "D";
                else if(glid[i+1]==glid[i]/10) cout << "E";
                else if(glid[i+1]==glid[i]+glid[i]/10) cout << "F";
                else if(glid[i+1]==glid[i]*10) cout << "G";
                cout << endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2992
from collections import defaultdict
dic = defaultdict(int)
N,M = map(int, input().split())
for i in range(N):
    tmp = list(map(int,input().split()))
    for j in range(1,len(tmp)):
        dic[tmp[j]] += 1

ans = 0
for i in range(1,M+1):
    if dic[i] == N: ans += 1
print(ans)

Measured memory_bytes: 3316
/*
AuThOr GaRyMr
技巧:
1.区别对待大数据&小数据！
2.Dp难推时算贡献！
3.long long (尤其乘法)！
4.long long INF 要大
5.Dp on trees: 换根法，每次清空当前的节点和换到的子节点
6.long double | 输出浮点数
7.注意特判!(prince and princess)
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int dp[6001+10],res=0;
int n,m;
mp a[3000+1];
int main(){
	cin>>n>>m;
	rb(i,1,n){
		scanf("%d %d",&a[i].FIR,&a[i].SEC);
	}
  	sort(a+1,a+1+n);
	rb(j,1,n){
		rl(i,6001,1){
			if(a[j].FIR<=i){
				if(i-a[j].FIR<m){
					dp[i]=max(dp[i],dp[max(0,i-a[j].FIR)]+a[j].SEC);	
				}
			}
			res=max(res,dp[i]);
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	int NUM = 100000;
	bool isprime[NUM];

	for(int i=0;i<NUM;i++){
		isprime[i] = true;
	}
	isprime[0] = false;
	isprime[1] = false;
	for(int i=2;i<NUM;i++){
		while(!isprime[i]) i++;
		for(int j=i*2;j<NUM;j+=i){
			isprime[j] = false;
		}
	}

	int N;
	scanf("%d",&N);

	long long mod = 1000000007;
 	long long ans = 1;

	for(int i=2;i<=1000;i++){
		long long t = 0;
		long long p = i;
		if(isprime[i]){
			while(N/p>0){
				t += N/p;
				p *= i;
			}
		}
		ans *= (t+1);
		ans %= mod;
	}

	printf("%lld\n", ans);


	return 0;
}


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

#define MAX 10000
#define NIL -1

struct Node{
  int parent, left, right;
};

struct Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u){
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL){
    h1 = setHeight(T[u].left) + 1;
  }
  if(T[u].right != NIL){
    h2 = setHeight(T[u].right) + 1;
  }
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL){
    return T[T[u].parent].left;
  }
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL){
    return T[T[u].parent].right;
  }
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  }
  else if(T[u].left == NIL && T[u].right == NIL) {
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}

int main(){
  int i, v, l, r, root = 0;
  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) T[i].parent = NIL;

  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d",&v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(i = 0 ; i < n ; i++){
    if(T[i].parent == NIL) root = i;
  }

  setDepth(root, 0);
  setHeight(root);

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

  return 0;
}

Measured memory_bytes: 624
import sys
sys.setrecursionlimit(10**9)
ans = []
dx = (1,1,1,0,0,-1,-1,-1)
dy = (1,0,-1,1,-1,1,0,-1)

def dfs(x,y):
    st[x][y] = True
    for i,j in zip(dx,dy):
        nx = x + i
        ny = y + j
        if nx < 0 or h <= nx: continue
        if ny < 0 or w <= ny: continue
        if st[nx][ny]: continue
        if c[nx][ny]: dfs(nx,ny)

while True:
    w,h = map(int,input().split())
    if w == 0 and h == 0: break
    c = [[int(i) for i in input().split()] for _ in range(h)]
    st = [[False]*w for _ in range(h)]
    cnt = 0
    for i in range(h):
        for j in range(w):
            if st[i][j]: continue
            if c[i][j]:
                dfs(i,j)
                cnt += 1
    ans.append(cnt)

print("\n".join(map(str,ans)))


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string s;cin>>s;
    for(int i=0;i<s.size();i++){
        for(int j=i;j<=s.size();j++){
            string t=s.substr(0,i)+s.substr(j,s.size()-j);
            if(t=="keyence"){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,X;cin >> N >> X;
  vector<int> L(N);
  rep(i,N) cin >> L[i];
  int D = 0;
  int count = 1;
  rep(i,N){
    D += L[i];
    if(D<=X) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define make_pair mp
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int maxn=100007;
const int inf=(1LL<<29);
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int main(){
    int a,b,c;cin>>a>>b>>c;
    int x=gcd(a,b);
    int cnt=0;
    for(int i=x;i>=1;i--){
        if(x%i==0){
            cnt++;
            if(cnt==c){
                printf("%d",i);return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <string>
#include <vector>

constexpr intmax_t mod=1e9+7;

int main() {
  size_t N;
  char buf[64];
  scanf("%zu %s", &N, buf);
  std::string S[2]={buf};
  scanf("%s", buf);
  S[1] = buf;

  std::vector<int> a;
  for (size_t i=0; i<N; ++i) {
    if (S[0][i] == S[1][i]) {
      a.emplace_back(3);
    } else {
      a.emplace_back(6);
      ++i;
    }
  }

  intmax_t res=a[0];
  for (size_t i=1; i<a.size(); ++i) {
    if (a[i-1] == 6 && a[i] == 6) {
        res = (res*3%mod);
    } else if (a[i-1] == 3) {
      res = (res*2%mod);
    }
  }

  printf("%jd\n", res);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する

vector<string> ans;

void cmd(int y1, int x1, int y2, int x2) {
//    cout << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
    string tmp;
    tmp += to_string(y1+1);
    tmp += " ";
    tmp += to_string(x1+1);
    tmp += " ";
    tmp += to_string(y2+1);
    tmp += " ";
    tmp += to_string(x2+1);
    ans.push_back(tmp);
}

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

    int H, W;
    cin >> H >> W;

    vector<vector<int> > a(H, vector<int>(W));
    rep(i, 0, H) {
        rep(j, 0, W) {
            cin >> a[i][j];
        }
    }

    rep(i, 0, H) {
        rep(j, 0, W - 1) {
            if (a[i][j] % 2) {
                a[i][j]--;
                a[i][j + 1]++;
                cmd(i, j, i, j + 1);
            }
        }
    }

    rep(i, 0, H - 1) {
        if (a[i][W - 1] % 2) {
            a[i][W - 1]--;
            a[i + 1][W - 1]++;
            cmd(i, W - 1, i + 1, W - 1);
        }
    }

    cout << ans.size() << endl;
    rep(i,0,ans.size()){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 6280
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
using namespace std;
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a[100000];
    cin >> n;
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    deque<int> que;
    rep(i, n) {
        if (i == 0 && a[i] >= 0 || a[i] < 0)
            ans -= a[i];
        else
            ans += a[i];
        que.push_back(a[i]);
    }
    if (a[n - 1] < 0) ans += a[n - 1] * 2;
    cout << ans << endl;
    rep(i, n - 1) {
        if (que.front() > 0) {
            int x = que.front();
            que.pop_front();
            int y = que.front();
            que.pop_front();
            cout << x << " " << y << endl;
            que.push_front(x - y);
        }
        else {
            if (que[que.size() - 2] <= 0) {
                int x = que.front(), y = que.back();
                que.pop_front();
                que.pop_back();
                cout << y << " " << x << endl;
                que.push_back(y - x);
            }
            else {
                int x = que.front(), y = que.back();
                que.pop_front();
                que.pop_back();
                cout << x << " " << y << endl;
                que.push_front(x - y);
            }
        }
    }
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    char a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "H" << endl;
    } else {
        cout << "D" << endl;
    }
}




Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        WriteLine(cin.Scanint.OrderBy(i => i).Take(2).Sum());
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

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

using namespace std;

const int MAXN = 105;

int n, x, a[MAXN];

int main() {
  cin >> n >> x;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if(i != n) {
      if(x - a[i] >= 0) {
        x -= a[i];
        ++ans;
      }
    } else {
      if(x == a[i]) ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
	long long n;
	char *slimes;
	long long i;
	char *king;
	scanf("%lld\n",&n);
	slimes = (char *)malloc(n+1);
	king = (char *)malloc(n+1);
	fgets(slimes, n+1,stdin);
	long long k = 0;
	//for(i = 0; slimes[i] != '\0';i++){
		if(k == 0){
			king[k] = slimes[0];
		}
		for(int j = 0; slimes[j] != '\0';j++){
			//if(slimes[i] == slimes[j]){
				if(king[k] != slimes[j]){
					k++;
					king[k] = slimes[j];
					i++;
					//j++;
				}else{
					continue;
				}
			}
		//}
	//}
	k++;
	//printf("%s\n",king);
	printf("%lld\n",k);
	return 0;
}


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


int X, Y;


void input() {
    cin >> X >> Y;
}


int main() {
    input();
    int ans = X + Y / 2;
    cout << ans << endl;
}


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

int main(void){
    string s;
    cin >> s;
    if(s=="Sunny")
        cout << "Cloudy" << endl;
    else if(s == "Cloudy")
        cout << "Rainy" << endl;
    else
        cout << "Sunny" << endl;
}


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

int main(){
    using namespace std;
    unsigned long R, C, K;
    cin >> R >> C >> K;
    vector<tuple<unsigned long, unsigned long, unsigned long>> item(K);
    for(auto&& [r, c, v] : item){
        cin >> r >> c >> v;
        --r;
        --c;
    }
    sort(begin(item), end(item), greater<>());
    vector<unsigned long> dp(C);
    for(unsigned long i{0}; i < R; ++i){
        unsigned long Z{dp[0]}, I{0}, N{0}, S{0};
        priority_queue<unsigned long, vector<unsigned long>, greater<>> pqi, pqn, pqs;
        pqi.push(0);
        pqn.push(0);
        pqn.push(0);
        pqs.push(0);
        pqs.push(0);
        pqs.push(0);
        const auto& push = [&](const auto& x){
            pqi.push(x);
            pqn.push(x);
            pqs.push(x);
            if(S < N + x){
                S = N + x;
                pqs = pqn;
            }else{
                S += x - pqs.top();
                pqs.pop();
            }
            if(N < I + x){
                N = I + x;
                pqn = pqi;
            }else{
                N += x - pqn.top();
                pqn.pop();
            }
            if(I < Z + x){
                I = Z + x;
                while(!pqi.empty())pqi.pop();
                pqi.push(x);
            }else{
                I += x - pqi.top();
                pqi.pop();
            }
        };
        for(unsigned long j{0}; j < C; ++j){
            Z = max(Z, dp[j]);
            if(const auto& [r, c, v] = item.back(); r == i && c == j){
                push(v);
                item.pop_back();
            }
            dp[j] = max({Z, I, N, S});
        }
    }
    cout << dp.back() << endl;
    return 0;
}

Measured memory_bytes: 7920
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

h, w = na()
c = nan(10)
a = nan(h)

def floyd_warshall(n, dist):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])

def main():
    dist = [[inf] * 10 for _ in range(10)]
    for i in range(10):
        for j in range(10):
            dist[i][j] = c[i][j]
    floyd_warshall(10, dist)
    ans = 0
    for i in range(h):
        for j in range(w):
            if a[i][j] == -1:
                continue
            ans += dist[a[i][j]][1]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40412
#include<iostream>
#include<algorithm>
using namespace std;
string s,t;
main()
{
  cin>>s;
  t=s;
  reverse(t.begin(),t.end());
  for(char&c:t)c=c=='b'?'d':c=='d'?'b':c=='p'?'q':'p';
  cout<<(s==t?"Yes":"No")<<endl;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);			
		int []  p = new int [5];
		int s=0;
		
		for(int i=0;i<5;i++){
			int x=sc.nextInt();
			p[i]=x;
		}
		
		for(int j=0;j<3;j++){
			for(int k=3;k<5;k++){
				if(j==0 && k==3) s=p[k]+p[j];
				if(s >p[k]+p[j]) s=p[k]+p[j];
			}
		}
		
		System.out.printf("%d\n",s-50);
		sc.close();
		System.exit(0);
	}
}

Measured memory_bytes: 17188
#include <bits/stdc++.h>  // ver2.2.2
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ

int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m;
  cin >> n >> m;
  int ans = 3*n - 3*(gcd(n,m));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define MINF INT_MIN
#define ll long long
#define PB push_back 
#define PF push_front
#define P_F pop_front
#define P_B pop_back
#define F front
#define B back
#define MP make_pair
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define forit(i, s) for(__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define foritr(i, s) for(__typeof ((s).rend ()) i = (s).rbegin (); i != (s).rend (); ++i)
 
using namespace std;
int n, edges, a, b, best = MINF;
vector<vector<int> > grafo;
 vector<int> seen;

void dfs(int nodo){
  int maxi = 0;
  
  FOR(i, 0, grafo[nodo].size()){
    if(seen[grafo[nodo][i]] == MINF)
      dfs(grafo[nodo][i]);
        
    if(seen[grafo[nodo][i]] + 1 > maxi)
      maxi = 1 + seen[grafo[nodo][i]];
  }
  seen[nodo] = maxi;
}

int main() {
  cin >> n >> edges;
  grafo.resize(n+1);
  seen.resize(n+1, MINF);
  vector<int> origenes(n+1, 1);
  
  FOR(i, 0, edges){
    cin >> a >> b;
    grafo[a].PB(b);
    origenes[b] = 0;
  }
  
  FOR(i, 1, n+1){
    if(origenes[i]){
      dfs(i);
      if(seen[i] > best)
        best = seen[i];
    }
  }
  
  cout << best << "\n";

  return 0;
}

Measured memory_bytes: 15596
from collections import Counter
N, M = map(int, input().split())
flags = [True for i in range(M)]
for i in range(N):
    l = list(map(int, input().split()))
    l.pop(0)
    for j in range(M):
        if j + 1 not in l:
            flags[j] = False

print(flags.count(True))

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

int main() {
  int n; cin>>n;
  vector<int> h(n);
  rep(i, n) cin>>h[i];
  
  int cnt = 0;
  int ans = 0;
  rep(i, n-1) {
    if (h[i] >= h[i+1]) cnt++;
    else {
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans, cnt);
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main(){
    IOS;
    in x, ans;
    cin >> x;
    ans = (x/500)*1000 + ((x%500)/5)*5;
    cout << ans << "\n";
}

Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*

val pw = PrintWriter(System.out)
val sc = Scanner(System.`in`)

fun main(args: Array<String>) {
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    println("${c} ${a} ${b}")
}

fun abc000(n:Int) {
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().dropLast(1).split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }



Measured memory_bytes: 29472
#include <iostream>

using namespace std;

int main()
{
    int n,flag=0,zero=0;
    long long a,b,c;
    double e,d;
    cin >>n;
    cin >>a;
    n=n-1;

    while(n--)
    {

        cin>>b;
        d=a;
        e=b;
        if(d*e>1000000000000000000)flag=1;
        if(b==0)
        {
            zero=1;
            break;
        }

        a=a*b;

    }
    if(a>1000000000000000000)flag=1;
    if(zero)cout<<0<<endl;
    else if(flag)cout<<-1<<endl;
    else cout <<a<<endl;

}


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

using namespace std;

int ans, x, n, cnt[100002];

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> x;
		cnt[x]++;
	}
	
	for(int i = 1; i <= 100000; ++i) ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1]);
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n;
  string s;
  cin>>n>>s;
  if(n%2==1){
    cout<<"No"<<endl;
    return(0);
  }
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[n/2+i]){
      cout<<"No"<<endl;
      return(0);
    }
  }
  cout<<"Yes"<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  ll N;
  cin >> N;
  cout << N + N * N + N * N * N << endl;
  

  return 0;
}

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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

const int mod = 1e9 + 7;
vector<ll> fact;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * x % mod;
            x = x * x % mod;
            n >>= 1;
    }
    return res;
}


ll inv(ll x) {
    return mod_pow(x, mod - 2, mod);
}

    
void init() {
    fact.resize(200010);
    fact[0] = 1;
    for(int i = 1; i < 200010; i++) {
        fact[i] = fact[i - 1] * i % mod;
    }
}

ll comb(ll n, ll k) {
    if (n < k) return 0;
    if (k < 0) return 0;
    return ((fact[n] * inv(fact[k])) % mod * inv(fact[n - k])) % mod;
}

void solve() {
    init();

    int N;
    cin >> N;
    vector<int> A(N + 1);
    for (int i = 0; i < N + 1; i++) {
        cin >> A[i];
    }
    map<int, int> cnt;
    int i1, i2;
    for(int i = 0; i < N + 1; i++) {
        if (cnt[A[i]]) {
            i1 = cnt[A[i]] - 1;
            i2 = i;
            break;
        }
        cnt[A[i]] = i + 1;
    }

    for(int k = 1; k <= N + 1; k++) {
        int t = i1 + N - i2;
        cout << (comb(N + 1, k) - comb(t, k - 1) + mod) % mod << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;



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

    int A, B;
    cin >> A >> B;

    int ans;
    if (A > 9 || B > 9) ans = -1;
    else ans = A * B;

    cout << ans << endl;

    return 0;
}

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

using namespace std;

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


int main() {
    int n;
    scanf("%d", &n);
    map<int, int> index;
    int m = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int k = i * 1005 + j;
            index[k] = m++;
        }
    }

    vector<vector<int>> adj(m);
    vector<int> d(m, 0);
    for (int i = 0; i < n; ++i) {
        int prev = -1;
        for (int j = 1; j < n; ++j) {
            int v;
            int u = i;
            scanf("%d", &v);
            --v;
            if (u > v) {
                swap(u, v);
            }
            int k = index[u * 1005 + v];
            if (prev != -1) {
                adj[prev].push_back(k);
                ++d[k];
            }
            prev = k;
        }
    }

    vector<int> remove;
    for (int i = 0; i < m; ++i) {
        if (d[i] == 0) {
            remove.push_back(i);
        }
    }

    int total = 0;
    int done = 0;
    while  (!remove.empty()) {
        vector<int> tmp;
        int rn = remove.size();
        for (int i = 0; i < rn; ++i) {
            int u = remove[i];
            for (int j = 0; j < adj[u].size(); ++j) {
                int v = adj[u][j];
                --d[v];
                if (d[v] == 0) {
                    tmp.push_back(v);
                }
            }
            ++done;
        }
        ++total;
        remove = tmp;
    }
    if (done == m) {
        printf("%d\n", total);
    } else {
        printf("-1\n");
    }
    return 0;
}



Measured memory_bytes: 52864
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
    rep(i, N) {
        ll num;
        cin >> num;
        if (num <= A)
            cnt1++;
        else if (num <= B)
            cnt2++;
        else
            cnt3++;
    }

    cout << min(min(cnt1, cnt2), cnt3) << "\n";

    return 0;
}

Measured memory_bytes: 3588
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// FizzBuzz
// 2012/09/19
public class Main{
	Scanner sc=new Scanner(System.in);

	long n;

	void run(){
		n=sc.nextLong();
		solve();
	}

	void solve(){
		long left=0, right=(long)1e17;
		for(; left<right-1;){
			long mid=(left+right)/2;
			if(length(mid)<n){
				left=mid;
			}else{
				right=mid;
			}
		}

		int margin=(int)(n-length(right-1)-1);
		String ans="";
		for(int i=0; i<20; i++){
			ans+=fizzBuzz(right+i);
		}
		println(ans.substring(margin, margin+20));
	}

	long length(long n){
		long length=0;
		long b=1;
		for(int i=1; i<=18; i++){
			// (left, right]
			long left=b-1, right=min(b*10-1, n);
			if(left>=right){
				break;
			}
			long nFizz=right/3-left/3;
			long nBuzz=right/5-left/5;
			long nFizzBuzz=right/15-left/15;
			long nString=nFizz+nBuzz-nFizzBuzz;
			length+=(right-left-nString)*i+nFizz*4+nBuzz*4;
			b*=10;
		}
		return length;
	}

	String fizzBuzz(long n){
		if(n%15==0){
			return "FizzBuzz";
		}else if(n%3==0){
			return "Fizz";
		}else if(n%5==0){
			return "Buzz";
		}else{
			return ""+n;
		}
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000