akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;

int a[100001];

int mpow(int b, int e)
{
    int ret=1;
    for(int i=0; i<e; i++)
    {
        ret=ret*b%mod;
    }
    return ret;
}

int g[101][101];

struct Edge
{
    int a, b, c;
};

vector<Edge> vec;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, ans=0;
    cin >> n >> m;
    for(int i=0; i<m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        g[a][b] = c;
        g[b][a] = c;
        vec.push_back({a, b, c});
    }
    while(!vec.empty())
    {
        Edge edge = vec.back();
        vec.pop_back();
        g[edge.a][edge.b]=0;
        g[edge.b][edge.a]=0;
        int dist[101];
        for(int i=1; i<=100; i++) dist[i] = 1001;
        bool ok=1;
        int s=edge.a;
        dist[s]=0;
        queue<int> q;
        int inq[101] = { 0 };
        q.push(s);
        while(!q.empty())
        {
            s=q.front();
            q.pop();
            inq[s]=0;
            for(int i=1; i<=100; i++)
            {
                if(g[s][i] && dist[s] + g[s][i] < dist[i])
                {
                    dist[i] = dist[s] + g[s][i];
                    if(!inq[i])
                    {
                        q.push(i);
                        inq[i]=1;
                    }
                }
            }
        }
        if(dist[edge.b]<edge.c) ans++;
        else
        {
            g[edge.a][edge.b] = edge.c;
            g[edge.b][edge.a] = edge.c;
        }
    }
    cout << ans;
}

//TODO: 51
//come back to 50D,


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define debug puts("&&&&&&")
#define read(x) scanf("%d",&x)
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
const int mod=1e9+7;
int n,k;
int u[maxn],v[maxn];
LL next[maxn],cnt,temp;
vector<int> ma[maxn];
void dfs(int f,int t,int deep) {
    cnt++;
    if(deep==0)return;
    for(int i=0;i<ma[f].size();i++) {
        if(ma[f][i] != t) {
            dfs(ma[f][i],f,deep-1);
        }
    }
}
int main() {
    while(read(n) != EOF) {
        read(k);
        for(int i=0;i<=n;i++) {
            ma[i].clear();
        }
        cnt=0;
        temp=0;
        LL ans=0;
        for(int i=1;i<=n-1;i++) {
            read(u[i]);
            read(v[i]);
            ma[u[i]].push_back(v[i]);
            ma[v[i]].push_back(u[i]);
        }
        if(k%2==1) {
            for(int i=1;i<=n-1;i++) {
                cnt=0;
                dfs(u[i],v[i],k/2);
                dfs(v[i],u[i],k/2);
                ans=max(ans,cnt);
            }
        }
        else {
            for(int i=1;i<=n;i++) {
                cnt=0;
                dfs(i,0,k/2);
                ans=max(ans,cnt);
            }
        }
        printf("%d\n",n-ans);
    }
}


Measured memory_bytes: 2688
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import sqrt
a=[]
for _ in range(int(input())):
    a.append([int(i) for i in input().split()])
summ=0
for i in a:
    for j in a:
        summ+=sqrt((i[0]-j[0])**2+(i[1]-j[1])**2)
print(summ/len(a))
        

