akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define REP_REV(i, n) for (ll i = n-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;

signed main() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll h, n;
  cin >> h >> n;
  vector<ll> a(n), b(n);
  REP(i, n) cin >> a[i] >> b[i];
  vector<ll> dp(h + 1e4 + 10, inf);
  dp[0] = 0;
  REP(i, n) {
    REP(j, h+1) {
      dp[j+a[i]] = min(dp[j+a[i]], dp[j] + b[i]);
    }
  }
  ll ans = inf;
  REP(i, 1e4) ans = min(ans, dp[h+i]);
  cout << ans << endl;
  return 0;
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n:i64,
        v:[i64;n],
        c:[i64;n]
    }
    let mut ans:i64=-100000;
    for bit in 0..(1<<n) {
        let mut sum:i64=0;
        for i in 0..n {
            if bit & (1<<i) !=0 {
                sum+=v[i as usize] - c[i as usize];
            }
        }
        ans=std::cmp::max(ans, sum);
    }
    println!("{}", ans);
}

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

struct UnionFind {
public:
    explicit UnionFind(int n)
        : roots(n)
        , sizes(n, 1)
    {
        for (int i = 0; i < n; i++) {
            roots[i] = i;
        }
    }

    // 頂点xの属する木の根である頂点を探す
    int find(int x) const
    {
        if (x == roots[x]) {
            return x;
        }
        roots[x] = find(roots[x]);
        return roots[x];
    }

    // 頂点x、頂点yが属する木を連結する
    void unite(int x, int y)
    {
        // 頂点x、頂点yのそれぞれの木の根rx、ryを得る
        auto rx = find(x);
        auto ry = find(y);

        // すでに同じ木かどうかチェック
        if (rx == ry) {
            return;
        }

        // 大きい方の木の下に小さい方の木を連結するようにする
        // (rxのほうが小さい時はrxとryを入れ替える)
        if (sizes[rx] < sizes[ry]) {
            swap(rx, ry);
        }

        // ryをrxに属するようにする
        roots[ry] = rx;
        sizes[rx] += sizes[ry];
    }

    // 頂点xと頂点yが同じ木に属するならtrue、そうでなければfalseを返す
    bool same(int x, int y) const
    {
        return find(x) == find(y);
    }

    // 頂点xが属する木の大きさを返す
    int size(int x) const
    {
        return sizes[find(x)];
    }

private:
    mutable vector<int> roots; // 頂点iの属する木の根を持つ(roots[i]が頂点iの属する木の根)
    vector<int> sizes; // 木の根iに属する頂点の数(木のサイズ)
};

struct town {
    long long no;
    long long x;
    long long y;
};

struct edge {
    long long cost;
    long long town1;
    long long town2;
};

