akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const vector<int> cost = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

vector<int> as;
vector<int> dp;

void calc_maximum_digits(const int N, const int M) {
    dp.resize(N + 1, -1);
    dp[0] = 0;

    for (int i = 0; i < M; i++) {
        const int a = as[i];
        for (int j = 0; j < N; j++) {
            if (j + cost[a]  > N) {
                continue;
            }
            if (dp[j] >= 0) {
                chmax(dp[j + cost[a]], dp[j] + 1);
            }
        }
    }
}

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

    as.resize(M);
    for (int i = 0; i < M; i++) {
        cin >> as[i];
    }
    sort(as.rbegin(), as.rend());

    calc_maximum_digits(N, M);

#ifdef DEBUG
    printf("dp: \n");
    for (int i = 0; i <= N; i++) {
        cout << dp[i] << " ";
    }
    cout << endl;
#endif

    const int maximum_digits = dp[N];
    int remain = N;
    string ans = "";
    for (int i = 0; i < maximum_digits; i++) {
        for (auto a : as) {
            if (remain - cost[a] < 0) {
                continue;
            }
            if (dp[remain] < 0 || dp[remain - cost[a]] < 0) {
                continue;
            }
            if (dp[remain - cost[a]] == dp[remain] - 1) {
                ans.push_back('0' + a);
                remain -= cost[a];
                break;
            }
        }
    }

    assert(remain == 0);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

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

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

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/

int main(){
    vector<ll> num(10);
    rep(i,10)cin >> num[i];
    sort(all(num));
    cout << num[9] << endl << num[8] << endl << num[7] << endl;
}


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

public class Test
{
	public static void Main()
	{
		Dictionary<string, int> dic = new Dictionary<string, int>();

		int n = int.Parse(Console.ReadLine());
	    string line;
	    for(int i = 0 ; i < n ; i++){
	        line = Console.ReadLine();
	        if(dic.ContainsKey(line)){
	            
	        } else {
	            dic.Add(line,1);
	        }
	    }
	    
	    Console.WriteLine(dic.Count());
	}                                                                                                                                                                       
}

Measured memory_bytes: 13268
#include <stdio.h>

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a == b && b == c) printf("1\n");
	else if (a == b || b == c || c == a) printf("2\n");
	else printf("3\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1656
#include <iostream>
#include <vector>

using namespace std;

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

    int penalties[26];

    for(int i = 0; i < 26; i++){
        int p;
        cin >> p;
        penalties[i] = p;
    }

    vector<int*> satis;

    for(int i = 0; i < days; i++){
        int *sat = new int[26];
        for(int j = 0; j < 26; j++){
            int s;
            cin >> s;
            sat[j] = s;
        }
        satis.push_back(sat);
    }

    int last[26];

    for(int i = 0; i < 26; i++){
        last[i] = -1;
    }

    int satis_sum = 0;
    for(int i = 0; i < days; i++){
        int cont;
        cin >> cont;
        cont -= 1;
        last[cont] = i;
        
        satis_sum += satis[i][cont];

        for(int j = 0; j < 26; j++){
            satis_sum -= penalties[j] * (i - last[j]);
        }
        cout << satis_sum << endl;
    }


    return 0;
}

