akhauriyash/Code-Regression huggingface dataset:
//============================================================================
// Name        : abc132_b.cpp
// Author      : abb
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

/*
 B - Ordinary Number

 実行時間制限: 2 sec / メモリ制限: 1024 MB

 配点 : 200 点

 問題文
 {1, 2, ..., n} の順列 p = {p_1, p_2, ..., p_n} があります。
 以下の条件を満たすような p_i (1 < i < n) がいくつあるかを出力してください。

 ・p_{i - 1}, p_i, p_{i + 1} の 3 つの数の中で、p_i が 2 番目に小さい。

 制約

 ・入力は全て整数である。
 ・3 <= n <= 20
 ・p は {1, 2, ..., n} の順列である。
 */
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

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

	int n, count = 0;
	cin >> n;
	int p[n]; // 各要素は重複しない
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	// 増え続けるか減り続けるならおｋ
	int d0 = p[1] - p[0], d1;
	for (int i = 1; i < n - 1; ++i) {
		// 増分の積が正なら条件を満たす
		d1 = p[i + 1] - p[i];
		// cerr << d0 << " " << d1 << endl;
		if (d0 * d1 > 0) {
			++count;
		}
		d0 = d1;
	}

	cout << count << endl; // prints !!!Hello World!!!
	return 0;
}


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll,ll> vll;
typedef pair<ll,ll> pll;

//next position?
bool DP[100010];

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n, k;
	cin >> n >> k;
	vi moves(n);
	M00(i, n) cin >> moves[i];
	sort(all(moves));
	DP[0] = false; //P position;
	for(int i = 1; i <= k; i++) {
		bool sum = false; //assume lose
		for(int j = 0; j < n && moves[j] <= i; j++) {
			if(!DP[i - moves[j]]) sum = true;
		}
		DP[i] = sum;
	}
	if(DP[k]) cout << "First" << endl;
	else cout << "Second" << endl;

}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while (!isdigit(c))
	{
		if (c=='-')
			f=-1;
		c=getchar();
	}
	while (isdigit(c))
	{
		ans=(ans<<3)+(ans<<1)+(c^48);
		c=getchar();
	}
	return ans*f;
}
void write(int x)
{
	if (x>=10)
	{
		write(x/10);
		x%=10;
	}
	putchar(x+'0');
}
struct req
{
	int l,r;
}r[100005];
bool cmp(req a,req b)
{
	if (a.l>b.l) return true;
	if (a.l<b.l) return false;
	return a.r<b.r;
}
int p[10005],cnt;
int main()
{
	int n,m;
	n=read(),m=read();
	for (int i=1;i<=m;i++)
		r[i]=(req){read(),read()-1};
	sort(r+1,r+m+1,cmp);
	for (int i=1;i<=m;i++)
	{
		for (int j=1;j<=cnt;j++)
			if (r[i].l<=p[j]&&p[j]<=r[i].r)
				goto end;
		p[++cnt]=r[i].l;
		end:;
	}
	write(cnt);
	return 0;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, q, r;
vector<pair<ll,int>> g[maxn];
ll dist[maxn];

void dfs(int at, int p, ll d) {
  dist[at] = d;
  for (auto ed: g[at]) {
    ll wei = ed.first;
    int to = ed.second;
    if (to == p) continue;
    dfs(to, at, d+wei);
  }
}

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

  cin>>n;
  for (int i=0; i<n-1; i++) {
    int u,v; ll w;
    cin>>u>>v>>w;
    g[u].push_back({w,v});
    g[v].push_back({w,u});
  }

  cin>>q>>r;

  dfs(r,-1,0);

  while (q--) {
    int u,v; cin>>u>>v;
    ll ans = dist[u] + dist[v];
    cout<<ans<<"\n";
  }
  

  return 0;
}


Measured memory_bytes: 37120
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

const inf = int(1e10)