void solve(long long N, std::vector<long long> x, std::vector<long long> y)
{
    std::vector<shared_ptr<town>> towns;
    for (long long i = 0; i < N; i++) {
        auto t = make_shared<town>();
        t->no = i + 1;
        t->x = x[i];
        t->y = y[i];
        towns.push_back(move(t));
    }

    vector<shared_ptr<edge>> edges;

    sort(begin(towns), end(towns), [](auto&& t1, auto&& t2) { return t1->x < t2->x; });
    for (long long i = 0; i < N - 1; i++) {
        auto e = make_shared<edge>();
        e->cost = towns[i + 1]->x - towns[i]->x;
        e->town1 = towns[i]->no;
        e->town2 = towns[i + 1]->no;
        edges.push_back(move(e));
    }

    sort(begin(towns), end(towns), [](auto&& t1, auto&& t2) { return t1->y < t2->y; });
    for (long long i = 0; i < N - 1; i++) {
        auto e = make_shared<edge>();
        e->cost = towns[i + 1]->y - towns[i]->y;
        e->town1 = towns[i]->no;
        e->town2 = towns[i + 1]->no;
        edges.emplace_back(move(e));
    }

    sort(begin(edges), end(edges), [](auto&& e1, auto&& e2) { return e1->cost < e2->cost; });

    UnionFind uf(N + 1);
    long long ans = 0;
    for (auto&& e : edges) {
        if (!uf.same(e->town1, e->town2)) {
            ans += e->cost;
            uf.unite(e->town1, e->town2);
        }
    }

    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 22636
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<int>edge[200005];
vector<int>edge2[200005];
int a,b,n;
P dp[200005];
int lca[200005][18],dist2[200005];
int calc(int x,int y){
	if(dist2[x] > dist2[y]) swap(x,y);
	rep(i,18){
		if((((dist2[y]-dist2[x])>>i)&1)){
			y = lca[y][i];
		}
	}
	for(int i=17;i>=0;i--){
		if(lca[x][i] != lca[y][i]){
			x = lca[x][i];
			y = lca[y][i];
		}
	}
	return (x==y?x:lca[x][0]);
}
bool fe;
int go(int a,int b){
	int c = calc(a,b);
	if(a == c){
		for(int i=0;i<18;i++){
			if((((dist2[b]-dist2[a]-1)>>i)&1)){
				b = lca[b][i];
			}
		}
		return b;
	}
	else{
		return lca[a][0];
	}
}
int ret = 0;
void dfs(int v,int u,int d){
	if(dp[v].fi >= 0){
		ret = max(ret,2*d+dp[v].fi*2);
	}
	for(int i=0;i<edge[v].size();i++){
		if(edge[v][i] == u) continue;
		int D = dist2[v]+dist2[edge[v][i]]-2*dist2[calc(v,edge[v][i])];
		//cout << v << " " << edge[v][i] << " " << " " << calc(v,edge[v][i]) << D << endl;
		if(D>=3 && lca[edge[v][i]][0] != dp[v].sc && lca[dp[v].sc][0] != edge[v][i] && edge[v][i] != dp[v].sc){
			
			fe = 1;
		}
		else {
			D = dist2[edge[v][i]]+dist2[dp[v].sc]-2*dist2[calc(edge[v][i],dp[v].sc)];
			if(D<=1){
				dp[edge[v][i]] = max(dp[edge[v][i]],mp(0,edge[v][i]));
			}
			else{
				dp[edge[v][i]] = max(dp[edge[v][i]],mp(D-1,go(dp[v].sc,edge[v][i])));
				dfs(edge[v][i],v,d+1);
			
			}
		}
	}
}
void dfs2(int v,int u,int d){
	dist2[v] = d; lca[v][0] = u;
	for(int i=0;i<edge2[v].size();i++){
		if(edge2[v][i] == u) continue;
		dfs2(edge2[v][i],v,d+1);
	}
}
int main(){
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<n;i++){
		int x,y; scanf("%d%d",&x,&y);
		edge[x].pb(y);
		edge[y].pb(x);
	}
	for(int i=1;i<n;i++){
		int x,y; scanf("%d%d",&x,&y);
		edge2[x].pb(y);
		edge2[y].pb(x);
	}
	dfs2(b,-1,0);
	dp[a] = mp(dist2[a],b);
	for(int j=0;j<17;j++) for(int i=1;i<=n;i++){
		if(lca[i][j] == -1) lca[i][j+1] = -1;
		else lca[i][j+1] = lca[lca[i][j]][j];
	}
	dfs(a,-1,0);
	if(fe) puts("-1");
	else cout << ret << endl;
}

Measured memory_bytes: 49916
/*
AizuOnline A2149
Title Luck Manipulator
*/
#include <stdio.h>
int N,A,B,C,X;
int Y[100];
//

main()
{
        int i,cnt,hc,v,ret,yp;

        while(scanf("%d %d %d %d %d",&N,&A,&B,&C,&X) && (N||A||B||C||X))
        {
                for(i=0;i<N;i++)
                        scanf("%d",&Y[i]);

                v=X;hc=0;yp=0;cnt=0;
                while(1)
                {
                        if(v==Y[yp])
                        {
                                hc++;
                                yp++;
                                if(hc>=N)
                                        break;
                        }
                        cnt++;
                        if(cnt>10000)
                        {
                                cnt=-1;
                                break;
                        }
                        v=(A*v + B) % C;
                }
                printf("%d\n",cnt);
        }
return(0);
}

Measured memory_bytes: 600
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	H := nextInt()
	cnt, ans := 0, 0
	for i := 0; i < N-1; i++ {
		next := nextInt()
		if next <= H {
			cnt++
		} else {
			cnt = 0
		}
		if ans < cnt {
			ans = cnt
		}
		H = next
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
    return a / gcd(a, b) * b;
}

string IntToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main()
{
    int n, q;
    string s;
    int l, r;

    ci >> n >> q >> s;

    int a[100001] = {};

    for(int i = 1; i < n; i++) {
	if(s[i - 1] == 'A' && s[i] == 'C') a[i]++;
	a[i] += a[i - 1];
    }
    
    rep(i, q) {
	ci >> l >> r;
	l--; r--;
	co << a[r] - a[l] << en;
    }
  
    return 0;
}


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

int main() {
	//おまじない
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;
	int A[200001];
	rep1(i, N) cin >> A[i];

	int AB[200001][20] = {};

	rep1(i, N) {
		rep(ii, 20) {
			AB[i][ii] = (A[i] >> ii) & 1;
		}
	}

	int skip[200001] = {};
	rep(i, N) {
		if (A[N - i] == 0) {
			skip[N - i - 1] = skip[N - i] + 1;
		}
	}
	ll kotae = 0;

	rep1(i, N) {
		int owari = 0;
		int kaisuu = 0;
		int B[20] = {};
		while (owari == 0 && i + kaisuu <= N) {

			rep(ii, 20) {
				B[ii] += AB[i + kaisuu][ii];
				if (B[ii] > 1) {
					owari = 1;
					break;
				}
			}
			if (owari == 0) kotae++;
			if (skip[i + kaisuu] != 0) {
				if (owari == 0) kotae += skip[i + kaisuu];
				kaisuu += skip[i + kaisuu];
			}
			kaisuu++;
		}

	}
	cout << kotae << "\n";

	Would you please return 0;
}

