akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

using PII = pair<ll, int>;
const int N = 200 * 1000 + 5;
vector <pair<int, int>> v[N];
void dijkstra(int s, vector<ll> &cnt, vector <ll> &dist) {
	set<PII> st;
	st.insert({0, s});
	cnt[s] = 1;
	dist[s] = 0;
	while(!st.empty()) {
		int x = (st.begin())->ss;
		st.erase(st.begin());
		for (auto g : v[x]) {
			if(dist[g.ff] > dist[x] + g.ss) {
				st.erase({dist[g.ff], g.ff});
				dist[g.ff] = dist[x] + g.ss;
				st.insert({dist[g.ff], g.ff});
				cnt[g.ff] = 0;
			}
			if(dist[g.ff] == dist[x] + g.ss) {
				cnt[g.ff] = (cnt[g.ff] + cnt[x]) % MOD;
			}
		}
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	int S, T;
	cin >> S >> T;
	vector <tuple<int, int, int>> ed;
	for (int i = 0; i < m; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		v[x].push_back({y, w});
		v[y].push_back({x, w});
		ed.push_back(make_tuple(x, y, w));
		ed.push_back(make_tuple(y, x, w));
	}
	
	vector <ll> cs(n + 1, 0);
	vector <ll> ds(n + 1, INF);
	dijkstra(S, cs, ds);
	
	vector <ll> ct(n + 1, 0);
	vector <ll> dt(n + 1, INF);
	dijkstra(T, ct, dt);
	
	ll mn = ds[T];
	ll total = (cs[T] * cs[T]) % MOD;
	for (int i = 1; i <= n; i++) {
		if(2 * ds[i] == mn && 2 * dt[i] == mn) {
			ll go = (cs[i] * ct[i]) % MOD;
			total -= (go * go) % MOD;
			total = (total + MOD) % MOD;
		} 
	}
	for (int i = 0; i < 2 * m; i++) {
		int x, y, w;
		tie(x, y, w) = ed[i];
		if(ds[x] + w + dt[y] == mn) {
			if(2 * ds[x] < mn && 2 * dt[y] < mn) {
				ll go = (cs[x] * ct[y]) % MOD;
				total -= (go * go) % MOD;
				total = (total + MOD) % MOD;
			}
		}
	}
	cout << total;
}


Measured memory_bytes: 24748
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a==1 && b==2)
        {
            System.out.println(3);
        }
        if(a==2 && b==3)
        {
            System.out.println(1);
        }
        if(a==3 && b==1)
        {
            System.out.println(2);
        }
        if(a==3 && b==2)
        {
            System.out.println(1);
        }
        if(a==1 && b==3)
        {
            System.out.println(2);
        }
        if(a==2 && b==1)
        {
            System.out.println(3);
        }
    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 1000000

//prototype
void enqueue(char*, int);
struct Queue dequeue();
int isEmpty();
int isFull();

//Structure
struct Queue{
  char name[10];
  int time; //time:??????????????????, sum_time:?????????????????????(??????)
};

//global variables
struct Queue Q[MAX];
int head=0,tail=0;

/* the method of enqueue */
void enqueue(char *name, int time){ //java??????????????????????????§?????°?????¨?????????????????????????????????????????????????????????????????????????????????????????´??§?????´????????????????????????

  //???????´??????£??\
  strcpy(Q[tail].name, name);
  Q[tail].time = time;

  if(tail + 1 == MAX){
    tail = 0; //?????°
  }else{
    tail++;
  }
}

/* the method of dequeue */
struct Queue dequeue(){
  struct Queue x;

  x = Q[head];
  if(head + 1 == MAX){ //?¬????????´???´????????¢????????´????????????????????????
    head = 0;
  }else{
    head++;
  }

//  printf("dequeue: %s %d\n",x.name, x.time); //@@

  return x;
}

 /**
  * Judge the queue is if Empty or not 
  * 1: is Empty
  * 0: is not Empty
  */
int isEmpty(){
  if(head==tail){
//    printf("Error: Underflow\n");
    return 1;
  }else{
    return 0;
  }
}

 /**
  * Judge the queue is if Full or not 
  * 1: is Full
  * 0: is not Full
  */
int isFull(){
  if(head == (tail+1)%MAX){ //%MAX??????????????¨???head==0, tail==MAX-1?????????head==tail+1??§Full??¨??????????????????
//    printf("Error: Overflow\n");
    return 1;
  }else{
    return 0;
  }
}