func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}
func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	var N int
	fmt.Scan(&N)
	h := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		h[i] = nextInt(sc)
	}
	dp := make([]int, N+10) // 大きめに準備
	for i := 0; i < len(dp); i++ {
		dp[i] = inf // dpテーブルをinfで初期化
	}
	dp[0] = 0 // 初期条件
	for i := 1; i < N; i++ {
		chmin(&dp[i], dp[i-1]+abs(h[i]-h[i-1]))
		if i > 1 {
			chmin(&dp[i], dp[i-2]+abs(h[i]-h[i-2]))
		}
		// fmt.Printf("i %d - dp %v\n", i, dp)
	}
	fmt.Println(dp[N-1])
}


Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;
set<string> s;
set<string>::iterator it;
string str,tmp,mins;
char sz[5001]={0};
int k;
void divide(string a)
{
    int i,j,len=a.length();
    for(i=1;i<=len;i++)
    {
	for(j=0;j<len-i+1;j++)
	{
	    s.insert(a.substr(j,i));
	}
    }
}
int main()
{
    int i,len;
    scanf("%s",sz);
    str=sz;
    scanf("%d",&k);
    len=str.length();
    if(k>len)
    {
	divide(str);
	it=s.begin();
        for(i=0;i<k-1;i++)
        {
	    it++;
        }
	printf("%s\n",(*it).c_str());
	return 0;
    }
    mins=str;
    for(i=0;i<len-k;i++)
    {
	tmp=str.substr(i,k);
	if(tmp<mins)
	{
	    divide(tmp);
	    mins=tmp;
	}
    }
    tmp=str.substr(len-k,k);
    divide(tmp);
    it=s.begin();
    for(i=0;i<k-1;i++)
    {
	it++;
    }
    printf("%s\n",(*it).c_str());
    return 0;
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
f = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
p = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n+1)]

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

ma = -1*(10**10)
for i in range(1,1024):
    s = Base_10_to_n(i,2).zfill(10)
    total = 0
    for j in range(n):
        point = 0
        for k in range(10):
            if int(s[k]) == 1 and f[j][k] == 1:
                point += 1
        total += p[j][point]
    ma = max(ma,total)   
print(ma)

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		private const int mod = 1000000007;  // 10^9+7

		static public void Solve(string[] args)
		{
			//int k = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int a = vs[0];
			int b = vs[1];
			int h = vs[2];
			int m = vs[3];

			double hd = (Math.PI / 180) * (h * 30 + (0.5 * m));
			double md = (Math.PI / 180) * (m * 6);
			double hx = Math.Sin(hd) * a;
			double hy = Math.Cos(hd) * a;
			double mx = Math.Sin(md) * b;
			double my = Math.Cos(md) * b;

			double ans = Math.Sqrt(Math.Pow(hx - mx, 2) + Math.Pow(hy - my, 2));
			Console.WriteLine(ans);

		}

	}
}


Measured memory_bytes: 28768
inf=1001001001
nv,ne,r=map(int,input().split())
d=[inf]*nv
d[r]=0
e=[]
for i in range(ne):
  e.append(list(map(int,input().split())))
for i in range(nv-1):
  flg=False
  for j in e:
    if d[j[1]]>d[j[0]]+j[2]: flg=True
    d[j[1]]=min(d[j[1]],d[j[0]]+j[2])
  if not(flg): break
for i in range(nv):
  print('INF' if d[i]==inf else d[i])


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

