akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return

#B
def B():
    n = II()
    s = S()
    ans = 0
    for i in range(n + 1):
        s1 = list(set(s[i:]))
        s2 = list(set(s[:i]))
        b = 0
        for si in s1:
            b += si in s2
        ans = max(ans, b)
    print(ans)
    return

#C
def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    for num,si in enumerate(s):
        if si == "E":
            dp[num] = dp[num-1]+1
        else:
            dp[num] = dp[num - 1]
    ans = float("INF")
    a = max(dp)
    for i in range(n):
        ans = min(ans,  a - dp[i] + i - dp[i] + (s[i] == "E"))
    
    print(ans)
    return

#D
def D():
    return



#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 40432
N,M=map(int,input().split())
L=[]
for i in range(M):
    a,b=map(int,input().split())
    L.append((a,b))

L_new=sorted(L,key=lambda x:x[1])
#print(L_new)
T=L_new[0][1]-1
count=1
for j in range(1,M):
    if L_new[j][0]<=T:
        pass
    else:
        count+=1
        T=L_new[j][1]-1

print(count)





Measured memory_bytes: 18972
#include <stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    int a[n],b[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=0;i<n;i++) b[a[i]-1]=i+1;
    for(i=0;i<n-1;i++) printf("%d ",b[i]);
    printf("%d\n",b[n-1]);
    return 0;
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    string o, e;
    cin >> o >> e;
    fo(i, (int) max(o.size(), e.size())) {
        if ( i < (int) o.size() ) {
            cout << o[i];
        }
        if ( i < (int) e.size() ) {
            cout << e[i];
        }
    }
    cout << endl;

    return 0;
}

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

using namespace std;

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

    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }

    cout << (h * w + 1) / 2 << endl;

    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int n = (int) s.size();
  vector<int> tmp, asw(n, 0);
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') {
      tmp.push_back(i);
    } else {
      while (not tmp.empty()) {
        int d = i - tmp.back();
        if (d % 2) {
          ++asw[i - 1];
        } else {
          ++asw[i];
        }
        tmp.pop_back();
      }
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'L') {
      tmp.push_back(i);
    } else {
      while (not tmp.empty()) {
        int d = tmp.back() - i;
        if (d % 2) {
          ++asw[i + 1];
        } else {
          ++asw[i];
        }
        tmp.pop_back();
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i > 0) {
      cout << " ";
    }
    cout << asw[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1480
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,s=0,x=0,i;
    char m[101];
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
    	if(m[i]=='I') s++;
		else s--;
		if(s>x) x=s; 
	}
	cout<<x;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

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

    ll sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        ll tmp = a[n] - a[i + 1];
        tmp %= MOD;
        sum += tmp * v[i];
        sum %= MOD;
    }
    cout << sum << endl;
}

Measured memory_bytes: 6424
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n;
P p[max_n];
int r[max_n];
int dp[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x,y;scanf("%d%d",&x,&y);
        p[i].fi=x+y,p[i].se=x-y;
    }
    sort(p+1,p+n+1);
    int ans=1;
    int mx=p[1].fi;
    for(int i=2;i<=n;i++){
        if(p[i].se>=mx){
            ans++;
            mx=p[i].fi;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
from operator import itemgetter

N = int(input())
score = []
for _ in range(N):
    a, b = map(int, input().split())
    score.append((a, b, a+b))

score.sort(key=itemgetter(2), reverse=True)

ans = 0
for i in range(N):
    if i%2 == 0:
        ans += score[i][0]
    else:
        ans -= score[i][1]
print(ans)

Measured memory_bytes: 22168
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int H = scan.nextInt();
        int M = scan.nextInt();

        double ax = A*Math.cos(Math.toRadians(90-30*H-M/2.0));
        double ay = A*Math.sin(Math.toRadians(90-30*H-M/2.0));
        double bx = B*Math.cos(Math.toRadians(90-6*M));
        double by = B*Math.sin(Math.toRadians(90-6*M));

        double ans = Math.sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));

        os.println(ans);
    }


}

Measured memory_bytes: 27180
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		BufferedReader r =
		        new BufferedReader(new InputStreamReader(System.in), 1);
		String s = r.readLine();
		
		if( s.charAt(0) ==  'a' || s.charAt(0) == 'i' || s.charAt(0) ==  'u' ||s.charAt(0) ==  'e' || s.charAt(0) ==  'o'){
			System.out.println("vowel");
		}
		else{
			System.out.println("consonant");
		}
		
		
	}
	
}