Measured memory_bytes: 3648
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n, m) = get!(usize, usize);
    let ab = get!(usize, usize; m);

    let mut g = vec![Vec::new(); n];

    for &(a, b) in &ab {
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }

    let mut stack = vec![(0, 1u8)];
    let mut ans = 0;

    while let Some((p, used)) = stack.pop() {
        if used == ((1 << n) - 1) as u8 {
            ans += 1;
        } else {
            for &to in &g[p] {
                if used & 1 << to == 0 {
                    stack.push((to, used | 1 << to));
                }
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL n;
double p[3005];
double ans = 0.0;
double dp[3005][3005];

int main(){
	scanf("%lld",&n);
	for(LL i = 1;i <= n;i ++) scanf("%lf",&p[i]);
	dp[0][0] = 1.0;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 0;j <= i;j ++){
			dp[i][j] = dp[i - 1][j] * (1.0 - p[i]);
			if(j) dp[i][j] += dp[i - 1][j - 1] * p[i];
		}
	}
	for(LL i = (n >> 1) + 1;i <= n;i ++) ans += dp[n][i];
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 68992
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<stdio.h>
#include<cmath>
using namespace std;
typedef long long int ll;
int const MAX=10005;
int const MAXM=100000005;
int par[MAX];
int rankn[MAX];
struct Dian
{
    int x;int y;
};
struct Edge
{
    int u,v;
    double cost;
}edge[MAXM];
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        rankn[i]=0;
    }
}
int findn(int x){
    if(par[x]==x)return x;
    else {return par[x]=findn(par[x]);}
}
void unite(int x,int y)
{
    x=findn(x);
    y=findn(y);
    if(x==y)return;
    if(rankn[x]<rankn[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(rankn[x]==rankn[y])rankn[x]++;
    }
}
bool same(int x,int y)
{
    return findn(x)==findn(y);
}
int N,M;
Dian dian[MAX];
double dis(int a,int b)
{
    double l;
    l=sqrt((dian[a].x-dian[b].x)*(dian[a].x-dian[b].x)+(dian[a].y-dian[b].y)*(dian[a].y-dian[b].y));
    return l;
}
bool comp(const Edge e1,const Edge e2)
{
    return e1.cost<e2.cost;
}
int main()
{
    while(cin>>N>>M){
    int a,b,c;
    double sum=0;
    for(int i=0;i<N;i++){
        cin>>a>>b;
        dian[i].x=a;
        dian[i].y=b;
    }
    for(int i=0;i<M;i++){
        cin>>a>>b;
        a--;
        b--;
        edge[i].u=a;
        edge[i].v=b;
        edge[i].cost=-dis(a,b);
        sum+=dis(a,b);
        //cout<<"!!!"<<dis(a,b)<<endl;
    }
    sort(edge,edge+M,comp);
    init(N);
    double res=0;
    for(int i=0;i<M;i++){
        Edge e=edge[i];//cout<<e.v<<" "<<e.u<<" ";
            //cout<<findn(e.u)<<"!!!! "<<findn(e.v)<<endl;
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res+=e.cost;

            //cout<<"###"<<e.cost<<endl;
        }
    }
    //cout<<res;
    //cout<<sum<<endl;
    printf("%.3f\n",sum+res);
    }
    return 0;
}



Measured memory_bytes: 3880
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;

main(){
    int n;
    cin>>n;
    ll a[400][400];
    rep(i,n)rep(j,n)cin>>a[i][j];
    ll ans=0;
    rep(i,n){
        rep2(j,i+1,n-1){
            ll temp=a[i][j];
            ll m=INF;
            rep(k,n){
                if(k==i||k==j)continue;
                m=min(m,a[i][k]+a[k][j]);
            }
            if(m<temp){ 
                ans=-1;break;
            }
            else if(m>temp)ans+=temp;
        }
        if(ans==-1)break;
    }
    printf("%lld",ans);
}

Measured memory_bytes: 1152
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main(){
	int N;
	string W[20000];
	int i,j;
	int ng = 0;

	cin >> N;
	for (i = 0; i < N; ++i) {
		cin >> W[i];
	}

	for (i = 0; i < N; ++i) {//重複判別
		for (j = 0; j < N; ++j) {
			if (i != j) {
				if (W[i] == W[j]) {
					++ng;
				}
			}
		}
	}

	for (i = 0; i < N-1; ++i) {
		if (W[i].back() != W[i + 1].front()) {
			++ng;
		}
	}




	if (ng == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

 }



Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int A;
	int B;
	int C;
	int D;
	int P;
	int x;
	int y;
	
	scanf("%d\n", &A);
	scanf("%d\n", &B);
	scanf("%d\n", &C);
	scanf("%d\n", &D);
	scanf("%d\n", &P);
	
	x = P * A;
	
	if (P > C){
		y = B + (P - C) * D;
	}
	else if (P <= C){
		y = B;
	}
	
	if (x < y){
		printf("%d", x);
	}
	else {
		printf("%d", y);
	}
	printf("\n");
	
	return (0);
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);

    int max_num = 0;
    int max_num_count = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        b[i] = a[i];
        if (max_num < a[i])
        {
            max_num = a[i];
            max_num_count = 0;
        }
        else if (max_num == a[i])
        {
            max_num_count++;
        }
    }

    if (max_num_count >= 2)
    {
        for (int i = 0; i < n; i++)
        {
            cout << max_num << endl;
        }
    }
    else
    {
        sort(b.begin(), b.end());
        for (int i = 0; i < n; i++)
        {
            if (a[i] != max_num)
            {
                cout << max_num << endl;
            }
            else
            {
                cout << b[b.size() - 2] << endl;
            }
        }
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=1;i<n;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) REP(i,v.size())cout<<#v<<"["<<i<<"]: "<<v[i]<<endl
#define ALL(a) (a).begin(),(a).end()