Measured memory_bytes: 3060
/*************************************************************************
	> File Name: 1.cpp
	> Author:Yhai! 
	> Mail: 
	> Created Time: 2020年03月21日 星期六 13时19分48秒
 ************************************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
struct node{
    ll i,j;
};
node fun(ll a){
    node ans;
    for (int i=(int)sqrt(a);i>=1;i--){
        if (a%i==0){
            ans.i=i,ans.j=a/i;
            return ans;
        }
    }
    return ans;
}
int main(){
    ll n;
    cin>>n;
    node ans;
    ans=fun(n);
    ll ans1=ans.i+ans.j-2;
    cout<<ans1<<endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  if((s.at(0)==s.at(1)&&s.at(2)==s.at(3)&&s.at(0)!=s.at(2))||(s.at(0)==s.at(2)&&s.at(1)==s.at(3)&&s.at(0)!=s.at(1))||(s.at(0)==s.at(3)&&s.at(1)==s.at(2)&&s.at(0)!=s.at(1))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main()
{
	int h, w;
	bool first = true;
	while (true)
	{
		std::cin >> h >> w;
		if (h == 0 && w == 0)break;

		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
			    if(i==0||i==h-1)
			    {
			       	std::cout << "#";
			    }
			    else if(j==0||j==w-1)
			    {
			        std::cout << "#";
			    }
			    else
			    {
			        std::cout << ".";
			    }

			}
			std::cout << "\n";
		}
		std::cout << "\n";
	}
}


Measured memory_bytes: 3072
# https://atcoder.jp/contests/abc106/tasks/abc106_d
# どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか？
# p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる
# このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数
# queryに高速に答えるために二次元累積和を構築する
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


import numpy as np

N, M, Q = read_ints()
LR = read_tuple(M)
pq = read_tuple(Q)

# 二次元座標上へのプロット
LR2d = np.zeros((N + 1, N + 1), np.int64)
for L, R in LR:
    LR2d[L, R] += 1

LR2d_accum = np.zeros((N + 2, N + 2), np.int64)
LR2d_accum[1:, 1:] = LR2d.cumsum(axis=0).cumsum(axis=1)  # 1次元累積和同様半開区間で考える
# つまりインデックスi,jとはもとの配列においてi,jを含まない四角形の領域の合計を出す

# queryに答えていく
for p, q in pq:
    print(LR2d_accum[q + 1, q + 1] - LR2d_accum[q + 1, p] -
          LR2d_accum[p, q + 1] + LR2d_accum[p, p])


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

int main() {
  int N;
  cin >> N;
  double sum = 0;
  int a[N];
  for(int i=0;i<N;i++){
    a[i]=i+1;
    if(a[i]%3!=0&&a[i]%5!=0){
      sum += a[i];
    }
  }
  cout << static_cast<long long int>(sum)<< endl;
  return 0;
}

Measured memory_bytes: 7484
#include <stdio.h>

int A[1000000], n;

int binarySearch(int key){
	int left = 0;
	int right = n;
	int mid;
	
	while(left < right){
		mid = (left + right) / 2;
		if(key == A[mid]){
			return 1;
		}
		if(key > A[mid]){
			left = mid + 1;
		}
		else if (key < A[mid]){
			right = mid;
		}
	}
	return 0;
}

int main()
{
	int i, q, k, sum=0;
	
	scanf("%d", &n);
	for(i = 0; i< n; i++){
		scanf("%d", &A[i]);
	}
	
	scanf("%d", &q);
	for(i = 0; i < q; i++){
		scanf("%d", &k);
		if(binarySearch(k)){
			sum++;
		}
	}
	printf("%d\n", sum);
	
	return 0;
	
}



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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	bool ans = false;
	for (int ii = 0; ii < 3; ++ii){
		if (s[ii] == '7'){
			ans = true;
		}
	}


	if (ans){
	cout << "Yes" << endl;

	} else {
	cout << "No" << endl;

	}


	return 0;
}


Measured memory_bytes: 3628
N = int(input())
red = [[int(i) for i in input().split()] for j in range(N)]
blue = [[int(i) for i in input().split()] for j in range(N)]

red.sort(key=lambda x:x[1])
red.reverse()
blue.sort()

ans = 0

while blue:
    bA = blue.pop(0)
    for i in range(len(red)):
        rA = red[i]
        if bA[0]>rA[0] and bA[1]>rA[1]:
            red.pop(i)
            ans += 1
            break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<ll>;
using vv = vector<vi>;
//const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1001001001001;

int main(){
    int n; cin >> n;
    ll ans = 0;
    ll amin = 0;
    rep(i,n){
        ll a;
        cin >> a;
        if(amin>a){
            ans += amin - a;
        }
        amin = max(amin, a);
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
    using namespace std;
     
    int main() 
	
	{
        int a, b, c;
        int cnt5 = 0;
        int cnt7 = 0;
     
     
        cin >> a >> b >> c;
        
        if (a == 5) 
            cnt5++;
        
        else if (a == 7) 
            cnt7++;
        
        
        if (b == 5) 
            cnt5++;
        
        else if (b == 7) 
            cnt7++;
        
     
        if (c == 5) 
            cnt5++;
        
        else if (c == 7) 
            cnt7++;
        
     
        if (cnt5 == 2 && cnt7 == 1) 
            cout << "YES" << endl;
        
        else 
            cout << "NO" << endl;
        
     
    }

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

int main() {

	string o, e; cin >> o >> e;
	string ans = "";
	int o_index = 0;
	int e_index = 0;
	for (int i = 0; i < o.size()+e.size(); i++) {
		if (i % 2 == 0) {
			ans += o[o_index];
			o_index++;
		}
		else {
			ans += e[e_index];
			e_index++;
		}
	}

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

Measured memory_bytes: 256
S = input()

Slst = [S.count('a'), S.count('b'), S.count('c')]
Slst.sort(reverse=True)

x = (len(S)-1) // 3
y = (len(S)-1) % 3
if y == 0:
    lst = [x+1, x, x]
elif y == 1:
    lst = [x + 1, x+1, x]
else:
    lst = [x+1, x+1, x+1]
if lst == Slst:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
int main(void)
{
	char a[10];
	char s[150];
	char c[10];
	scanf("%s %s %s",a,s,c);
	printf("%c%c%c\n",a[0],s[0],c[0]);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

int main(void) {
	string a;
	int num = 0;
	cin >> a;
	for(int i = 0;i < 3;i++) {
		if (a[i]== '1')num++;
	}
	cout << num << endl;


	

	
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		int ans = Integer.MAX_VALUE;

		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		
		Arrays.sort(h);
		
		for (int i = 0; i < n - (k - 1) ; i++) {
			if ((h[i + k - 1] - h[i]) < ans) {
				ans = h[i + k - 1] - h[i];
			}
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 50520
#include<iostream>
#include<cstdio>
using namespace std;
int dp[8001][16001];
int a[8001];
int main()
{
	string s;
	int x,y;
	cin>>s>>x>>y;
	int k=0;
	int w=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='T')
		{
			k++;
			a[k]=w;
			w=0;
		}
		else
		{
			w++;
		}
	}
	k++;
	a[k]=w;
    dp[1][a[1]+8000]=1;

    

	
	
	for(int i=3;i<=k;i+=2){
		for(int j=0;j<=16000;j++){
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	
	dp[0][8000]=1;
	for(int i=2;i<=k;i+=2){
		for(int j=0;j<=16000;j++){
			if(j+a[i]<=16000)
			dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
			dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	
	int ans;
	if(k%2==0){ 
		ans=dp[k][y+8000]&&dp[k-1][x+8000];
	}
	else{
		ans=dp[k][x+8000]&&dp[k-1][y+8000];
	}
	cout<<(ans==0?"No":"Yes");
	return 0;
}

Measured memory_bytes: 497792
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    string s=to_string(a)+to_string(b);
    long long c=stoll(s);
    if((int)pow((int)(pow(c,0.5)),2)==c)
    cout<<"Yes";
    else
    cout<<"No";
}

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

int main() {
	//input
	int N;
	cin >> N;

	//calculation
	int ones = N % 10;

	//output
	switch (ones) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon" << endl;
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon" << endl;
		break;
	case 3:
		cout << "bon" << endl;
		break;
	}


	return 0;
}


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

int main()
{
    int n,cnt8,ans;

    cin >> n;
    ans = 0;
    for (int i = 1;i <= n;i += 2) {
        cnt8 = 0;
        for (int j = 1;j <= n;++j){
            if (i % j == 0)
                ++cnt8;
        }
        if (cnt8 == 8)
            ++ans;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3604
#include<cstdio>
#include<cctype>

int main(){
    char ch;
    while(1){
        scanf("%c",&ch);
        if(isalpha(ch)){
            if(islower(ch)) printf("%c",toupper(ch));
            else printf("%c",tolower(ch));
        }else printf("%c",ch);
        if(ch=='\n') break;
    }
    return 0;
}


Measured memory_bytes: 2596
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    int tree[n];
    for (int i = 0; i < n; i++){
        cin >> tree[i];
    } 
    sort(tree, tree + n);
    int d = tree[k - 1] - tree[0];
    int i = 0;
    while(i + k != n){
        if(d > tree[i + k] - tree[i + 1]) d = tree[i + k] - tree[i + 1];
        i++;
    }
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define MAX 0x3f3f3f3f
using namespace std;

int mpa[12][12];

int n,flag;

void floyd()
{
    for(int k=0; k<=10; k++)
    {
        for(int i=0; i<=10; i++)
        {
            for(int j=0; j<=10; j++)
            {
                if(mpa[i][j]>mpa[i][k]+mpa[k][j])
                    mpa[i][j]=mpa[i][k]+mpa[k][j];
            }
        }
    }
}


int main()
{
    while(cin>>n,n!=0)
    {
        flag=0;
        memset(mpa,MAX,sizeof(mpa));
        for(int i = 1; i <= n; i++)
        {
            int a, b, c;
            cin>>a>>b>>c;

            if(mpa[a][b]>c)
            {
                mpa[a][b]=c;
                mpa[b][a]=c;
            }
        }

        floyd();

        for(int i=0; i<=10; i++)
            mpa[i][11]=0;

        int  mmin=MAX,a1,a2,flag=0;
        for(int i=0; i<=10; i++)
        {
            for(int j=0 ; j<=10; j++)
            {
                if(i == j)
                    mpa[i][j]=0;
                if(mpa[i][j]!=MAX)
                    mpa[i][11]+=mpa[i][j];
            }
            if(mmin>mpa[i][11] && mpa[i][11]!=0)
            {
                mmin=mpa[i][11];
                a1=i;
            }
        }

        cout<<a1<<" "<<mpa[a1][11]<<endl;

    }
    return 0;
}

Measured memory_bytes: 3036
package main

import (
	"container/heap"
	"fmt"
	"sort"
)

type Heap struct {
	data []int
}

func (h *Heap) Len() int           { return len(h.data) }
func (h *Heap) Less(i, j int) bool { return h.data[i] < h.data[j] }
func (h *Heap) Swap(i, j int)      { h.data[i], h.data[j] = h.data[j], h.data[i] }
func (h *Heap) Push(i interface{}) { h.data = append(h.data, i.(int)) }
func (h *Heap) Pop() interface{} {
	i := h.data[len(h.data)-1]
	h.data = h.data[:len(h.data)-1]
	return i
}

type Data struct {
	b, c int
}
type DataSlice struct {
	data []*Data
}

func (s DataSlice) Len() int           { return len(s.data) }
func (s DataSlice) Swap(i, j int)      { s.data[i], s.data[j] = s.data[j], s.data[i] }
func (s DataSlice) Less(i, j int) bool { return s.data[i].c > s.data[j].c }

func main() {
	n, m := oneInt(), oneInt()
	input := scanNums(n)

	dataSlice := &DataSlice{[]*Data{}}
	for i := 0; i < m; i++ {
		b, c := oneInt(), oneInt()
		dataSlice.data = append(dataSlice.data, &Data{b, c})
	}

	h := calc(input, dataSlice)

	sum := 0
	for _, v := range h.data {
		sum += v
	}
	fmt.Println(sum)

}

func calc(input []int, dataSlice *DataSlice) *Heap {
	h := &Heap{}
	heap.Init(h)
	for _, a := range input {
		heap.Push(h, a)
	}

	sort.Sort(dataSlice)
	for _, d := range dataSlice.data {
		for i := 0; i < d.b; i++ {
			if m, ok := heap.Pop(h).(int); ok {
				if m < d.c {
					heap.Push(h, d.c)
				} else {
					heap.Push(h, m)
					return h
				}
			}
		}
	}
	return h
}

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}

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

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


Measured memory_bytes: 11908
# ABC122 B ATCoder

s = input()
ans = 0

for i in range(len(s)+1):
    for j in range(i):
        _s = s[j:i]
        _l = len(_s)
        for k in range(_l):
            if _s[k] not in "ACGT":
                break
        else:
            if(ans < _l):
                ans = _l

print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s = "qwertasdfgzxcvb";
    string t = "yuiophjklnm";
    string u;
    while (cin >> u && u != "#") {
        int flg = -1;
        
        int bflg = -1;
        int c = 0;
        rep(i, u.size()) {
            rep(j, s.size()) if (u[i] == s[j]) flg = 0;
            rep(j, t.size()) if (u[i] == t[j]) flg = 1;
            if (flg != bflg) c++;
            bflg = flg;
        }
        cout << c - 1 << endl;
    }
}





Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
//#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};


template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}

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

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long int ll;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];

	vector<ll> sm(N);
	sm[0] = A[0];
	for (int i = 1; i < N; ++i) sm[i] = sm[i - 1] + A[i];

	map<ll, ll> mp;
	for (int i = 0; i < N; ++i) mp[sm[i]]++;

	ll ans=0;
	for (auto p = mp.begin(); p != mp.end(); ++p) {
		ll val = p->first;
		ll num = p->second;
		if (val == 0) ans += num;
		ans += num * (num - 1) / 2;
	}

	cout << ans << endl;
}

Measured memory_bytes: 15872
# ABC126D - Even Relation
import sys

sys.setrecursionlimit(10 ** 9)


def dfs(v: int, p: int) -> None:
    for u, w in T[v]:
        if u != p:
            D[u] = D[v] + w
            dfs(u, v)


def main():
    global T, D
    N, *A = map(int, open(0).read().split())
    T = [[] for _ in range(N + 1)]
    for i in range(0, (N - 1) * 3, 3):
        v, u, w = A[i : i + 3]
        T[v] += [(u, w)]
        T[u] += [(v, w)]
    D = [0] * (N + 1)  # D[i] := distance from vertex 1 (root)
    dfs(1, -1)
    ans = [i % 2 for i in D[1:]]  # same parity of distance -> same group
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Measured memory_bytes: 86708
#include <bits/stdc++.h>
using namespace std;
int main(){
 long long n,k;
  cin>>n>>k;
  long long a[n];
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
 for(int i=0;i<n-k;i++){
 	if(a[i]<a[i+k]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
 }
}

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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        long[] input = ReadLongs();
        long A = input[0];
        long B = input[1];
        long C = input[2];
        long K = input[3];        
        if (K <= A)
        {
            return K.ToString();
        }
        else if (K - A <= B)
        {
            return A.ToString();
        }
        else
        {
            return (2 * A + B - K).ToString();
        }
        return "0";
    }

    public static int Gcd(int a, int b)
    {
        if (a < b)
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    for (int i=0; i<m; i++) {
        int a;
        cin >> a;
        n -= a;
    }

    if (n >= 0) cout << n << endl;
    else cout << -1 << endl;

}

Measured memory_bytes: 3636
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/2/24
Solved on 2019/2/24
@author: shinjisu
"""


# ABC 119
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def probA():
    S = input()
    dmp(S)
    y = int(S[0:4])
    m = int(S[5:7])
    d = int(S[8:10])
    dmp((y,m,d))
    HEI = 'Heisei'
    if y <= 2018:
        return HEI
    if m <= 4:
        return HEI
    else:
        return 'TBD'


debug = False  # True False
print(probA())


def probB():
    N, M = getIntList()
    A = getIntMat(N)
    dmp((N, M))
    dmp(A)
    food = set([])
    food = set(A[0][1:])
    dmp(food)
    for i in range(N):
        food2 = set(A[i][1:])
        food = food & food2
        dmp(food)
    return len(food)


def gcd(x, y):  # 最大公約数
    m = max(x, y)
    n = min(x, y)
    while m % n != 0:
        w = m % n
        m = n
        n = w
    return n


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hp = A[N-1]
    for i in range(N-1):
        hp = gcd(hp, A[i])
        dmp(hp)
    return hp


def probD():
    N, M = getIntList()
    A = getIntList()
    dmp((N, M))
    dmp(A)
    return num




Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin >> n >> x;
    int m[n];
    int sum = 0;
    int Min = 100000;
    for(int i = 0;i < n;i++)
    {
        cin >> m[i];
        if(m[i] < Min)
        {
            Min = m[i];
        }
        sum += m[i];
    }
    cout << (x - sum) / Min + n;

    return 0;
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

n,m = iim()

if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m-2)
elif m == 1:
    print(n-2)
else:
    print((n-2)*(m-2))

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

#define TEISU 1000000
#define INF 1145141919810LL
#define BLACK 2
#define GRAY 1
#define WHITE 0
#define MAX_N 500000

long long d[MAX_N];
long long color[MAX_N];
vector<long long> x[MAX_N];

priority_queue<long long,vector<long long>,greater<long long>>Q;
 
void dijkstra(){
    while(!Q.empty()){
        long long A=Q.top()/TEISU;
        long long B=Q.top()%TEISU;
        Q.pop();
        color[B]=BLACK;
 
        if(d[B]<A*(-1))continue;
 
        for(int v=0;v<x[B].size();v++){
            int w=x[B][v]/TEISU;
 
            if(color[w]==BLACK)continue;
 
            if(d[w]>d[B]+x[B][v]%TEISU){
 
                d[w]=d[B]+x[B][v]%TEISU;
                Q.push(d[w]*TEISU+w);
                color[w]=GRAY;
 
            }
        }
    }
}

int main(){
	long long n,m,r,a,b,c;
	cin>>n>>m>>r;
	for(int i=0;i<m;i++){
		cin>>a>>b>>c;
		x[a].push_back(b*TEISU+c);
	}
	Q.push(r);
	for(int i=0;i<MAX_N;i++){color[i]=WHITE;d[i]=INF;}
	d[r]=0;color[r]=GRAY;
	dijkstra();
	for(int i=0;i<n;i++){if(d[i]==INF){cout<<"INF"<<endl;}else{cout<<d[i]<<endl;}}
	return 0;
}

Measured memory_bytes: 29940
#input
N = int(input())
S = str(input())

#output
def a_s_translator(s):
    n = ord(s)
    n += N
    if 65 <= n <= 90:
        t = chr(n)
    else:
        n -= 26
        t = chr(n)
    return t

T = []
for i in range(len(S)):
    T.append(a_s_translator(S[i]))

print(*T, sep = "")

Measured memory_bytes: 4724
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
 
int A[1000000], n;
 
int binalySearch(int key) {
    int left = 0;
    int right = n;
    int mid;
    while (left < right) {
        mid = (left + right) / 2;
        if (key == A[mid])return 1;
        if (key > A[mid])left = mid+1;
        else if (key < A[mid])right = mid;
    }
    return 0;
}
 
int main() {
    int i, q, k, sum = 0;
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
        }
 
    scanf("%d", &q);
    for (i = 0; i < q; i++){
        scanf("%d", &k);
        if (binalySearch(k))sum++;
    }
    printf("%d\n", sum);
 
    return 0;
}

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

struct node{
  int p,l,r;
  string str;
};

node t[1001];

void pr(int n,int d){
  if(n<0) return;
  for(int i=0;i<d;i++)cout<<".";
  cout<<t[n].str<<endl;
  pr(t[n].l,d+1);
  pr(t[n].r,d);
}

int main(){
  int n,u;
  cin>>u;
  for(int i=0;i<u;i++) t[i].l=-1,t[i].p=-1,t[i].r=-1;
  string str;
  int f[1001]={};

  for(int i=0;i<u;i++){
    cin>>n>>str;
    t[i].str=str;
    t[i].p=n-1;
    if(f[n]==0)t[n-1].l=i;
    else if(f[n]==1) t[t[n-1].l].r=i;
    else if(f[n]>1){
      int prev=t[n-1].l;
      for(int j=0;j<f[n]-1;j++)prev=t[prev].r;
      t[prev].r=i;
    }
    f[n]++;
  }
  pr(0,0);   
  
  return 0;
}

Measured memory_bytes: 1388
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> x(n);
    vector<int> y(n);
    for(int i=0;i<n;i++){
        cin>>x.at(i);
        y.at(i)=x.at(i);
    }
    sort(x.begin(),x.end());
    for(int i=0;i<n;i++){
        if(y.at(i)<=x.at(n/2-1))cout<<x.at(n/2)<<endl;
        else cout<<x.at(n/2-1)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3712
n = int(input())
mod = 10**9+7
#nまでの素因数を列挙してp^a+q^b+...となるとき、正の約数は
#
def factorization(n,dic):
    tmp=n
    flag = True
    for i in range(2,int(-(-n**0.5//1))+1):
        if tmp%i==0:
            flag = False
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            dic[i]=dic.get(i,0)+cnt
    if tmp!=1:
        flag = False
        dic[tmp]=dic.get(tmp,0)+1
    if flag:
        dic[n]=dic.get(n,0)+1
    return dic

dic = {}
for i in range(1,n+1):
    dic = factorization(i,dic)

if len(dic)==1:
    print(1);exit()

tmp = 1
for k,v in dic.items():
    if k!=1:
        tmp=tmp*(v+1)%mod
print(tmp)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long int dp[3][100001];
long int a[100001],b[100001],c[100001];
long int cost(int t,int i){
    if(i<0){
        return 0;
    }
    if(dp[t-1][i]!=-1)return dp[t-1][i];
    if(t==1) {
        return dp[0][i]=a[i]+max(cost(2,i-1),cost(3,i-1));
    }
    
    if(t==2) {
        return dp[1][i]=b[i]+max(cost(1,i-1),cost(3,i-1));
    }
    
    else {
        return  dp[2][i]=c[i]+max(cost(2,i-1),cost(1,i-1));
    }
 }
 
int main(){
    int n;
    cin >>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
        dp[0][i]=-1;
        dp[1][i]=-1;
        dp[2][i]=-1;
    }
    cost(1,n-1);
    cost(2,n-1);
    cost(3,n-1);
    long int tmp=max(dp[0][n-1],dp[1][n-1]);
    cout << max(tmp,dp[2][n-1])<<endl;
    
    // for(int i=0;i<3;i++){
    //     for(int j=0;j<=n;j++)
    //         cout<<dp[i][j]<<" ";
    //     cout<<"\n";
    // }
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long x,a,b;
    cin>>x>>a>>b;
	if(x>1&&b>=a||x==1&&a==b)
	{
	  	cout<<(x-2)*(b-a)+1<<endl;
	}
	else
	{
		cout<<0<<endl;
	}
    return 0;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

signed main() {
  i64 n;
  cin >> n;
  vector<pair<i64, i64>> P(n);
  cin >> P;
  map<pair<i64, i64>, i64> C;
  REP(j, n) {
    REP(i, j) {
      i64 x = P[i].first - P[j].first;
      i64 y = P[i].second - P[j].second;
      C[{x, y}] += 1;
      C[{-x, -y}] += 1;
    }
  }
  auto m = max_element(C.begin(), C.end(), COMP(second))->first;
  vector<i64> D(n);
  REP(j, n) {
    REP(i, j) {
      i64 x = P[i].first - P[j].first;
      i64 y = P[i].second - P[j].second;
      if (x == m.first && y == m.second || -x == m.first && -y == m.second) {
        D[i] += 1;
        D[j] += 1;
      }
    }
  }
  i64 x = 0, y = 0, z = 0;
  REP(i, n) {
    if (D[i] == 2) {
      x += 1;
    } else if (D[i] == 1) {
      y += 1;
    } else if (D[i] == 0) {
      z += 1;
    } else {
      assert(false);
    }
  }
  cout << (y / 2 + z) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

const int MAX_V = 1024;
const int MAX_E = 2048;
const int INF = 1<<29;

struct edge {int from, to, cost;};

edge es[MAX_E];

int dis[MAX_V];
int V, E;
//ゴールに続く負の閉路が存在すればtrueを返す
bool bellmanford(int s) {
	rep(V, v) dis[v] = INF;
	dis[s] = 0LL;
	rep(V, i) {
		rep(E, e) {
			edge ne = es[e];
			if (dis[ne.from] != INF && dis[ne.to] > dis[ne.from] + ne.cost) {
				dis[ne.to] = dis[ne.from] + ne.cost;
				if (i == V-1) return true;
			}
		}
	}
	return false;
}

void solve(void){
	int r;
	cin >> V >> E >> r;
	rep(E, i)
	{
		int s, t, d;
		cin >> s >> t >> d;
		es[i] = edge{s, t, d};
	}

	if (bellmanford(r))
	{
		cout << "NEGATIVE CYCLE" << endl;
		return;
	}

	rep(V, i)
	{
		if (dis[i] == INF)
		{
			cout << "INF" << endl;
		}
		else
		{
			cout << dis[i] << endl;
		}
	}

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 3144
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

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();
		int k = sc.nextInt();
		
		// 計算
		int result = 0;
		if(k <= a){
		    result = k;
		}else if(k <= a + b){
		    result = a;
		}else{
		    result = a - (k - a - b);
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 25324
#include<stdio.h>
#include<math.h>

int main(){
 int n,i,j,X,Y;/*Y??????j???for?????§????¢??????????????????????*/
 scanf("%d",&n);
 for(i=1;i<=n;i++){
  Y =0;
  if(i%3==0){
   printf(" %d",i);}
  else{
  for(j=1;j<5 && Y==0;j++){
   X =pow(10,j-1);
   if(3*X <= i%(X*10) && 4*X > i%(X*10)){
    printf(" %d",i);
    Y=1;}}}}
 printf("\n");
 return 0;}

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