//MAIN
int main(){
  int i,n,q_orig,q,time,sum_time=0;
  char name[10];
  struct Queue x; // dequeue()???????????????????´?

  //input default data(the number of elements & quantum time)
  scanf("%d%d",&n,&q_orig);

  //???????????\???&????´? completing Q[]
  for(i=0;i<n;i++){
    scanf("%s %d", name, &time);
    if(isFull()){ //full??????exit()
      exit(1);
    }else{
      enqueue(name, time);
    }
  }

  q = q_orig; //?????????????????????????????\???????????????
  while(!isEmpty()){ //Q[]???????´????????????????
//    printf("q: %d\nsum_time: %d\n",q,sum_time); //@@
    x = dequeue();
//    printf("time %d\n",x.time); //@@
    if(x.time<=q){ //????????????????????§??????
//      printf("enter <=q\n"); //@@
//      if(q==x.time){ //???????????????????????£???????????´??????????????????????¬????????´?????????????????????????????????????
//        q = q;
//      }else{
//        q -= x.time;
//      }
      q = q_orig;
      sum_time += x.time; //??????????????????????????????
      printf("%s %d\n",x.name, sum_time);
    }else{
//      printf("enter >q\n"); //@@
      sum_time += q; //??????????????????????????????
      x.time -= q; //???????????????????????????
//      printf("x_name: %s x_time: %d\n",x.name, x.time); //@@
      enqueue(x.name, x.time); //???????????¨Q[]??????????????????????????????
      q = q_orig; //?????????????????????
    }
  }

  return 0;
}

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

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];

    ll ans = 0;
    for (int i = 1; i < n; i++) {
        int diff = max(a[i - 1] - a[i], 0ll);
        ans += diff;
        a[i] += diff;
    }

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


Measured memory_bytes: 5180
#include <stdio.h>

#define MAX_H 251

int parent(int );
int left(int );
int right(int );


int main(){
  int H=0;
  int A[MAX_H];
  int i=0;

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)!=0)printf("parent key = %d, ",A[i/2]);
    if(left(i)<=H)printf("left key = %d, ",A[2*i]);
    if(right(i)<=H)printf("right key = %d, ",A[2*i+1]);
    printf("\n");
  }

  return 0;
}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}



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