// true: ISONO WIN
// false: NAKAJIMA WIN
bool dfs(int turn,int li,int ri,int ln,int rn){
  if(li>=5 && ri>=5)return false;
  if(ln>=5 && rn>=5)return true;
  if(turn==0){
    //ISONO TURN
    bool result = false;
    if(ln<5&&li<5)result = result || dfs(1,li,ri,ln+li,rn);
    if(ln<5&&ri<5)result = result || dfs(1,li,ri,ln+ri,rn);
    if(rn<5&&li<5)result = result || dfs(1,li,ri,ln,rn+li);
    if(rn<5&&ri<5)result = result || dfs(1,li,ri,ln,rn+ri);
    return result;
  }else{
    //NAKAJIMA TURN
    bool result = true;
    if(li<5&&ln<5)result = result && dfs(0,li+ln,ri,ln,rn);
    if(li<5&&rn<5)result = result && dfs(0,li+rn,ri,ln,rn);
    if(ri<5&&ln<5)result = result && dfs(0,li,ri+ln,ln,rn);
    if(ri<5&&rn<5)result = result && dfs(0,li,ri+rn,ln,rn);
    return result;
  }
}

string solve(){
  string ISONO="ISONO", NAKAJIMA="NAKAJIMA";
  int li,ri,ln,rn;
  cin>>li>>ri>>ln>>rn;
  bool result = dfs(0,li,ri,ln,rn);
  if(result)return ISONO;
  else return NAKAJIMA;
}

int main(){
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000000000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL N,M,i,ans=0;
  scanf("%lld%lld",&N,&M);
  if(N>=0)ans+=N*(N-1)/2;
  if(M>=0)ans+=M*(M-1)/2;

  printf("%lld\n",ans);
	return 0;
}


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

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



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

   int a[n];
   int sum=0;
   rep(i,n){
      cin>>a[i];
      sum+=min(2*a[i],2*(k-a[i]));
   }
   cout<<sum<<endl;

   
   return 0;
}



Measured memory_bytes: 256
import itertools
import math

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

x.sort()

dis = []
for i in range(m-1):
    dis.append(x[i+1]-x[i])

dis.sort(reverse=True)
for i in range(min(n-1,len(dis))):
    dis[i] = 0

print(sum(dis))

Measured memory_bytes: 56872
#include <iostream>

using namespace std;

int main()
{
	unsigned long int a, b;
	
	cin >> a >> b;
	
	int count = 1;
	
	while (1){
		if (a <= b/2){
			count++;
			b /= 2;
		}
		else {
			cout << count << "\n";
			break;
		}
	}
	
	return (0);
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		StringBuilder str = new StringBuilder(sc.nextLine());
		for(int i=0; i < str.length() - 4; i++){
			String temp = str.substring(i, i+5);
			if("peach".equals(temp)){
				str.replace(i, i+5, "apple");
			}
			else if("apple".equals(temp)){
				str.replace(i, i+5, "peach");
			}
		}
		System.out.println(str.toString());

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

	}

}

Measured memory_bytes: 12000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
const long long mod = 1e9+7;

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

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

bool comp(const pair<int, ll>& p1, const pair<int, ll>& p2){
    return p1.second > p2.second;
}

