akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<int>l;
	int a;
	int x, y, z;
	while (cin >> x >> y >> z) {
		if (x == -1 && y == -1 && z == -1)break;
		l.push_back(120 * 60 - z - y * 60 - x * 60 * 60);
	}
	for (int i : l) {
		a = i;
		int x, y, z;
		z = a % 60;
		a -= z;
		a /= 60;
		y = a % 60;
		a -= y;
		x = a / 60;
		cout << '0' << x << ':';
		if (y >= 10)cout << y << ':';
		else cout << '0' << y << ':';
		if (z >= 10)cout << z << endl;
		else cout << '0' << z << endl;
		a = i * 3;
		z = a % 60;
		a -= z;
		a /= 60;
		y = a % 60;
		a -= y;
		x = a / 60;
		cout << '0' << x << ':';
		if (y >= 10)cout << y << ':';
		else cout << '0' << y << ':';
		if (z >= 10)cout << z << endl;
		else cout << '0' << z << endl;
	}
	char c;
	cin >> c;
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;

int main(){
    ll n; cin >> n;
    ll p[30];
    for(int i=0;i<n;++i){
        cin >> p[i];
    }
    ll ans = 0;
    for(int i=1;i<n-1;++i){
        //priority_queue<ll> pq;
        if(p[i] > p[i-1] && p[i] <= p[i+1]){
            ++ ans;
        }else if(p[i] <= p[i-1] && p[i] > p[i+1]) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n;
    cin>>n;
    ll a[n],b[n];
    rep(i,n){
        cin>>b[i];
    }
    rep(i,n){
        cin>>a[i];
    }
    priority_queue<pair<ll,ll>, vector<pair<ll,ll> > ,greater<pair<ll,ll> > > pq;
    rep(i,n){
        ll diff = a[i]-(a[(i+n-1)%n]+a[(i+n+1)%n]+b[i]);
        DEBUG{cout << diff << endl;}
        if(diff>=0){
            pq.push(make_pair(diff,i));
        }
    }
    ll cnt=0;
    DEBUG{
        cout << pq.size() << endl;
    }
    while(!pq.empty()){
        ll cur = pq.top().second;
        ll val = pq.top().first;
        pq.pop();
        cnt+=(a[cur]-b[cur])/(a[(cur-1+n)%n]+a[(cur+1+n)%n]);
        a[cur] = (a[cur]-b[cur])%(a[(cur-1+n)%n]+a[(cur+1+n)%n])+b[cur];
        // a[cur] -= a[(cur-1+n)%n]+a[(cur+1+n)%n];
        DEBUG{
            cout << "cnt : "<<cnt<< " cur : " << cur << " val : "<< val << endl;
        }
        assert(cur>=0&&cur<=n-1);
        for(ll i=cur-1;i<=cur+1;i+=2){
            ll diff = a[(i+n)%n]-(a[(i+n-1)%n]+a[(i+n+1)%n]+b[(i+n)%n]);
            if(diff>=0){
                pq.push(make_pair(diff,(i+n)%n));
            }
        }
    }
    rep(i,n){
        if(a[i]!=b[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 6260
import fractions

a, b, c, d = map(int, input().split())

lcm = c*d // fractions.gcd(c,d)


b_num = b - (b//c + b//d - b//lcm)
a_num = a-1 - (a-1)// c - (a-1)//d + (a-1) // lcm

ans = b_num - a_num
print(ans)

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

void Solve(){
	int n;
	cin>>n;
	map<int, int> mm;
	long long sum = 0;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		++mm[a];
		sum += a;
	}
	int q;
	cin>>q;
	while(q--){
		int x, y;
		cin>>x>>y;
		sum -= (long long)x * mm[x];
		mm[y] += mm[x];
		sum += (long long)y * mm[x];
		mm[x] = 0;
		cout<<sum<<'\n';
	}

}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T = 1;
	//cin>>T;
	while(T--){
		Solve();
	}
}

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

int main(){
    string A, B;
    cin >> A >> B;
    if(A.size()>B.size()){
        cout << "GREATER" << endl;
    }else if(A.size()<B.size()){
        cout << "LESS" << endl;
    }else{
        if(A>B){
            cout << "GREATER" << endl;
        }else if (A<B){
            cout << "LESS" << endl;
        }else{
            cout << "EQUAL" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

ll dp[110][110000];

int main(){
  for(int i=0;i<110;i++){
    for(int j=0;j<110000;j++) dp[i][j]=INF;
  }
  ll N,W,w[110],v[110];
  cin>>N>>W;
  for(int i=1;i<=N;i++){
    cin>>w[i]>>v[i];
  }
  
  dp[0][0]=0;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=MAX;j++){
      dp[i][j]=dp[i-1][j];
      if(j-v[i]>=0) dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
    }
  }
  ll ans=0;
  for(int i=0;i<=MAX;i++){
    if(dp[N][i]<=W) ans=i;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 94848
#import numpy as np
import math

H, N = map(int, input().split())
#mahou = np.array([list(map(int, input().split())) for _ in range(N)])
mahou = [list(map(int, input().split())) for _ in range(N)]


dp = [float("inf")]*(H+1)
dp[0] = 0

for h in range(H):
  for d, m in mahou:
    new_hp = min(h + d, H)
    dp[new_hp] = min(dp[new_hp], dp[h] + m)
print(int(dp[-1]))


Measured memory_bytes: 43996
#include<bits/stdc++.h>
using namespace std;
int n,m;
priority_queue<int>q;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        q.push(x);
    }
    while(m--)
    {
        int now=q.top();q.pop();
        q.push(now/2);
    }
    long long ans=0;
    while(!q.empty()) ans+=q.top(),q.pop();
    printf("%lld\n",ans);
}


Measured memory_bytes: 892
import sys

for i in sys.stdin:
    a,b=list(map(int, i.split()))
    d=a*b
    if a>b:
        temp=a
        a=b
        b=temp
    c=a%b
    while c!=0:
        a=b
        b=c
        c=a%b
    g=b
    l=int(d/g)
    print("{} {}".format(g,l))

Measured memory_bytes: 5596
#include<stdio.h>
int main(void){
	int a,b,c,i,n=0;
	while(1){
		if(scanf("%d",&a)==EOF){
			break;
		}	
		scanf("%d",&b);
		c=a+b;
		
		while(1){
			c=c/10;
			n=n+1;
			if(c==0){
				printf("%d\n",n);
				n=0;
				break;
			}
		}
	}
	return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    string s,ans="YES";cin>>s;
    int sz=s.size();
    reverse(all(s));
    int p=0;
    while(true){
        if(p>=sz)break;
        if(s.substr(p,5)=="maerd")p+=5;
        else if(s.substr(p,5)=="esare")p+=5;
        else if(s.substr(p,6)=="resare")p+=6;
        else if(s.substr(p,7)=="remaerd")p+=7;
        else {ans="NO";break;}
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3768
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)




#ifdef _MSC_VER
#include <intrin.h>

#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>



using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << endl
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;
void Yes(bool cond) { cout << (cond ? "Yes" : "No") << '\n'; }
void YES(bool cond) { cout << (cond ? "YES" : "NO") << '\n'; }

void solve() {
	int D, T, S; cin >> D >> T >> S;
	Yes(S*T >= D);
}



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

	//int q;
	//cin >> q;
	//while (q--)
	solve();

}



Measured memory_bytes: 3676
import fractions
import math
A,B=map(int,input().split())

x=fractions.gcd(A,B)

l=[]
for i in range(2, math.floor(math.sqrt(x))+1):
  count=0
  while x%i==0:
    count+=1
    x/=i
  if count>=1:
    l.append([i,count])
if x>math.floor(math.sqrt(x)):
  l.append([x, 1])
print(len(l)+1)




Measured memory_bytes: 5556
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=3007;
const ll mod=1000*1000*1000+7;

int n, m;

ll dp[nax][nax][2];

ll wyn;

void dod(ll &a, ll b)
{
	a=(a+b)%mod;
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i=0; i<=n; i++)
		dp[0][i][0]=1;
	for (int i=0; i<m; i++)
	{
		for (int j=0; j<=n; j++)
		{
			for (int l=0; l<2; l++)
			{
				if (j)
				{
					dod(dp[i+1][j][l|(j==1)], dp[i][j][l]);
					dod(dp[i+1][j-1][l|(j==1)], dp[i][j][l]);
				}
				if (j<n)
				{
					dod(dp[i+1][j][l|(j==0)], dp[i][j][l]);
					dod(dp[i+1][j+1][l|(j==0)], dp[i][j][l]);
				}
			}
		}
	}
	for (int j=0; j<=n; j++)
		dod(wyn, dp[m][j][1]);
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 141312
import random
import copy
import numpy as np


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]

    t = [0] * D

    # ペナルティが多い順にindexを並べる
    penalty = np.array(c)
    for i in range(D):
        ind = 0
        tmp = 0
        for j in range(26):
            if penalty[j] + s[i][j] > tmp:
                tmp = penalty[j] + s[i][j]
                ind = j
        penalty[ind] = 0
        t[i] = ind + 1
        for j in range(26):
            penalty[j] += c[j]

    for tt in t:
        print(tt)


def calc(s, c, t):
    d = [0] * 26

    ans = 0
    days = 0
    for tt in t:
        for i in range(26):
            d[i] += 1
        d[tt-1] = 0
        ans += s[days][tt-1]
        for i in range(26):
            ans -= d[i] * c[i]
        days += 1
        print(ans)

    return ans


if __name__ == "__main__":
    main()


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

int main(){
  string str1,str2;

  while(cin >> str1, str1!="."){
    cin >> str2;
    bool frg = true;
    int er_cnt = 0;
    int j=0;
    int v1_cnt = 0;
    int v2_cnt = 0;
    for(int i=0; i<str1.size(); ++i){
      vector<char> v1;
      vector<char> v2;

      while(str1[i]!= '"' && i<str1.size()){
	v1.push_back(str1[i]);
	++i;
      }
      
      while(str2[j]!='"' && j<str2.size()){
	v2.push_back(str2[j]);
	++j;
      }
      ++j;
      
      if(v1!=v2 || v1.size()!=v2.size()){
	if(frg == true){
	  er_cnt = er_cnt+2;
	}else if(frg == false){
	  ++er_cnt;
	}
      }
      frg = !frg;
    }
    for(auto i: str1){
      if(i=='"'){++v1_cnt;}
    }
    for(auto i: str2){
      if(i=='"'){++v2_cnt;}
    }
    if(v1_cnt != v2_cnt){
      er_cnt = er_cnt + 2;
    }

    if(er_cnt == 0){
      cout << "IDENTICAL" << endl;
    }else if(er_cnt == 1){
	cout << "CLOSE" << endl;
      }else{
      cout << "DIFFERENT" << endl;
    }
    
  }
  return 0;
}



Measured memory_bytes: 3168
s = input()
t = input()
ans = len(t)

for i in range(len(s)-len(t)+1):
  ss = s[i:i+len(t)]
  count = 0
  for x,y in zip(t, ss):
    if x==y:
      count += 1
    ans = min(ans, len(t)-count)
  
print(ans)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int table[3][3],tmp[3][3];

void copy_table(){

	for(int row = 0; row < 3; row++){
		for(int col = 0; col < 3; col++){

			tmp[row][col] = table[row][col];
		}
	}
}

int main(){

	for(int row = 0; row < 3; row++){
		for(int col = 0; col < 3; col++){

			scanf("%d",&table[row][col]);
		}
	}

	copy_table();

	//2列,3列から1列を引く
	for(int col = 1; col <= 2; col++){
		for(int row = 0; row < 3; row++){

			tmp[row][col] -= tmp[row][0];
			if(row > 0 && tmp[row][col] != tmp[row-1][col]){
				//縦が全て同じにならないなら不可
				printf("No\n");
				return 0;
			}
		}
	}

	copy_table();

	for(int row = 1; row <= 2; row++){
		for(int col = 0; col < 3; col++){

			tmp[row][col] -= tmp[0][col];
			if(col > 0 && tmp[row][col] != tmp[row][col-1]){
				//横が全て同じにならないなら不可
				printf("No\n");
				return 0;
			}
		}
	}

	//あとは、a[1]+b[1] == c[1,1]となる任意の整数を選べば、残りの変数は自動決定する
	printf("Yes\n");

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int n,a[15];
void dfs(int step,int pre){//pre记录之前出现的最大字母
	int i,j,now;
	if(step==n){
		for(j=0;j<n;j++)printf("%c",a[j]+'a');
		printf("\n");
		return ;
	}
	now=min(step,pre+1);//当前字母可选范围
	for(i=0;i<=now;i++){
		a[step]=i,pre=max(pre,i);
		dfs(step+1,pre);
	}
}
int main(){
	scanf("%d",&n);
	dfs(0,-1);
	return 0;
}

Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define lint long long
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = 1e-9;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	if (!b)return T(1);
	if (b & 1)return mypow(a, b - 1) * a;
	T memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int n;
unsigned lint a[100010];
std::pair<unsigned lint,unsigned lint> p[100010];
int main(){
	std::cin>>n;
	n++;
	rep(i,n)std::cin>>a[i];
	if(n==1){
		if(a[0]==1)std::cout<<1<<std::endl;
		else std::cout<<-1<<std::endl;
		return 0;
	}
	if(a[0]){
		std::cout<<-1<<std::endl;
		return 0;
	}
	p[n-1]=std::make_pair(a[n-1],a[n-1]);
	for(int i=n-2;i>0;i--){
		p[i]=std::make_pair((p[i+1].first+1)/2+a[i],p[i+1].second+a[i]);
	}
	if(2<p[1].first){
		std::cout<<-1<<std::endl;
		return 0;
	}
	unsigned lint ans=1,now=1;
	REP(i,n-1){
		now=std::min(p[i].second,(now-a[i-1])*2);
		ans+=now;
	}
	std::cout<<ans<<std::endl;
	return 0;
}

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

int main()
{
  int n,m;
  map<int,int>cm;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    int t;
    cin>>t;
    cm[t]++;
  }
  
  set<int>ds;
  map<int,int>dm;
  cin>>m;
  for(int i=0;i<m;i++)
  {
    int t;
    cin>>t;
    dm[t]++;
    ds.insert(t);
  }
  for(auto t:ds )
  {
    if(dm[t]>cm[t])
    {
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >>b >>c;
  for(int i = 1; i<=b; i++){
    if(i*a%b==c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
# https://juppy.hatenablog.com/entry/2019/04/05/%E8%9F%BB%E6%9C%AC_Python_%E3%83%97%E3%83%A9%E3%82%A4%E3%82%AA%E3%83%AA%E3%83%86%E3%82%A3%E3%82%AD%E3%83%A5%E3%83%BC_2_heapq_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3
import heapq
#これを加える！！！！
def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

n,m,*a = map(int, open(0).read().split())


# a = [1,7,3,5,4]

# #heapify
# #配列a = [1,7,3,5,4]をheapにする
heapq._heapify_max(a)
# print(a) #[7, 5, 3, 1, 4]

# #heappop
# #最大値の取り出し
# print(_heappop_max(a)) #7
# print(a) #[5, 4, 3, 1]

# #heappush
# #要素(2)の挿入
# _heappush_max(a,2)
# print(a) #[5, 4, 3, 1, 2]

# #最大値の取り出し
# print(_heappop_max(a)) #5
s = sum(a)
d = 0
for i in range(m):
  t = _heappop_max(a)
  d += t-t//2
  _heappush_max(a, t//2)
  # print(a)

print(s-d)

Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=998244353;
vector<ll>ans;

ll add(ll a, ll b)  {return ( (a%mod) + (b%mod) )%mod;}

ll multiply(ll a, ll b) {return ((a%mod) * (b%mod))%mod;}

ll power(ll a, ll b)
{
    if(b==0) return 1;
    ll temp=power(a,b/2);
    if(b%2==1) return multiply(temp,multiply(temp,a));
    else return multiply(temp,temp);
}

int main()
{
  //vector<ll>v(5);
  for(int i=0;i<5;i++)
  {
      ll a;
      cin>>a;
      if(a==0)
      {
          cout<<i+1<<"\n";
      }
  }
}

Measured memory_bytes: 3568
#include <iostream>
#include <set>

using namespace std;

int main(void) {
    string s;
    cin>>s;
    set<char> sc;
    for (int i=0; i<s.size(); ++i) {
        sc.insert(s[i]);
    }
    if (s.size() == sc.size()) {
        cout<<"yes"<<endl;
    } else {
        cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int n;
  cin>>n;
  while(n--){
    int ans=1;
    for(int i=0,a,p=0,q=0;i<10;++i){
      cin>>a;
      if(ans){
          if(p>=a&&q>=a) ans=0;
          else{
            if(p>q) (p<a)?p=a:q=a;
            else (q<a)?q=a:p=a;
          }
      }
    }
    cout<<(ans?"YES":"NO")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100000)
#define INF (1000000000)

using namespace std;

int main() {
  // read inputs
  int N, vss[MAX_N][3];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d", &vss[i][0], &vss[i][1], &vss[i][2]);
  }

  // solve dp
  int dpss[MAX_N + 1][3];
  // initialize
  for (int j = 0; j < 3; j++) {
    dpss[N][j] = 0;
  }
  // update
  for (int i = N - 1; i >= 0; i--) {
    for (int j = 0; j < 3; j++) {
      int dp = -INF;
      for (int k = 0; k < 3; k++) {
        if (k != j) {
          dp = max(dp, dpss[i + 1][k] + vss[i][k]);
        }
      }
      dpss[i][j] = dp;
    }
  }
  printf("%d\n", max(dpss[0][0], max(dpss[0][1], dpss[0][2])));
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    ll n = s.length();
    ll ans = n*(n-1)/2;
    vector<ll> cnt(26, 0);
    for(char c : s) cnt[c-'a']++;
    for(int i = 0; i < 26; i++){
        ans -= cnt[i]*(cnt[i]-1)/2;
    }
    cout << ans+1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
ll cmb(ll n, ll k)
{
    ll tmp=1;
    REP(i,k){
        tmp=tmp*n;
        n--;
        tmp %= MOD;
        tmp=tmp*modinv(k-i,MOD)%MOD;
    }
    return tmp;
}
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans=modpow(2,n,MOD)-1;
    ll tmp=cmb(n,a)+cmb(n,b);
    ans-=tmp;
    ans%=MOD;
    if(ans<0){
        ans+=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 100 + 10;
const int Mod = 1e9 + 7;
int N, M;
int A[MAXN];
int f[MAXN][MAXN][MAXN];
int ans;

int main() {
	register int i, j, k, u, l, r;
	scanf("%d", &N); M = (N << 1) - 1;
	for(i = M; i; --i)
		scanf("%d", A + i);
	sort(A + 1, A + M + 1);
	f[N][0][0] = 1;
	for(i = N; i > 1; --i) {
		l = (A[i] != A[i - 1]); r = (A[M - i + 1] != A[M - i + 2]);
		for(j = M - (i << 1) + 1; ~j; --j)
			for(k = M - (i << 1) + 1; ~k; --k)
				if(f[i][j][k]) {
					(f[i - 1][j + l][k + r] += f[i][j][k]) %= Mod;
					for(u = 0; u < j + l; ++u)
						(f[i - 1][u][k + r + 1] += f[i][j][k]) %= Mod;
					for(u = 0; u < k + r; ++u)
						(f[i - 1][j + l + 1][u] += f[i][j][k]) %= Mod;
				}
	}
	for(i = 0; i <= M; ++i)
		for(j = 0; j <= M; ++j)
			(ans += f[1][i][j]) %= Mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3456
n, k = map(int, input().split())
*a, = map(int, input().split())
d = {}
for i in a:
    d[i] = d.get(i, 0)+1
cnt = len(d)
ans = 0
for _, i in sorted(d.items(), key=lambda x: x[1]):
    if cnt <= k:
        break
    ans += i
    cnt -= 1
print(ans)

Measured memory_bytes: 38964
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;

	vector<string> s(h);
	REP(i, h) cin >> s[i];

	vvi cost(h, vi(w, INF));
	queue<pair<int, int> > que;
	REP(i, h){
		REP(j, w){
			if(s[i][j] == '#'){
				cost[i][j] = 0;
				que.push(make_pair(i, j));
			}
		}
	}

	int dy[] = { -1,0,0,1 }, dx[] = { 0,-1,1,0 };
	int ans = 0;
	while(!que.empty()){
		pair<int, int> tmp = que.front();
		que.pop();
		int y = tmp.first, x = tmp.second;
		REP(i, 4){
			int ny = y + dy[i], nx = x + dx[i];
			if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
			if(s[ny][nx] == '.'){
				cost[ny][nx] = min(cost[ny][nx], cost[y][x] + 1);
				ans = max(ans, cost[ny][nx]);
				s[ny][nx] = '#';
				que.push(make_pair(ny, nx));
			}
		}
	}

	cout << ans << endl;
}//解答解説参考.

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

int main(){
  string a;
  cin >> a;
  if(a.at(2)==a.at(3) && a.at(4) == a.at(5)){
    cout <<"Yes"<< endl;
  }
  else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9+5)
#define INFLL ((LL)4e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<string> line(N);
	REP(i, N){
		cin >> line[i];
		sort(ALL(line[i]));
	}
	sort(ALL(line));
	string bn = line[0];
	LL count = 1;
	LL ans = 0;
	REPA(i, N){
		if(bn == line[i]){
			++count;
		}else{
			ans += count * (count - 1) / 2;
			count = 1;
			bn = line[i];
		}
	}
	ans += count * (count - 1) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7296
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    string s;
    cin >> s;

    int ret = 700;
    for(int i=0; i<s.length(); i++){
        if(s[i] == 'o') ret += 100;
    }
    cout << ret << endl;

    return 0;
}



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

int main() {
	long long a, b, n, x;
	cin >> a >> b >> n;
	x = n < b ? n : b - 1;
	if (x == 0)
		x++;
	cout << floor((a * x) / b) - a * floor(x / b);


	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define P           pair<int, int>
#define dint        long double

void solve() {
    int n, a, b, c; cin >> n >> a >> b >> c;
    string s[n+1]; s[n]="";
    vector<char> move;
    for(int i=0; i<n; i++) cin >> s[i];
    for(int i=0; i<n; i++) {
        if(s[i]=="AB") {
            if(a==0 && b==0) {
                cout << "No\n"; return;
            } if(a==1 && b==1) {
                if(s[i+1]=="AC") a++, b--, move.push_back('A');
                else a--, b++, move.push_back('B');
            } else {
                if(a>b) a--, b++, move.push_back('B');
                else a++, b--, move.push_back('A');
            }
        } else if(s[i]=="BC") {
            if(b==0 && c==0) {
                cout << "No\n"; return;
            } if(b==1 && c==1) {
                if(s[i+1]=="AB") b++, c--, move.push_back('B');
                else b--, c++, move.push_back('C');
            } else {
                if(b>c) b--, c++, move.push_back('C');
                else b++, c--, move.push_back('B');
            }
        } else {
            if(a==0 && c==0) {
                cout << "No\n"; return;
            } if(a==1 && c==1) {
                if(s[i+1]=="AB") a++, c--, move.push_back('A');
                else a--, c++, move.push_back('C');
            } else {
                if(a>c) a--, c++, move.push_back('C');
                else a++, c--, move.push_back('A');
            }
        }
    }
    cout << "Yes\n";
    for(char c : move) {
        cout << c << endl;
    }
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve();
    }
    return 0;

}



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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, K;
  cin >> N >> K;
  int d;

  vector<int> count(N, 0);

  REP(i, K) {
    cin >> d;
    int a;
    REP(j, d) {
      cin >> a;
      --a;
      ++count.at(a);
    }
  }

  int ans = 0;
  REP(i, N) {
    if (count.at(i) == 0) {
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n][3];
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    int ans=0;
    int dp[n][3]={};
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];

    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
               if(k!=j) dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
            }
        }
    }
    ans=max(dp[n-1][0],max(dp[n-1][2],dp[n-1][1]));
    cout<<ans;
    
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(void){
	int N,R;
	scanf("%d %d",&N,&R);
	if(N<10){
		printf("%d",R+100*(10-N));
	}else{
		printf("%d",R);
	}

}


Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int x[110000];
int y[110000];
int UF[110000];
int FIND(int a){
	if(UF[a]<0)return a;return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
pair<int,int>p[110000];
pair<int,int>q[110000];
pair<int,pair<int,int> > edge[210000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)UF[i]=-1;
	for(int i=0;i<a;i++){
		scanf("%d%d",x+i,y+i);
		p[i]=make_pair(x[i],i);
		q[i]=make_pair(y[i],i);
	}
	std::sort(p,p+a);
	std::sort(q,q+a);
	int sz=0;
	for(int i=0;i<a-1;i++){
		edge[sz++]=make_pair(p[i+1].first-p[i].first,make_pair(p[i].second,p[i+1].second));
		edge[sz++]=make_pair(q[i+1].first-q[i].first,make_pair(q[i].second,q[i+1].second));

	}
	std::sort(edge,edge+sz);
	long long ret=0;
	for(int i=0;i<sz;i++){
		if(FIND(edge[i].second.first)!=FIND(edge[i].second.second)){
			ret+=edge[i].first;
			UNION(edge[i].second.first,edge[i].second.second);
		}
	}
	printf("%lld\n",ret);
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

int main() {
  ll N; cin >> N;
  vector<ll> a(N); REP(i, N) cin >> a[i];

  ll A = 0;
  ll B = 0;

  A = a[0];
  REP(i, N) {
    if(i == 0) continue;
    B += a[i];
  }

  ll C = 0;
  ll ans = 999999999999999999;
  REP(i, N - 1) {
    if(i != 0) {
      A += a[i];
      B -= a[i];
    }

    C = abs(A - B);
    if(ans > C) ans = C;
    // cout << A << " " << B << " " << ans << endl;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i] >> b[i] >> c[i];
    }
    std::vector<int> dp[3];
    for (int i = 0; i < 3; i++) dp[i].resize(n);
    dp[0][0] = a[0]; dp[1][0] = b[0]; dp[2][0] = c[0];
    for (int i = 1; i < n; i++) {
        dp[0][i] = std::max(dp[1][i - 1], dp[2][i - 1]) + a[i];
        dp[1][i] = std::max(dp[0][i - 1], dp[2][i - 1]) + b[i];
        dp[2][i] = std::max(dp[0][i - 1], dp[1][i - 1]) + c[i];
    }

    std::cout << std::max({ dp[0][n - 1], dp[1][n - 1], dp[2][n - 1] }) << std::endl;

    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

string S;
int N, M;
int U[100001], R[100001];
int A[100001], T[100001];
int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> S >> M;
  N = S.length();
  rep(i, N) {
    A[i] = S[i]-(i>0?S[i-1]:'a');
    if (A[i] < 0) A[i] += 26;
  }
  rep(i, N+1) U[i] = i, R[i] = 1;
  rep(i, N+1) unite(i, N-i);
  rep(i, M) {
    int l, r;
    cin >> l >> r;
    l--;
    unite(l, r);
  }
  rep(i, N+1) T[find(i)] += A[i];
  rep(i, N+1) {
    if (i == find(0)) continue;
    if (T[i] % 26) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}


Measured memory_bytes: 1872
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    string s, t; cin >> s >> t;
    t.pop_back();
    cout << (s == t ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


// 1白
// 2黒

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int co[100002]={};
	vector<P> tree[n];
	FOR(i,0,n-1){
		int a,b,w;
		cin >> a >> b >> w;
		a--;b--;
		tree[a].push_back({b,w});
		tree[b].push_back({a,w});
	}
	queue<int> q;
	q.push(0);
	co[0] = 1;
	while(!q.empty()){
		int now = q.front();
		q.pop();
		for(auto to:tree[now]){
			if(co[to.first]==0){
				if(to.second%2){
					co[to.first] = 3 - co[now];
				}else{
					co[to.first] = co[now];
				}
				q.push(to.first);
			}
		}
	}
	FOR(i,0,n){
		cout << co[i]-1 << endl;
	}
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
using P = pair<string, int>;
int main() {
    queue<pair<string, int>> a;
    int n; cin >> n;
    int q; cin >> q;
    rep(i, n){
        string s;
        int t;
        cin >> s >> t;
        a.push(make_pair(s, t));
    }
    int time=0;
    while(!a.empty()){
        P p = a.front();
      	a.pop();
        if (p.second - q <=0){
            time += p.second;
          	cout << p.first << " " << time << endl;
        }
        else{
            p.second -= q;
            time += q;
            a.push(p);
        }
    }
}



Measured memory_bytes: 6320
#include<stdio.h>
int main(){
   int a,b,c;
   scanf("%d %d %d",&a,&b,&c);
   if(a==b&&a!=c &&b!=c ||a==c &&a!=b&&c!=b ||b==c &&b!=a &&c!=a){
      printf("Yes\n");
   }else{
      printf("No\n");
   }
   return 0;
}


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

int main() {
  string N;
  cin >> N;
  if(N[0] == '7'){
    cout << "Yes" <<endl;
    return 0;
  }
  if(N[1] == '7'){
    cout << "Yes" <<endl;
    return 0;
  }
  if(N[2] == '7'){
    cout << "Yes" <<endl;
    return 0;
  }
  cout << "No" <<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif


int n,m,u[N],v[N],vis[N];
struct _ {int to,id;};
vector<_> g[N];
int dfs(int x, int f, int w) {
	vis[x] = 1;
	int cnt = 0;
	for (_ e:g[x]) if (e.to!=f) {
		int y=e.to,id=e.id;
		if (vis[y]) {
			if (!u[id]) { 
				u[id]=x,v[id]=y,++cnt;
			}
			continue;
		}
		int ok = dfs(y,x,id);
		if (ok) u[id]=x,v[id]=y,++cnt;
	}
	if (cnt&1) {
		if (!f) puts("-1"),exit(0);
		u[w]=x,v[w]=f;
		return 0;
	}
	else return 1;
}
int main() {
	scanf("%d%d",&n,&m);
	REP(i,1,m) {
		int u,v;
		scanf("%d%d", &u, &v);
		g[u].pb({v,i}),g[v].pb({u,i});
	}
	dfs(1,0,0);
	REP(i,1,m) printf("%d %d\n",u[i],v[i]);
}









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

int main() {
  int N, K;
  cin >> N >> K;
  if (N == 1) cout << K << endl;
  else if (N == 2) cout << K * (K-1) << endl;
  else {
    long long s = K;
    for (int i=1; i<N; i++)
      s *= K-1;
    cout << s << endl;
  }
}

Measured memory_bytes: 256
/*
 * atcoder/abc119/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * S, Tを座標昇順にソートしてQ回の二分探索はどう？ O(Q x log(max(A, B)))
 * SとTそれぞれ先に訪れる２つの場合の最小値
 * S -> Tの場合)
 * Sをxで二分探索して|S[n]-x|を最小化するnを見つける.
 * 次にTをS[n]で二分探索して、|T[m]-S[n]|を最小化するmを見つける.
 * コストは|S[n]-x| + |T[m]-S[n]|
 *
 * 上記ではダメだ. 最小値を求める事ができない.
 * 以下のようなケース. x = 0, s 100 でt = 101でより小さいt1=1が存在する場合.
 * 最小値は100なのに、sから最も近いt1が選択されて101となる.
 *
 * なので、s, tともにxから最も近い2点(s1, s2, t1, t2)ずつ探して
 * s1 -> t1
 * s1 -> t2
 * s2 -> t1
 * s2 -> t2
 * tも同様につき8通りのうち最短経路.
 *
 * 2000: s0 -> t0 が最短
 * 900 -> 600が最短
 * 100           600
 *          400          900 1000
 *                   899                               2000
 */
const ll INF = 10000000000000000;
int A, B, Q;
vector<ll> S, T;
ll x;
void solve() {
  cin >> A >> B >> Q;
  S.resize(A+2); T.resize(B+2);
  loop(i,1,A+1) cin >> S[i];
  loop(i,1,B+1) cin >> T[i];
  S[0] = T[0] = -INF;
  S[A+1] = T[B+1] = INF;
  A += 2; B += 2;
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  loop(q,0,Q) {
    cin >> x;
    vector<ll> ss;
    vector<ll> ts;
    int s_n = lower_bound(S.begin(), S.end(), x) - S.begin();
    int t_n = lower_bound(T.begin(), T.end(), x) - T.begin();
    ss.push_back(S[s_n]);
    ss.push_back(S[s_n-1]);
    ts.push_back(T[t_n]);
    ts.push_back(T[t_n-1]);
    ll min_ = INF;
    for (auto&&s: ss) for (auto&&t: ts) {
      ll cost1 = abs(x-s) + abs(s-t);
      ll cost2 = abs(x-t) + abs(s-t);
      chmin(min_, cost1);
      chmin(min_, cost2);
    }

    cout << min_ << endl;
  }
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  double ans=0;
  vector<double> a(n),b(n);
  vector<int> s(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i)>>b.at(i);
    s.at(i)=i;
  }
  do{
    for(int k=1;k<n;k++){
      int i=s.at(k),j=s.at(k-1);
      ans+=sqrt((a.at(i)-a.at(j))*(a.at(i)-a.at(j))+(b.at(i)-b.at(j))*(b.at(i)-b.at(j)));
    }
  }while(next_permutation(s.begin(),s.end()));
  for(int i=1;i<n+1;i++)ans/=i;
  cout<<setprecision(12)<<ans<<endl;
}


Measured memory_bytes: 256