Measured memory_bytes: 17408
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


def main():
    n = int(input())
    s = list(input())
    w_cnt = s.count('W')
    r_cnt = n - w_cnt
    ideal = list('R' * r_cnt + 'W' * w_cnt)
    exchange = 0
    replace = 0
    flag = 0
    for i in range(n-1, -1, -1):
        if s[i] == 'R' and not flag:
            flag = 1
        if flag and s[i] == 'W':
            replace += 1
        if s[i] != ideal[i] and s[i] == 'W':
            exchange += 1
    print(min(replace, exchange))



# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 84036
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;cin>>N;
vector<int>data(N);
for(int i=0;i<N;i++)cin>>data[i];
sort(data.begin(),data.end());
int cnt=0;
for(int i=0;i<N;i++){
  for(int j=i+1;j<N;j++){
    int left=data[j];
    int right=data[i]+data[j];
    int tmp=lower_bound(data.begin(),data.end(),right)-data.begin();
    cnt+=tmp-j-1;    
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
/* When Talent doesn't work, Hard work beats Talent*/

#include"bits/stdc++.h"

using namespace std;

#define FIX_IT cout<<fixed<<setprecision(20);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define double long double
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI=3.141592653589793;

void solve()
{
	FIX_IT;
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double ang=m*6;
	double s=(h+m/60.0)*30;
	ang=abs(s-ang);
	ang=ang*PI/180;
	double len= a*a + b*b - 2*a*b*cos(ang);
	len=sqrt(len);
	cout<<len<<nl;
	return ;
}

int32_t main()
{
	FastIO;
	solve();
	return 0;
}


Measured memory_bytes: 4136
#include <stdio.h>

int main(void) {
	int n; scanf("%d",&n);
	double ary[n]; for(int i=0;i<n;i++) scanf("%lf",&ary[i]);
	double sum;
	for (int i=0; i<n; i++) {
		sum += (1/ary[i]);
	}
	printf("%lf",1/sum);
	
	return 0;
}


Measured memory_bytes: 128
# include <stdio.h>

int main(){
    int A, B, maior=-1001,i, m[3], k;

    scanf("%d %d", &A, &B);
    m[0] = A+B;
    m[1] = A-B;
    m[2] = A*B;
    for(i=0; i<3; i++){
        if(m[i]>= maior){
            maior = m[i];
        }
    }
    printf("%d", maior);
    return 0;
}

Measured memory_bytes: 128
using System;

public class Test
{
	public static void Main( )
	{
		int size = 'z'-'a'+1;
		int[] cnt = new int[ size ];		
		string strs;
		while( null != (strs = Console.ReadLine()) ) {
			strs = strs.ToLower();
			for( var i=0; i<strs.Length; i++ ) {
				if( char.IsLetter( strs[i] ) ) {
					cnt[ strs[i]-'a' ]++;
				}
			}
		}
		for( var i=0; i<size; i++ ) {
			Console.WriteLine( "{0} : {1}", Convert.ToChar('a'+i), cnt[i] );
		}
	}
}

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


int main(){
    int n_ball,n_person;
    cin>>n_ball>>n_person;
    if(n_person==1){
        cout<<0<<endl;
    }
    else{
        int max_num=n_ball-n_person;
        cout<<max_num<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;


int32_t main(){
	ios::sync_with_stdio(false);

    int a;
    int b;
    cin>>a>>b;
    int ans=0;
    if(a>=13){
        ans=b;
    }
    else if(a>=6){
        ans=b/2;
    }
    cout<<ans<<"\n";


	return 0;
}

Measured memory_bytes: 256
hw = list(map(int, input().split()))
h = hw[0]
w = hw[1]
a = list()
for i in range(h):
    a.append(list(input()))
h_blank = list()
w_blank = list()
for i in range(h):
    flag = 0
    if not "#" in a[i]:
        h_blank.append(i)
for i in range(w):
    flag = 0
    for j in range(h):
        if a[j][i] == "#":
            break
        flag += 1
    if flag == h:
        w_blank.append(i)
x = 0
for i in h_blank:
    a.pop(i - x)
    x += 1
for i in range(h - x):
    y = 0
    for j in w_blank:
        a[i][j] = ""
        y += 1
for i in a:
    print("".join(i))


Measured memory_bytes: 3188
# python template for atcoder1
import heapq
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
# -*- coding: utf-8 -*-
# python template for atcoder1
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class UnionFind:
    """
    sizeによる実装
    """

    def __init__(self, N, L):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]
        self.costs = [[l] for l in L]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y) -> "min cost":
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
            for new_mem in self.costs[px]:
                heapq.heappush(self.costs[py], new_mem)
            self.costs[px] = []
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]
            for new_mem in self.costs[py]:
                heapq.heappush(self.costs[px], new_mem)
            self.costs[py] = []

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

    def get_parents(self) -> "list":
        return [i for i, p in enumerate(self.parent) if i == p]


N, M = map(int, input().split())
L = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]