void solve(){
    int x, a;
    cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = int;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main() {
	ll  n;cin >>n;
    ll x=0, y=0, p=0;
	for(int i = 0; i < n; ++i) {
      ll a, b, t;cin >> t>>a>> b;
      p=t-p;x=abs(a-x);y=abs(b-y);
      if(x+y>p || (x+y)%2 != p%2){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 500010
using namespace std;
ll n,k[N],l[N],r[N],ans;
vector<pair<ll,ll> > lf,rg;
priority_queue<ll> pq;
int main(){
	//freopen("b.in","r",stdin);
	//freopen("b.out","w",stdout);
	ll T,tp,i;
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld%",&n);
		lf.clear();
		rg.clear();
		ans=0;
		for(i=0;i<n;i++)
		{
			scanf("%lld%lld%lld",&k[i],&l[i],&r[i]);
			k[i]--;
			if(r[i]>=l[i])
			{
				rg.push_back(make_pair(k[i],l[i]-r[i]));
				ans+=r[i];
			}
			else
			{
				lf.push_back(make_pair(k[i],r[i]-l[i]));
				ans+=l[i];
			}
		}
		sort(lf.begin(),lf.end());
		sort(rg.begin(),rg.end());
		reverse(rg.begin(),rg.end());
		tp=0;
		while(!pq.empty())
		{
			pq.pop();
		}
		for(i=0;i<lf.size();i++)
		{
			pq.push(lf[i].S);
			if(tp>lf[i].F)
			{
				ans+=pq.top();
				pq.pop();
			}
			else
			{
				tp++;
			}
		}
		tp=n-1;
		while(!pq.empty())
		{
			pq.pop();
		}
		for(i=0;i<rg.size();i++)
		{
			pq.push(rg[i].S);
			if(tp<=rg[i].F)
			{
				ans+=pq.top();
				pq.pop();
			}
			else
			{
				tp--;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 12912
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const long long MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す//計算量は0(log(max(a,b))
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す//計算量は0(log(max(a,b))
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す//計算量は0(log(y))
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す//計算量は0(sqrt(a))
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N;
  string S;
  cin>>N;
  int b=N%1000;
  //cout<<b<<endl;
  int a=1000-b;
  if(a==1000){cout<<0<<endl;}
  else{cout<<a<<endl;}
}

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

int main(){
  int N,A;

  scanf("%d%d",&N,&A);
  while(1){
    if(N>=500)N-=500;
    else break;
  }
  if(N<=A) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n;
    cin >> n;
    lint ans = 1;
    const lint mod = 1e9 + 7;
    repeat_from_to(i, 1, n) {
        ans *= i;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
struct Point{double x,y;};
double dis(Point a,Point b){
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
Point tri(Point a, Point b, Point c){
  double a1,a2,b1,b2,c1,c2;
  a1=2*(b.x-a.x);
  b1=2*(b.y-a.y);
  c1=a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y;
  a2=2*(c.x-a.x);
  b2=2*(c.y-a.y);
  c2=a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y;
  Point p;
  p.x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
  p.y=(c1*a2-c2*a1)/(a1*b2-a2*b1);
  return p;
}
int main(){
  int n;
  cin >> n;
  int i;
  for(i=0;i<n;i++){
  Point a,b,c;
  cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
  Point x = tri(a,b,c);
  printf("%.3f %.3f %.3f\n",x.x,x.y,dis(x,a));
  }
  return 0;
}

Measured memory_bytes: 1244
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader r = new BufferedReader (new InputStreamReader (System.in));
		String s1 = r.readLine();
		long num = Long.valueOf(s1.split(" ")[0]);
		long count = Long.valueOf(s1.split(" ")[1]);
		double val = 0.0d;

		double kitei = ((double)1 / num);
		for (long i = 1; i <= num; i++) {
			if (i >= count) {
				val += kitei;
				continue;
			}
			
			double v = 1;
			long v2 = i;
			for (long j = 0; j < count; j++) {
				v2 = v2 * 2;
				v = v / 2;
				if (v2 >= count) {
					val += kitei * v;
					break;
				}
			}
		}
		
		System.out.println(val);
	}
}


Measured memory_bytes: 23124
import java.util.*;
import java.io.*;

class Counter<T> extends HashMap<T,Integer>{
    public Counter(){
        super();
    }
    public Integer get(Object elm){
        return getOrDefault(elm,0);
    }
    public void add(T elm, int amount){
        if(!this.containsKey(elm)) put(elm, amount);
        else replace(elm, get(elm)+amount);
    }
    public void addOne(T elm){
        add(elm, 1);
    }
    public void remove(T elm, int amount){
        replace(elm, Math.max(get(elm)-amount, 0));
    }
    public void removeOne(T elm){
        remove(elm, 1);
    }
}

public class Main {
    static void yes(){
        System.out.println("Yes");
        System.exit(0);
    }
    static void no(){
        System.out.println("No");
        System.exit(0);
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        Counter<Character> count = new Counter<>();
        for(int i=0; i<S.length(); i++) count.addOne(S.charAt(i));
        for(char c: count.keySet()) if(count.get(c)!=2) no();
        yes();
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
int isprime(int n)
{
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		    return 0;
	}
	return 1;
}
int main()
{
	int x;
	scanf("%d", &x);
	while(!isprime(x)) x++;
	printf("%d\n", x);
	return 0;
}

Measured memory_bytes: 128
/* ex9_1
   TakayukiY*/

#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 10

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        return '\0';
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

int main(void){
    char input[10+1],*ptr;
    stack stk;
    int i;
    //スタックを初期化（ポインタ渡しで関数にわたすこと）
    initialize_stack(&stk);

    scanf("%s",input);
    ptr=input;
    while(*ptr!='\0'){
        if(*ptr=='B') pop(&stk);
        else push(&stk,*ptr);
        ptr++;
    }

    for(i=stk.count-1;i>=0;i--){
        printf("%c",*(stk.top+i));
    }

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;

int main(){

    ll N, A, B;
    cin >> N >> A >> B;

    string s;
    cin >> s;

    ll a_num = 0;
    ll b_num = 0; 
    ll a_pass = 0;
    ll b_pass = 0; 

    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'a'){
            a_num ++;
            if(a_pass + b_pass < A + B){
                cout << "Yes" << endl;
                a_pass ++;
            } 
            else cout << "No" << endl; 
        }
        if(s[i] == 'b'){
            b_num ++;
            if(a_pass + b_pass < A + B && b_num <= B){
                cout << "Yes" << endl;
                b_pass ++;
            } 
            else cout << "No" << endl; 
        }
        if(s[i] == 'c'){
            cout << "No" << endl;
        }

    }


}

Measured memory_bytes: 896
N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)

Measured memory_bytes: 68260
N=int(input())
abc=[tuple(map(int,input().split())) for _ in range(N)]

dp = [[0]*3 for _ in range(N)]

for i in range(N):
  for j in range(3):
    if i == 0:
      dp[i][j] = abc[i][j]
      continue
    op1, op2 = [(1,2),(0,2),(0,1)][j]
    dp[i][j] = max(dp[i-1][op1], dp[i-1][op2])+abc[i][j]
    
print(max(dp[-1]))

Measured memory_bytes: 101516
/* ****revpro**** */
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define N  100005
vi a(N);
vector <pii> seg(4*N);
void build(ll cur,ll st,ll end)
{
    if(st==end)
    {
        seg[cur].F=a[st];
        seg[cur].S=st;
        return;
    }
    ll mid=(st+end)>>1;
    build((cur<<1),st,mid);
    build((cur<<1)+1,mid+1,end);
    if(seg[cur<<1].F<seg[cur<<1|1].F)
    	seg[cur]=seg[cur<<1];
    else if(seg[cur<<1].F>seg[cur<<1|1].F)
    	seg[cur]=seg[cur<<1|1];
    else {seg[cur]=seg[(cur<<1)];seg[cur].S=min(seg[cur<<1].S,seg[cur<<1|1].S);}//+seg[(cur<<1)+1];                   /* 1-change */
}
void update(ll cur,ll start,ll end,ll idx,ll val)
{
    if(start == end)
        seg[cur].F = min(val,seg[cur].F);
    else
    {
        ll mid = (start + end) >> 1;
        if(start <= idx and idx <= mid)
            update((cur<<1), start, mid, idx, val);
        else
            update((cur<<1)+1, mid+1, end, idx, val);
    if(seg[cur<<1].F<seg[cur<<1|1].F)
    	seg[cur]=seg[cur<<1];
    else if(seg[cur<<1].F>seg[cur<<1|1].F)
    	seg[cur]=seg[cur<<1|1];
    else {seg[cur]=seg[(cur<<1)];seg[cur].S=min(seg[cur<<1].S,seg[cur<<1|1].S);}
    }
}
pii query(ll cur,ll st,ll end,ll l,ll r)
{
    if(st>end||st>r||end<l) return {hell,-1};
    if(st>=l&&end<=r) return seg[cur];
    ll mid=(st+end)>>1;
    pii ans;
    pii ans1=query((cur<<1),st,mid,l,r);
    pii ans2=query((cur<<1)+1,mid+1,end,l,r);
    if(ans1.F<ans2.F)
    	ans=ans1;
    else if(ans1.F>ans2.F)
		ans=ans2;
    else {ans=ans1;ans.S=min(ans1.S,ans2.S);}
    return ans;
   	            /* 14-change */
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n,m;
		string s;
		cin>>n>>m>>s;
		a[0]=0;
		ll idx[n+1];
		idx[0]=-1;
		rep(i,1,n+1) a[i]=hell;
		build(1,0,n);
		rep(i,1,n+1){
			if(s[i]=='0'){
				pii p=query(1,0,n,i-m,i-1);
				idx[i]=p.S;
				update(1,0,n,i,p.F+1);
			}
		}
		ll cur=n;
		if(query(1,0,n,n,n).F>=hell) {
			cout<<-1;
			return 0;
		}
		vi v;
		while(cur!=0){
			v.pb(cur-idx[cur]);
			cur=idx[cur];
		}
		reverse(all(v));
		for(auto i:v) cout<<i<<' ';
	}
	return 0;
}									

Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, m, y[111111], p[111111];
    vector<int> c[111111];
    cin>>n>>m;
    rep(i, m) {
        cin>>p[i]>>y[i];
        p[i]--;
        c[p[i]].push_back(y[i]);
    }
    rep(i, n) sort(all(c[i]));
    rep(i, m) printf("%012lld\n", (p[i] + 1) * 1000000 + (int)(lower_bound(all(c[p[i]]) , y[i]) - c[p[i]].begin()) + 1);
}


Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[100005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint lb = 2, ub = 2;
	for(int i = n; i >= 1; i--){
		lb = (lb+a[i]-1)/a[i]*a[i];
		ub = ub/a[i]*a[i];
		if(lb > ub){
			cout << -1 << endl;
			return 0;
		}
		ub += a[i]-1;
	}
	cout <<lb << " " << ub << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {

ll K; cin>>K;

ll x=100;
ll ans=0;

while(1){
  x+=x/100; ans++;
  if(x>=K) break;
}
cout <<ans << endl;


return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
lli mod = 1e9 +7;
lli ExGCD(lli a, lli b, lli &x, lli &y){
	lli d=a;
	x=1; y=0;
	if(b!=0){ d=ExGCD(b, a%b, y, x); y-=a/b*x; }
	return d;
}
lli inverse(lli a){
	lli x,y;
	ExGCD(a, mod, x, y);
	return x>0? x: mod+x;
}

lli fact[300001];
lli inv[300001];
void maketable(){
	fact[0] = 1;
	for(int i=0; i<300000; i++){
		fact[i+1] = fact[i]*(i+1) %mod;
	}
	lli y;
	for(int i=0; i<300000; i++){
		ExGCD(fact[i], mod, inv[i], y);
		while(inv[i]<0) inv[i]+=mod;
	}
}

int main(){
	maketable();
	int n;
	cin >> n;
	vector<lli> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}

	vector<lli> w(n);
	w[0] = 0;
	for(int i=0; i<n-1; i++){
		w[i+1] = a[i+1] -a[i];
	}
	for(int i=0; i<n-1; i++){
		w[i+1] += w[i];
	}
	lli ans = 0;
	lli cost = 0;
	int r=n-2, l=0;
	for(int i=0; i<n-2; i++){
		cost += w[r] -w[l] +mod;
		cost %= mod;
		lli prob = fact[i] *inv[i+2] %mod;
		ans += cost *prob %mod;
		ans %= mod;
		l++; r--;
	}
	for(int i=0; i<n-1; i++){
		lli cost = w[n-1] -w[i];
		cost %= mod;
		lli prob = fact[n-2-i] *inv[n-1-i] %mod;
		ans += cost *prob %mod;
		ans %= mod;
	}
	ans = ans *fact[n-1] %mod;
	cout << ans << endl;
	return 0;
}

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

int main ()
{
    int n, a, cnt = 0;
    cin >> n;
    while(n--)
    {
        cin >> a;
        int i = 2, rang = sqrt(a);
        while((a % i != 0) && (i <= rang)) i++;
        if (i > rang) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3112
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
//入力
template<typename T> T input() {T x; cin >> x; return x;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//余り切り上げ
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
//最大値・最小値
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b) {a = b; return true;} return false;}
//最大公約数
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
//最小公倍数
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//n乗の余り
ll modpow(ll x,ll n,ll mod){ll res=1;for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
ll MODpow(ll x,ll n){ll res=1;for(ll i=0;i<n;i++){res=res*x%MOD;}return res;}


/*--------------------------------------------------------------------------*/

//main関数
int main() {
    ll q,w,e; cin >> q >> w >> e;
    Yes(!((q == w && w == e)||(q != w && w != e && e != q)));
}



Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

struct edge {
    int to, cost;
};

int n;
vector<vector<edge>> g;
vector<int> color;

void dfs(int v, int p, int c) {
    color[v] = c;
    for(const auto &e : g[v]) {
        if(e.to != p) {
            dfs(e.to, v, (e.cost & 1) ? 1 - c : c);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    g.resize(n);
    color.resize(n, -1);
    for(int i = 0; i < n - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        g[--a].push_back(edge{--b, c});
        g[b].push_back(edge{a, c});
    }
    dfs(0, -1, 0);
    for(int i = 0; i < n; i++) {
        print(color[i]);
    }
}

Measured memory_bytes: 8960
#include<iostream>
using namespace std;
int main(){
	int a[5],i,flg,j;
	while(1){
		int g=0,t=0,p=0;
		int mflg,kflg;
		int aaflg;
		flg=0;
		for(i=0;i<5;i++){
			cin>>a[i];
			if(a[i]==0) break;
			if(a[i]==1) g=1;
			else if(a[i]==2) t=1;
			else p=1;
		}
		if(a[0]==0) break;
		aaflg=0;
		for(i=1;i<5;i++) {
			if(a[0]!=a[i]) aaflg=1;
		}
		if(g==1 && t==1 && p==1 || aaflg==0) {
			for(i=0;i<5;i++) cout<<"3"<<endl;
		}
		else {
			for(i=0;i<5;i++){
				mflg=0;
				kflg=0;
				for(j=0;j<5;j++){
					if(a[i]==a[j]) ;
					else if(a[i]==1 && a[j]==3 || a[i]==2 && a[j]==1 || a[i]==3 && a[j]==2) mflg=1;
					else kflg=1;
				}
				if(mflg==1) cout<<"2"<<endl;
				else cout<<"1"<<endl;
			}
		}
	}	
	return 0;
}

Measured memory_bytes: 3036
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };




/******************************************************************************************/

int main(){

	int n;
	cin >> n;
	vector<int> b;
	b.push_back(1e9);

	for (int i = 0; i < n-1; i++)
	{
		int c;
		cin >> c;
		b.push_back(c);
	}
	b.push_back(1e9);

	vector<int> a(n);

	for (int i = 0; i < n; i++)
	{
		a[i] = min(b[i], b[i + 1]);
	}

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		ans += a[i];
	}
	cout << ans << endl;
	




	return 0;
}


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

int up(const void *a , const void *b){
  return *(int *)a - *(int *)b;
}

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

  int  a[n];
  for(int i = 0;i < n;i ++){
    scanf("%d",&a[i]);
  }

  qsort(a,n,sizeof(int),up);
  int flag = 0;
  for(int i = 0;i < n - 1;i ++){
    if(a[i] == a[i + 1]){
      flag = 1;
      i += n;
    }
  }
  if(flag == 0){
  printf("YES\n");
  }
  else{
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1777777777;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int A, B; cin >> A >> B;
  if(A<10 and B<10) cout << A*B << endl;
  else cout << -1 << endl;
}

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

int main (){
  string array,ans;
  int m,h;
  while(true){
    cin >> array;
    if(array == "-") break;
    cin >> m;
    for(int i = 0; i < m; i++){
      cin >> h;
      ans = array.substr(h) + array.substr(0,h);
      //cout << "ans: " << ans << endl;
      array = ans;
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define MOD 998244353

struct SegTree {
	std::vector<int> data;
	int n;
	SegTree(int n_) {
		for (n = 1; n < n_; n *= 2);
		data.resize(2 * n);
	}
	void add(int i, int val) {
		for (i += n; i; i >>= 1) data[i] += val;
	}
	int sum(int l, int r) {
		int res = 0;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (r & 1) r--, res += data[r];
			if (l & 1) res += data[l], l++;
		}
		return res;
	}
};

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

struct Point {
	int x;
	int y;
	int id;
	int y_comped;
};

int main() {
	int n = ri();
	Point a[n];
	for (int i = 0; i < n; i++) a[i].x = ri(), a[i].y = ri(), a[i].id = i;
	
	int b2[n + 3];
	b2[0] = 1;
	for (int i = 1; i <= n + 2; i++) {
		b2[i] = b2[i - 1] + b2[i - 1];
		if (b2[i] >= MOD) b2[i] -= MOD;
	}
	
	std::sort(a, a + n, [](const Point &a, const Point &b) { return a.y < b.y; });
	int cnt = 0;
	for (auto &i : a) i.y_comped = cnt++;
	std::sort(a, a + n, [](const Point &a, const Point &b) { return a.x < b.x; });
	
	SegTree tree(cnt);
	
	uint64_t res = 0;
	for (int i = 0; i < n; i++) {
		int v = tree.sum(0, a[i].y_comped);
		res += b2[v];
		res += b2[i - v];
		res += b2[a[i].y_comped - v];
		res += b2[n - a[i].y_comped - 1 - i + v];
		
		tree.add(a[i].y_comped, 1);
	}
	res += (uint64_t) (b2[n] - 1) * n;
	res -= b2[n + 2] - 4;
	std::cout << res % MOD << std::endl;
	
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;

    int C[10][10];
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            cin >> C[i][j];
        }
    }

    int A[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> A[i][j];
        }
    }

    for(int k=0; k<10; k++){
        for(int i=0; i<10; i++){
            for(int j=0; j<10; j++){
                C[i][j] = min(C[i][j], C[i][k]+C[k][j]);
            }
        }
    }

    int ans = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(A[i][j] == -1) continue;
            if(A[i][j] == 1) continue;
            ans += C[A[i][j]][1];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int h = sc.nextInt();
    int a = sc.nextInt();
    
    int result = h / a;
    if (h%a>0) {
      result ++;
    }
    
    System.out.println(result);
    
  }
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

struct Sieve {
  vector<bool> isprime;
  vector<int> pcount;

  void init(size_t max){
    if(max+1 > isprime.size()){     // resizeで要素数が減らないように
        isprime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    }
    isprime[0] = false; // 0は素数ではない
    isprime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
      if(isprime[i]) // iが素数ならば
        for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
          isprime[i*j] = false;      // 素数ではない
  }

  void count(int max) {
    pcount.resize(max);
    pcount[0] = 0;
    FOR(i, 1, max) {
      pcount[i] = pcount[i-1] + isprime[i];
    }
  }
};


int main () {
  cin.tie(0);
  cout << setprecision(10);

  Sieve s;
  s.init(123457 * 2);
  s.count(123457 * 2);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    cout << s.pcount[2*n] - s.pcount[n] << endl;
  }
}



Measured memory_bytes: 3708
import bisect


I = lambda: map(int, input().split())
N = int(input())
A = list(I())
B = list(I())
C = list(I())
B.sort()
C.sort()

s = [0] * (N + 1)
for i, bi in enumerate(B):
    s[i + 1] = s[i] + N - bisect.bisect_right(C, bi)

print(sum(s[N] - s[bisect.bisect_right(B, ai)] for ai in A))

Measured memory_bytes: 23360