Measured memory_bytes: 8148
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {

    int n, A[1000];

    while (true) {
        cin >> n;
        if (n == 0) break;

        for (int i = 0; i < n; ++i) cin >> A[i];

        int sum = 0;
        for (int i = 0; i < n; ++i) sum += A[i];

        double avg = 1.0 * sum / n;
        double dist = 0.0;
        for (int i = 0; i < n; ++i) {
            dist += (avg - A[i]) * (avg - A[i]);
        }

        printf("%lf\n", sqrt(dist / n));
    }
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    vector<int> res;
    vector<int> L(N , 0);
    for (int i = 0; i < N; i++) {
        if (S[i] == 'o') L[i] = i >= C + 1 ? L[i - C - 1] + 1 : 1;
        L[i] = max(i == 0 ? 0 : L[i - 1], L[i]);
    }
    vector<int> R(N, 0);
    for (int i = N - 1; i >= 0; i--) {
        if (S[i] == 'o') R[i] = i + C + 1 < N ? R[i + C + 1] + 1 : 1;
        R[i] = max(R[i], i == N - 1 ? 0 : R[i + 1]);
    }
    // for (int i = 0; i < N; i++) cout << L[i] << " ";
    // cout << endl;
    // for (int i = 0; i < N; i++) cout << R[i] << " ";
    // cout << endl;
    vector<int> bad(N, 0);
    for (int i = 0; i < N; i++) {
        int before = i == 0 ? 0 : L[i - 1];
        int after = i == N - 1 ? 0 : R[i + 1];
        if (before + after < K) res.push_back(i + 1);
        // if (!bad[L[i]]) {
        //     res.push_back(i + 1);
        //     bad[L[i]] = 1;
        // } else if (!res.empty() && L[i] == L[res.back() - 1]) {
        //     res.pop_back();
        // }
        // for (auto v: res) cout << v << " ";
        // cout << endl;
    }
    // vector<int> nxto(N, 0);
    // int cur = N;
    // for (int i = N - 1;i >= 0 ;i--) {
    //     if (S[i] == 'o') {nxto[i] = i; cur = i;}
    //     else nxto[i] = cur;
    // }

    // vector<int> seen(N + 1, 0);
    // deque<int> q;
    // for (int i = 0; i < N; i++) {
    //     if (S[i] == 'x') break;
    //     q.push_back(i);
    //     seen[i] = 1;
    // }

    // while (!q.empty()) {
    //     if (q.size() == 1) res.push_back(q.front() + 1);
    //     deque<int> nxtq;
    //     while (!q.empty()) {
    //         int cur = q.front(); q.pop_front();
    //         if (nxto[cur] == N) continue;
    //         if (!seen[nxto[cur]]) {
    //             seen[nxto[cur]] = 1;
    //             nxtq.push_back(nxto[cur]);
    //         }
    //     }
    // }
    if (res.empty()) cout << endl; 

    for (auto v: res) {
        cout << v << endl;
    }

    return 0;
}