int main() {
	string s;
	cin >> s;

	int cnt = 0;
	for (int i = 0; i < 4-1; i++) {
		for (int j = i+1; j < 4; j++) {
			if (s.at(i) == s.at(j)) {
				cnt++;
			}
		}
	}
	string ans = "No";
	if (cnt == 2) {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int N;
	string S;
	cin >> N >> S;
	bool X[26],Y[26];
	int ret = 0;

	REP(i,S.length()-1){
		REP(j,26){
			X[j]=false;
			Y[j]=false;
		}
		REP(j,S.length()){
			if(j <= i){
				X[S[j]-'a']=true;
			}else{
				Y[S[j]-'a']=true;
			}
		}
		int cnt = 0;
		REP(j,26){
			if(X[j] && Y[j]) cnt++;
		}
		ret = max(ret,cnt);
	}

	println(ret);
	return 0;
}


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

int a,b,a1,b1,k;
int main(){

    cin>>a>>b>>a1>>b1>>k;
    int h=(a1-a)*60+b1-b-k;
    cout<<h;
    return 0;

}




Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#define SQR(x) ((x)*(x))
 
int cmp(const void *a,const void *b){
    return *(double *)a-*(double *)b;
}
 
int main(void){
    int n,r,i;
    double c[3];
    for(i=0;i<3;i++){
      scanf("%lf",&c[i]);
    }
    if(!(c[0]+c[1]+c[2]))
      return 0;
    qsort(c,3,sizeof(double),cmp);
    scanf("%d",&n);
    while(n--){
      scanf("%d",&r);
      if(SQR(r)>SQR(c[0]/2)+SQR(c[1]/2))puts("OK");
      else puts("NA");
    }
    main();
    return 0;
}

Measured memory_bytes: 616
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void insert(int);
struct node{
  int key;
  struct node *p;
  struct node *right;
  struct node *left;
};
struct node *Node,*NIL;


void insert(int a){
   struct node *y=NIL;
   struct node *x=Node;
   struct node *z;
   z = malloc(sizeof(struct node));
    z->key=a;
    z->left=NIL;
    z->right=NIL;
    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    z->p=y;
    if(y == NIL){
        Node=z;
    }else{
        if(z->key < y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}
void pre(struct node *a){
  if(a==NIL)return;
  printf(" %d",a->key);
  pre(a->left);
  pre(a->right);
}
void in(struct node *a){
  if(a==NIL)return;
  in(a->left);
  printf(" %d",a->key);
  in(a->right);
}
struct node *find(struct node* a,int b){
  while(a!=NIL&&b!=a->key){
    if(b<a->key){
      a=a->left;
    }else{
      a=a->right;
    }
  }
    return a;
}
int main(){
  int i,j,n;
  char M[10];
  struct node *a;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",M);
    if(strcmp(M,"insert")==0){
    scanf("%d",&j);
    insert(j);
    }else if(strcmp(M,"print")==0){
      in(Node);
      printf("\n");
      pre(Node);
      printf("\n");
    }else if(strcmp(M,"find")==0){
      scanf("%d",&j);
      a=find(Node,j);
      if(a!=NIL){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
  return 0;
  
}



Measured memory_bytes: 20512
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;
ll c[10]={1,11,112,1124,11248,112496,1124992,11249984,112499968,1124999936};
unsigned long long ans;
string s;

int main() {
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        ans += (c[s.size() - 1 - i] * (s[i] - '0') * (1 << i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using ll = long long;
using ld = long double;
using Pa = std::pair<ll, ll>;
using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n,ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow(((x * x)%mod), n / 2,mod));
	else
		return ((x%mod) * pow(x, n - 1,mod));
}
bool prime(int n) {
	int i = 2;
	if (n == 2)return true;
	else if(n <= 1)return false;
	if (n % i == 0)return false;
	i = 3;
	while (i <= sqrt(n)) {
		if (n % i == 0)return false;
		i += 2;
	}
	return true;
}
ll mod = 998244353;
int main() {
	ll a, b,c; cin >> a >> b>>c;
	cout << c * ((a - 1 + b) / b) << endl;
}

Measured memory_bytes: 3648
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    println!("{}", n * ((n % 2) + 1));
}


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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int N=2e6+100,MOD=1e9+7;

int f[N+1],r[N+1],p25[N+1],p26[N+1];

int ppow(int x,int y)
{
    int res=1;
    while(y)
    {
        if(y&1)
            res=res*x%MOD;
        y>>=1;
        x=x*x%MOD;
    }
    return res;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    f[0]=1;
    for(int i=1;i<=N;i++)
        f[i]=f[i-1]*i%MOD;
    r[N]=ppow(f[N],MOD-2);
    for(int i=N-1;i>=0;i--)
        r[i]=r[i+1]*(i+1)%MOD;
    p25[0]=1;
    for(int i=1;i<=N;i++)
        p25[i]=p25[i-1]*25%MOD;
    p26[0]=1;
    for(int i=1;i<=N;i++)
        p26[i]=p26[i-1]*26%MOD;

    int k;
    string s;
    cin>>k>>s;
    int n=s.size();
    int ans=0;
    for(int i=n;i<=n+k;i++)
        ans=(ans+f[i-1]*r[n-1]%MOD*r[i-n]%MOD*p25[i-n]%MOD*p26[n+k-i])%MOD;
    cout<<ans;
}


Measured memory_bytes: 66772
#include <iostream>
#include <string>

using namespace std;

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

    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i >= k && t[i] == t[i-k]) {
            t[i] = '#';
        } else {
            ans += t[i] == 'r' ? p : t[i] == 's' ? r : s;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
d = lr()
m = ir()
t = lr()
dic = collections.Counter(d)
flag = True
for num in t:
    if num in dic:
        if dic[num] == 0:
            flag = False
            break
        else:
            dic[num]-=1
    else:
        flag = False
        break
if flag:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 142764
Q, H, S, D = list(map(int, input().split()))
N = int(input())
res = 0
if N >= 2:
    res += min(D, S * 2, H * 4, Q * 8) * (N // 2)
    N %= 2
if N >= 1:
    res += min(S, H * 2, Q * 4)
print(res)


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            int bias = 0;
            List<long> A = Console.ReadLine()
                              .Split()
                              .Select(i => {
                                  bias++;
                                  return long.Parse(i) - bias;
                              })
                              .ToList();
            A.Sort();
            int middle = (int)(N - 1) / 2;
            long b = (N % 2 == 0) ? (A[middle] + A[middle + 1]) / 2 : A[middle]; 
            long ans = A.Select(i => Math.Abs(i - b)).Sum();
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 30340
from collections import deque
N,M=map(int,input().split())
tree=[[] for _ in range(N+M)]

for i in range(N):
    l=list(map(int,input().split()))
    K=l[0]
    n=len(l)
    for j in range(1,n):
        tree[i].append(l[j]+N-1)
        tree[l[j]+N-1].append(i)
#print(tree)

d=deque()
seen=[0]*(N+M)
d.append(0)
while len(d)>0:
    v=d.popleft()
    seen[v]=1
    for i in tree[v]:
        if seen[i]==0:
            d.append(i)
#print(seen)
#print(seen[:N])
if sum(seen[:N])==N:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 72756
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int y = 700;
        if (s.charAt(0) == 'o') y += 100;
        if (s.charAt(1) == 'o') y += 100;
        if (s.charAt(2) == 'o') y += 100;
        System.out.println(y);
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  string X;
  cin>>X;
 
  while(1){
    n=X.length();
    for(int i=0;i<X.length();i++){
      if(X[i]=='S'&&X[i+1]=='T'){
	for(int j=0;j<X.length();j++){
	  if(X[i-j]=='S'&&X[i+1-j]=='T'){
	    X.erase(X.begin()+i-j,X.begin()+i+2-j);
	  }else{
	    break;
	  }
	}
      }
    }
    if(n==X.length())break;
  }
  
  cout<<X.length()<<endl;
 
  return 0;
}


Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
const ll mod=1e9+7;
ll f[N],n,m,a,b;
ll powmod(ll x,ll n)
{
	ll s=1;
	while(n)
	{
		if(n&1)
			s=(s*x)%mod;
		x=(x*x)%mod;
		n>>=1;
	}
	return s;
}
ll C(ll n,ll m)
{
	ll a=f[n],b=(f[m]*f[n-m])%mod;
	return (a*powmod(b,mod-2))%mod;
}
int main()
{
	f[0]=1;
	for(int i=1;i<N;i++)
		f[i]=(f[i-1]*i)%mod;
	while(cin>>n>>m>>a>>b)
	{
		ll ans=0;
		for(int i=b+1;i<=m;i++)
		{
			int tem=(C(i-1+n-a-1,n-a-1)*C(m-i+a-1,a-1))%mod;
			ans=(ans+tem)%mod;	
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> a,b,c;
typedef long long ll;
void input(vector <int>& v){
    for(int i = 0;i<n;i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    return ;
}
bool compare1(int a,int b){
    return a > b;
}
int main(){
    cin >> n;
    ll res = 0;
    input(a);
    input(b);
    input(c);
    sort(a.begin(),a.end(),compare1);
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    for(int i = 0;i<n;i++){
        ll res1 = 0,res2 = 0;
        int index2 = upper_bound(c.begin(),c.end(),b[i]) - c.begin();
        if(index2 != n) res1 = (n - index2);
        int index1 = upper_bound(a.begin(),a.end(),b[i],compare1) - a.begin();
        if(index1 != n) res2 = (n - index1);
        res += res1 * res2;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4624
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,k;
  cin>>n>>k;
  vector<int>a(n);
  for(int i;i<n;i++){
    cin>>a.at(i);
  }
  if(((n-1)%(k-1))==0){
    cout<<(n-1)/(k-1)<<endl;
  }
  else{
    cout<<(n-1)/(k-1)+1<<endl;
  }

}

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

int i, n, x, cnt1, cnt0;

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

  cin >> n;
  for(i = 1; i <= n; ++i) {
    cin >> x;
    if(x & 1) ++cnt1;
    else ++cnt0;
  }

  if(cnt1 & 1) cout << "NO\n";
  else cout << "YES\n"; 

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
  int x,a,b;
  cin >> x >> a >> b;

  cout << (x-a)%b << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        if(A==B && A==C && B==C){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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


int main() {
  bool prim[100010];
  for(int i=0;i<100010;i++){
    prim[i]=true;//primeを全てtrueにする
  }

  prim[1]=false;//prime[1]だけはfalseにする
 for(int i=2;i<100010;i++){
   if(prim[i]){
     int b=i*2;
     while(b<=100010){
       prim[b]=false;//iが素数なら、その2倍の数はfalseにする。
       b+=i;    //bにiを足してb=3*iにする。以降100010までbをiの倍数にしてfalse
     }
   }
 }
int a[100010];
 for(int i=1;i<100010;i++){
   if(prim[i]&&prim[(i+1)/2]){
     a[i]=1;
   }
   else{
     a[i]=0;
   }
 }
int sum[100010];sum[1]=0;
 for(int i=2;i<100010;i++){
   sum[i]=sum[i-1]+a[i-1];
 }
 int Q;
 cin >> Q;
 int l[Q],r[Q],ans[Q];

 for(int i=0;i<Q;i++){
   cin >> l[i] >>r[i];
   ans[i]=sum[r[i]+1]-sum[l[i]];
 }

 for(int i=0;i<Q;i++){
   cout << ans[i] << endl;
 }
// thank you kkktym
}

Measured memory_bytes: 2688
A,B = map(int,input().split())
MAX = 100
ans = []
for i in range(MAX): #下地として上半分は白、下半分は黒。
  if i < MAX//2:
    temp = ["."]*MAX
  else:
    temp = ["#"]*MAX
  ans.append(temp)
#print(ans)
A-=1;B-=1
h = 0; w = 0
for j in range(B): #上半分に黒を置く。
  ans[h][w] = "#"
  w += 2
  if w > MAX-1:
    h += 2
    w = 0

#print(ans)
h = MAX//2+1; w = 0
for j in range(A):
  ans[h][w] = "."
  w += 2
  if w > MAX-1:
    h += 2
    w = 0
L = [MAX,MAX]
print(*L)
for i in range(MAX):
  output = "".join(ans[i])
  print(output)
  

Measured memory_bytes: 9240
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int n, m, k, s, p;
	cin >> n >> m;
	vector<vector<int> > wiring(m, vector<int>(n, 0));

	for (int i = 0; i < m; ++i) {
		cin >> k;
		for (int j = 0; j < k; ++j) {
			cin >> s;
			--s;
			wiring[i][s] = 1;
		}
	}
	vector<int> P(m);
	for (int i = 0; i < m; ++i) cin >> P[i];

	int res = 0;
	for (int bit = 0; bit < (1 << n); ++bit) {
		vector<int> switches(n, 0);
		for (int i = 0; i < n; ++i) {
			if (bit & (1 << i)) {
				switches[i] = 1;
			}
		}
		bool ok = true;
		for (int i = 0; i < m; ++i) {
			int cnt = 0;
			for (int j = 0; j < n; ++j) {
				if (wiring[i][j] == 1 && switches[j] == 1)
					++cnt;
			}
			if (cnt % 2 != P[i])
				ok = false;
		}
		if (ok) ++res;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()

    y, m, d = S.split('/')
    n = int(y + m + d)

    if n <= 20190430:
        print('Heisei')
    else:
        print('TBD')

if __name__ == '__main__':
    resolve()


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

using namespace std;
using LLONG = long long;

int main()
{
    int A, B;
    char op;
    cin >> A >> op >> B;
    if (op == '+')
    {
        cout << A + B << endl;
    }
    else
    {
        cout << A - B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

y,m,d = list(map(int, stdin.readline().split('/')))

a = True
if y>2019:
  a = False
elif y==2019:
  if m>4:
    a = False
  elif m==4:
    if d > 30:
      a = False

print("Heisei" if a else "TBD")

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

int main() {
	int n, m;
	while(cin >> m >> n, m || n) {
		vector<int> nex;
		nex.resize(m);
		for(int i = 0; i < m; i++) nex[i] = 0;
		int p = 0;
		int cnt = m;
		for(int t = 1; t <= n; t++) {
			string str;
			cin >> str;
			if(cnt == 1) continue;
			bool flg = false;
			int num = 0;
			flg = (str == "Fizz") || (str == "Buzz") || (str == "FizzBuzz");
			if(!flg) {
				flg = true;
				for(int i = 0; i < str.size(); i++) {
					num *= 10;
					num += str[i] - '0';
					flg &= '0' <= str[i] && str[i] <= '9';
				}
			}
			if(flg) {
				if(t%15==0)
					flg = str == "FizzBuzz";
				else if(t%3==0)
					flg = str == "Fizz";
				else if(t%5==0)
					flg = str == "Buzz";
				else
					flg = num == t;
			}
			if(!flg) {
				nex[p] = -1;
				cnt--;
			}
			for(int i = 1; i < m; i++) {
				if(nex[(p+i)%m]+1) {
					p = (p+i)%m;
					break;
				}
			}
		}

		bool f = false;
		for(int i = 0; i < nex.size(); i++) {
			if(nex[i]+1) {
				if(f) cout << " ";
				f = true;
				cout << i+1;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
  cin >> N;
  vector<int> d(20);
  int M;
  M=N;
  for (int i=0; i<20; i++){
  	d.at(i)=M%10;
    M =M/10;
  }
  int sum=0;
  for (int i=0; i<20; i++){
  	sum += d.at(i);
  }
  if (N%sum==0){
    cout << "Yes" << endl;
  } else{
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 256
N = int(input())
lst = []
for i in range(N):
    a = int(input())
    xy = [[int(x) for x in input().split()] for _ in range(a)]
    lst.append(xy)
ans = 0
for i in range(1, 2**N):
    f = 1
    tmp = [i >> j & 1 for j in range(N)]
    cnt = sum(tmp)
    for i, yi in enumerate(tmp):
        if (yi == 0): continue
        if any([tmp[x-1] != y for x, y in lst[i]]):
            f = 0
            break
    if (f): ans = max(cnt, ans)
print(ans)


Measured memory_bytes: 50648
M = 1000000007

def main():
    n, m = map(int,input().split())
    print(solve(n, m))

def solve(n, m):
    d = abs(n-m)

    if d > 1:
        return 0
    elif d == 1:
        return fact(n) * fact(m) % M
    else:
        return fact(n) * fact(m) * 2 % M

def fact(n):
    s = 1
    for i in range(2, n+1):
        s = (s * i) % M
    return s

main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define input for(int i = 0; i < n; ++i) cin >> a[i]
#define output for(int i = 0; i < n; ++i) cout << a[i] << " "
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pll pair<long long ,long long >
#define ppll pair < pll , pll >
int main(){
    SPEED;
    int n;
    cin >> n;
    int a[n];
    input;
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);
    for(int i = 2; i < n; ++i){
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    } 
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

string S;
int ans = 0;

int main(){
	
	cin>>S;
	
	REP( i, S.size()-1 ){
		if( S[i] == 'A' && S[i+1] == 'C' ) ans = 1;
	}
	
	if( ans ) puts("Yes");
	else{     puts("No");}
	
	return 0;

}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
   int sum=0;
   sum+=sc.nextInt();
   sum+=sc.nextInt()*5;
   sum+=sc.nextInt()*10;
   sum+=sc.nextInt()*50;
   sum+=sc.nextInt()*100;
   sum+=sc.nextInt()*500;
   if(sum>=1000)System.out.println(1);
   else System.out.println(0);
		  
         }
  }

Measured memory_bytes: 17356
/*
 * chain_matrix.cpp
 *
 *  Created on: 2017/07/11
 *      Author: LitMc
 */

//#define MYDEBUG
#include <bits/stdc++.h>

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
#define EPS = 1e-14;
using std::vector;
using std::cout;
using std::cin;
using std::endl;
using std::max;
using std::min;
using std::swap;
using std::string;
using std::fill;
using std::pair;
using std::sort;
using std::reverse;
using std::pair;
using std::greater;
using std::priority_queue;
using std::ostream;

template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i] << endl;
  }
  return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last) {
      out << ",";
    }
  }
  out << "]";
  return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

typedef pair<int, int> P;
bool cmp(const P &p1, const P &p2) {
  if (p1.first == p2.first) {
    return p1.second > p2.second;
  } else {
    return p1.first < p2.first;
  }
}
typedef pair<int, int> P;
static const int MAX_N = 110;
static const int INF = 100000000;
int n, r, c;
P M[MAX_N];
int dp[MAX_N][MAX_N];

//dp[i][j]: M[i]??????M[j]?????§??????????????????????°??????°
//dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + prod)
//k = [i, j)
//prod = M[i].row * M[k].col * M[j].col

void solve() {
  cin >> n;
  rep(i,0,n)
  {
    cin >> M[i].first >> M[i].second;
    dp[i][i] = 0;
  }
  for (int i = 0; i + 1 < n; ++i) {
    dp[i][i + 1] = M[i].first * M[i].second * M[i + 1].second;
    dbp4(i, M[i], M[i + 1], dp[i][i + 1]);
  }
  for (int num_matrix = 3; num_matrix <= n; ++num_matrix) { //number of matrix A*B*C -> 3
    for (int i = 0, j = i + num_matrix - 1; j < n; ++i, ++j) {
      dbp4(i, M[i], M[j], dp[i][j]);
      int mini = INT_MAX;
      for (int k = i; k + 1 <= j; ++k) {
        int prod = M[i].first * M[k].second * M[j].second;
        mini = min(mini, dp[i][k] + dp[k + 1][j] + prod);
      }
      dp[i][j] = mini;
      dbp4(i, M[i], M[j], dp[i][j]);dbp("----------");
    }
  }
  cout << dp[0][n - 1] << endl;
}

int main() {
  solve();
}

Measured memory_bytes: 3088
package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)

func nextLine() string {
	var buf, line []byte
	isPrefix := true
	var err error
	for isPrefix {
		buf, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		line = append(line, buf...)
	}
	return string(line)
}
func main() {
	s := nextLine()
	l := len(s)/2 + 1
	if len(s)%2 == 0 {
		l = len(s) / 2
	}
	bs := make([]byte, l)
	for i := 0; i < len(s); i += 2 {
		bs[i/2] = s[i]
	}
	fmt.Println(string(bs))
}


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

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

using namespace std;

int main(){
  ll n,m,k;cin>>n>>m>>k;
  bool f=false;
  rep(p,n+1)rep(q, m+1){
    if(p*q + (n-p)*(m-q) == k || p*(m-q) + (n-p)*q == k)f=true;
  }

  if(f) cout<<"Yes";
  else cout<<"No";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int
main(int argc, char** argv) {
    int A, B;
    std::cin >> A >> B;

    int ans = 0;
    if (A == B) {
       ans = A * 2;
    } else {
       int maxV = std::max(A, B);
       ans = maxV + maxV - 1;
    }

    std::printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class B {
    static void Main(string[] args) {
        var st = Console.ReadLine().Split().Select(int.Parse).ToArray();

        int H = st[0];
        int N = st[1];

        var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

        int sum = A.Sum();

        Console.WriteLine(H <= sum ? "Yes" : "No");

    }
}

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

using namespace std;
const int N = 1e6+100;
typedef long long ll;
int main(){
	ll R,G,B,n;
	cin>>R>>G>>B>>n;
	ll ans=0;
	for(int i=0;i<=3001;i++){
		for(int j=0;j<=3001;j++){
			if((n-i*R-j*G)>=0&&(n-i*R-j*G)%B==0) ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    std::vector<int64_t> B;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        B.push_back(t);
    }

    std::vector<int64_t> C;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        C.push_back(t);
    }


    std::sort(std::begin(A), std::end(A));
    std::sort(std::begin(B), std::end(B));
    std::sort(std::begin(C), std::end(C));

    size_t a, c;

    size_t ans = 0;

    a = c = 0;
    for (size_t b = 0; b < N; ++b) {
        // 上にのるサイズ
        for (; A[a] < B[b] && a < N; ++a)
            ;
        for (; B[b] >= C[c] && c < N; ++c)
            ;
        ans += (a) * (N - c);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

bool flg = true;
int n, s = 0;

int main(){
	std::cin >> n;
	rep(i, n) {
		char c;
		int x;
		std::cin >> c >> x;
		if (s < 0)flg = false;
		if (c == '(')s += x;
		else if (c == ')')s -= x;
	}

	if (!s && flg)std::cout << "YES" << std::endl;
	else std::cout << "NO" << std::endl;

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll h,m;
    cin>>h>>m;
    if(h==1||m==1)
    {
        cout<<1<<endl;
    }
    else
    {
        ll b=m*h;
        if(b%2==0)
            cout<<b/2<<endl;
        else
            cout<<b/2+1<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

#define PMAX 10
#define TMAX 50
#define INF 1000000000

int main(){

	int M,T,P,R;
	int m,t,p,j;
	int accepted[TMAX+1];
	int wrong[TMAX+1][PMAX+1];
	int sumwrong[TMAX+1];
	int time[TMAX+1];
	int rank[TMAX];

	while(1){
		cin>>M>>T>>P>>R;
		if(M==0&&T==0&&P==0&&R==0) break;

		for(int i=1;i<=TMAX;i++){
			accepted[i]=0;
			sumwrong[i]=0;
			time[i]=0;
			for(int j=1;j<=PMAX;j++){
				wrong[i][j]=0;
			}
		}

		for(int i=0;i<R;i++){
			cin>>m>>t>>p>>j;
			if(j!=0) wrong[t][p]++;
			else{
				accepted[t]++;
				time[t]+=m;
				sumwrong[t]+=wrong[t][p];
			}
		}

		for(int i=1;i<=T;i++){
			time[i]+=sumwrong[i]*20;
		}

		for(int i=0;i<T;i++){
			rank[i]=i+1;
		}

		for(int i=0;i<T;i++){
			for(int j=T-1;j>i;j--){
				if(accepted[rank[j]]>accepted[rank[j-1]]) swap(rank[j],rank[j-1]);
			}
		}
		for(int i=0;i<T;i++){
			for(int j=T-1;j>i;j--){
				if(accepted[rank[j]]==accepted[rank[j-1]]&&time[rank[j]]<time[rank[j-1]]) swap(rank[j],rank[j-1]);
			}
		}
		for(int i=0;i<T;i++){
			for(int j=T-1;j>i;j--){
				if(accepted[rank[j]]==accepted[rank[j-1]]&&time[rank[j]]==time[rank[j-1]]&&rank[j]>rank[j-1]) swap(rank[j],rank[j-1]);
			}
		}

		cout<<rank[0];
		for(int i=1;i<T;i++){
			if(accepted[rank[i]]==accepted[rank[i-1]]&&time[rank[i]]==time[rank[i-1]]) cout<<"="<<rank[i];
			else cout<<","<<rank[i];
		}
		cout<<endl;
	}

}

Measured memory_bytes: 1160
import sys
sys.setrecursionlimit(10**9)

N = int(input())
adjL = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    adjL[u-1].append((v-1, w))
    adjL[v-1].append((u-1, w))

def dfs(vNow):
    useds[vNow] = True
    ans = anss[vNow]
    for v2, wt in adjL[vNow]:
        if useds[v2]: continue
        if wt % 2:  # 長さが奇数ならば、色を反転
            anss[v2] = 1-ans
        else:
            anss[v2] = ans
        dfs(v2)

useds = [False] * N
anss = [0] * N
anss[0] = 0
dfs(0)

print('\n'.join(map(str, anss)))


Measured memory_bytes: 80156
#include "bits/stdc++.h"
#include <fstream>

typedef long long int ll;
using namespace std;

int main()
{

    //freopen("14","r",stdin);
    //freopen("sparse.out","w",stdout);
    char c[100006];
    scanf("%s",c);
    bool se[26];
    for(int i=0;i<26;i++)se[i]=false;
    for(int i=0;i<strlen(c);i++)se[c[i]-'a']=true;
    for(int i=0;i<26;i++){
        if(!se[i]){
                printf("%c",i+'a');
                return 0;
        }
    }
    printf("None");
    return 0;
}


Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

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

bool isSquare(int n) {
	int p = sqrt(n);
	if (p * p == n) return true;
	else return false;
}

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i <= b; i++) {
		if (i <= a + k - 1 || b - k + 1 <= i) cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
s=[]
for x in range(n):
    s.append(input())
m=int(input())
t=[]
for y in range(m):
    t.append(input())
q=0
for i in range(n):
    v=s[i]
    c=0
    for k in range(i,n):
        if v==s[k]:
            c+=1
    for j in range(m):
        if v==t[j]:
            c-=1
    if c>q:
        q=c
print(q)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

void solve(){
    int n, k;
    cin >> n >> k;
    ll l = 0, r = n, ans = 0;
    for (int i = 1; i <= n+1; i++){
        if (i >= k){
            ans += r-l+1;
            ans %= MOD;
        }
        l += i;
        r += n-i;
    }
    cout << ans;
}

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3668
while True:
    H, W = (int(x) for x in input().split())
    if(H == 0 and W == 0): break
    for h in range(H):
        for w in range(W):
            if ((h + w) % 2 == 0): print("#", end="")
            else: print(".", end="")
        print()
    print()


Measured memory_bytes: 7012
#include<stdio.h>   

void func(float); 

int main(void) 
{
	float tai;
	
	while(scanf("%f",&tai)!=EOF)    { 
        	func(tai);
	}  
   	return 0;
}	 
	void func(float tai) 
	{     
	float lim[10]={48.0,51.0,54.0,57.0,60.0,64.0,69.0,75.0,81.0,91.0};   
  	char kai[11][13]={"light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy"};    
 	int i;
       	
	for(i=0;i<10;i++)    {    
		if(lim[i]>=tai){  
			break;   
	      } 
	}     
	printf("%s\n",kai[i]);
}

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

int main() {
    int antena[5], k;
    for (int i=0; i<5; i++) cin >> antena[i];
    cin >> k;

    int min_=123, max_=0;
    for (int i=0; i<5; i++) {
        if (antena[i] < min_) min_ = antena[i];
        if (max_ < antena[i]) max_ = antena[i];
    }
    if (max_ - min_ > k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}

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

 using namespace std;

 int main() {
   int W, a, b;

   cin >> W >> a >> b;

   if (a <= b) {
     if (a + W <= b) cout << b - (a + W) << endl;
     else cout << 0 << endl;
   }

   else {
     if (b + W <= a) cout << a - (b + W) << endl;
     else cout << 0 << endl;
   }
 }


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,sum=0;
  scanf("%d %d",&a,&b);
  if(a>b){
    sum+=a;
  if(a-1>b)
    sum+=a-1;
    else
    sum+=b;
  }
  else if(a<=b){
    sum+=b;
  if(b-1>a)
    sum+=b-1;
    else
    sum+=a;
  }
  printf("%d",sum);
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    long long odd = 1;
    int x;
    for (int i = 0; i < n; i++){
        cin >> x;
        int tmp = 0;
        for (int i = x - 1; i <= x + 1; i++) if (i % 2) tmp++;
        odd *= tmp;
    }
    cout << (long long)pow(3, n) - odd << endl;
}

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

const ll MOD = 1e9 + 7;
const int MAX = 1000005;
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(){
    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 == 0) {
        COMinit();
        int a = (2 * y - x) / 3;
        int b = (2 * x - y) / 3;
        cout << COM(a + b, a) << endl;
    }
    else cout << 0 << endl;
    return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int> B(N), W(N);
    for (int i = 0; i < N; i++) {
        if (S[i] == '#') B[i]++;
        if (S[i] == '.') W[i]++;
    }
    for (int i = 1; i < N; i++) {
        B[i] += B[i - 1];
        W[i] += W[i - 1];
    }

    int res = 1000000000;
    for (int i = 0; i < N; i++) {
        int b = B[i];
        int w = W[N - 1] - W[i];

        res = min(res, b + w);
    }

    res = min(res, B[N - 1]);
    res = min(res, W[N - 1]);

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2180