akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  int x, y, z;
  cin >> x >> y >> z;
  x -= z;

  int cnt = 0, num = 0;
  while(true){
    if(num + y + z <= x){
      num += y + z;
      cnt++;
    } else{
      break;
    }
  }
  cout << cnt << ln;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
char upperCase(char a){int d = (int)a - 97 + 65;char c = (char)d;return c;} 
char lowerCase(char a){int d = (int)a - 65 + 97;char c = (char)d;return c;}  
bool isInt(char a){int d = (int)a - 48;if(d>=0 && d<=9){return true;}return false;}
//string char_to_string(char a){string d = (1,a);return d;}
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
//unordered_map<int,int> um;
//unordered_set<int> us;
//set<int> s;
// v.front() gives the first element of vector 
// v.back()  gives the last element of vector
// insert erase substr

//bool bySecond(pair<int,int> a,pair<int,int> b){
//  return a.second < b.second;
//} 

//bool f(vector<ll> a,vector<ll> b){
//	return a[1] > b[1];
//}

//swap(a,b);
 
int main(){
  int a ,b , c;
  cin >> a >> b >> c;
  if(a+b+c>21){
	  cout << "bust";
  }else{
	  cout << "win";
  }
 
 return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int calc(int x){
    if (x < 0 || x > 2000) return 0;
    return min(x+1, 2000-x+1);
}

int main() {
    int n;
    while (cin >> n){
        ll ans = 0;
        FOR(i,0,n){
            ans += calc(i) * calc(n-i);
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int d, t, s;
  cin >> d >> t >> s;
  int a = t * s;
  if(d <= a) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

int main(){
    int n,inp;
    cin >> n;
    vector<pair<int,int>> v;
    for(int t=0;t<n;t++){
        cin >> inp;
        v.emplace_back(make_pair(inp,0));
    }
    v[1].second=abs(v[0].first-v[1].first);
    for(int i=2;i<n;i++){
        v[i].second=min(abs(v[i-1].first-v[i].first)+v[i-1].second,abs(v[i-2].first-v[i].first)+v[i-2].second);
    }
    cout << v[n-1].second << '\n';
}

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

int main() {
	int a, b;
	char op;
	while (1) {
		cin >> a >> op >> b;
		if (op == '+')cout << a + b << endl;
		if (op == '-')cout << a - b << endl;
		if (op == '*')cout << a * b << endl;
		if (op == '/')cout << a / b << endl;
		if (op == '?')break;
	}
	return 0;
}

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

int main() {
	int s, m, h;
	cin >> s;
	m = s / 60;
	h = m / 60;
	cout << h << ":" << (m - 60 * h) << ":" << (s - 3600 * h - 60 * (m - 60 * h)) << endl;
	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
#define F first
#define S second
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
    ll n;
    cin >> n;
    ll k = -1;
    rep(i,1,n+1){
        if(i*(i-1) == 2*n){         
            k = i;
            break;
        }
    }
    if(n == 1){
        cout << "Yes" << endl << 2 << endl;
        cout << 1 << " " << 1 << endl << 1 << " " << 1 << endl;
        return 0;
    }
    if(k == -1){
        cout << "No" << endl;
        return 0;
    }
    if(n == 1){
        cout << "Yes" << endl << 2 << endl;
        cout << 1 << endl << 1 << endl;;
    }
    vector <vector <ll> > a(k);
    int x = 1;
    int in = 0;
    int num = k-1;
    while(num > 0){
        int xx = x;
        REP(i,num){
            a[in].pb(xx);
            xx += 1;
        }
        xx = x;
        rep(i,in+1, k){
            a[i].pb(xx);
            xx++;
        }
        in++;
        x = xx;
        num--;
    }
    cout << "Yes" << endl;
    cout << k << endl;
    REP(i,k){
        cout << k-1 << " ";
        REP(j,k-1){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }



    return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <string.h>

int main(void)
{
	char s[5];
	char t[5];
	scanf("%s%s",s,t);
	int sum = 0;
	if(s[0] == t[0])
		sum++;
	if(s[1]==t[1])
		sum++;
	if(s[2]==t[2])
		sum++;
	printf("%d\n",sum);
	return(0);
}



Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;


int main(void) {
	int n, a, b;
	int p;
	int total;
	int count = 0;

	cin >> n >> a >> b;

	FOR(i, 1, n) {
		total = 0;
		p = i;
		while (1) {
			if (p != 0) {
				total += (p % 10);
				p /= 10;
			}
			else {
				if (total >= a&&total <= b) {
					count += i;
				}
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

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

int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int t1 = h1*60+m1;
    int t2 = h2*60+m2;
    cout << max(0, t2-t1-k) << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include<string>
#include <cassert>
#include <algorithm>
#include <functional>
#include<stdio.h>

using namespace std;


int main() {
	int N;
	int K;
	string S;
	cin >> N >> K >> S;
	for (int i = 0; i <= N; ++i) {
		if (i == K) {
			S[K-1] += 0x20;
		}
	}
	cout << S << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	int out = 0;
	rep1(i, n) {
		if (i % 2 == 0)continue;
		int cnt = 0;
		rep1(j, i) {
			if (i%j == 0)cnt++;
		}
		if (cnt == 8)out++;
	}
	cout << out << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

bool judge(vector<ll> h, const ll &k, const ll &a, const ll &b) {
  ll cnt = 0;
  rep(i, h.size()) {
    h[i] -= k * b;
    if (h[i] > 0)
      cnt += (h[i] +a - b -1)/ (a - b);
  }
  return k >= cnt;
}

void solve(istream &ccin = cin, ostream &ccout = cout) {
  ll n, a, b;
  ccin >> n >> a >> b;

  vector<ll> h(n);
  rep(i, n) ccin >> h[i];

  ll lower = -1;
  ll higher = ll(1e9);
  while (higher - lower > 1) {
    ll mid = (higher + lower) / 2;
    if (judge(h, mid, a, b)) {
      higher = mid;
    } else {
      lower = mid;
    }
  }

  ccout << higher << endl;
}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Measured memory_bytes: 1792
n=int(input());l=[0,1];a=0;b=c=1;p=998244353
for i in range(2,n):l+=[l[p%i]*(p-int(p/i))%p]
for i in range(n,n//2,-1):a+=b*c%p;b+=b%p;c=c*i*l[n+1-i]%p
print((pow(3,n,p)-2*a)%p)

Measured memory_bytes: 220312
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

int main(void){
    long N,M;
    std::cin >> N >> M;
    long H[100000],A[100000],B[100000];
    for(long i=0; i<N; i++){
        std::cin >> H[i];
    }

    long C[100000]={};
    for(long i=0; i<M; i++){
        std::cin >> A[i] >> B[i];
    }


    for(long i=0; i<M; i++){
        if(H[A[i]-1]<H[B[i]-1]){
            C[A[i]-1]=1;
        }else if(H[A[i]-1]>H[B[i]-1]){
            C[B[i]-1]=1;
        }else if(H[A[i]-1]==H[B[i]-1]){
            C[A[i]-1]=1; 
            C[B[i]-1]=1;
        }
    }

long count=0;
    for(long i=0; i<N; i++){
        if(C[i]==0){
            count++;
        }
    }
    std::cout << count << std::endl;
    return 0;
}

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

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

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


void calc_primefactorization(long long in, vector<vector<long long> >& out){
	
	long long N = in, Ntmp;
	long long p,e,p_init = 2;
	vector<long long> out_tmp(2);
	
	if( in == 1 ){
		out_tmp[0] = 1;
		out_tmp[1] = 1;
	}
	else{
		while( 1 ){

			Ntmp = N;
				
			p = N;
			e = 1;

			for(long long i = p_init;i * i <= N;i++){
						
				if( Ntmp % i == 0 ){
					e = 0;
					while( 1 ){
						if( Ntmp % i != 0 ){
							break;
						}
						else{
							Ntmp = Ntmp / i;
							e++;
						}
					}
					p = i;
					break;
				}
				
			}
			
			out_tmp[0] = p;
			out_tmp[1] = e;
			out.push_back(out_tmp);
			
			for(int i = 0;i < e;i++){
				N = N / p;
			}
			
			if( N == 1 ){
				break;
			}
			
		}
	}
	
}

int bitmask(int n){
	
	int a = 1;
	
	return ( a << (n - 1) );
	
}

bool judge(int a, int b){
	
	if( (a & bitmask(b)) > 0 ){
		return true;
	}
	else{
		return false;
	}
	
}

int main(){
	
	
	int H, W, K;
	
	cin >> H >> W >> K;
	
	vector<vector<string> > c(H, vector<string>(W));
	vector<vector<int> > ci(H, vector<int>(W));
	
	for(int h = 0;h < H;h++){
		string ctmp;
		cin >> ctmp;
		for(int w = 0;w < W;w++){
			c[h][w] = ctmp[w];
			ci[h][w] = ( ( c[h][w] == "#" ) ? 1 : 0 );
		}
	}
	
	int ans = 0;
	for(int hh = 0;hh < pow(2,H);hh++){
		for(int ww = 0;ww < pow(2,W);ww++){
			
			int sum = 0;
			for(int h = 0;h < H;h++){
				if( !judge(hh, h + 1) ){
					for(int w = 0;w < W;w++){
						if( !judge(ww, w + 1) ){
							sum = sum + ci[h][w];
							//cout << hh << " " << ww << " " << h << " " << w << " " << c[h][w] << endl;
						}
					}
				}
			}
			//cout << sum << endl;
			if( sum == K ){
				//cout << hh << " " << ww << endl;
				ans++;
			}
			
		}
	}
	
	/*
	vector<vector<int> > sum;
	sum.resize(2);
	sum[0].resize(H + 1);
	sum[1].resize(W + 1);
	
	for(int h = 0;h < H;h++){
		for(int w = 0;w < W;w++){
			sum[0][h + 1] = sum[0][h + 1] + ci[h][w];
		}
	}
	
	for(int w = 0;w < W;w++){
		for(int h = 0;h < H;h++){
			sum[1][w + 1] = sum[1][w + 1] + ci[h][w];
		}
	}
	*/
	cout << ans;

	
	return 0;
	
}


Measured memory_bytes: 4124
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();
        int K = nextInt();
        int Q = nextInt();
        int[] A = new int[N];

        for(int i=0; i<Q; i++) {
            A[nextInt()-1] += 1;
        }

        for(int i=0; i<N; i++){
            if(A[i] + K - Q > 0){
                println("Yes");
            }else{
                println("No");
            }
        }
    }

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

    static Long nextLong() {
        return Long.parseLong(next());
    }

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

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 57928
from collections import deque
import math
n,d,a = map(int,input().split())
F = []
for _ in range(n):
    x,h = map(int,input().split())
    F.append((x,h))
F.sort()
total = 0
d *=2
ans = 0
q = deque([])
for x,h in F:
    while q and q[0][0]<x:#累積和
        total -= q.popleft()[1]
    h-=total
    if h >0:
        tmp = math.ceil(h/a)
        ans += tmp
        damage = tmp*a
        total += damage
        q.append((x+d,damage))
print(ans)


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, d, x, temp;
    cin >> n >> d >> x;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        for(int j = 1; j <= d;) {
            x++;
            j += temp;
        }
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    long long a, b;
    cin >> a >> b;
    long long g = __gcd(a, b);
    g = a * b / g;
    cout << g << endl;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = sc.nextInt();
    Integer t[] = new Integer[N+1];
    Integer x[] = new Integer[N+1];
    Integer y[] = new Integer[N+1];
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    int time;
    int move;
    String ans = "Yes";
    for(int i=1; i<N+1; i++){
      t[i] = sc.nextInt();
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
      time = t[i] - t[i-1];
      move = Math.abs(x[i] - x[i-1]) + Math.abs(y[i] - y[i-1]);
      if(time < move || (time%2 != move%2) ){
        ans = "No";
        break;
      }
      
    }
    out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

ll n,m,q,an=0;
ll A[11],a[51],b[51],c[51],d[51];

void dfs(ll dep,ll now){
    A[dep]=now;
    if(dep==n-1){
        ll tmp=0;
        rep(i,0,q){
            if(A[b[i]]-A[a[i]]==c[i])tmp+=d[i];
        }
        an=max(an,tmp);
        return;
    }
    
    rep(i,now,m+1){
        dfs(dep+1,i);
    }
}

int main(){
    cin>>n>>m>>q;
    rep(i,0,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;b[i]--;
    }
    dfs(0,1);
    cout<<an<<endl;
}
    









Measured memory_bytes: 3604
# coding: utf-8
# Your code here!

n,x = map(int,input().split())

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

tmp = 0
for il,i in zip(l,range(len(l))):
    tmp+=il
    if tmp > x:
        i-=1
        break
    
if l[0] <= x:
    print(i+2)
else:
    print(0)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
long long p = 998244353;
vel kai(4001, 1);
vel ink(4001, 1);
vel uni(vel &list) {
	if (list.size() == 0) { return list; }
	sort(list.begin(), list.end());
	vel ql(1, list[0]);
	rep(i, list.size() - 1) {
		if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); }
	}
	return ql;
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, 4000) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, 4001) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
signed main() {
	int n; cin >> n;
	V<V<pin>> way(n);
	rep(i, n - 1) {
		int u, v, w; cin >> u >> v >> w; u--; v--;
		way[u].push_back(mkp(v, w % 2));
		way[v].push_back(mkp(u, w % 2));
	}
	V<bool> is_use(n, false); is_use[0] = true;
	queue<int> qu;
	qu.push(0);
	vel dis(n, 0);
	while (!qu.empty()) {
		int now = qu.front(); qu.pop();
		rep(i, way[now].size()) {
			int nex = way[now][i].first;
			if (!is_use[nex]) {
				is_use[nex] = true;
				qu.push(nex);
				dis[nex] = dis[now] + way[now][i].second;
			}
		}
	}
	rep(i, n) { cout << dis[i] % 2 << endl; }
	return 0;
}

Measured memory_bytes: 8704
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,A[1100];
int check(int k1){
//	cout<<k1<<endl;
	int fir=k1%10,k=k1; k1/=10;
	while (k1){
		int k2=k1%10; k1/=10;
		if (k2!=fir-1) return -1;
		fir=k2;
	}
	return k;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	int ans=-1;
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			ans=max(ans,check(A[i]*A[j]));
	cout<<ans<<endl; return 0;
}

Measured memory_bytes: 3236
n, q = [int(_) for _ in input().split()]
s = input()

Q = [(input().split()) for i in range(q)]
Q.reverse()
l = 0
r = n - 1
for t,d in Q:
    if s[l] == t and d == "L":
        l += 1
    elif l > 0 and s[l - 1] == t and d == "R":
        l -= 1
    if s[r] == t and d == "R":
        r -= 1
    elif r < n - 1 and s[r + 1] == t and d == "L":
        r += 1
    # print(r,l,r-l+1)
    if l > r:
        break
print(r - l + 1)


Measured memory_bytes: 39348
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=410,Mod=1e9+7;
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
#define inf 1e17
int n,a[25][25],dp[(1<<21)+10];
void add(int &a,int b)
{
  a+=b;
  if(a>=Mod) a-=Mod;
}
int main()
{
  cin>>n;
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];
  dp[0]=1;
  for(int mask=0;mask<(1<<n);mask++)
  {
    int v=__builtin_popcount(mask);
    for(int b=0;b<n;b++) if(!(mask&(1<<b)) && a[v][b]) add(dp[mask^(1<<b)],dp[mask]);
  }
  cout<<dp[(1<<n)-1]<<endl;
  return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;



int main(){
	ll N;
	cin >> N;
	string S;
	cin >> S;
	ll wcounter=0;
	for(ll i=0;i<N;i++){
		if(S[i]=='.')wcounter++;
	;}
	ll ans=wcounter;
	ll num=wcounter;
	for(ll i=0;i<N;i++){
		if(S[i]=='#')num++;
		else if(S[i]=='.')num--;
		ans=min(ans,num)
	;}
	cout<<ans<<endl;

return 0;
}  



Measured memory_bytes: 640
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,M,C = map(int, sys.stdin.readline().split())
    b= list(map(int, sys.stdin.readline().split()))
    a= [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]

    ans=0
    for i in range(N):
        l=[]
        for j in range(M):
            n = a[i][j]*b[j]
            l.append(n)
        s = sum(l)
        if s + C >0:
            ans += 1
    print(ans)


Measured memory_bytes: 5068
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();
        
        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let (n, m) = read_cols!(usize, usize);
    let nums = {
        let mut nums = read_vec::<i64>();
        nums.sort();
        nums
    };
    assert_eq!(m, nums.len());

    if n >= m {
        println!("0");
        return;
    }

    let mut dist: Vec<_> = nums.iter().skip(1).zip(nums.iter())
                    .map(|(x, y)| x - y)
                    .collect::<Vec<_>>();
    dist.sort();
    let ans: i64 = dist.iter().take(m - n).sum();
    
    println!("{}", ans);
}

Measured memory_bytes: 6396
n, x = map(int,input().split())
A = list(map(int,input().split()))

ans = 10**18
mins = [a for a in A]
for k in range(n):
    for i in range(n):
        if k <= i:
            mins[i] = min(A[i-k], mins[i])
        else:
            mins[i] = min(A[n-(k-i)], mins[i])
    ans = min(sum(mins)+k*x, ans)
print(ans)


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int main() {
  std::cout << std::fixed << std::setprecision(20);
  int x, y;
  cin >> x >> y;

  double a, b;
  b = (y - 2*x)/2.0;
  a = (4*x-y)/2.0;
  if(a < 0 || b < 0){
    cout << "No" << endl;
    return 0;
  }
  if(  b - (int)b != 0 || a - (int)a != 0){
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  int N;
  cin >> N;
  map<char, int>M;
  for(char i='a';i<='z';i++)
    M[(char)i] = 50;
  for(int i=0;i<N;i++){
    string S; cin >> S;
    map<char, int>m;
    for(auto &s: S){
      if(m.find(s) == m.end()) m[s] = 1;
      else m[s] = m[s] + 1;
    }
    
    for(char j='a';j<='z';j++){
      M[(char)j] = min(M[(char)j], m[(char)j]);
    }
  }


  for(char i='a';i<='z';i++){
    for(int j=0;j<M[i];j++)
      cout << (char)i;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 3005;

int n;
long long arr[N];
long long dp[N][N][2];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int L = 1; L <= n; L++) {
    for (int i = 0; i + L - 1 < n; i++) {
      int j = i + L - 1;
      for (int p = 0; p < 2; p++) {
        if (L == 1) {
          dp[i][j][p] = arr[i];
        } else if (L == 2) {
          if (p == 0) {
            dp[i][j][p] = max(arr[i] - arr[j], arr[j] - arr[i]);
          } else {
            dp[i][j][p] = min(arr[i] - arr[j], arr[j] - arr[i]);
          }
        } else {
          if (p == 0) {
            long long ans = arr[i] + dp[i + 1][j][1];
            ans = max(ans, dp[i][j - 1][1] + arr[j]);
            dp[i][j][p] = ans;
          } else {
            long long ans = dp[i + 1][j][0] - arr[i];
            ans = min(ans, dp[i][j - 1][0] - arr[j]);
            dp[i][j][p] = ans;
          }
        }
      }
    }
  }
  cout << dp[0][n - 1][0] << endl;
  return 0;
}


Measured memory_bytes: 139648
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long 

int32_t main()
{
    IOS;
    string s;
    cin>>s;
    int w;
    cin>>w;
    for(int i=0;i<s.size();i+=w)
    	cout<<s[i];
    return 0;
}   

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pp = pair<string, pair<int, int>>;


int main() {
	int N;
	cin >> N;
	map<string, vector<P>> mp;
	for (int i = 1; i <= N; ++i) {
		string s;
		int p;
		cin >> s >> p;
		mp[s].push_back(P(p, i));
	}

	for (auto it = mp.begin(); it != mp.end(); ++it) {
		vector<P> v = it->second;
		sort(v.rbegin(), v.rend());
		for (int i = 0; i < v.size(); ++i) {
			cout << v[i].second << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {}

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

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

        // merge by size
        // force size of x to be bigger than that of y
        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)];
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, M;
    cin >> N >> M;

    int A[N];
    REP(i, N) {
        cin >> A[i];
        --A[i];
    }

    UnionFind uf(N);
    REP(i, M) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        uf.merge(x, y);
    }

    int ans = 0;
    REP(i, N) {
        if (uf.issame(i, A[i])) ++ans;
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()
#include <numeric>

#define rep(i, n) for(int i=0; i<(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) cout << "debug (" #a "):" << endl << (a) << endl;

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;

template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);

//uint64_t a, b, c, d;
//uint64_t i, j;
lint n, m;
lint h, w,k;

int main(){
//////////////////////////////////////////////////////

    cin >> n >> k;

    if( k == 1)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << n-k << endl;
    }
    
    

    

   

    // sort(input.begin() , input.end());

    // uint64_t max = numeric_limits<uint64_t>::max();


    //////////////////////////////////////////////////////
    // DP

//     // 無限大の値
//     const uint64_t INF = (uint64_t)1 << 60;
//     //const int64_t NINF = -1 * ((int64_t)1 << 60 );
 
//     // DP テーブル
//     uint64_t dp[100010];

//     //DPテーブル初期化（最小化用）
//     for (int i = 0; i < 100010; ++i)
//     {
//         //dp[i] = INF;
//         dp[i] = 0;
//     } 

//     // 初期条件
//     dp[0] = 0;

//     // ループ
//     for (int i = 1; i <= n; ++i) {
//         //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] ));
//         //if (i < 2)continue;
//         //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] ));



//         // chmax ( dp [i] , dp[i - 1]);
//         // chmax ( dp [i] , dp[i - 1] + input[i]);
//         // cout << "dp[" << i <<"] = " << dp[i] << endl;

//     }



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

//     cout << dp[n] << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


//最小化用関数
template<class T> inline bool chmin(T& a, T b)
{
    if (a > b) 
    {
        a = b;
        return true;
    }
    return false;
}

//最大化関数
template<class T> inline bool chmax(T& a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}


// vectorprint用
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

// //合計
// template<class T> lint sum(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0);
// }


// //平均
// template<class T> double ave(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0.0) / a.size();
// }


Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
discount = [list(map(int, input().split())) for _ in range(M)]
ans = min(a) + min(b)

for i in range(M):
    tmp = a[discount[i][0]-1] + b[discount[i][1]-1] - discount[i][2]
    if  tmp < ans:
        ans = tmp

print(ans)

Measured memory_bytes: 38492
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string S;
string C = "AGCT";

void solve() {
	cin >> S;
	N = sz(S);
	int res = 0;
	rep(i, 0, N) {
		rep(j, i, N) {
			bool ok = true;
			rep(k, i, j + 1) {
				bool found = false;
				rep(q, 0, 4) {
					found |= (C[q] == S[k]);
				}
				if(!found) {
					ok = false;
					break;
				}
			}
			if(ok) MAX(res, j - i + 1);
		}
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int func(long long n, long long m, std::vector<long long> x) {
    // cout << fixed << setprecision(8);
    sort(all(x));

    vi d;
    rep(i, m - 1) { d.push_back(x[i + 1] - x[i]); }
    sort(all(d));
    ll  ans = 0;
    int u   = m - n;
    int cnt = max(0, u);
    rep(i, cnt) ans += d[i];
    cout << ans << endl;

    return 0;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> X(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &X[i]);
    }

    func(N, M, std::move(X));

    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h,n;
    cin>>h>>n;
    int a[n+1];
    int b[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
    int ar[h+1];
    for(int i=1;i<=h;i++)
        ar[i]=INT_MAX;
    ar[0]=0;
    for(int j=1;j<=n;j++)
    {
        for(int i=1;i<=h;i++)
        {
            int mini=max(0,i-a[j]);
            ar[i]=min(ar[mini]+b[j],ar[i]);
        }
    }
    cout<<ar[h];
	return 0;
}

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

int main(){

  int n,m,k[10000];
  string s[10000];
  string t[10000];
  bool d = true;
  int ans;

  while(true){
    cin >> n >> m;
    if(!n && !m) break;

    ans = 0;

    for(int i=0;i<n;i++){
      cin >> s[i];
      cin >> k[i];
    }

    for(int i=0;i<m;i++) cin >> t[i];

    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	d = true;

	for(int l=7;l>=0;l--){
	  if(s[i][l] == '*') break;
	  if(s[i][l] != t[j][l]) d = false;
	}

	if(d == true) ans += k[i];

      }
    }

    cout << ans << endl;

  }
}

Measured memory_bytes: 1420
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

//DFS
int id;
vector<int> seen;
void dfs(const Graph &G, int v, int &cnt) {
    seen[v] = id; //vに訪問IDをつける
    cnt++;
    //vから行ける各頂点next_vについて
    for(auto next_v : G[v]) {
        if(seen[next_v] != -1) continue; //next_vが探索済みなら無視
        dfs(G, next_v, cnt); //再帰的に探索
    }
}

int main() {
    //人、友達関係、ブロック関係
    int N, M, K;
    cin >> N >> M >> K;

    vector<int> A(M);
    vector<int> B(M);
    Graph G(N);
    //友達関係から無向グラフを作成
    for(int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }

    vector<int> C(K);
    vector<int> D(K);
    //ブロック関係
    for(int i = 0; i < K; i++) {
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;
    }

    //頂点0をスタートとした探索
    seen.assign(N, -1); //全頂点を未訪問に初期化
    id = 0;
    vector<int> num;
    for(int i = 0; i < N; i++) {
        if(seen[i] == -1) {
            int cnt = 0;
            dfs(G, i, cnt);  
            num.push_back(cnt);
            id++;
        }
    }

    //同じ連携成分の数から既に友達の数を引く（1は自身）
    vector<int> ans(N);
    for(int i = 0; i < N; i++) {
        ans[i] = num[seen[i]] - 1 - (int)G[i].size();
    }

    //同じ連結成分にあるブロック関係を引く
    for(int i = 0; i < K; i++) {
        if(seen[C[i]] == seen[D[i]]) {
            ans[C[i]]--;
            ans[D[i]]--;
        }
    }

    for(int i = 0; i < N; i++) {
        cout << ans[i];
        if(i != N-1) {
            cout << ' ';
        }
        else {
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 9600
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline unsigned getMaxEffectiveBit(ull a)
{
	ll index = 0;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

// computational complexity: o(log(max(a, b))) 
template<class ll>
inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b)
{
	if (b == 0)
	{
		return { 1, 0 };
	}
	auto sol = getBezoutsIdentitySolution(b, a % b);
	return { sol.second, sol.first - (a / b) * sol.second };
}

template<class Integer>
inline Integer getPower(Integer base, unsigned exponential)
{
	Integer res = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			res *= base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return res;
}



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

	ll X, Y, Z, K;
	cin >> X >> Y >> Z >> K;

	vector<ll> As(X), Bs(Y), Cs(Z);
	for (ll i = 0; i < X; ++i)
	{
		cin >> As[i];
	}
	for (ll i = 0; i < Y; ++i)
	{
		cin >> Bs[i];
	}
	for (ll i = 0; i < Z; ++i)
	{
		cin >> Cs[i];
	}

	vector<ll> BCs(Y * Z);
	for (ll i = 0; i < Y; ++i)
	{
		for (ll j = 0; j < Z; ++j)
		{
			BCs[i * Z + j] = Bs[i] + Cs[j];
		}
	}
	sort(As.begin(), As.end(), greater<ll>());
	sort(BCs.begin(), BCs.end(), greater<ll>());

	priority_queue<ll> vals;
	for (ll i = 0; i < min(K, static_cast<ll>(As.size())); ++i)
	{
		for (ll j = 0; j < min(K, static_cast<ll>(BCs.size())); ++j)
		{
			vals.push(As[i] + BCs[j]);
		}
	}

	for (ll i = 0; i < K; ++i)
	{
		cout << vals.top() << endl;
		vals.pop();
	}

	return 0;
}


Measured memory_bytes: 42984
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
vector<vector<int>> a;
vector<pair<int, int>> b;
vector<int> c, d;
int ans = 0, used = 0;
void func(int ind)
{
	d[ind] = c[used++];
	for(int i = 0; i < a[ind].size(); ++i)
	{
		if(!d[a[ind][i]])
		{
			ans += c[used];
			func(a[ind][i]);
		}
	}
}
int main()
{
	int n;
	scanf("%d", &n);
	a.resize(n, vector<int>(0));
	b.resize(n);
	for(int i = 0; i < n; ++i)
	{
		b[i] = make_pair(0, i);
	}
	for(int i = 0, j, k; i < n - 1; ++i)
	{
		scanf("%d%d", &j, &k);
		a[j - 1].push_back(k - 1);
		a[k - 1].push_back(j - 1);
		++b[j - 1].fst;
		++b[k - 1].fst;
	}
	c.resize(n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &c[i]);
	}
	sort(b.begin(), b.end(), greater<pair<int, int>>());	
	sort(c.begin(), c.end(), greater<int>());
	d.resize(n, 0);
	func(b[0].scd);
	printf("%d\n", ans);
	for(int i : d)
	{
		printf("%d ", i);
	}
	printf("\n");
}

Measured memory_bytes: 1152
line = int(input())
words =[input() for i in range(line)]

import collections

output = []
words_col = collections.Counter(words).most_common()
max_num = words_col[0][1]
for most_word in words_col:
  if max_num != most_word[1]: 
    break
  output.append(most_word[0])

output.sort()
print("\n".join(output))

Measured memory_bytes: 120272
n,m = map(int, input().split())
h = list(map(int, input().split()))
d = {}
e = {}
for num,i in enumerate(h):
  e[num+1] = i
for i in range(m):
  a,b = map(int, input().split())
  if a in d:
    d[a] = max(d[a],e[b])
  else:
    d[a] = e[b]
  if b in d:
    d[b] = max(d[b],e[a])
  else:
    d[b] = e[a]
ans = 0
k_ = 0
for k,v in d.items():
  if e[k] > v:
    ans +=1
  k_ += 1
print(ans+n-k_)


Measured memory_bytes: 28956
import itertools
from collections import Counter

n = int(input())
l = list(map(int,input().split()))
a = sorted(list(set(l)))
b = Counter(l)
ans = 0
for v in itertools.combinations(a, 3):
    if v[0]+v[1]>v[2]:
        ans += b[v[0]]*b[v[1]]*b[v[2]]
print(ans)

Measured memory_bytes: 9468
N,M=map(int,input().split())
d={}
for i in range(M):
    a,*b=map(int,input().split())
    d[i]=b
p=list(map(int,input().split()))
cnt=0
for i in range(2**N):
    t=bin(i)[2:]
    t='0'*(N-len(t)+1)+t
    t=list(t)
    f=True
    for j in range(M):
        s=0
        for k in d[j]:
            s+=int(t[k])
        if s%2!=p[j]:
            f=False
            break
    if f:cnt+=1
print(cnt)

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

void zeroOrOneSwap(int& size, int arr[])
{
    bool swap = false;

    int start = 1;
    // replace start with i+1??

    for (int i = 0; i < size; i++)
    {
        //printf("arr[i]: %d\n", arr[i]);
        //printf("start: %d\n", start);
        
        if (arr[i] != start && swap)
        {
            printf("NO\n");
            return;
        }

        else if (arr[i] != start)
        {
            int other = arr[arr[i]-1];
            // swap...
            if (other == start)
            {
                //printf("other: %d\n", other);
                swap = true;
                arr[arr[i]-1] = arr[i];
                arr[i] = other;
            }

            else
            {
                printf("NO\n");
                return;
            }
        }

        start++;
    }

    printf("YES\n");
}

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

    int arr[size];

    for (int i = 0; i < size; i++) scanf("%d", &arr[i]);

    zeroOrOneSwap(size, arr);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>

using namespace std;

#define D double
 
D heron(D a,D b,D c){
  D s = (a + b + c) / 2;
  D S = sqrt(s*(s - a)*(s - b)*(s - c));
  return S;
}
 
int main(){
  D x1,y1,x2,y2,x3,y3,xp,yp;
   
  while( cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp ){
    D a = sqrt(pow(x1-x2,2) + pow(y1-y2,2));
    D b = sqrt(pow(x1-x3,2) + pow(y1-y3,2));
    D c = sqrt(pow(x3-x2,2) + pow(y3-y2,2));
    D S1 = heron(a,b,c);
     
    D x = sqrt(pow(x1-xp,2) + pow(y1-yp,2));
    D y = sqrt(pow(x2-xp,2) + pow(y2-yp,2));
    D z = sqrt(pow(x3-xp,2) + pow(y3-yp,2));
    D S2 = heron(x,y,a) + heron(x,z,b) + heron(y,z,c);
     
    if ((float)S1 == (float)S2){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1216
#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 a,b;
	scanf("%d %d", &a, &b);

	if(a%3==0){
		printf("Possible\n");
	}else if(b%3==0){
		printf("Possible\n");
	}else if((a+b)%3==0){
		printf("Possible\n");
	}else{
		printf("Impossible\n");
	}

	return 0;
}


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

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

using namespace std;
using lint=long long;

int main(){
	lint a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max({a*c,a*d,b*c,b*d})<<'\n';
	return 0;
}


Measured memory_bytes: 3632