akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int a = sc.nextInt();
		Monster[] monsters = new Monster[n];
		for (int i = 0; i < n; i++) {
		    monsters[i] = new Monster(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(monsters);
		int damage = 0;
		long total = 0;
		ArrayDeque<Time> deq = new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
		    while (deq.size() > 0 && deq.peek().point < monsters[i].point) {
		        damage -= deq.poll().times * a;
		    }
		    monsters[i].helth -= damage;
		    if (monsters[i].helth > 0) {
		        int count = (monsters[i].helth + a - 1) / a;
		        deq.add(new Time(count, monsters[i].point + 2 * d));
		        damage += count * a;
		        total += count;
		    }
		}
		System.out.println(total);
	}
	
	
	static class Time {
	    int times;
	    int point;
	    
	    public Time(int times, int point) {
	        this.times = times;
	        this.point = point;
	    }
	}
	static class Monster implements Comparable<Monster> {
	    int point;
	    int helth;
	    
	    public Monster(int point, int helth) {
	        this.point = point;
	        this.helth = helth;
	    }
	    
	    public int compareTo(Monster another) {
	        return point - another.point;
	    }
	}
}


Measured memory_bytes: 115004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];
long long POW[MAX];

ll N, M;

// テーブルを作る前処理
void COMinit() {
    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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void powinit(ll X) {
    POW[0] = 1;
    for (int i = 1; i < MAX; i++) {
        POW[i] = (POW[i - 1] * X) % MOD;
    }
}

ll powmod(ll N) {
    return POW[N];
}

int main() {
    ll N, M, K; cin >> N >> M >> K;
    COMinit();
    powinit(M - 1);

    ll ans = (M * powmod(N - 1)) % MOD;
    for (int i = 1; i <= K; i++) {
        ll x = (M * powmod(N - 1 - i)) % MOD;
        ans += (x * COM(N - 1, i)) % MOD;
        ans %= MOD;
    }

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

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

int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>>hyo(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> hyo.at(i).at(j);
    }
  }
  for(int i=0;i<w;i++){
    bool c = true;
    for(int j=0;j<h;j++){
      if (hyo.at(j).at(i) == '#'){
        c = false;
        break;
      }
    }
    if(c){
      for(int j=0;j<h;j++){
        hyo.at(j).at(i) = ' ';
      }
    }
  }
  for(int i=0;i<h;i++){
    bool c = true;
    for(int j=0;j<w;j++){
      if (hyo.at(i).at(j) == '#'){
        c = false;
        break;
      }
    }
    if(c){
      for(int j=0;j<w;j++){
        hyo.at(i).at(j) = ' ';
      }
    }
  }
  for(int i=0;i<h;i++){
    bool c = false;
    for(int j=0;j<w;j++){
      if(hyo.at(i).at(j)!=' '){
      cout << hyo.at(i).at(j);
        c=true;
      }
    }
    if(c)
    cout << endl;
  }
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  int ans = 2e9;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    int cnt = 0;
    while (t % 2 == 0) {
      t /= 2;
      cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3628
import math,itertools,fractions,heapq,collections,bisect,sys,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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Union-Find -- START --
class UnionFind():
  def __init__(self,sz):
    self.sz=sz
    self.data=[-1]*sz

  def unite(self,x,y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return False
    if self.data[x]>self.data[y]:
      x,y=y,x
    self.data[x]+=self.data[y]
    self.data[y]=x
    return True

  def find(self,k):
    if self.data[k]<0:
      return k
    self.data[k]=self.find(self.data[k])
    return self.data[k]

  def size(self,k):
    return -self.data[self.find(k)]
# Union-Find --- END ---

def main():
  N,M=LI()
  uf=UnionFind(N)

  for _ in range(M):
    a,b=LI()
    a-=1
    b-=1
    uf.unite(a,b)

  d={}
  renketsu=0
  for i in range(N):
    par=uf.find(i)
    if par not in d:
      d[par]=uf.size(i)

  l=[]
  for value in d.values():
    l.append(value)

  # print(l)

  l.sort()
  ans=0
  now=0

  for x in l:
    nxt=x
    x-=now
    ans+=x
    now=nxt

  return ans

# main()
print(main())


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

using namespace std;

typedef long long ll;

ll mod = 998244353;

ll todeg(ll num, ll deg) {
    ll ans = 1;
    for (int i = 32; i >= 0; --i) {
        ans = (ans * ans) % mod;
        if ((deg >> i) & 1) {
            ans = (ans * num) % mod;
        }
    }
    return ans;
}

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }
    if (d[0] != 0) {
        cout << "0\n";
        return 0;
    }
    sort(d.begin(), d.end());
    vector<ll> cou(d.back() + 1, 0);
    for (int i = 0; i < d.size(); ++i) {
        ++cou[d[i]];
    }
    if (cou[0] != 1) {
        cout << "0\n";
        return 0;
    }
    ll ans = 1;
    for (int i = 2; i < cou.size(); ++i) {
        //cout << i << ": " << todeg(cou[i - 1], cou[i]) << '\n';
        ans = (ans * todeg(cou[i - 1], cou[i])) % mod;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    vector<double> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(all(v));
    double memo=v[0];
    for(int i=1;i<n;i++){
        memo=(memo+v[i])/2;
        //cout<<memo<<endl;
    }
    cout<<memo<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using pint = pair<int,int>;
typedef long long ll;

int n;
vector<vector<pint>> v;

bool judge(int bit){
    for(int i=0;i<n;++i){
        if(!(bit & (1<<i))) continue;
        for(pint xy :v[i]){
            int x = xy.first;
            int y = xy.second;
        if(y==1 && !(bit & (1<<x))) return false;
        if(y==0 && (bit & (1<<x))) return false;
        }
    }

    return true;
}

int main(){
    cin>>n;
    v.resize(n);
    for(int i=0;i<n;++i){
        int a;cin>>a;
        v[i].resize(a);
        for(int j=0;j<a;++j){
            cin>>v[i][j].first >>v[i][j].second;
            --v[i][j].first;
        }
    }

    int res=0;
    for(int bit = 0;bit< (1<<n);++bit){
        if(judge(bit)){
            int count = 0;
            for(int i=0;i<n;++i){
                if(bit & (1<<i)) ++count;
            }
            res = max(res,count);
        }
    }
    cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	a = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll i,n,m,a,ans=0ll;
	cin >> n;
	for(i=1ll; i*i<=n; ++i){
		if(n%i){
			continue;
		}
		m = i-1;
		a = n/i;
		if(m>0 && a<m){
			ans += m;
		}
		if(n/i==i){
			continue;
		}
		m = n/i-1;
		a = i;
		if(m>0 && a<m){
			ans += m;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int n, s[55], h[55], c[55], d[55];

int main() {

	cin >> n;

	for (int i = 0; i<n; i++) {
		char p; int q;
		cin >> p >> q;
		if (p == 'S') {
			s[q] = 1;
		}
		else if (p == 'H') {
			h[q] = 1;
		}
		else if (p == 'C') {
			c[q] = 1;
		}
		else if (p == 'D') {
			d[q] = 1;
		}
	}

	for (int i = 1; i <=13 ; i++) {

		if (s[i]==0) {
			cout << 'S' << " " << i << endl;
		}

	}

	for (int i = 1; i <= 13; i++) {

		if (h[i]==0) {
			cout << 'H' << " " << i << endl;
		}

	}

	for (int i = 1; i <= 13; i++) {

		if (c[i]==0) {
			cout << 'C' << " " << i << endl;
		}

	}

	for (int i = 1; i <= 13; i++) {

		if (d[i]==0) {
			cout << 'D' << " " << i << endl;
		}

	}
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

int main() {

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

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

    if (b-a == c-b) {
        cout << "YES\n";
    } else cout << "NO\n";

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
const int INF=100100100;
using namespace std;
int n,m;
int K[32][32];

int main(){

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

  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      K[i][j]=INF;
    }
  }
  int a,b,c,d;
  for(int i=0;i<m;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    K[a][b]=c;
    K[b][a]=d;
  }
  int start,goal,inp,val;
  scanf("%d,%d,%d,%d",&start,&goal,&inp,&val);
  for(int k=1;k<=n;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
	if(K[i][j] > K[i][k]+K[k][j]){
	  K[i][j]=K[i][k]+K[k][j];
	}
      }
    }
  }
  int ans=inp-val-K[start][goal]-K[goal][start];
  printf("%d\n",ans);
}

  
  
    

  

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

int main() {
    int N;
    scanf("%d", &N);
    vector<ll> x(N+3);
    for (int i = 1; i <= N; i++) scanf("%lld", &x[i]);
    ll L;
    scanf("%lld", &L);
    x[N+1] = x[N]+L;
    x[N+2] = x[N]+2*L;
    vector<vector<int>> db(N+2, vector<int>(20, 0));
    db[N+1][0] = N+1;
    int a = 1, b = 1;
    while (a <= N) {
        while (x[b+1]-x[a] <= L)b++;
        db[a][0] = b;
        a++;
    }
    
    for (int j = 1; j <= 19; j++) {
        for (int i = 1; i <= N+1; i++) {
            db[i][j] = db[db[i][j-1]][j-1];
        }
    }
    int Q;
    scanf("%d", &Q);
    
    for (int z = 0; z < Q; z++) {
        int A, B;
        scanf("%d %d", &A, &B);
        int ans = 0;
        if (A > B) swap(A, B);
        int now = A;
        while (now < B) {
            int i = 0;
            while (db[now][i+1] <= B) i++;
            now = db[now][i];
            ans += (1 << i);
        }
        printf("%d\n", ans);
    }
    
    return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int MAXN = 100100;
const ll MOD = 998244353;

int N;
int arr[MAXN];
int nc[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> arr[i];
        if ((i == 0) != (arr[i] == 0))
        {
            cout << "0\n";
            return 0;
        }

        nc[arr[i]]++;
    }

    ll ans = 1;
    for (int i = 1; i < N; i++)
    {
        for (int j = 0; j < nc[i]; j++)
        {
            ans = (ans * nc[i-1]) % MOD;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include<stdio.h>
#include <string.h>
#include<iostream>
#include <cmath>

using namespace std;

int Check(int &N,int &K){

  //Kを求める
  double root;
  root = sqrt(2*N);
  //  cout << "root:" <<root <<endl;  
  K=ceil(root);
  //    cout<<"root:"<<root<<endl;
  //    cout<<"N:"<<N<<endl;
  //    cout<<"K:"<<K<<endl;
  
  if(K*(K-1)/2 == N){
    return 0;
  }else{
    return -1;
  }
}

int MakeSet(int &K){
  int N = K*(K-1)/2;

  //array initialize
  //なんかうまく初期化できなかったので、力尽くで実施   
  int array[N][K] ;//(x,y)
  for (int i=0;i<N;i++){
    for (int j=0;j<K;j++){
      array[i][j]=0;
    }
  }
  
  // K=5の場合                                                                  
  //  y                                                                         
  //                                                                            
  //K   X X X 4 | X X 7 | X 9 | 10
  //    X X 3 X | X 6 X | 8 X | 10
  //    X 2 X X | 5 X X | 8 9 | XX
  //    1 X X X | 5 6 7 | X X | XX
  //    1 2 3 4 | X X X | X X | XX
  //                                x
  
  //phase (0,0)=x
  int x=0;
  int y=0;
  int num=K-1; 
  for(int i=0; i<K;i++){
    //    cout<<"x  :"<<x <<endl;       //debut
    //    cout<<"y  :"<<y <<endl;       //debut 
    //    cout<<"num:"<<num <<endl;     //debut 
    //列指定
    for(int jx=0; jx<num;jx++){
      //行指定
      for(int jy=0; jy<num+1;jy++){	
	if(jy==0){
	  array[jx+x][jy+y]=1;
	  //	  cout<<jx+x <<endl;
	}
	if(jx+1==jy){
          array[jx+x][jy+y]=1;
	}
      }
    }
    //原点の移動
    x=x+num;
    y=y+1;
    num=num-1;
  }




  //output***************::::::
  for(int y=K-1; y>-1;y--){
    //合計値
    int sum=0;
    for(int i=0;i<N;i++){
      sum=array[i][y]+sum;
    }
    cout << sum << " ";        //|Sx|
    //    cout <<"S"<<y <<" ";
    for(int x=0; x<N;x++){
      if (array[x][y]==1){
	cout <<x+1<<" " ;     //要件
      }else
	cout <<"  " ;
	//	cout <<"X"<<" " ;       //debug
    }
    cout <<endl;
  }
  return 0;
}








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

  result=Check(N,K);
  //  cout<<"result:"<<result<<endl;
  
  if(result ==-1){
    cout <<"No"<<endl;   //要件
  }else if (result ==0){
    cout <<"Yes"<<endl;  //要件
    cout <<K<<endl;      //要件
    MakeSet(K);
  }else{
    cout <<"Error function Check"<<endl;
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;

int ima[2020];

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

    string s;
    cin >> s;
    ima[0] = 1;
    ll res = 0;
    int tren = 0;
    int n = s.size();
    int t10 = 1;
    for(int i=n-1; i>=0; i--){
        tren = tren + t10*(s[i]-'0');
        tren %= 2019;
        res += ima[tren];
        ima[tren]++;
        t10 *= 10;
        t10 %= 2019;
    }
    cout << res;
    return 0;
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a; cin>>a;
  string s; cin>>s;
  (a>=3200)?cout<<s<<endl:cout<<"red"<<endl;
}


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

typedef long long ll;

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

    for(int i=0;;i++){
        int h,w; 
        cin >> h >> w;
        if(h==0 && w==0) break;
        for(int j=0;j<h;j++){
            for(int k=0;k<w;k++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n,k,q;
  cin >> n >> k >> q;
  int p[n];
  rep(i,n) p[i]=0;
  int a[q];
  rep(i,q){
    cin >> a[i];
    a[i]--;
    p[a[i]]++;
  }
  rep(i,n){
    if(p[i]>=q-k+1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  
  return 0;
    

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	VI a(3); REP(i,3) cin >> a[i];
	vector<string> s(n);
	VVI p(3,VI(0));
	REP(i,n){
		cin >> s[i];
		p[s[i][0]-'A'].push_back(i);
		p[s[i][1]-'A'].push_back(i);
	}
	VI pm(3);
	REP(i,3) pm[i]=p[i].size();
	VI nowp(3,0);
	vector<char> ans;
	REP(i,n){
		int x=s[i][0]-'A', y=s[i][1]-'A';
		if(a[x]==0&&a[y]==0){
			cout << "No" << endl;
			return 0;
		}
		int lifex, lifey;
		if(nowp[x]+a[x]>=pm[x])
			lifex=INF;
		else
			lifex=p[x][nowp[x]+a[x]];
		if(nowp[y]+a[y]>=pm[y])
			lifey=INF;
		else
			lifey=p[y][nowp[y]+a[y]];
		if(lifex<lifey){
			ans.push_back(s[i][0]);
			a[x]++; a[y]--;
		}
		else{
			ans.push_back(s[i][1]);
			a[x]--; a[y]++;
		}
		nowp[x]++; nowp[y]++;
	}
	cout << "Yes" << endl;
	REP(i,n)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 8736
package main
import "fmt"
func main(){
    var s string
    fmt.Scan(&s)
    str := []byte(s)
    var yy, mm int
    for i, _ := range str {
        str[i]-= 48
    }
    yy = int(str[0]*10 + str[1])
    mm = int(str[2]*10 + str[3])
    if yy<13&&yy>0&&mm<13&&mm>0{
        fmt.Println("AMBIGUOUS")
    }else if yy<13&&yy>0{
        fmt.Println("MMYY")
    }else if mm<13&&mm>0{
        fmt.Println("YYMM")
    }else{
        fmt.Println("NA")
    }
}


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

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define all(v) v.begin(), v.end()
#define ar array

#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;

const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-7;

const int N = 1e5 + 5;

vector <pii> g[N];

int ans[N];

void dfs (int v, int p = -1) {
	for (auto to : g[v]) if (to.F != p) {
		ans[to.F] = ans[v] ^ to.S;
		dfs (to.F, v);
	}
}

void solve () {
	int n;
	cin >> n;
	for (int i = 1 ; i < n ; ++ i) {
		int a, b, w;
		cin >> a >> b >> w;
		g[a].push_back ({b, w & 1});
		g[b].push_back ({a, w & 1});
	}
	dfs (1);
	for (int i = 1 ; i <= n ; ++ i) {
		cout << ans[i] << "\n";
	}
}

int main () {
	ios;
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
}




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

#define loop(i,n) for(int i=1;i<=n;i++)
int a[1002];
int b[1002];
int hyou[1002];

int main(){
  int n,m;
  cin>>n>>m;
  loop(i,n)cin>>a[i];
  loop(j,m)cin>>b[j];
  loop(i,n)hyou[i]=0;
  loop(j,m){
    loop(i,n){
      if(a[i]<=b[j]){
        hyou[i]++;
        break;
      }
    }
  }
  int max=0,maxi=0;
  loop(i,n){
    if(hyou[i]>max)max=hyou[i],maxi=i;
  }
  cout<<maxi<<endl;
  return 0;
}

Measured memory_bytes: 3088
s=input()
K = int(input())
c = []
for i in range(len(s)):
    if s[i]=='a':
        c.append(0)
    else:
        c.append(123-ord(s[i]))
for i in range(len(s)):
    if c[i] <= K:
        K -= c[i]
        c[i]=0
    else:
        continue
if K >0 and c[-1]==0:
    c[i]+= K%26
else:
    c[i] = (-c[i] +K)%26
si = ''
for i in range(len(c)-1):
    if c[i]==0:
        si += 'a'
    else:
        si += s[i]
si += chr(97+c[-1])
print(si)


Measured memory_bytes: 10164
#include <cstdio>

int main()
{
  int n;
  scanf("%d",&n);
  int a[100];
  for(int i=0;i<n;i++){
    scanf("%d",a+i);
  }
  int l=-101,r=101;
  while(l+1<r){
    int m1=(2*l+r+600)/3-200,m2=(l+2*r+600)/3-200;
    int M1=0,M2=0;
    for(int i=0;i<n;i++){
      M1+=(a[i]-m1)*(a[i]-m1);
      M2+=(a[i]-m2)*(a[i]-m2);
    }
    if(M1<M2){
      r=m2;
    }
    else{
      l=m1+1;
    }
  }
  int M=0;
  for(int i=0;i<n;i++){
    M+=(a[i]-l)*(a[i]-l);
  }
  printf("%d",M);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(void) {

	int N,i;

	scanf("%d", &N);

	i = N;

	while (1) {
		if (N % 2 == 0 && N % i == 0) {
			printf("%d", N);
			break;
		}
		N++;
	}


	return 0;
}

Measured memory_bytes: 128
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        ii = S.find(str(i))
        if ii == -1:
            break
        for k in range(10):
            jj = S[ii+1::].find(str(j))
            if jj == -1:
                break
            jj += ii+1
            kk = S[jj+1::].find(str(k))
            if kk != -1:
                ans += 1
print(ans)

Measured memory_bytes: 71584
n, k, q = map(int,input().split())
P = [0]*n
Q = [k]*n
for i in range(q):
    a = int(input())
    P[a - 1] += 1
for i in range(n):
    Q[i] -= (q - P[i])
for i in range(n):
    if Q[i] > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 72780
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
//using namespace atcoder
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

struct UnionFind
{
    vector<int> par;
   
    UnionFind(int n) : par(n,-1){}
    void init(int n) { par.assign(n,-1);}
 
    int root(int x){
        if(par[x]<0) return x;
        return par[x]=root(par[x]);
    }
 
    bool issame(int x, int y){
        return root(x)==root(y);
    }
    bool merge(int x, int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x; //大きさが正になるよ
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
        int n, q;
    cin >> n >> q;
 
    atcoder::dsu d(n);
 
    for (int i = 0; i < q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else {
            cout << d.same(u, v) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3972
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	dishes := scanNums(5)
	a := calc(dishes)
	fmt.Print(a)
}

func calc(dishes []int) int {
	ans := 0
	overheads := 0

	maxOverhead := 0
	for _, d := range dishes {
		amari := d % 10
		ans += d
		if amari != 0 {
			oh := 10 - amari
			overheads += oh
			ans += oh
			if maxOverhead < oh {
				maxOverhead = oh
			}
		}
	}
	return ans - maxOverhead
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func scanString() string {
	var s string
	fmt.Scan(&s)
	return s
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		str = nextString()
		strings = append(strings, str)
	}
	return
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}


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

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B; cin >> A >> B;
    
    int ans = 0;
    for (int i=1; i<1000; i++) {
        int ha = i * (1 + i) / 2;
        int hb = (i + 1)*(2 + i) / 2;

        for (int x = 1; x < ha; x++) {
            if (ha -x == A && hb -x == B) {
                ans = x;
                break;
            }
        }
        if (ans > 0) break;
    }

    cout << ans << endl;

    return 0;
}

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

long f(long n) {
    long r = 1;
    for (long i = 2; i * i <= n; i++) {
        long x = 0;
        while (n % i == 0) {
            x++;
            n /= i;
        }
        if (x > 0) {
            r *= x + 1;
        }
    }
    if (n > 1) {
        r *= 2;
    }
    return r;
}

int main() {
    long n;
    long s = 0;
    cin >> n;
    for (long i = 1; i <= n - 1; i++) {
        s += f(i);
    }
    cout << s << endl;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long a = sc.NextLong();
        long b = sc.NextLong();
        long k = sc.NextLong();

        bool turn = true;

        for (int i = 0; i < k; i++)
        {
            if (turn)
            {
                if (a % 2 == 1)
                {
                    a--;
                }
                b += a / 2;
                a /= 2;
            }
            else
            {
                if (b % 2 == 1)
                {
                    b--;
                }
                a += b / 2;
                b /= 2;
            }
            turn = !turn;
        }

        string answer = a + " " + b;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27440
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
  int N,n;
  int X[101],Y[101];
  double p;
  scanf("%d\n",&N);
  for(n=0;n<N;n++)
    scanf("%d",&X[n]);
  for(n=0;n<N;n++)
    scanf("%d",&Y[n]);

  p=0;
  for(n=0;n<N;n++) {
    p = p + abs(X[n]-Y[n]);
  }
  printf("%.6lf\n",p);

  p=0;
  for(n=0;n<N;n++) {
    p = p + (X[n]-Y[n])*(X[n]-Y[n]);
  }
  printf("%.6lf\n",sqrt(p));

  p=0;
  for(n=0;n<N;n++) {
    p = p + abs(X[n]-Y[n])*(X[n]-Y[n])*(X[n]-Y[n]);
  }
  printf("%.6lf\n",pow(p,((double)1.0/3)));

  p=0;
  for(n=0;n<N;n++) {
    double a = abs(X[n]-Y[n]);
    if (a>p)
      p=a;
  }
  printf("%.6lf\n",p);

  return 0;
}

Measured memory_bytes: 680
/**
 * Created by hiramekun at 20:44 on 2019-12-08.
 */
#include <bits/stdc++.h>

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

int main() {
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w)), b(h, vector<ll>(w));
//    int a[h][w], b[h][w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];

    ll max_diff = 2 * 80 * 160;
    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(max_diff)));
//    bool dp[h][w][max_diff];
    rep(i, h) rep(j, w) rep(l, max_diff) dp[i][j][l] = false;

    ll mid = max_diff / 2;
    dp[0][0][b[0][0] - a[0][0] + mid] = true;
    dp[0][0][-b[0][0] + a[0][0] + mid] = true;

    rep(i, h) {
        rep(j, w) {
            rep(l, max_diff) {
                if (!dp[i][j][l]) continue;
                if (i + 1 <= h - 1) {
                    dp[i + 1][j][l + b[i + 1][j] - a[i + 1][j]] = true;
                    dp[i + 1][j][l - b[i + 1][j] + a[i + 1][j]] = true;
                }
                if (j + 1 <= w - 1) {
                    dp[i][j + 1][l + b[i][j + 1] - a[i][j + 1]] = true;
                    dp[i][j + 1][l - b[i][j + 1] + a[i][j + 1]] = true;
                }
            }
        }
    }
    ll ans = 1e18;
    rep(i, max_diff) {
        if (dp[h - 1][w - 1][i]) ans = min(ans, abs(i - mid));
    }
    cout << ans << '\n';
}

Measured memory_bytes: 23040
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const int N = 2e5 + 10;
int n, k, c, pf[N], sf[N], sum[N];
bool ok[N];
string s;
int SUM(int l, int r){
	r = min(r, n - 1);
	l = max(l, 0);
	if(l == 0){
		return sum[r];
	}
	return sum[r] - sum[l - 1];
}
main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> k >> c >> s;
	for(int i = 0; i < n; i++){
		if(s[i] == 'x'){
			if(i == 0)pf[i] = 0;
			if(i != 0)pf[i] = pf[i - 1];
			continue;
		}
		if(i > c){
			pf[i] = pf[i - c - 1] + (s[i] == 'o');  
		}else{
			pf[i] = s[i] == 'o'; 
		}
		if(pf[i] > k){
			return 0;
		}
	}
	for(int i = n - 1; i >= 0; i--){
		if(s[i] == 'x'){
			if(i == n - 1)sf[i] = 0;
			if(i != n - 1)sf[i] = sf[i + 1];
			continue;
		}
		if(i + c + 1 <= n - 1){
			sf[i] = sf[i + c + 1] + (s[i] == 'o');
		}else{
			sf[i] = s[i] == 'o'; 
		}
	}
	for(int i = 0; i < n; i++){
		if(s[i] == 'x')continue;
		if(i > c && i + c + 1 < n){
			if(pf[i - c - 1] + sf[i + c + 1] + 1 == k){
				ok[i] = true;
			}
		}else{
			if(i > c){
				if(pf[i - c - 1] + 1 == k){
					ok[i] = true; 
				}
			}else{
				if(sf[i + c + 1] + 1 == k){
					ok[i] = true; 
				}
			}
		}
	}
	sum[0] = ok[0];
	for(int i = 1; i < n; i++){
		sum[i] = sum[i - 1] + ok[i];
	}
	for(int i = 0; i < n; i++){
		if(ok[i] && SUM(i - c, i + c) == 1){
			cout << i + 1 << '\n';
		}
	}
}

Measured memory_bytes: 4372
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

using ll = long long;

int N;
ll A[301][301];
bool fl[301][301];

int main()
{
  scanf( "%d", &N );
  rep( i, N ) rep( j, N )
    scanf( "%lld", &A[i][j] );

  ll dec = 0;
  rep( i, N ) rep( j, i ) rep( k, j )
  {
    if( A[i][j]+A[j][k] < A[i][k] || A[k][i]+A[i][j] < A[k][j] || A[i][k]+A[k][j] < A[i][j] )
    {
      puts("-1");

      return 0;
    }

    if( A[k][j]+A[j][i] == A[k][i] )
      fl[k][i] = fl[i][k] = true;
    if( A[k][i]+A[i][j] == A[k][j] )
      fl[k][j] = fl[j][k] = true;
    if( A[i][k]+A[k][j] == A[i][j] )
      fl[i][j] = fl[j][i] = true;
  }

  ll ans = -dec;
  rep( i, N ) rep( j, i ) if( !fl[i][j] )
    ans += A[i][j];

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

  return 0;
}

Measured memory_bytes: 896
N = int(input())
l = list(map(int,input().split()))

len_l = len(l)
st = l[0]
count = 1
count_l = []
for i in range(1,len_l):
    if l[i]==st:
        count+=1
    else:
        count_l.append(count//2)
        st = l[i]
        count = 1
count_l.append(count//2)
print(sum(count_l))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n], b[m];
	f(i,n)cin>>a[i];
	f(i,m)cin>>b[i];
	for(int i=1;i<n;i++)a[i] = a[i] + a[i-1];
	for(int i=1;i<m;i++)b[i] = b[i] + b[i-1];
	
	ll ans = 0 ;
	f(i,m){
		if(b[i]<=k)ans = i+1;
	}
	f(i,n){
		ll left = k-a[i];
		if(left>=0){
			ll in = 0;
			ll low = 0, high = m-1;
			while(low<=high){
				ll mid = low + (high-low)/2;
				if(b[mid]<=left){
					low = mid + 1;
					in = mid;
				}else
					high = mid-1;
			}
			if(b[in]<=left)
				ans = max(ans,(ll)(i+1+in+1));
			else
				ans = max(ans,(ll)(i+1));
		}
	}
	cout<<ans<<"\n";
}

int main(){
	int tests=1;
//	cin>>tests;
	while(tests--){
		test();
	}
}


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



#define pp pair<int,int>
#define oo 100000000
#define RRR ios_base::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define int ll


int ar[200000];
int ar2[200000];

bool iseven(string a)
{
    if (a.size() % 2 == 1)
        return false;
    int j = a.size()/2;
    for (int i=0;i<a.size()/2;i++)
    {
        if (a[i] != a[j])
            return false;
        j++;
    }
    return true;
}

int32_t main()
{
   string s;
   cin >> s;
    while (1)
    {
        s.erase(s.end()-1);
        if (iseven(s))
            return cout << s.size(),0;
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int n;
	int[] l, c;
	double[] v;

	double EPS=1e-6;
	int INF=1<<28;

	void run(){
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			R[] rs=new R[n];
			for(int i=0; i<n; i++){
				rs[i]=new R();
				rs[i].l=sc.nextInt();
				rs[i].c=sc.nextInt();
				rs[i].v=1.0/rs[i].l;
			}
			Arrays.sort(rs, new Comparator<R>(){
				@Override
				public int compare(R r1, R r2){
					return (int)((r2.v-r1.v)*100000);
				}
			});

			for(int t=1;; t++){
				double first=INF;
				double end=rs[n-1].x;
				for(int i=0; i<n; i++){
					if(rs[i].goal){
						continue;
					}
					rs[i].x+=rs[i].v;
					first=rs[i].x=Math.min(rs[i].x, first);
					if(rs[i].x+EPS>2){
						rs[i].c--;
						rs[i].x-=2;
						end=rs[i].x=Math.min(rs[i].x, end);
						rs[i].goal=rs[i].c==0;
					}
				}
				Arrays.sort(rs, new Comparator<R>(){
					@Override
					public int compare(R r1, R r2){
						if((Math.abs(r1.x-0)<EPS&&Math.abs(r2.x-0)<EPS)
								||(Math.abs(r1.x-1)<EPS&&Math.abs(r2.x-1)<EPS)){
							// ツスツタツーツトorツ静慊づィツ陛板つオ
							return (int)((r2.v-r1.v)*100000);
						}
						return (int)((r2.x-r1.x)*100000);
					}
				});
				int sumC=0;
				for(R r : rs){
					sumC+=r.c;
				}
				if(sumC==0){
					println(t+"");
					break;
				}
			}
		}
	}

	class R{
		int l, c;
		double v, x, r;
		boolean goal;
	}

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

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

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

	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,T,A;
    cin>>N>>T>>A;
    vint h(N);
    REP(i,N) cin>>h[i];

    double diff_min=1e9;
    int ans_idx=-1;
    REP(i,N){
        double diff=abs(T-h[i]*0.006-A);
        if(diff<diff_min){
            diff_min=diff;
            ans_idx=i+1;
        }
    }
    cout<<ans_idx<<endl;

}


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

using namespace std;
int X, Y, Z,K;
vector<long> a, b, c;

bool can(long V, int K) {
    int i,j,k, cnt = 0;
    for (i =0 ; i < X; i++) {
        for (j = 0; j < Y; j++) {
            for (k = 0; k < Z; k++){
                if (a[i]+b[j]+c[k] >= V) cnt++;
                if (cnt >= K) {
                    return true;
                }
            }
        }
    }
    return false;
}

int main() {
    int i, j, k;
    long t;
    cin >> X >> Y >> Z >> K;
    for (i = 0; i < X; i++) {cin >> t; a.push_back(t);}
    for (i = 0; i < Y; i++) {cin >> t; b.push_back(t);}
    for (i = 0; i < Z; i++) {cin >> t; c.push_back(t);}
    vector<long> ans;
    vector<long> XY;
    vector<long> st;

    for (i = 0; i < X; i++) {
        for (j = 0; j < Y; j++) {
            st.push_back(a[i]+b[j]);
        }
    }
    sort(st.rbegin(),st.rend());
    int cnt = 0;
    for(i=0;i<K&&i<X*Y;i++){
        for(j=0;j<Z;j++){
            ans.push_back(st[i]+c[j]);
        }
    }
    sort(ans.rbegin(),ans.rend());
    for(i=0;i<K;i++){
        cout<<ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 43384
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
int n, q;
ll m, c;
vector<pair<int,int>> edge[2];
const int maxn = 100001;
int s[maxn], b[maxn];
string res[2] = {"No\n", "Yes\n"};
int find(int i){
	return i == b[i] ? i : b[i] = find(b[i]);
}
void merge(int x, int y){
	x = find(x), y = find(y);
	if(s[x] < s[y])swap(x, y);
	if(x != y){
		s[x] += s[y];
		b[y] = b[x];
		--c;
	}
}
#define same(a, b) (find(a) == find(b))
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> q;
	for(int i = 0, a, b, c;i < q;++i){
		cin >> a >> b >> c;
		edge[c].emplace_back(a, b);
	}
	if(m == n-1)return cout << res[edge[1].empty()], 0;
	c = n;
	for(int i = 1;i <= n;++i)b[i] = i, s[i] = 1;
	for(auto &p : edge[0])merge(p.first, p.second);
	for(auto &p : edge[1])if(same(p.first, p.second))return cout << res[0] , 0;
	cout << res[m <= n-c + c*(c-1)/2];
}

Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
	cin>>a;
	for(int i=0;i<a.size();i++)
	{
		switch(a[i])
		{
			case '0':b+='0';break;
			case '1':b+='1';break;
			case 'B':
				{
					if(b.size()>0)
					{
						string c;
						for(int i=0;i<b.size()-1;i++)
						{
							c+=b[i];
						}
						b=c;
					}
					break;
				}
		}
	}
	cout<<b;
}

Measured memory_bytes: 3628
s = input()
if (int(s[0:4]) < 2019):
    print("Heisei")
elif (int(s[0:4]) > 2019):
    print("TBD")
else:
    if (s[5:7] == "01" or s[5:7] == "02" or s[5:7] == "03" or s[5:7] == "04"):
        print("Heisei")
    else:
        print("TBD")


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

ll gcd(ll a,ll b);
ll lcm(ll a,ll b);

int main(){

    int n;
    cin >> n;
    ll ans = 1;
   
    for(int i = 0;i < n;i++){
        ll tmp = 0;
        cin >> tmp;
        
        ans = lcm(ans,tmp);
    }
       
    cout << ans << endl;

    return 0;
}

ll gcd(ll a,ll b){

    if(b == 0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}

ll lcm(ll a,ll b){

    ll tmp = gcd(a,b);
    return a/tmp*b;
}



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

const int maxn = 6000;
int n, sum[maxn + 3], tot, m[maxn + 3], k, l, a[maxn + 3], b[maxn + 3], p[maxn + 3], sz[maxn + 3];
char str[maxn + 3], s[maxn + 3][maxn + 3], res[maxn + 3][maxn + 3], tmp[maxn + 3];
bool vis[maxn + 3];

bool check(char s[], int n, char t[], int m) {
	for (int i = 1; i <= min(n, m); i++) {
		if (s[i] > t[i]) return true;
		if (s[i] < t[i]) return false;
	}
	return n > m;
}

void solve(char s[], char ret[], int n, int &m) {
	k = l = m = 0;
	for (int i = 1; i <= n; i++) {
		vis[i] = false;
		if (s[i] == 'a') {
			a[++k] = i, p[i] = k;
		} else {
			b[++l] = i, p[i] = l;
		}
	}
	if (s[1] == 'a') {
		for (int i = 1; i <= n; i++) {
			if (vis[i]) continue;
			for (int j = a[p[i]]; j < b[p[i]]; j++) {
				vis[b[p[j]]] = true;
			}
			ret[++m] = 'a';
			ret[++m] = 'b';
			i = b[p[i]];
		}
	} else {
		for (int i = 1; i <= k; i++) {
			int c = 0;
			for (int j = 1; j <= n; j++) {
				if (p[j] >= i) tmp[++c] = s[j];
			}
			if (check(tmp, c, ret, m)) {
				m = c;
				for (int j = 1; j <= c; j++) {
					ret[j] = tmp[j];
				}
			}
		}
	}
}

int main() {
	scanf("%d %s", &n, str + 1);
	for (int i = 1; i <= n * 2; i++) {
		sum[i] = sum[i - 1] + (str[i] == 'a' ? 1 : -1);
	}
	int lst = 1;
	for (int i = 1; i <= n * 2; i++) {
		if (sum[i] == 0) {
			++tot;
			for (int j = lst; j <= i; j++) {
				s[tot][++m[tot]] = str[j];
			}
			lst = i + 1;
		}
	}
	for (int i = 1; i <= tot; i++) {
		solve(s[i], res[i], m[i], sz[i]);
	}
	string s = "";
	for (int i = tot; i; i--) {
		string t = "";
		for (int j = 1; j <= sz[i]; j++) {
			t += res[i][j];
		}
		t += s;
		if (t > s) {
			s = t;
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 36608
/*
	AIZU ONLINE A0004
        Simultaneous Equation
*/
#include <stdio.h>
#include <float.h>
#define EPS 1e-9

main()
{	double a,b,c,d,e,f,x,y;
	double det;
	
	while(EOF != scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f))
	{	det = a*e - b*d;
		x   = (e*c - b*f)/det;
		y   = (-d*c+ a*f)/det;
		printf("%.3lf %.3lf\n",x+EPS,y+EPS);
	}
	return(0);
}

Measured memory_bytes: 0
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: isize,
        y: isize,
    }

    let mut r = false;
    for i in 0..=x {
        let sum = 4 * (x - i) + 2 * i;

        if sum == y {
            r = true;
            break;
        }
    }

    println!("{}", if r { "Yes" } else { "No" })
}


Measured memory_bytes: 2184
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

rate = [0]*9

for ai in a:
    if ai < 3200:
        rate[ai//400] = 1
    else:
        rate[8] += 1
        
if sum(rate[:-1]) == 0:
    print(1,rate[8])
    
else:
    print(sum(rate[:-1]), sum(rate[:-1])+rate[8])
    

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
		int a,b,c,max;
		scanf("%d%d%d",&a,&b,&c);
		max=a;
		if(max<b)max=b;
		if(max<c)max=c;
		printf("%d",max*10+a+b+c-max);
		return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);
static const long long mod = 2019;

int main() {
  long long L, R;
  cin >> L >> R;

  if (R - L >= mod) {
    cout << 0 << endl;
    return 0;
  }

  long long ans = 3000;
  for (int i = L; i < R; i++) {
    for (int j = i+1; j <= R; j++) {
      long long tmp = ((i%mod)*(j%mod)) % mod;
      ans = min(ans, tmp);
    }
  }

  cout << ans << endl;
      

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int X, Y;
	cin >> X >> Y;
	cout << X + Y / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long n;
  cin >> n;
  vector<long long> a(3*n);
  
  for(long long i = 0; i < 3*n; i++) {cin >> a[i];}
        sort(a.begin(),a.end(),greater<long long>());
 
        long long ans = 0;
        int cnt = 0;
        for(long long i = 1 ; i < 3*n; i += 2){
                if(cnt == n) break;
                ans += a[i];
                cnt++;
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 2560
def main():
    n,a,b=map(int,input().split(' '))
    x=list(map(int,input().split(' ')))
    tmp = x[0]
    ans = 0
    for i in x[1:]:
        if a*(i - tmp) <=b:
            ans += a*(i-tmp)
        else:
            ans += b
        tmp = i
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14252