int main() {
	int n,a,b,temp;cin>>n>>a>>b;
  	int q1=0,q2=0,q3=0;
  	for(int i=0;i<n;i++){
    	cin>>temp;
      	if(temp<=a){
        	q1++;
        }else if(temp>a && temp<=b){
        	q2++;
        }else{
        	q3++;
        }
    }
  	cout<<min(q1,min(q2,q3))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  vector<int> l(4, 0);
  rep(i, 3) {
    int a, b;
    cin >> a >> b;
    l[a-1]++;
    l[b-1]++;
  }

  rep(i, 4) {
    if (l[i] >= 3) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;



int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll mx=0,ans=0;
    for(ll i=0;i<n;i++){
        if(a[i]>mx)
            mx=a[i];
        else{
            ans+=mx-a[i];
        }
    }
    cout<<ans;



    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 4780
L = int(input())
A = [int(input()) for i in range(L)]

Asum = [0]
for i, a in enumerate(A):
    Asum.append(Asum[i] + a)

Emin = [0 for i in range(L + 1)]
Zmin = [0 for i in range(L + 1)]

for i in range(L)[:: -1]:
    a = A[i]
    if a == 0:
        Emin[i] = 2 + Emin[i + 1]
        Zmin[i] = 1 + min(Emin[i + 1], Zmin[i + 1])
    elif a % 2 == 0:
        Emin[i] = Emin[i + 1]
        Zmin[i] = 1 + min(Emin[i + 1], Zmin[i + 1])
    else:
        Emin[i] = 1 + Emin[i + 1]
        Zmin[i] = min(Emin[i + 1], Zmin[i + 1])
    Emin[i] = min(Emin[i], Asum[L] - Asum[i])
    Zmin[i] = min(Zmin[i], Asum[L] - Asum[i])


A.reverse()

Asum = [0]
for i, a in enumerate(A):
    Asum.append(Asum[i] + a)

Emin2 = [0 for i in range(L + 1)]
Zmin2 = [0 for i in range(L + 1)]

for i in range(L)[:: -1]:
    a = A[i]
    if a == 0:
        Emin2[i] = 2 + Emin2[i + 1]
        Zmin2[i] = 1 + min(Emin2[i + 1], Zmin2[i + 1])
    elif a % 2 == 0:
        Emin2[i] = Emin2[i + 1]
        Zmin2[i] = 1 + min(Emin2[i + 1], Zmin2[i + 1])
    else:
        Emin2[i] = 1 + Emin2[i + 1]
        Zmin2[i] = min(Emin2[i + 1], Zmin2[i + 1])
    Emin2[i] = min(Emin2[i], Asum[L] - Asum[i])
    Zmin2[i] = min(Zmin2[i], Asum[L] - Asum[i])

ans = 3000000
for i in range(L):
    ans = min(ans, min(Emin[i], Zmin[i]) + min(Emin2[L - i], Zmin2[L - i]))

print(ans)

Measured memory_bytes: 85412
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pii e[100005];

int main()
{
	string S;
	cin >> S;
	int N = S.length();
	if (S[0] == '0' || S[N - 1] == '1')
	{
		cout << -1 << endl;
		return 0;
	}
	int p = 0;
	REP(i, N - 1)
	{
		if (N - 2 - i >= 0 && S[i] != S[N - 2 - i])
		{
			cout << -1 << endl;
			return 0;
		}
		e[i].first = i + 1;
		e[i].second = p;
		if (S[i] == '1')
		{
			p = i + 1;
		}
		//else
		{
			
		}
	}

	REP(i, N - 1)
	{
		cout << e[i].first + 1 << " " << e[i].second + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
int main ()
{
   int  n,cnt=0;
    cin>>n;
    for(int i=-1000;i<=1000;i++)
    {
        for(int j=-1000;j<=1000;j++)
        {
            if(pow(i,5)-pow(j,5)==n)
            {    cnt=1;
                cout<<i<<" "<<j<<endl;
               return 0;
            }
        }

    }

    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main() {
    int Q;
    cin >> Q;
    deque<int> v;
    while (Q--) {
        int q; cin >> q;
        if (q == 0) {
            int d, x;
            cin >> d >> x;
            if (d == 0) v.push_front(x);
            else v.push_back(x);
        } else if (q == 1) {
            int x;
            cin >> x;
            cout << v[x] << endl;
        } else {
            int d;
            cin >> d;
            if (d == 0) v.pop_front();
            else v.pop_back();            
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  int T[N + 1];
  for (int i = 1; i <= N; i++) {
    cin >> T[i];
  }

  int M;
  cin >> M;
  int sum[M + 1];

  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    sum[i] = 0;
    for (int j = 1; j <= N; j++) {
      if (j == a) {
        sum[i] += b;
      } else {
        sum[i] += T[j];
      }
    }
  }

  for (int i = 1; i <= M; i++) cout << sum[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<chrono>
#define ll long long
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;


int main() {
	cin >> N;
	bool flag = 0;
	for (int i = 0; i <= N / 7;i++) {
		if ((N - i * 7) % 4 == 0) {
			flag = 1;
			break;
		}
	}
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x,y,z;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x<a.x;
//        return z>a.z;
    }
};

vector<int> v[100055];
//bitset<4001000> b;
int a,c,i,b,k,d,n,m,e;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[110515];
int o[100510];
int dx[10]={0,1,0,-1},dy[10]={1,0,-1,0},dz[10]={0,0,0,0,1,-1};

long long x,y,z,mod=1000000007;
P u[11];
int j[55];

stack<int> s;
queue<int> q;

//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int > p;
//list<int> l;
//string r[111],r2;
char r[510][555];


bool as(P a,P b)
{
   // if(a.x!=b.x)
        return a.x<b.x;
    //return a.y>b.y;
}

int f(int a)
{
    if(!v[a].size()) return 1;
    if(l[a]>=0) return l[a];
    for(int h=0;h<v[a].size();h++)
        l[a]=max(l[a],f(v[a][h])+1);
    if(l[a]>=b&&o[a]!=1) k++,l[a]=0;
    return l[a];
}

int main()
{
    scanf("%d %d",&a,&b);
    memset(l,-1,sizeof(l));
    for(int t=1;t<=a;t++)
        scanf("%d",&o[t]);
    if(o[1]!=1) k++,o[1]=1;
    for(int t=1;t<=a;t++)
        v[o[t]].push_back(t);
    
    for(int t=2;t<=a;t++)
    if(b>1)
    {
        l[t]=f(t);
        //printf("%d ",l[t]);
        //if(o[t]>1)
        //if(b==1||!l[t]%b) k++;
    }
    else if(o[t]>1) k++;
    //for(int t=1;t<=a;t++)
    //printf("%d ",l[t]);
    printf("%d",k);

}


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

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();		
		int prcsum = sc.nextInt();
		int tp = sc.nextInt();
		int calsum = sc.nextInt();
		int[] cal = new int[n];
		
		for(int i =0; i< n;i++){
			cal[i] = sc.nextInt();
		}
		for(int i = 0; i<n;i++){
			for(int k=0;k<n;k++){
				if(cal[i]>cal[k]){
					int work = cal[i];
					cal[i] = cal[k];
					cal[k] = work;
				}
			}
		}
		
		int max = calsum / prcsum;

		for(int i = 0; i<n; i++){
			calsum += cal[i];
			prcsum += tp;
			int pizza = calsum / prcsum;
			if(max < pizza){
				max = pizza;
			}
		}
		System.out.println(max);
	}

}

Measured memory_bytes: 18152
/*input
3 8
3 30
4 50
5 60
*/
// 283477GR
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int maxn =210;
int w[maxn] , v[maxn];
const int Max = 1e6;
int dp[Max];
signed main()
{
    	int n , W;
    	cin >> n >> W;
    	for ( int i =1 ; i <= n ; i++){
    		cin >> w[i] >> v[i];
    	} 
    	fill(dp , dp + Max , 1e9+5);
    	dp[0] = 0;
    	for ( int i = 1 ; i <=n; i++){
    		for ( int j = Max -500; j >= 0; j-- ){
    			dp[j + v[i]] = min( dp[j] + w[i] ,  dp[j+v[i]]);
    		}
    	}
    	for ( int i = Max -1; i >= 0 ; i-- ){
    		if ( dp[i] <= W){
    			cout << i << "\n";
    			break;
    		}
    	}
}

Measured memory_bytes: 8064
#include<iostream>
#include<string>
using namespace std;
int main(){
    int i,n,cnt=0;
    string s;
    cin >> n>>s;
    if(n%2!=0){
        cout << "No";
    }
    else {
        for(i=0;i<n/2;i++){
            if(s[i]==s[i+n/2]){
                cnt++;
            }
        }
        if(cnt==n/2){
            cout << "Yes";
        }
        else{
            cout << "No";
        }
    }
}

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

#define ll  int
#define intmax INT_MAX
#define pi 3.14159265358979323846
#define ff first 
#define ss second
#define pb push_back
#define watch(x) cerr<<(#x)<<"  "<<x<<"\n";
const int MOD=998244353;
const int MAXN = 3e5+4;
int dp[MAXN][3],a[MAXN][3];

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

int n; cin>>n;
for(int i=1;i<=n;i++) for(int j=0;j<3;j++) cin>>a[i][j];


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

cout<<max(dp[n][2],max(dp[n][0],dp[n][1]))<<"\n";


return 0;
}


Measured memory_bytes: 5944
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);
#define FOR(n) for(int i(0);i<n;++i)
#define ASC(i,a,b) for(int i(a); i <=b; ++i)
#define DESC(i,a,b) for(int i(a);i>=b;i--)
#define WL(t) while(t--)
#define SZ(a) int((a).size())
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define BB begin()
#define EE end()
#define all(c) c.BB, c.EE
#define present(container, element) (container.find(element) != container.end())
// ^^for set,map etc
#define cpresent(container, element) (find(all(container), element) != container.end())
// for vector,array etc
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef map<char,int> mci;
typedef pair<int, int> pii;
typedef map<int,pii> ipii;
const float INF = numeric_limits<float>::infinity();
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
const LL big=998244353;

#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

int maxi(int a,int b,int c){
	int d=max(a,b);
	return max(d,c);
}

int mini(int a,int b,int c){
	int d=min(a,b);
	return min(d,c);
}

int dp[4001];

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	cout << a[0]+a[1];

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n;
    cin >> n;
    map<ll,ll> A;
    for(ll i=0;i<n;i++){
        ll a; cin >> a;
        A[a]++;
    }

    ll ans = 0;
    map<ll,ll>::iterator it;
    for(it=A.begin();it!=A.end();it++){
        if(it->second%2 == 1) ans++;
    }

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



Measured memory_bytes: 6528