Measured memory_bytes: 5004
#include <iostream>
#include <bits/stdc++.h>
using namespace std ;
int main(){
  int n , flag = 1 , i ;
  std::cin >> n ;
  string s ;
  std::cin >> s ;
  if(s.size()%2==1)  printf("No") ;
  else{
    for(i=0;i<s.size()/2;++i){
      if(s[i]!=s[s.size()/2+i])	flag = 0 ;
    }
    if(flag==1)	printf("Yes") ;
    else	printf("No") ;
  }
  return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int maxn = 2000005;

void solve() {
    ll a;
    cin >> a;
    ll sum = 0;
    ll cur = a;
    f(3) {
        sum += cur;
        cur *= a;
    }
    cout << sum << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 3576
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    long long x,y;
    cin>>x>>y;
    if(x==y||y==1||x%y==0){cout<<-1<<endl;return 0;}
    for(int i=2*x;i<=1e18;i+=x){
        if(i%y!=0){cout<<i<<endl;return 0;}
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 504
#include <iostream>
    #include <sstream>
    #include <vector>
    using namespace std;
    
    //関数getinputdata宣言
    vector<vector<string>> getinputdata();

    int main(){
    
        vector<vector<string>> vec_arr_result;

        vec_arr_result=getinputdata();
 
        string t=vec_arr_result[0][0];
        string x=vec_arr_result[0][1];
       
        cout << atof(t.c_str()) / atoi(x.c_str()) << endl;
        
        return 0;
    }
    
    //関数getinputdata実装
    vector<vector<string>> getinputdata(){
    
        string str;
        string ret;
        stringstream ss;
        vector<string> v1;
        vector<vector<string>> vec_arr;
    
        //標準入力から入力がある間ループ処理でvector配列にデータ格納
        while (getline(cin, str)) {
    
            v1.push_back(str);
    
        }
    
        //stringstreamを利用してvector配列v1をスペースで分解処理
        for (string s : v1) {
    
            vector<string> array_data;
            ss << s;
    
            while (!ss.eof()) {
    
                ss >> ret;
    
                array_data.push_back(ret);
            }
    
            //vector配列に追加
            vec_arr.push_back(array_data);
    
            //バッファクリア
            ss.str("");
            //ストリームクリア
            ss.clear(stringstream::goodbit);
    
        }
    
        return vec_arr;
    
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

typedef long long int ll;
const int N = 2e5 + 10;
const ll oo = 1e18;

struct node {
  int l, r;
  node *left, *right;
  ll val, lazy;
  node(int L, int R) {
    val = lazy = 0;
    l = L, r = R;
    if(l == r) return;
    int m = (l + r) >> 1;
    left = new node(l, m);
    right = new node(m + 1, r);
  }
  void prop() {
    if(lazy == 0) return;
    val += lazy;
    left->lazy += lazy, right->lazy += lazy;
    lazy = 0;
  }
  ll get() { return val + lazy; }
  ll query_max(int L, int R) {
    if(R < l || L > r) return -oo;
    if(L <= l && r <= R) return get();
    prop();
    return max(left->query_max(L, R), right->query_max(L, R));
  }
  void update(int L, int R, ll x) {
    if(R < l || L > r) return;
    if(L <= l && r <= R) {
      lazy += x;
      return;
    }
    prop();
    left->update(L, R, x);
    right->update(L, R, x);
    val = max(left->get(), right->get());
  }
};

int n, m;
vector<pair<int, ll>> a[N];
node *st;

void solve() {
  cin >> n >> m;
  st = new node(0, n + 1);
  for(int i = 0; i < m; ++i) {
    int l, r, x;
    cin >> l >> r >> x;
    a[l].emplace_back(r, x);
    a[r + 1].emplace_back(l - 1, -x);
  }
  for(int i = 1; i <= n + 1; ++i) {
    for(auto &p : a[i]) {
      st->update(0, p.first, p.second);
    }
    ll cur = st->query_max(0, i);
    st->update(i, i, -(st->query_max(i, i))+cur);
  }
  cout << st->query_max(0, n) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(9);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 34176
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG


int main()
{
  int n;
  cin >> n; cin.ignore();

  DPRINTF("num of nodes: %d\n", n);

  bool graph[n][n];

  // init
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      graph[i][j] = 0;

  // make a graph
  for (int i = 0; i < n; i++)
  {
    int node;
    int degree;

    cin >> node >> degree;

    DPRINTF("node %d (degree %d)\n", node, degree);

    for (int j = 0; j < degree; j++)
    {
      int adj; cin >> adj;

      // note that index starts from #0 though node and adj from #1
      graph[node - 1][adj - 1] = true;
    }

    cin.ignore();
  }

  // print a graph as a matrix form
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if (j == 0)
        printf("%d", graph[i][j]);
      else
        printf(" %d", graph[i][j]);
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

string s;
int n;
ll dp[1000005][2];
int main(){
    cin>>s;
    n=s.size();
    reverse(s.begin(),s.end());
    memset(dp,0x3f,sizeof(dp));
    dp[0][0]=0;
    rep(i,n)rep(j,2){
        dp[i+1][0]=min(dp[i+1][0],dp[i][j]+(s[i]-'0')+j);
        dp[i+1][1]=min(dp[i+1][1],dp[i][j]+10-(s[i]-'0')-j);
    }
    cout<<min(dp[n][0],dp[n][1]+1)<<endl;
    return 0;
}

Measured memory_bytes: 17028
def Check(A, i, j, W, H) :
    if j-1 >= 0 :
        if A[i][j-1] == "." :
            A[i][j-1] = "+"
            Check(A, i, j-1, W, H)
    if i+1 < H :
        if A[i+1][j] == "." :
            A[i+1][j]= "+"
            Check(A, i+1, j, W, H)
    if j+1 < W :
        if A[i][j+1] == "." :
            A[i][j+1] = "+"
            Check(A, i, j+1, W, H)
    if i-1 >= 0 :
        if A[i-1][j] == "." :
            A[i-1][j] = "+"
            Check(A, i-1, j, W, H)
    return(A)

while True :
    W, H = map(int, input().split())
    if W == 0 and H == 0 :
        break
    
    Tile = [list(input()) for i in range(H)]
    for i in range(H) :
        for j in range(W) :
            if Tile[i][j] == "@" :
                my_i = i
                my_j = j
    Tile[my_i][my_j] = "+"
    Tile_new = Check(Tile, my_i, my_j, W, H)
    count = 0
    for i in range(H) :
        for j in range(W) :
            if Tile_new[i][j] == "+" :
                count += 1
    print(count)


Measured memory_bytes: 5760
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    n=int(input())
    b = list(map(int, input().split()))
    
    sum=0
    sum+=b[0]
    sum+=b[n-2]
    for i in range(n-2):
        sum+=min(b[i],b[i+1])
    print(sum)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 70508
fun main(args:Array<String>?): Unit {
    val acgt = "ACGT"
    val s = readLine()!!.trim()
    println(
            (1 .. s.length).reversed().find{length -> (0 .. s.length - length).any{from -> (from until from + length).all{s[it] in acgt}}} ?: 0
    )
}

Measured memory_bytes: 31732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    string s; cin >> s;
    for(auto c: s){
        if(c == ',')
            cout << " ";
        else
            cout << c;
    }
    puts("");
}


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

int main() {
  int n;cin>>n;
  vector<int> d(n);
  rep(i,n)cin>>d[i];
  sort(all(d));
  int ans=d[n/2]-d[n/2-1];
  cout<<ans<<endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B;
    cin >> A >> B;

    int res = -1;

    for(int i = 10000;i>=1;i--){
        if(int(i*0.08f)==A && int(i*0.1f)==B){
            res = i;
        }
    }

    cout << res << endl;

    //8%:
}

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

int main(){
  int H, W;
  while (true) {
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    } else {
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        if ((i + j) % 2 == 0){
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  }
  return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

void solve(int n, vector<int> d) {
    sort(d.begin(), d.end());
    // int l = 0;
    //int r = 0;
    //int ret = 24;
    for (int i = 0; i < d.size(); i+=2) {
        d[i] = 24 - d[i];
    }
    sort(d.begin(), d.end());
    int ret = 24;
    int a = 0;
    for (int i = 0; i < d.size(); i++) {
        ret = min(ret, d[i] - a);
        a = d[i];
    }
    ret = min(ret, 24 - d.back());
    std::cout << ret << std::endl;
}

int main() {
    struct timeval start,end;
    long long span;
    int n;

    gettimeofday(&start,NULL);

    std::cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        std::cin >> d[i];
    }
    solve(n, d);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	var outputs []string
	for _, char := range s {
		s := string(char)
		if s == "B" {
			if len(outputs) > 0 {
				outputs = outputs[:len(outputs)-1]
			}
			continue
		}
		outputs = append(outputs, s)
	}

	fmt.Println(strings.Join(outputs, ""))
}


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

using namespace std;

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

    long long a, b, k;
    cin >> a >> b >> k;
    long long rem = min(a, k);
    a -= rem; k -= rem;
    if (k) {
        rem = min(b, k);
        k -= rem; b -= rem;
    }
    cout << a << ' ' << b << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<int, int> P;

bool ps1(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first昇順
    return forall_a_in_P.first < forall_b_in_P.first;
}
bool ps2(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first降順
    return forall_a_in_P.first > forall_b_in_P.first;
}
bool ps3(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second昇順
    return forall_a_in_P.second < forall_b_in_P.second;
}
bool ps4(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second降順
    return forall_a_in_P.second > forall_b_in_P.second;
}
int main()
{
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<char>>cake(h,vector<char>(w));
    vector<vector<int>>stb(h);
    vector<vector<int>>grid(h,vector<int>(w,0));
    int cnt=0;
    vector<bool>used(h,false);
    rep(i,h)rep(j,w){
        cin>>cake[i][j];
        if(cake[i][j]=='#'){
            cnt++;
            stb[i].push_back(j);
            used[i]=true;
            grid[i][j]=cnt;
        }
    }
    rep(i,h){
        if(used[i]){
            int now=grid[i][stb[i][0]];
            rep(j,w){
                if(grid[i][j]==0){
                    grid[i][j]=now;
                }else{
                    now=grid[i][j];
                }
            }
        }
    }
    rep(i,h){
        if(!used[i]){
            FOR(j,i,h){
                if(used[j]){
                    rep(k,w){
                        grid[i][k]=grid[j][k];
                    }
                    j=h+1;
                    used[i]=true;
                }
                
            }
        }
    }
    rep(i,h){
        int ite=h-1-i;
        if(!used[ite]){
            FOR(j,i,h){
                int jte=h-1-j;
                if(used[jte]){
                    rep(k,w){
                        grid[ite][k]=grid[jte][k];
                    }
                    j=h+1;
                    used[ite]=true;
                }
            }            
        }
    }
    rep(i,h)rep(j,w){
        cout<<grid[i][j];
        if(j!=w-1){
            cout<<" ";
        }else{
            cout<<endl;
        }
    }






}

Measured memory_bytes: 1792
// AtCorder Beginner Contest 148 B.cpp
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	string str1, str2, str3;
	cin >> n >> str1 >> str2;

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

		str3 += str1[i];

		str3 += str2[i];

	}

	cout << str3 << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
#include<vector>
#define llong long long
#define pll pair<llong,llong>
#define mkpr make_pair
using namespace std;

const int N = 1<<17;
int son[N+3][2];
llong w[N+3];
vector<pll> dp[N+3];
vector<pll> aux1,aux2;
int n,en;
llong mid;

void dfs(int u)
{
//	printf("dfs %d\n",u);
	dp[u].clear(); int ls = son[u][0],rs = son[u][1];
	if(!ls)
	{
		dp[u].push_back(mkpr(0ll,0ll));
		return;
	}
	dfs(ls); dfs(rs);
	aux1.clear(); aux2.clear();
	if(dp[rs].size())
	{
		int j = 0;
		for(int i=0; i<dp[ls].size(); i++)
		{
			while(j<dp[rs].size()-1 && dp[rs][j+1].first+dp[ls][i].second+w[ls]+w[rs]<=mid) {j++;}
			if(j<dp[rs].size() && dp[rs][j].first+dp[ls][i].second+w[ls]+w[rs]<=mid) {aux1.push_back(mkpr(dp[ls][i].first+w[ls],dp[rs][j].second+w[rs]));}
		}
//	printf("aux1: "); for(int i=0; i<aux1.size(); i++) printf("(%lld,%lld) ",aux1[i].first,aux1[i].second); puts("");
	}
	if(dp[ls].size())
	{
		int j = 0;
		for(int i=0; i<dp[rs].size(); i++)
		{
			while(j<dp[ls].size()-1 && dp[ls][j+1].first+dp[rs][i].second+w[ls]+w[rs]<=mid) {j++;}
			if(j<dp[ls].size() && dp[ls][j].first+dp[rs][i].second+w[ls]+w[rs]<=mid) {aux2.push_back(mkpr(dp[rs][i].first+w[rs],dp[ls][j].second+w[ls]));}
		}
//	printf("aux2: "); for(int i=0; i<aux2.size(); i++) printf("(%lld,%lld) ",aux2[i].first,aux2[i].second); puts("");
	}
	int j = 0,k = 0; llong cur = 1ll<<34;
	while(j<aux1.size() || k<aux2.size())
	{
		if(k==aux2.size() || (j<aux1.size() && aux1[j].first<=aux2[k].first))
		{
			if(aux1[j].second<cur) {dp[u].push_back(aux1[j]); cur = aux1[j].second;}
			j++;
		}
		else
		{
			if(aux2[k].second<cur) {dp[u].push_back(aux2[k]); cur = aux2[k].second;}
			k++;
		}
	}
//	printf("dp[%d]: ",u); for(int i=0; i<dp[u].size(); i++) printf("(%lld,%lld) ",dp[u][i].first,dp[u][i].second); puts("");
}

bool check()
{
	dfs(1);
	if(dp[1].size()) {return true;}
	else {return false;}
}

int main()
{
	scanf("%d",&n);
	for(int i=2; i<=n; i++)
	{
		int u; llong x; scanf("%d%lld",&u,&x);
		w[i] = x; if(son[u][0]) son[u][1] = i; else son[u][0] = i;
	}
	llong left = 0ll,right = 1ll<<34;
	while(left<right)
	{
		mid = left+((right-left)>>1);
//		printf("mid=%lld\n",mid);
		bool ok = check();
		if(ok) {right = mid;}
		else {left = mid+1;}
	}
	printf("%lld\n",right);
	return 0;
}

Measured memory_bytes: 29532
#include<iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

typedef long long int ll;
const ll maxn = 1000 + 5;
ll x, y, z, k;
ll A[maxn], B[maxn], C[maxn];
ll ans[10];

struct py
{
	ll value;
	int a;
	int b;
	int c;
};

struct cmp
{
	bool operator() (const py &a, const py &b) const
	{
		return a.value < b.value;
	}
};

struct cmp2
{
	bool operator() (const py &x, const py &y) const
	{
		if(x.a != y.a) return x.a > y.a;
		else if(x.b != y.b) return x.b > y.b;
		else return x.c > y.c;
	}
};

priority_queue<py, vector<py>, cmp> que;
set<py, cmp2> s;

void solve()
{
	py res;
	res.value = A[0] + B[0] + C[0];
	res.a = 0; res.b = 0; res.c = 0;
	que.push(res);
	s.insert(res); 
	int cnt = 0;

	while(!que.empty())
	{
		py p = que.top(); que.pop(); 
		cout << p.value << endl;
		cnt++; if(cnt == k) break;

		for(int i = 0; i < 3; i++)
		{
			py np = p;
			if(i == 0) { if(np.a == x-1) continue; np.a++; }
			else if(i == 1) { if(np.b == y-1) continue; np.b++; }
			else if(i == 2) { if(np.c == z-1) continue; np.c++; }

			if(!s.count(np)) //当在已存的坐标中没有时继续插入新坐标
			{
				np.value = A[np.a] + B[np.b] + C[np.c];
				que.push(np);
				s.insert(np);
			}
		}
	}
}

int main()
{
	cin >> x >> y >> z >> k;
	for(ll i = 0; i < x; i++) scanf("%lld", &A[i]); sort(A, A+x, greater<ll>());
	for(ll i = 0; i < y; i++) scanf("%lld", &B[i]); sort(B, B+y, greater<ll>());
	for(ll i = 0; i < z; i++) scanf("%lld", &C[i]); sort(C, C+z, greater<ll>());
	solve();
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


bool compPol(vector<pair<int,int> > &schPol,vector<pair<int,int> > col){
	if(schPol.size() != col.size())
		return false;

	pair<int,int> diff;
	diff.first = schPol[0].first - col[0].first;
	diff.second = schPol[0].second - col[0].second;

	for(int i = 0; i < col.size(); i++){
		col[i].first += diff.first;
		col[i].second += diff.second;
	}

	for(int l = 0; l < 4; l++){
		// 90xñ]µÄêv·é©`FbN
		bool f = false;
		vector<pair<int,int> > npol;
		npol.push_back(col[0]);
		for(int i = 1; i < schPol.size(); i++){
			pair<int,int> pointDiff;
			pointDiff.first = col[i].first - col[0].first;
			pointDiff.second = col[i].second - col[0].second;
			// ÀWðñ]
			swap(pointDiff.first,pointDiff.second);
			pointDiff.second = -pointDiff.second;
			
			pair<int,int> distP = col[0];
			distP.first += pointDiff.first;
			distP.second += pointDiff.second;
			// êv
			if(distP.first == schPol[i].first && distP.second == schPol[i].second){
				npol.push_back(distP);
			}
			else{
				f=true;
			//	break;
				npol.push_back(distP);
			}
		}
		if(f){
			for(int i = 0; i < npol.size(); i++){
				col[i] = npol[i];
			}
			npol.clear();
		}
		else{
			return true;
		}
	}
	return false;
}

int main(){

	int n;
	while(cin >> n && n != 0){
		vector<vector<pair<int,int> > > lines;
		for(int i = 0; i < n+1; i++){
			int m;
			cin >> m;
			vector<pair<int,int> > vpii;
			for(int j = 0; j < m; j++){
				pair<int,int> p;
				cin >> p.second >> p.first;
				vpii.push_back(p);
			}
			lines.push_back(vpii);
		}

		vector<int> matchNumList;
		vector<pair<int,int> > schPol = lines[0];
		// vZ
		for(int i = 1; i < n+1; i++){
			vector<pair<int,int> > col = lines[i];
			// är
			if(compPol(schPol,col)){
				matchNumList.push_back(i);
			}
			else{
				reverse(col.begin(),col.end());
				if(compPol(schPol,col)){
					matchNumList.push_back(i);
				}
			}
		}
		if(matchNumList.size() == 0){
		}
		else{
			for(int i = 0; i < matchNumList.size(); i++){
				cout << matchNumList[i] << endl;
			}
		}
		cout << "+++++" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(){
	int n,i;
	char data[2000001];
	char out[2000001];
	char r;
	int k,m;
	char num[11]="0123456789";
	while(cin>>n){
		if(n==0){break;}
		cin>>data;
		for(int j=0;j<n;j++){
			k=0;
			m=1;
			r=data[0];
			for(i=1;data[i]!='\0';i++){
				if(data[i]==r){
					m+=1;
				}else{
					if(m<10){
						out[k]=num[m];
						k+=1;
					}else if(m<100){
						out[k]=num[m/10];
						k+=1;
						out[k]=num[m-m/10*10];
						k+=1;
					}else{
						out[k]=num[m/100];
						k+=1;
						out[k]=num[m/10-m/100*10];
						k+=1;
						out[k]=num[m-m/10*10];
						k+=1;
					}
					out[k]=r;
					k+=1;
					r=data[i];
					m=1;
				}
			}
			if(m<10){
				out[k]=num[m];
				k+=1;
			}else if(m<100){
				out[k]=num[m/10];
				k+=1;
				out[k]=num[m-m/10*10];
				k+=1;
			}else{
				out[k]=num[m/100];
				k+=1;
				out[k]=num[m/10-m/100*10];
				k+=1;
				out[k]=num[m-m/10*10];
				k+=1;
			}
			out[k]=r;
			k+=1;
			out[k]='\0';
			for(i=0;out[i]!='\0';i++){
				data[i]=out[i];
			}
			data[i]='\0';
		}
		cout<<data<<endl;
	}
	return 0;
}

Measured memory_bytes: 3248
def main():
    N = list(map(int, input()))

    c = 0
    for i in range(len(N) - 1):
        if N[i] == N[i + 1] and N[1] == N[2]:
            c += 1
    
    if c == 2 or c == 3:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    public static List<List<Integer>> switchList;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Set<String> prizes = new HashSet<>();
        for (int i = 0; i < N; i++) {
            String val = sc.next();
            if (!prizes.contains(val)) {
                prizes.add(val);
            }
        }
        sc.close();

        System.out.println(prizes.size());

    }

}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,ans=-1,b,c,d;
	cin>>n;
	map<int,int>mp;
	for(int i=0;i<n;i++){
		cin>>a;
		mp[a]++;
		b=mp[a]+mp[a-1]+mp[a+1];
		c=mp[a]+mp[a+1]+mp[a+2];
		d=mp[a]+mp[a-1]+mp[a-2];
		ans=max({b,c,d,ans});
	}
	cout<<ans<<endl;
}


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

int main()
{
    long long N, W;
    cin >> N >> W;

    long long w[N];
    long long v;
    vector<vector<long long>> v_list(4);
    for (int i = 0; i < N; i++)
    {
        cin >> w[i] >> v;
        v_list[w[i] - w[0]].push_back(v);
    }
    for (int i = 0; i < 4; i++)
    {
        sort(v_list[i].rbegin(), v_list[i].rend());
    }

    vector<vector<long long>> v_sum(4);
    for (int i = 0; i < 4; i++)
    {
        v_sum[i] = vector<long long>(v_list[i].size() + 1, 0);
        for (int j = 0; j < v_list[i].size(); j++)
        {
            v_sum[i][j + 1] = v_sum[i][j] + v_list[i][j];
        }
    }

    vector<long long> count(4);
    long long score;
    long long ans = 0;
    long long weight;
    for (int i = 0; i * w[0] <= W && i <= v_list[0].size(); i++)
    {
        for (int j = 0; i * w[0] + j * (w[0] + 1) <= W && j <= v_list[1].size(); j++)
        {
            for (int k = 0; i * w[0] + j * (w[0] + 1) + k * (w[0] + 2) <= W && k <= v_list[2].size(); k++)
            {
                for (int l = 0; i * w[0] + j * (w[0] + 1) + k * (w[0] + 2) + l * (w[0] + 3) <= W && l <= v_list[3].size(); l++)
                {
                    count[0] = i;
                    count[1] = j;
                    count[2] = k;
                    count[3] = l;
                    score = 0;
                    for (int m = 0; m < 4; m++)
                    {
                        score += v_sum[m][count[m]];
                    }
                    ans = max(ans, score);
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def divisors(num):
    array = []
    limit = int(num ** 0.5) + 1
    for i in range(1, limit):
        if num % i == 0:
            div1 = i
            div2 = num//i
            array.append(div1)
            if div1 != div2:
                array.append(div2)
    return array


n = int(input())
ans = set(divisors(n-1))

candidates = divisors(n)
candidates.remove(1)
for k in candidates:
    num = n // k
    while num % k == 0:
        num //= k
    residue = num % k
    if residue == 1:
        ans.add(k)

ans.discard(1)
print(len(ans))



Measured memory_bytes: 39536
def c_align(N, A):
    A.sort()
    seq = [0] * N
    if N % 2 == 0:
        for k in range(N - 2, -1, -2):
            seq[k] = A.pop()
        for k in range(N - 1, 0, -2):
            seq[k] = A.pop()
        ans = 0
        for k in range(N - 1):
            ans += abs(seq[k] - seq[k + 1])
    else:
        tmp = A[:]
        for k in range(N - 3, -1, -2):
            seq[k] = tmp.pop()
        seq[N - 1] = tmp.pop()
        for k in range(N - 2, 0, -2):
            seq[k] = tmp.pop()

        seq2 = [0] * N
        tmp = A[:]
        for k in range(1, N - 1, 2):
            seq2[k] = tmp.pop()
        seq2[N - 1] = tmp.pop()
        for k in range(0, N - 2, 2):
            seq2[k] = tmp.pop()

        ans1, ans2 = 0, 0
        for k in range(N - 1):
            ans1 += abs(seq[k] - seq[k + 1])
        for k in range(N - 1):
            ans2 += abs(seq2[k] - seq2[k + 1])
        ans = max(ans1, ans2)
    return ans

N = int(input())
A = [int(input()) for _ in range(N)]
print(c_align(N, A))

Measured memory_bytes: 9440
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int N,M;
    cin >> N >>M;
    map<int,int> mp;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        for(int j=0; j<a; j++){
            int num;
            cin >> num;
            mp[num]++;
        }
    }
    int count = 0;
    for(auto it : mp){
        if(it.second==N){
            count++;
        }
    }
    cout << count <<endl;
}

Measured memory_bytes: 3616
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
dp = [0]*(n+1)

for i in range(1,n+1):
    c = dp[i-1]
    for j in range(6):
        a = i-9**j if i-9**j >= 0 else i-1
        c = min(c, dp[a])
    for j in range(7):
        a = i-6**j if i-6**j >= 0 else i-1
        c = min(c, dp[a])
    dp[i] = c+1

print(dp[n])

Measured memory_bytes: 3828
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(b<a-w)System.out.println(a-b-w);
		else if(b>a+w)System.out.println(b-a-w);
		else System.out.println(0);
	}
}

Measured memory_bytes: 23124
n=int(input())
a_list=list(map(int,input().split()))
b_list=[]
for i in a_list:
    b_list.append(abs(i))
answer=0
if 0 in a_list:
    print(sum(b_list))
else:
    count=0
    for i in a_list:
        if i<0:
            count=count+1
    if count%2==0:
        print(sum(b_list))
    else:
        print(sum(b_list)-2*min(b_list))

    
        
    

    
    
    




    
        


Measured memory_bytes: 64928
N = int(input())

for h in range((N + 3) // 4, 3501):
    for n in range((N + 3) // 4, 3501):
        a = N * h * n
        b = 4 * h * n - N * (h + n)
        if a > 0 and b > 0 and a % b == 0:
            print("{0} {1} {2}".format(h, n, a//b))
            exit()


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

int main(void) {
    int AB, BC, CA;
    cin >> AB >> BC >> CA;
    int ans;
    if (AB > BC && AB > CA) {
        ans = BC * CA / 2;
    } else if (BC > AB && BC > CA) {
        ans = AB * CA / 2;
    } else {
        ans = AB * BC / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string B;
    long long A,B100;
    long long ans;
    cin >> A >> B;
    B100=(B.at(0)-'0')*100+(B.at(2)-'0')*10+(B.at(3)-'0');
    ans=A*B100/100;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<ll, ll>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

vector<ll> ans(100010);
Graph G;
void dfs(int n, int p, ll dist)
{
    ans[n] = dist % 2;

    for (auto &&i : G[n])
    {
        if (i.first == p)
            continue;
        dfs(i.first, n, dist + i.second);
    }
}
int main()
{
    long long N;
    scanf("%lld", &N);
    G.assign(N, vector<Edge>());

    for (int i = 0; i < N - 1; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        G[a].push_back(Edge(b, c));
        G[b].push_back(Edge(a, c));
    }
    ans[0] = 0;

    dfs(0, -1, 0);

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

    return 0;
}


Measured memory_bytes: 10112
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {

	int e, y, a[4] = { 1868, 1912, 1926, 1989 }, co = 0;

	cin >> e >> y;

	if (e == 0) {
		for (int i = 0; i < 4; i++)
			if (a[i] <= y) co++;
		switch (co) {
		case 1:
			cout << "M" << y - a[co - 1]+1;
			break;
		case 2:
			cout << "T" << y - a[co - 1]+1;
			break;
		case 3:
			cout << "S" << y - a[co - 1]+1;
			break;
		case 4:
			cout << "H" << y-a[co-1]+1;
			break;
		}
		cout << endl;
	}
	else {
		cout << a[e - 1] + (y - 1) << endl;
	}
	

	return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
  int n,bell;
  string s;
  while(1){
    cin >> s;
    if(cin.eof()){
      break;
    }
    for(int i=0;s[i]!='\0';i++){
      if(s[i]=='@'){
	i++;
	bell=(int)s[i];
	bell-=48;
	i++;
	for(int j=0;j<bell;j++){
	  cout << s[i];
	}
      }
      else{
	cout << s[i];
      }
    }
    cout << endl;
  }
}

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

int main()
{
    auto K = 100;
    string S = "";

    {
        string num_str = "";
        getline( cin, num_str );
        K = stoi( num_str );
    }
    getline( cin, S );


    if( S.length() <= K )
    {
        cout << S << endl;
    }
    else
    {
        auto short_S = S.substr(0, K);
        cout << short_S << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
/* You lost the game. */
 
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cfloat>
#include <numeric>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <vector>
//#include <pthread.h>
 
#define fin(i,n) for (int i = (L) 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define mod 1000000007
#define PI 3.1415926535897932384626
#define EXP1 2.718281828459045
 
#define si(n) scanf("%d", &n)
#define sii(n,m) scanf("%d %d", &n, &m)
#define siii(n,m,k) scanf("%d %d %d", &n, &m, &k)
#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define sd(n) scanf("%lf", &n)
#define sdd(n,m) scanf("%lf %lf", &n, &m)
#define sddd(n,m,k) scanf("%lf %lf %lf", &n, &m, &k)
#define sc(c) scanf("%c", &c)
#define ss(s) scanf("%s", s)
#define sai(t,n) fin(i,n) { scanf("%d", &t[i]); }
#define sal(t,n) fin(i,n) { scanf("%lld", &t[i]); }
#define sad(t,n) fin(i,n) { scanf("%lf", &t[i]); }
 
#define pc(n) printf("%c\n", n)
#define ps(s) printf("%s\n", s)
#define pi(n) printf("%d\n", n)
#define pii(n,m) printf("%d %d\n", n, m)
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define plll(n,m,k) printf("%lld %lld %lld\n", n, m, k)
#define pd(n) printf("%lf\n", n)
#define pdd(n,m) printf("%lf %lf\n", n, m)
#define pai(t,n) fin(i,n) { printf("%d ", t[i]); } printf("\n")
#define pal(t,n) fin(i,n) { printf("%lld ", t[i]); } printf("\n")
#define pad(t,n) fin(i,n) { printf("%lf ", t[i]); } printf("\n")

#define OK ps("OK")
#define OK1 ps("OK1")
#define OK2 ps("OK2")
 
#define L long long int
#define D double
#define C char
#define PII pair<int, int>
#define VPII vector<PII>
#define VL vector<L>
#define VI vector<int>
#define VVI vector<VI>
#define VD vector<D>
#define VVD vector<VD>
#define VVPII vector<VPII>
#define VC vector<C>
 
using namespace std;


int main() {
    int n;
    char s[100100];
    ss(s);
    n = strlen(s);
    VC a;
    int m = 0;
    fin(i, n) {
        if (s[i] != 'x') { a.pb(s[i]); m++; }
    }
    int ok = 1;
    fin(i, m/2) {
        if (a[i] != a[m-1-i]) { ok = 0; break; }
    }
    if (ok == 0) { pi(-1); return 0; }
    int j = 0, c = 0, k = 0;
    VI p1, p2;
    while (j <= m/2 - 1 + (m%2)) {
        while (k < n && s[k] != a[j]) { k++; c++; }
        k++;
        j++;
        p1.pb(c);
        c = 0;
    }
    j = 0, k = n-1;
    while (j <= m/2 - 1 + (m%2)) {
        while (k >= 0 && s[k] != a[m-1-j]) { k--; c++; }
        k--;
        j++;
        p2.pb(c);
        c = 0;
    }
    int r = 0;
    fin(i, p1.size()) { r += abs(p1[i]-p2[i]); }
    pi(r);
    return 0;
}

Measured memory_bytes: 1020