Un = UnionFind(N, L)
for s, g in edges:
    Un.union(s, g)


if M == N-1:
    print(0)
elif N < 2*(N-M-1):
    print("Impossible")
else:
    cost = 0
    cnt = 0
    for l in Un.get_parents():
        cost += heapq.heappop(Un.costs[l])
        cnt += len(Un.costs[l])

    remain_l = []
    for l in Un.get_parents():
        for v in Un.costs[l]:
            heapq.heappush(remain_l, v)
    for _ in range(2*(N-M-1)-len(Un.get_parents())):
        cost += heapq.heappop(remain_l)
    print(cost)


Measured memory_bytes: 45252
import sys
N = int(input())
t = [0]
x = [0]
y = [0]
for i in range(N):
    tmp_t, tmp_x, tmp_y = map(int, input().split())
    t.append(tmp_t)
    x.append(tmp_x)
    y.append(tmp_y)

    
def go(t, d):
    if t == d:
        return True
    elif t > d:
        if (t - d) % 2 == 0:
            return True
        else:
            return False
    else:
        return False
        


for i in range(N):
    delta_t = t[i+1] - t[i]
    distance = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i])
    if go(delta_t, distance):
        continue
    else:
        print('No')
        sys.exit()
print('Yes')

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

using namespace std;
typedef long long ll;

int main()
{
  ll N,X,M;


  cin >> N >> X >> M;


  ll ans=X;

  ll A = X;

  vector<ll> amari(M,-1);
  vector<ll> wa(0);

  amari[X] = 1;

  wa.push_back(0);
  wa.push_back(X);

  int roop_s = -1;
  int roop_e = -1;
  for(int i=2;i<=N;i++){


    A= (A*A)%M;

    ans+=A;

    

    wa.push_back(ans);



    if(amari[A]!=-1){

      roop_s = amari[A];
      roop_e = i-1;
      break;

    }
    else{

      amari[A] = i;
    }

  }


  if(roop_e!=-1){

    ll unit = wa[roop_e] - wa[roop_s-1];

    ll kuso_unit = wa[roop_s-1];


    ll K = N-(roop_s-1);

    ll sub = K/(1+roop_e -roop_s);

    ll sumo = K%(1+roop_e -roop_s);


    ll sumo_unit = wa[sumo+roop_s-1]- wa[roop_s-1];


    cout << sumo_unit+unit*sub+ kuso_unit << endl;

  }
  else{

  cout << ans << endl;;

  }



  return 0;
}


Measured memory_bytes: 4512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  auto f = [&] () {
    int n = (int) s.size();
    for (int i = 0, j = n - 1; i <= j; i++, j--) if (s[i] != s[j]) return false;
    for (int i = 0, j = (n - 2) / 2; i <= j; i++, j--) if (s[i] != s[j]) return false;
    for (int i = (n + 2) / 2, j = n - 1; i <= j; i++, j--) if (s[i] != s[j]) return false;
    return true;
  };
  cout << (f() ? "Yes\n" : "No\n");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