int main(void){
  int n;
  while(cin >> n, n){
    int a = 0;
    int b = 0;
    for(int i = 0; i < n; i++){
      int pa;
      int pb;
      cin >> pa >> pb;
      if(pa > pb){
        a += pa + pb;
      } else if(pa < pb){
        b += pa + pb;
      } else {
        a += pa;
        b += pb;
      }
    }
    cout << a << " " << b << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int a, b; cin >> a >> b;
  if (b % a == 0) cout << a + b << endl;
  else cout << b - a << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int ans = b % a == 0 ? a + b : b - a;
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 23636
#include <iostream>

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

int main() {
	char a[10], b[10], c[10]; cin >> a >> b >> c;

	cout << (char)(a[0] - ' ') << (char)(b[0] - ' ') << (char)(c[0] - ' ') << endl;

	return 0;
}

Measured memory_bytes: 256
A, B, C = list(input()[::-1]), list(input()[::-1]), list(input()[::-1])
t = A.pop()
while True:
  if t=="a":
    L = A
  elif t=="b":
    L = B
  else:
    L = C
  if not L:
    print(t.upper())
    break
  else:
    t = L.pop()

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

using namespace std;

typedef long long llint;
typedef pair <int, int> pi;

int n, mx, ok = 1;
multiset <int> st;

void izbaci (int x) {
    if (st.find(x) == st.end()) {
        ok = 0;
        return;
    }
    st.erase(st.find(x));
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        st.insert(x);
    }
    mx = *st.rbegin();
    for (int i = 0; i <= mx; i++) {
        izbaci(max(i, mx - i));
    }
    int lo = (mx + 1) / 2 + 1;
    for (auto x : st) {
        if (!(lo <= x && x <= mx)) ok = 0;
    }
    if (ok) cout << "Possible"; else cout << "Impossible";
    return 0;
}


Measured memory_bytes: 3656
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
b = readints()
c = readints()
ans = 0
for i in range(n):
    ans += b[a[i]-1]
# print(ans)
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        # print(a[i])
        #print('c', c[i-1])
        ans += c[a[i]-1]
print(ans)


Measured memory_bytes: 59884
/*author : Yashvardhan
Sunday, April 19, 2020
6:39 PM
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

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

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

	time_t t1, t2;
	t1 = clock();
	
	int n,k;
	cin >> n >> k;

	int pref[n + 2];
	pref[0] = 0;
	for(int i = 1; i <= n + 1; i++){
		pref[i] = pref[i - 1] + (i - 1);
	}

	int ans = 0;
	for(int i = k; i <= (n + 1); i++){
		int curr = (pref[n + 1] - pref[n + 1 - i])  - pref[i] + 1;
		ans = (ans + curr % mod) % mod;
	}

	cout << ans << endl;
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



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

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = k;
    for (ll i = 1; i < n; i++)
    {
        ans *= (k - 1);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0

for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j and j ==k:
                ans += i
            elif i==j or j==k or i==k:
                ans += gcd(i,j,k)*3
            else:
                ans += gcd(i,j,k)*6

print(ans)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    string a,b;cin >>a>>b;
    a+=b;
    ll ans=0;
    for (int i = 0; i < a.size(); ++i) {
        ans*=10;
        ans+=a[i]-'0';
    }
    bool flg=false;
    for (int i = 0; i <=1000; ++i) {
        if(ans==i*i){
            flg=true;
        }
    }
    if(flg)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

s = input()
n = len(s)
ans = 0
p = 0
cnt_a = 0
while True:
    while p<n and s[p] == 'A':
        cnt_a += 1
        p += 1
    
    while p<n-1 and s[p] == 'B' and s[p+1] == 'C':
        ans += cnt_a
        p+=2
    while p<n and s[p] == 'C':
        p+=1
        cnt_a = 0
    while p<n and s[p] == 'B':
        p+=1
        cnt_a=0
    
    if p>=n:
        break
print(ans)

Measured memory_bytes: 86396
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

int main() {
	int n, m,p;
	std::cin >> n >> m >> p;

	std::vector<int> us(m);
	std::vector<int> vs(m);
	std::vector<int> ws(m);
	for (int i = 0; i < m; i++) {
		std::cin >> us[i] >> vs[i] >> ws[i];
		us[i]--;
		vs[i]--;
        ws[i]-=p;
	}

	constexpr long long INF = 1e18;
	std::vector<long long> d(n, -INF);

	d[0] = 0;
	for (int i = 0; i < 5000; i++) {
		for (int j = 0; j < m; j++) {
			d[vs[j]] = std::max(d[vs[j]], d[us[j]] + ws[j]);
		}
	}
	long long ans1 = d[n - 1];
	for (int i = 0; i < 5000; i++) {
		for (int j = 0; j < m; j++) {
			d[vs[j]] = std::max(d[vs[j]], d[us[j]] + ws[j]);
		}
	}
	long long ans2 = d[n - 1];
	if (ans1 != ans2) {
		std::cout << -1 << std::endl;
	} else {
		std::cout << std::max(0LL,ans1) << std::endl;
	}
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N;

    scanf("%d", &N);

    char s[N][11];

    for(int i = 0; i < N; i++){
        scanf("%s", s[i]);
    }

    int M;

    scanf("%d", &M);

    char t[M][11];

    for(int i = 0; i < M; i++){
        scanf("%s", t[i]);
    }

    int max = 0;

    for(int i = 0; i < N; i++){
        int m = 0;
        for(int j = 0; j < N; j++){
            if(strcmp(s[i], s[j]) == 0){
                m++;
            }
        }
        for(int j = 0; j < M; j++){
            if(strcmp(s[i], t[j]) == 0){
                m--;
            }
        }
        if(m > max){
            max = m;
        }
    }

    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

// 繰り返し二乗法
// a^n mod pを高速に求める
long long modPow(long long a, long long n, long long p) {
    if (n == 0)
        return 1;
    if (n == 1)
        return a % p;
    if (n % 2 == 1)
        // 奇数のとき
        return (a * modPow(a, n - 1, p)) % p;
    // 偶数のとき
    long long t = modPow(a, n / 2, p);
    return (t * t) % p;
}

// 余りが負なら正にして返す
long long modPositive(long long v, long long p) {
    long long res = v % p;
    if (res < 0)
        res += p;
    return res;
}

int main() {
    long long n;
    cin >> n;

    // 全通り →10^n 通り
    // 0がない → 9^n 通り
    // 9がない → 9^n 通り
    // 0と9がない → 8^n 通り
    // 0または9がある → 10^n - 9^n - 9^n + 8^n

    long long ans = modPow(10, n, MOD) - 2 * modPow(9, n, MOD) + modPow(8, n, MOD);
    ans = modPositive(ans, MOD);
    ans = modPow(ans, 1, MOD);

    cout << ans << endl;
}


Measured memory_bytes: 3600
from fractions import gcd

a,b = [int(x) for x in input().split()]

def prime_factor(n):
    x = int(n**0.5)
    res = [1]
    for i in range(2,x+1):
        if n%i==0:
            while n%i==0:
                n //= i
            res.append(i)
    if n!=1:
        res.append(n)
    return res

z = gcd(a,b)
print(len(prime_factor(z)))

Measured memory_bytes: 5432
#include <iostream>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main(){
	vector<int> dice1(6),dice2(6);
	for(auto &a:dice1){
		cin >> a;
	}
	for(auto &a:dice2){
		cin >> a;
	}
	for(int i=0;i<4;i++){
        int tmp1=dice1[0];
        dice1[0]=dice1[2], dice1[2]=dice1[5], dice1[5]=dice1[3], dice1[3]=tmp1;
        for(int j=0;j<4;j++){
            int tmp2=dice1[0];
            dice1[0]=dice1[1], dice1[1]=dice1[5], dice1[5]=dice1[4], dice1[4]=tmp2;
            for(int k=0;k<4;k++){
                int tmp3=dice1[1];
                dice1[1]=dice1[2], dice1[2]=dice1[4], dice1[4]=dice1[3], dice1[3]=tmp3;
                if(equal(dice1.cbegin(),dice1.cend(),dice2.cbegin())){
					cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
	cout << "No" << endl;
	return 0;
}			

Measured memory_bytes: 3096
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll l2(ll n)
{
	ll a = 0;
	n /= 2;
	while (n)
	{
		a++;
		n /= 2;
	}
	return a;
}


int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	long double a, b;
	cin >> a >> b;
	int c = round(b * 100);
	cout << fixed << setprecision(0) << ((floor((a * c) / 100)));
	return 0;
}



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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    sort(h.begin(), h.end());

    int ans = 1001001001;
    for(int i = 0; i+k-1 < n; i++){
        if(h[i+k-1]-h[i] < ans) ans = h[i+k-1]-h[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

const int INF = 1e18;

template <class T> class CumulativeSum2D {
	public:
		vector<vector<T>> s;
		int h, w;
		CumulativeSum2D(const vector<vector<T>> &a) {
			h = a.size();
			w = a[0].size();
			s = vector<vector<T>>(h + 1, vector<T>(w + 1, 0));
			rep(i, h) rep(j, w) s[i + 1][j + 1] = a[i][j];
			rep(i, h + 1) rep(j, w) s[i][j + 1] += s[i][j];
			rep(i, h) rep(j, w + 1) s[i + 1][j] += s[i][j];
		}

		int sum(int i, int j, int h, int w) {
			return s[i + h][j + w] - s[i][j + w] + s[i][j] - s[i + h][j];
		}

		int maximumSubMatrix(){
			int ret = -INF;
			rep(i,h + 1) rep(j,w + 1) range(k,1,h - i + 1) range(l,1,w - j + 1){
				ret = max(ret, sum(i,j,k,l));
			}
			return ret;
		}
};

signed main(){
	int n, m, q;
	cin >> n >> m >> q;

	vector<vector<int>> p(n, vector<int>(n,0));
	rep(i,m){
		int l, r;
		cin >> l >> r;
		p[l - 1][r - 1]++;
	}

	CumulativeSum2D<int> c(p);
	rep(i,q){
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << c.sum(l,l,r - l + 1, r - l + 1) << endl;
	}
}


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


using namespace std;


struct UnionFind {
	std::vector<int> parent;

	UnionFind(int N) : parent(N){
		for(int i=0; i<N; i++) parent[i] = i;
	}

	int root(int x){
		if(parent[x]==x) return x;
		return parent[x] = root(parent[x]);
	}

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        parent[rx] = ry;
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N, M; cin >> N >> M;
    UnionFind union_find_tree(N);

    int p[100001];
    for(int i=0; i<N; i++){
        int p_; cin >> p_;
        p[i] = p_;
    }


    for (int i = 0; i < M; ++i){
        int x,y; cin >> x >> y;
        union_find_tree.unite(x-1, y-1);
    }

    int cnt=0;
    for(int i=0; i<N; i++){
        if(union_find_tree.same(i, p[i]-1)) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

	int n = scan.nextInt();
	int k = scan.nextInt();

	int re=0;

		int[] array = new int[n];

		for(int i=0;i<k;i++) {

			int d = scan.nextInt();

			for(int j=0;j<d;j++) {
				int idx = scan.nextInt();
				array[idx-1]+=1;
			}
		}

		for(int i:array) {
			if(i == 0)
				re++;
		}
		System.out.println(re);
	}

}


Measured memory_bytes: 37296
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	int n;
	scanf("%d", &n);
	printf("%d\n", 800 * n - 200 * int(n / 15));

	Please AC;
}


Measured memory_bytes: 256
#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>;

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(200010);

int main() {
  int n, k; cin >> n >> k;
  mint ans = 0;
  for (int i = 0; i <= min(k, n); i++)
    ans += comb(n, i) * comb(n-1, i);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3328
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}


fn main() {
    input!{
        s:String,
        t:String
    }
    println!("{}", t + &s);
}


Measured memory_bytes: 4352
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

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

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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


int h,w,a[501][501];
vector<pair<pi,pi>> ans;

signed main(){
    I(h); I(w);
    REP(i,h) REP(j,w) { I(a[i][j]); a[i][j] &= 1;};
    bool hold = false;
    int pi=-1,pj=-1;
    for (int i=0; i<h; i++){
        if(i%2 == 0){
            for(int j=0; j<w; j++){
                if(hold) ans.eb( mp(pi+1, pj+1), mp(i+1, j+1));
                hold ^= a[i][j];
                pi = i;
                pj = j;
            }
        } else {
            for(int j=w-1; j>=0; j--){
                if(hold) ans.eb( mp(pi+1, pj+1), mp(i+1, j+1));
                hold ^= a[i][j];
                pi = i;
                pj = j;
            }
        }
    }
    printf("%lld\n",sz(ans));
    for (auto v:ans){
        printf("%lld %lld %lld %lld\n", v.first.first, v.first.second, v.second.first, v.second.second);
    }
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n,k; cin >> n >> k;
    vc d(k);
    rep(i,k)cin>>d[i];
    for(ll i = n;;i++){
        string s = to_string(i);
        bool is_res = true;
        rep(j,s.size()){
            rep(l,k){
                if(s[j] == d[l])is_res = false;
            }
        }
        if(is_res){
            out(i);
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int c=0;
    cin>>a;
    for(int i=0; i<a.size(); i++)
    {
        if(a[i]=='o')
        {
            c++;
        }
    }
    cout<<700+c*100<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main (){
    int N,K;
    cin >> N;
    cin >> K;
    int i = K;
    int cnt = 1;
    while(i<=N){
        i = K*i;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
//***********//
int main() {
	long double R;
	cin >> R;
	long double PI = 3.14159;
	R *= 2 * PI;
	cout << fixed << setprecision(12) << R;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
#define pb push_back

/*int pare(int en,int start,int par[])
{
	if(par[en]==start)
	{
		return en;
	}
	pare(par[en],start,par);
}*/

int main()
{
    int tst=1;
    //scanf("%d",&tst);
    while(tst--)
    {
		string s;
		cin >> s;
		int i,l=s.size(),c=0,cm=0,j;
		for(i=0;i<l;i++)
		{
			if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T')
			{
				c=1;
				for(j=i+1;j<l;j++)
				{
					if(s[j]=='A' || s[j]=='C' || s[j]=='G' || s[j]=='T')
					{
						c++;
					}
					else
					{
						break;
					}
				}
				cm=max(c,cm);
				c=0;
			}
		}
		cout << cm << endl;	
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
//char a[2000][2000];
using namespace std;
bool check(ll m,ll k,ll n,ll a ,ll b){
  ll rem = n-m;
  if( k > rem*b + a*m)
      return 1;
  else
    return 0;

}
int getMod(string s,int k){
  ll sum = 0;
  for(int i = 0;i<s.size();i++){
    sum = sum*10+(s[i]-'0');
    sum = sum%k;
  }
  return sum%k;

}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);            
    //std::setprecision(20);    
    int tests=1;
      //freopen("input.txt", "r", stdin);   
     // cin>>tests;
  while(tests--)
    {
      int n,a,b;
      cin>>n>>a>>b;
      cout<<min(n*a,b);

    }
    
}

Measured memory_bytes: 256
/*
memo for solution
*/
#include <cstdlib> 
#include <numeric>
#include <cstring>
#include <cstdio> 
#include <cfloat> 
#include <map> 
#include <cassert>
#include <cmath> 
#include <climits> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <iomanip>
#include<sys/time.h>
using namespace std; 
double e_time(void){static struct timeval now;gettimeofday(&now, NULL);return (double)(now.tv_sec  + now.tv_usec/1000000.0);}
#define REP(i,b,n) for(int i=b;i<n;i++) 
#define rep(i,n)      REP(i,0,n) 
#define pb push_back  
#define mp make_pair 
#define ALL(C)   (C).begin(),(C).end() 
#define fe(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr != (c).end();itr++)
#define BITSHIFT(X)     ( (1<<(X)) )
#define CONTAIN(S,X) ( ((S)&BITSHIFT(X)) != 0)
typedef complex<double>P; 
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int,int> pii; 
typedef vector<int> vint;
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}  
template<class T> T ceilUp(const T& a,const T& b){return (a+b-1)/b;}
const ll mod =   1000000009;
inline ll modadd(ll a,ll b){a %= mod;b %= mod;return (a+b)%mod;}
inline ll modsub(ll a,ll b){a %= mod;b %= mod;a-=b;a%=mod;if (a<0)a+=mod;return a;}
inline ll modmul(ll a,ll b){a %= mod;b %= mod;return (a*b)%mod;}
inline ll modeq(ll a,ll b,ll m){a = (a%m+m)%m; b = (b%m+m)%m;return a == b;}
//ll modpow(ll n,ll p){if (p == 0)return 1;if (p == 1)return n;ll ret=mypow(n,p/2);ret=ret*ret%mod;if (p&1)ret=ret*n%mod;return ret;}
//ll getinv(ll a){return mypow(a,mod-2);}
ll mypow(ll n,ll p){
  if (p == 0)return 1;
  if (p == 1)return n;
  ll ret=mypow(n,p/2);
  ret=ret*ret;
  if (p&1)ret=ret*n;
  return ret;
}

const int N = 100001;
int color[N];
struct Edge{
  int to;
  int cost;
};
vector<Edge> edge[N];
void dfs(int now, int current_color){
  if (color[now] != -1)return;
  color[now] = current_color;
  for(int i = 0;i < edge[now].size();i++){
    int next_color = current_color;
    if (edge[now][i].cost%2 == 1){
      next_color = 1-next_color;
    }
    dfs(edge[now][i].to, next_color);
  }
}

int main(){
  int n;
  cin >> n;
  fill(color, color+n, -1);
  for(int i = 0;i < n-1;i++){
    int f, t , w;
    cin >> f >> t >> w;
    f--;t--;
    edge[f].push_back((Edge){t, w});
    edge[t].push_back((Edge){f, w});
  }
  dfs(0, 0);
  rep(i,n)cout << color[i] << endl;
  return 0;
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int>arr(n);
	for(int i=0;i<n;i++)
	   cin>>arr[i];
	vector<int>dp(n,INT_MAX);
	dp[n-1]=0;
	for(int i=n-2;i>=0;i--)
	{
	    for(int j=1;j<=k && j<n;j++)
		{
			if((i+j)<n)
			    dp[i]=min(dp[i],dp[i+j]+abs(arr[i]-arr[i+j]));
		}	
	} 
	cout<<dp[0]<<"\n";
	
}

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

using namespace std;



int mod(int a, int b){
  if(a>b)
    return a-b;
  return b-a;
}

int maximum(int a, int b)
{
  if(a>b)
    return a;
  return b;
}

int main(){
  string s,t;
  cin >> s >> t;
  int x=s.size(), y= t.size();
  int dp[x+1][y+1];
  for(int i=0;i<=x;i++)
    for(int j=0;j<=y;j++)
        dp[i][j]=0;
  for(int i=1;i<=x;i++) {
      for(int j=1;j<=y;j++) {
          //cout << i << " " << j << " " << s[i-1] << " " << t[j-1] << endl;
          if(s[i-1]==t[j-1]){
              dp[i][j] = 1+dp[i-1][j-1];
          }
          else
          {
              dp[i][j]=maximum(dp[i-1][j], dp[i][j-1]);
          }
          //cout << dp[i][j] << " ";
      }
      //cout << endl;
  }
  int ans=dp[x][y];
  int i=x,j=y;
  string res="";
  while(i>0 && j>0){
      if(s[i-1]==t[j-1]){
          i--;
          j--;
          res=s[i]+res;
      }
      else if(dp[i-1][j]>=dp[i][j-1]){
          i--;
      }
      else{
          j--;
      }
  }
  cout << res<< endl;
  return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

typedef pair<int, int> P;

int main() {
    int N, K;
    cin >> N >> K;
    int mx = (N - 1) * (N - 2) / 2; // 作成可能な最短距離が2である頂点対の最大値
    if (mx < K) {
        puts("-1");
        return 0;
    }

    vector<P> ans;
    rep(i, N - 1) {
        ans.push_back(P(i + 1, N)); // グラフの形状がスターになるように頂点1～n-1を頂点Nと結ぶ
    }

    // 辺を追加して最短距離が2である頂点対の個数を減らしていく
    int add = mx - K; // 追加する辺の個数
    vector<P> edge;
    rep(i, N - 1) rep(j, i) edge.push_back(P(i + 1, j + 1)); // 頂点i,j(i>j && i<N)間の辺の候補を作成
    rep(i, add) ans.push_back(edge[i]); // add個分だけ辺を追加する

    cout << ans.size() << endl;
    rep(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}


Measured memory_bytes: 384
using System;
using System.Linq;

namespace AGC010
{
    class A
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int count = 0;
            for (int i = 0; i < N; i++)
            {
                if (n[i] % 2 != 0) count++;
            }

            if (count % 2 != 0) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}


Measured memory_bytes: 19552
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

n,r=map(int,input().split())
x2 = Base_10_to_n(n, r)
print( len(x2) )

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int x,y; cin >> x >> y;

    cout << x + (y / 2) << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,l;
    vector<string> s;
    cin >> n >> l;
    REP(i,n){
        string temp;
        cin >> temp;
        s.push_back(temp);
    }
    SORT(s);
    REP(i,n){
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

doTest=0

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    a=[]
    b=[]
    n,m=list(map(int, readline().strip().split()))
    for _ in range(n):
        a.append(readline().strip())
    for _ in range(m):
        b.append(readline().strip())

    hikaku=""
    for one in b:
        hikaku += one

    #n*n
    #m*m
    for i in range(n-m+1):
        for j in range(n-m+1):
            tmp=""
            for k in range(m):
                tmp+=str(a[j+k])[i:i+m]
            if tmp==hikaku:
                print("Yes")
                return
    print("No")

    return

if doTest==0:
    resolve()
    sys.exit()

Measured memory_bytes: 5688
import copy
n = int(input())
graph = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(int,input().split())
    graph[a-1].append([c,b-1])
    graph[b-1].append([c,a-1])
q,k = map(int,input().split())
wait = [k-1]
d = [0]*n
done = [False]*n
while wait:
    nxt = []
    for i in wait:
        for l in graph[i]:
            if not done[l[1]]:
                done[l[1]] = True
                d[l[1]] = d[i] + l[0]
                nxt.append(l[1])
    wait = copy.copy(nxt)


for i in range(q):
    x,y = map(int,input().split())
    print(d[y-1]+d[x-1])

Measured memory_bytes: 93216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int count = sc.nextInt();
		int answer = 1;
		int before = sc.nextInt();
		for(int i =1;i < count; i++) {
			int after = sc.nextInt();
			if(before >= after) {
				answer++;
				before = after;
			}
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 64444
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

#ifdef EBUG
#define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n";
#else
#define debug(x)
#endif

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

int main() {
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    if (w >= v) {
        cout << "NO" << endl;
        return 0;
    }
    if (abs(a-b) <= abs(v-w) * t) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}


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

using ll = long long;
using pii = pair<int, int>; using pll = pair<ll, ll>;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ s >> p.first >> p.second; return s;}

int main()
{
    int N; cin >> N;
    map<string, int> m;
    rep(i, N) {
        string s;
        cin >> s;
        m[s]++;
    }

    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}


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

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

    while(~scanf("%d %d %d",&a,&b,&c))
    {
        if(c>=a&&c<=b)
        printf("Yes\n");
       else
         printf("No\n");


    }
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="Y"){
            cout<<"Four"<<endl;
            return 0;
        }
    }

    cout<<"Three"<<endl;
}

Measured memory_bytes: 256