int main(int argc, char const *argv[]){
	int fig_1,fig_2;
	std::vector<int> dig;

	while(std::cin >> fig_1 >> fig_2){
		dig.push_back(log10(fig_1+fig_2)+1);
	}

	for (int i = 0; i < dig.size(); ++i){
		std::cout << dig[i] << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3248
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, L, Q, W, H, T, X, Y, S;

int main()
{
    cin >> N;
    ll cnt = 0;
    for (int i = 0; i < N; ++i) {
        int l,r;cin >> l >> r;
        cnt += r-l+1;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int fiveTen,hund,fiveHund;
  int money;
  int i,j,k;
  int count = 0;
  
  scanf("%d\n",&fiveHund);
  scanf("%d\n",&hund);
  scanf("%d\n",&fiveTen);
  scanf("%d\n",&money);
  
  
  for(i=0;i<=fiveHund;i++){
    for(j=0;j<=hund;j++){
      for(k=0;k<=fiveTen;k++){
        if(500*i + 100*j + 50*k == money){
          count += 1; 
        } 
      }
    }  
  }     
    
  printf("%d",count);
  
  return 0;
}

Measured memory_bytes: 256
n, a, b = gets.strip.split.map(&:to_i)

def digit(n)
  sum = 0
  while n > 0 do
    sum += n % 10
    n /= 10
  end
sum
end

ans = (1..n)
        .map { |i| [i, digit(i)] }
        .select { |d| a <= d[1] && d[1] <= b }
        .inject(0) { |sum, d| sum + d[0] }
puts ans 


Measured memory_bytes: 2172
#include<stdio.h>

int main(){
	int S = 0;
	for( ; ;)
		if(S < 10000 || S > 999)
		break;
	scanf("%d",&S);

	
	
	if(S / 1000 % 10 == S / 100 % 10 ||  S / 100 % 10 == S / 10 % 10 || S / 10 % 10 == S % 10)
		printf("Bad");
	else	printf("Good");
		
		return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define llong long long
#define pii pair<int,int>
#define riterator reverse_iterator
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int N = 150;
llong P;
int n,m;

void updsum(llong &x,llong y) {x = x+y>=P?x+y-P:x+y;}

namespace Solve1
{
	llong f[N+3];
	void solve()
	{
		m>>=1; f[0] = 1ll;
		for(int i=1; i<=n; i++)
		{
			for(int j=max(0,i-m-1); j<i; j++)
			{
				updsum(f[i],f[j]);
			}
		}
		llong ans1 = 0ll,ans2 = 0ll;
		for(int i=max(0,(n>>1)-m); i<=(n>>1); i++) updsum(ans1,f[i]);
		for(int i=max(0,(n+1>>1)-m); i<=(n+1>>1); i++) updsum(ans2,f[i]);
//		printf("ans1=%lld ans2=%lld\n",ans1,ans2);
		printf("%lld\n",ans1*ans2%P);
	}
}

namespace Solve2
{
	llong f[N+3][N+3][N+3];
	void solve()
	{
		f[0][0][0] = 1ll;
		for(int i=1; i+i-m<=n; i++)
		{
			for(int j=0; j<=m+1; j++) for(int k=0; k<=n; k++)
			{
				updsum(f[i][0][0],f[i-1][j][k]);
			}
			if(i+i<=n)
			{
				for(int j=0; j<=m+1; j++) for(int k=0; k<=n; k++)
				{
					updsum(f[i][0][k+1],f[i-1][j][k]);
				}
			}
			if(i+i-m>=1)
			{
				for(int j=0; j<=m; j++) for(int k=0; k<=n; k++)
				{
					updsum(f[i][j+(j>0)][0],f[i-1][j][k]);
				}
			}
			if(i+i<=n&&i+i-m>=1)
			{
				for(int j=0; j<=m; j++) for(int k=0; k<=n; k++)
				{
					int jj = max(j+1,k+2);
					if(jj<=m+1)
					{
						updsum(f[i][jj][k+1],f[i-1][j][k]);
					}
				}
			}
		}
		llong ans = 0ll;
		for(int j=0; j<=m+1; j++) for(int k=0; k<=n; k++)
		{
			updsum(ans,f[(n+m)>>1][j][k]);
		}
		printf("%lld\n",ans);
	}
}

int main()
{
	scanf("%d%d%lld",&n,&m,&P);
	if(!(m&1)) {Solve1::solve();}
	else {Solve2::solve();}
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 2e5 + 5;
const long long MOD = 1e9 + 7;

int N;
string s, arr[] = {"AC", "WA", "TLE", "RE"};
map<string, int> cnt;

int main() { speedhack()
	
	cin >> N;

	forn (i, N) {
		cin >> s;
		cnt[s]++;
	}

	for (int i = 0; i < 4; i++) 
		cout << arr[i] << " x " << cnt[arr[i]] << endl;
		
	

	return 0;
}

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

int main() {
    ll ans = 1;
    int N;
    cin >> N;
    while (N > 0) {
        ans *= N;
        ans %= 1000000000 + 7;
        N -= 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(0, c - (a - b)) << endl;
}

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

using namespace std;
vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//


ll computeXOR(ll n)
{
	switch (n & 3) // n % 4
	{
		case 0:
			return n;     // if n is multiple of 4
		case 1:
			return 1;     // If n % 4 gives remainder 1
		case 2:
			return n + 1; // If n % 4 gives remainder 2
		case 3:
			return 0;     // If n % 4 gives remainder 3
	}
}

int main()
{
	IOS

	ll a, b;
	cin >> a >> b;
	cout << (computeXOR(b) ^ computeXOR(a - 1));

return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


class Node{
  Node parent = null;
  Node left = null;
  Node right = null;
  int id;

  void printInfo(){
    System.out.print("node " + id + ": ");
    System.out.print("parent = " + this.getParentID() + ", ");
    System.out.print("sibling = " + this.getSiblingID() + ", ");
    System.out.print("degree = " + this.getDegree() + ", ");
    System.out.print("depth = " + this.getDepth() + ", ");
    System.out.print("height = " + this.getHeight(0) + ", ");
    System.out.println(this.getType());
  }

  int getParentID(){
    if(parent == null)
      return -1;
    else
      return parent.id;
  }

  int getSiblingID(){
    if(parent == null)
      return -1;
    else{
      if(this == parent.left && parent.right != null)
        return parent.right.id;
      else if(this == parent.right && parent.left != null)
        return parent.left.id;
      else
        return -1;
    }
  }

  int getDegree(){
    int deg = 0;
    if(left != null)deg++;
    if(right != null)deg++;
    return deg;
  }

  int getDepth(){
    int depth = 0;
    Node u = this;
    while(u.parent != null){
      depth++;
      u = u.parent;
    }
    return depth;
  }

  int getHeight(int h){
    if(this.left == null && this.right == null)
      return h;
    else{
      int h1 = 0;
      int h2 = 0;
      if(left != null)
        h1 = left.getHeight(h+1);
      if(right != null)
        h2 = right.getHeight(h+1);
      return (h1 > h2) ? h1 : h2;
    }
  }

  String getType(){
    if(parent == null)
      return "root";
    else if(left == null && right == null)
      return "leaf";
    else
      return "internal node";
  }
}

class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    Node[] node = new Node[n];

    for(int i = 0; i < n; i++)
      node[i] = new Node();

    for(int i = 0; i < n; i++){
      int id = stdIn.nextInt();
      int leftid = stdIn.nextInt();
      int rightid = stdIn.nextInt();
      node[id].id = id;
      if(leftid != -1){
        node[id].left = node[leftid];
        node[leftid].parent = node[id];
      }
      if(rightid != -1){
        node[id].right = node[rightid];
        node[rightid].parent = node[id];
      }
    }
    for(int i = 0; i < n; i++)
      node[i].printInfo();
  }
}

Measured memory_bytes: 26312
A = []
A += input().split()
A += input().split()
A += input().split()
N = int(input())
b = [input() for _ in range(N)]
 
for i in range(N):
  if b[i] in A:
    A[A.index(b[i])] = '.'
    
if (A[0] == '.' and A[3] == '.' and A[6] == '.') or (A[1] == '.' and A[4] == '.' and A[7] == '.') or (A[2] == '.' and A[5] == '.' and A[8] == '.') or (A[0] == '.' and A[1] == '.' and A[2] == '.') or (A[3] == '.' and A[4] == '.' and A[5] == '.') or (A[6] == '.' and A[7] == '.' and A[8] == '.') or (A[0] == '.' and A[4] == '.' and A[8] == '.') or (A[2] == '.' and A[4] == '.' and A[6] == '.'): print('Yes')
else: print('No')

Measured memory_bytes: 9252
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> a(n), b(n), c(n);
	vector<vector<int>> dp(n,vector<int>(3));
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	dp[n-1][0]=a[n-1];
	dp[n-1][1]=b[n-1];
	dp[n-1][2]=c[n-1];
	for(int i=n-2;i>=0;i--){
		dp[i][0]=a[i]+max(dp[i+1][1],dp[i+1][2]);
		dp[i][1]=b[i]+max(dp[i+1][0],dp[i+1][2]);
		dp[i][2]=c[i]+max(dp[i+1][1],dp[i+1][0]);
	}
	cout<<max({dp[0][0],dp[0][1],dp[0][2]});
}


Measured memory_bytes: 6912
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

#define MAX_V 10000
int V;

typedef int Weight;
const Weight INF = 1000000000;

struct Edge{
  int src, dest;
  int cap, rev;
  Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

Weight h[MAX_V];                // potential
Weight dist[MAX_V];             // minimum distance
int prevv[MAX_V], preve[MAX_V]; // previous vertex and edge

void add_edge(Graph &g, int src, int dest, int cap, int weight) {
  g[src].push_back((Edge){src, dest, cap, (int)g[dest].size(), weight});
  g[dest].push_back((Edge){dest, src, 0, (int)g[src].size() - 1, -weight});
}

Weight min_cost_flow(Graph &g, int s, int t, int f) {
  Weight res = 0; V = g.size();
  memset(h, 0, sizeof(h));
  typedef pair<Weight, int> P;
  while (f > 0) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(dist, dist + V, INF);
    dist[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
      P p = que.top(); que.pop();
      int v = p.second; 
      if (dist[v] < p.first) continue;
      REP(i, g[v].size()) {
        Edge &e = g[v][i];
        if (e.cap > 0 && dist[e.dest] > dist[v] + e.weight + h[v] - h[e.dest]) {
          dist[e.dest] = dist[v] + e.weight + h[v] - h[e.dest];
          prevv[e.dest] = v;
          preve[e.dest] = i;
          que.push(P(dist[e.dest], e.dest));
        }
      }
    }
    REP(v, V) h[v] += dist[v];
    if(h[t] >= 0) break;

    int d = f;
    for (int v = t; v != s; v = prevv[v]) d = min(d, g[prevv[v]][preve[v]].cap);
    f -= d;
    res += d * h[t];
    for (int v = t; v != s; v = prevv[v]) {
      Edge &e = g[prevv[v]][preve[v]];
      e.cap -= d;
      g[v][e.rev].cap += d;
    }
  }
  return res;
}

int main() {
  int n;
  cin>>n;
  vector<int> v;
  Graph g(n*3+1);
  vector<int> a(n);
  vector<int> b(n);
  REP(i,n){
    cin>>a[i]>>b[i];
    v.push_back(a[i]);
    v.push_back(b[i]);
    add_edge(g, 0, i*3+1, 1, 0);
    add_edge(g, i*3+1, i*3+2, 1, -a[i]);
    add_edge(g, i*3+1, i*3+3, 1, -b[i]);
  }
  sort(begin(v),end(v));
  auto itr=unique(begin(v),end(v));
  v.erase(itr,end(v));
  REP(i,v.size()){
    g.emplace_back();
  }
  g.emplace_back();
  REP(i,v.size()){
    add_edge(g, n*3+1+i, n*3+1+v.size(), 1, 0);
  }
  REP(i,n){
    int ai=lower_bound(begin(v),end(v),a[i])-begin(v);
    int bi=lower_bound(begin(v),end(v),b[i])-begin(v);
    add_edge(g, i*3+2, n*3+1+bi, 1, 0);
    add_edge(g, i*3+3, n*3+1+ai, 1, 0);
  }
  int val = min_cost_flow(g, 0, n*3+1+v.size(), INF);
  cout<<-val<<endl;
  return 0;
}

Measured memory_bytes: 1860
#include <iostream>
using namespace std;
int a[110];
int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		a[t]=1;
	}
	for(int i=1;i<=110;i++)
	 if(a[i]==1)
	 ans++;
	 cout<<ans;
	 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return 1; 
    if (n <= 3) 
        return 2; 

    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return 1; 

    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return 1; 

    return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll x,t;
        cin>>x>>t;
        if(x-t<=0)
        cout<<"0";
        else
        cout<<x-t;

    }
    return 0;
}


Measured memory_bytes: 3528
S = input()

a, b = int(S[:2]), int(S[2:])

if a >= 1 and a <= 12:
    if b >= 1 and b <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if b >= 1 and b <= 12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 3060
//#include "bits/stdc++.h"
#include "vector"
#include "iostream"
#include <fstream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <numeric>
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;



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

	int N;
	cin >> N;

	vvi g(N), dist(N);
	REP(i, N-1) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		g[v].emplace_back(u);
		g[u].emplace_back(v);
		dist[v].emplace_back(w);
		dist[u].emplace_back(w);
	}


	queue<int> q;
	q.push(0);
	vi ans(N, -1);
	ans[0] = 0;

	while (!q.empty()) {
		int now = q.front(); q.pop();
		
		REP(i,g[now].size()) {
			if (ans[g[now][i]] != -1) continue;
			ans[g[now][i]] = (ans[now] + dist[now][i]) % 2;
			q.push(g[now][i]);
		}
		
	}

	for (int i : ans) cout << i << endl;
	return 0;
}


Measured memory_bytes: 11904
package main
 
import (
    "fmt"
)
 
func main() {
	var N,X,i,sum,z int
  	s:= []int{}
    fmt.Scan(&N)
  	i=0
  	for i<N {
      	fmt.Scan(&X)
      	s=append(s,X)
      	i++
  	}
   	i=0
  	for i<=100 {     	
      	z = All_Sum(s,i)
      	if i==0 || sum > z {
          	sum = z          	
        }
      	i++
  	}
  	fmt.Print(sum)
}
func All_Sum(s []int, P int) int {
  	var j,sum int
  	for j<len(s) {
      	sum += (s[j] - P) * (s[j] - P)
      	j++
  	}
  	return sum
}

Measured memory_bytes: 512
from math import gcd
from functools import reduce

N, *A = map(int, open(0).read().split())

t = [0] * (10 ** 6 + 1)
for a in A:
    t[a] += 1

for i in range(2, 10 ** 6 + 1):
    c = 0
    for j in range(i, 10 ** 6 + 1, i):
        c += t[j]
    if c > 1:
        break
else:
    print('pairwise coprime')
    exit()

if reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 121888
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >>s;
    bool t=true;
    int n=s.size();
    if (s[0]!='1' || s[n-1]!='0') t=false;
    rep(i,0,n-1){
        if (s[i]!=s[n-2-i]) t=false;
    }
    if (!t) cout <<-1 << "\n";
    else{
        /*
        int a=1, b=1;
        cout << 1 <<" "<<2 <<"\n";
        rep(i,1,n-1){
            if (s[i-1]=='1'&&s[i]=='1'){
                cout << a+1 <<" "<<b+2 <<"\n";
                b++;
                a=b;
            }
            if (s[i-1]=='1'&&s[i]=='0'){
                cout << a+1 <<" "<<b+2 <<"\n";
                cout << a+1 << " "<<b+3 <<"\n";
                a++;
                b+=2;
            }
            if (s[i-1]=='0'&&s[i]=='0'){
                cout << a << " "<<b+2 <<"\n";
                b++;
            }
        }*/
        int a=1;
        rep(i,0,n-1){
            cout << a <<" "<<i+2<<"\n";
            if(s[i]=='1') a=i+2;
        }
    }
}



Measured memory_bytes: 1616
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	ll l;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	ll nextLong(){
		scanf("%lld", &l);
		return l;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;


int dx1[]={-1,-1,0,+1,0,-1};
int dy1[]={0,-1,-1,0,+1,+1};
int dx2[]={-1,0,+1,+1,+1,0};
int dy2[]={0,-1,-1,0,+1,+1};

int d[110][110];
bool used[110][110];

bool isOutOfRange(int x, int y, int w, int h){
	if(x <= 0 || y <= 0 || x > w || y > h) return true;
	return false;
}

int main(){
	while(1){
		int w = in.nextInt(), h = in.nextInt();
		if(w == 0 && h == 0) break;
		int s = in.nextInt();
		queue<pii> q;
		rep(i, 110) rep(j, 110) d[i][j] = INF;
		rep(i, s){
			int a = in.nextInt(), b = in.nextInt();
			q.push(mp(0, a * 1000 + b));
			d[a][b] = 0;
		}

		while(!q.empty()){
			int x = q.front().se / 1000, y = q.front().se % 1000, c = q.front().fi; q.pop();
			rep(i, 6){
				int nx = x + ((y % 2 == 1) ? dx1[i] : dx2[i]);
				int ny = y + ((y % 2 == 1) ? dy1[i] : dy2[i]);
				if(isOutOfRange(nx, ny, w, h) || d[nx][ny] != INF) continue;

				d[nx][ny] = c + 1;
				q.push(mp(c + 1, nx * 1000 + ny));
			}
		}

		int t = in.nextInt(), ans = 0;
		rep(i, t){
			int a = in.nextInt(), b = in.nextInt(), tmp = d[a][b] == 0 ? 0 : 1;
			q.push(mp(0, a * 1000 + b));
			rep(i, 110) rep (j, 110) used[i][j] = false;
			used[a][b] = true;
			while(!q.empty()){
				int x = q.front().se / 1000, y = q.front().se % 1000, c = q.front().fi; q.pop();
				rep(i, 6){
					int nx = x + ((y % 2 == 1) ? dx1[i] : dx2[i]);
					int ny = y + ((y % 2 == 1) ? dy1[i] : dy2[i]);
					if(isOutOfRange(nx, ny, w, h) || d[nx][ny] <= c + 1 || used[nx][ny]) continue;

					tmp++;
					used[nx][ny] = true;
					q.push(mp(c + 1, nx * 1000 + ny));
				}
			}
			ans = max(ans, tmp);
			//cout<<" "<<tmp<<endl;
		}
		printf("%d\n", ans);

		// rep(i, h + 1){
		// 	rep(j, w + 1){
		// 		if(d[j][i] == INF) printf("   ");
		// 		else if(i & 1) printf("%2d ", d[j][i]);
		// 		else printf(" %2d", d[j][i]);
		// 	}
		// 	printf("\n");
		// }
	}
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int a,b,c; cin >> a >> b >> c;
    cout << min({a+b,b+c,c+a}) << endl;
    return 0;
}

Measured memory_bytes: 3580
s = input()[::-1]
a,b,c,d = "dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1]

while s:
  if s[0:7] == b:
    s = s.replace(b,"",1)
  elif s[0:6] == d:
    s = s.replace(d,"",1)
  elif s[0:5] == a or s[0:5] == c:
    s = s.replace(s[0:5],"",1)
  else:
    print("NO")
    break

if s == "":
  print("YES")

Measured memory_bytes: 3188
# AtCoder用のライブラリ
# 参照
# https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a


# a ** n mod m
def mod_pow(a, n, m=10 ** 9 + 7):
    res = 1
    while n > 0:
        if n & 1 == 1:
            res = res * a % m
        a = a * a % m
        n >>= 1
    return res


N = int(input())

ALL = mod_pow(10, N)
side = mod_pow(9, N)
none = mod_pow(8, N)

MOD = 10 ** 9 + 7

print((ALL - side * 2 + none) % MOD)


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

int main(){
    int N,X;
    cin >> N >> X;

    vector<int> l(N);
    for(int i = 0; i < N ; i++){
        cin >> l[i];
    }
    int ans = 1;
    int p = 0;
    for(int i = 0; i < N; ++i){
        p += l[i];
        if(p <= X)
            ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256