akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
    int N,D,X,i,sum;
    int A[101];
    scanf("%d¥n",&N);
    scanf("%d",&D);
    scanf("%d¥n",&X);
    sum = X;
    for(i = 1; i<=N;i++){scanf("%d¥n",&A[i]);
        if(D%A[i]  ==0){sum +=D/A[i];
        }else{ sum +=(D/A[i]+1);
        }}
    printf("%d",sum);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[][] values = new boolean[n][];
		int[] counts = new int[60];
		for (int i = 0; i < n; i++) {
		    values[i] = getArray(sc.nextLong());
		    for (int j = 0; j < 60; j++) {
		        if (values[i][j]) {
		            counts[j]++;
		        }
		    }
		}
		long base = 1;
		long ans = 0;
		for (int i = 0; i < 60; i++) {
		    long tmp = (long)(n - counts[i]) * (counts[i])  % MOD;
		    ans += tmp * base % MOD;
		    ans %= MOD;
		    base *= 2;
		    base %= MOD;
		}
		System.out.println(ans);
	}
	
	static boolean[] getArray(long x) {
	    boolean[] ret = new boolean[60];
	    for (int i = 0; i < 60; i++) {
	        ret[i] = (x % 2 == 1);
	        x /= 2;
	    }
	    return ret;
	}
}


Measured memory_bytes: 84928
/**
 *Code Author: codeknight13
 *Institution: IIT(ISM)
**/
 
#include <bits/stdc++.h>
using namespace std;

//remember-> largest 2d memory that can be allocated is dp[5100][5100];
#define ll int
#define v vector
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define str string
#define pq priority_queue
#define vi vector< ll >
#define vii vector< vi >
#define viii vector< vii >
#define pii pair< ll, ll >
#define vpii vector< pii >
#define len length()
#define pb push_back
#define mp make_pair3
#define ff first
#define ss second
#define nl cout <<  endl
#define all(ar) ar.begin(), ar.end()
#define ini(X,Y) ll X; X=Y
#define inx(X) ll X; cin >> X
#define inxy(X, Y) ll X, Y; cin >> X >> Y
#define iter(arr) for (ll i=0; i<arr.size(); i++)
#define ret return
#define cont continue
ll inf=1000000007;

ll min1(ll a, ll b, ll c)
{
	ret (max(a,max(b,c)));
}

str a,b;

int main()
{
	fast;
	int n,m;
	cin >> n >> m;
	vii arr(n+1,vi(m+1,1));
	vii dp (n+1,vi(m+1,0));
	for (int i=1; i<n+1; i++)
	{
		for (int j=1; j<m+1; j++)
		{
			char c;
			cin >> c;
			if (c=='#')
			{
				arr[i][j]=0;
			}
		}
	}
	for (int i=1; i<m+1; i++)
	{
		if (arr[1][i]==0)
		{
			dp[1][i]=0;
			break;
		}
		else 
		{
			dp[1][i]=1;
		}
	}
	for (int i=2; i<n+1; i++)
	{
		for (int j=1; j<m+1; j++)
		{
			if (arr[i][j])
			dp[i][j]=dp[i-1][j]%inf+dp[i][j-1]%inf;
			dp[i][j]%=inf;
		}
	}
	cout << dp[n][m]%inf;
	ret 0;
}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		ArrayList<Character> list = new ArrayList<Character>();
		while(n > 0) {
			int amari = (int) (n % 26);
			list.add(toS(amari));
			if(n % 26 == 0) {
				n -= 1;
			}
			n /= 26;
		}
		Collections.reverse(list);
		Character[] name = list.toArray(new Character[list.size()]);
		char[] name2 = new char[list.size()];
		for(int i = 0; i < list.size(); i++) {
			name2[i] = (char)name[i];
		}
		String na = new String(name2);
		System.out.println(na);
	}
	
	public static char toS(int n) {
		if(n == 0) {
			return 'z';
		}
		int a = 'a' - 1;
		a = n + a;
		return (char)a;
	}
}


Measured memory_bytes: 27060
n, w, h = map(int, raw_input().split())
a, b = [], []
for i in xrange(n):
	x, y = map(int, raw_input().split())
	a.append(x)
	b.append(y)
ans = 0
for i in xrange(n):
	if a[i] >= w and b[i] >= h:
		ans += 1
print ans

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

#define ff first
#define ss second
#define pb push_back

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 100005;

int cnt[N];
int v[N];

bool ok(vector<int> &ans){
	for(int i = 1; i < (int)ans.size(); i++){
		if(v[ans[i-1]] == ans[i]) return 0;
	}
	return 1;
}

int main() {
	int n;
	scanf("%d", &n);
	set<int> s;
	for(int i = 1; i <= n; i++){
		s.insert(i);
		scanf("%d", v+i);
		cnt[v[i]]++;
	}
	if(n == 2) return printf("-1\n"), 0;
	vector<int> ans;
	int lt = 0;
	for(int i = 0; i < n-3; i++){
		int p = *s.begin();
		if(p == lt){
			if(s.size() == 1){
				printf("-1\n");
				return 0;
			}
			p = *next(s.begin());
		}
		if(s.size()-1 && max(cnt[v[*s.begin()]], cnt[v[*s.rbegin()]]) == s.size()-1){
			int x = *s.begin();
			int y = *s.rbegin();
			p = cnt[v[x]] > cnt[v[y]] ? v[x] : v[y];
		}
		s.erase(p);
		ans.pb(p);
		lt = v[p];
		cnt[lt]--;
		cnt[lt] = max(cnt[lt], 0);
		cnt[p] = 0;
	}
	vector<int> v2;
	for(int i : s) v2.pb(i);
	do{
		for(int i : v2){
			ans.pb(i);
		}
		if(ok(ans)){
			break;
		}
		for(int i : v2){
			ans.pop_back();
		}
	}while(next_permutation(v2.begin(), v2.end()));
	for(int i : ans){
		printf("%d ", i);
	}
	printf("\n");

	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

vector<ll> binary_count (ll n) {
    vector<ll> ret;
    ll target = n+1;

    ll now = 2;
    while(now/2 <= target){
        if(now == 2){
            ret.push_back((target/2)%2);
            now *= 2;
            continue;
        }
        // cout << ((target/now)-(now/2) + now+1)%2 << endl;
        ret.push_back((max(0LL,(target%now)-(now/2)))%2);
        now *= 2;
    }
    
    return (ret);
}

ll powll(ll a, ll x){
    if(x == 0) return 1;
    else return powll(a, x-1)*a;
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B;
    cin >> A >> B;

    vector<ll> Aans = binary_count(A-1);
    vector<ll> Bans = binary_count(B);

    // ll Asize = Aans.size();
    // ll Bsize = Bans.size();
    // for(auto iter: Aans){
    //     cout << iter;
    // }
    // cout << endl;
    
    // reverse(Aans.begin(), Aans.end());
    // reverse(Bans.begin(), Bans.end());

    ll Aans10 = 0;
    for(ll i=0; i<Aans.size(); i++){
        if(Aans[i] == 1){
            Aans10 += powll(2, i);
        }
    }
    // cout << Aans10 << endl;
    ll Bans10 = 0;
    for(ll i=0; i<Bans.size(); i++){
        if(Bans[i] == 1){
            Bans10 += powll(2, i);
        }
    }
    // cout << Bans10 << endl;

    cout << (Aans10 ^ Bans10) << endl;
    return 0;
}

Measured memory_bytes: 3636
n, w = map(int, input().split())
dp = [[0] * (w + 1) for _ in range(n + 1)]
wv = [[0, 0]] + [list(map(int, input().split())) for _ in range(n)]

for i in range(1, n + 1):
    for j in range(1, w + 1):
        if j - wv[i][0] >= 0:
            dp[i][j] = max(dp[i - 1][j - wv[i][0]] + wv[i][1], dp[i-1][j])
        else:
            dp[i][j] = dp[i - 1][j]

print(dp[n][w])

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

#define     ll          long long
#define     ld          long double
#define     sz(s)       s.size()
#define     pb          push_back
#define     ff          first
#define     ss          second
#define     mk          make_pair
#define     pii         pair<int, int>
#define     pll         pair<long long int, long long int>
#define     ALL(s)      (s).begin(), (s).end()
#define     rALL(s)     (s).rbegin(), (s).rend()
#define     fast        ios_base::sync_with_stdio(false);cin.tie(NULL)
#define     show(x)     cout << #x << " : "<< x << endl;
#define     f0(n)       for(int i=0; i<n; i++)
#define     f1(n)       for(int i=1; i<=n; i++)
#define     vi(v,n)     for (int i=0;i<n;i++){int a;cin >> a;v.push_back(a);}
#define     vll(v,n)    for (ll i=0;i<n;i++){ll a;cin >> a;v.push_back(a);}
#define     M           100005
#define     limit       -pow(2, 32)
#define     pi          acos(-1)
#define     fuck        return 0;

using namespace std;




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

   ll y=0, x=100;
   while(x < n)
   {
       x += (x/100);
       ++y;
   }

   cout << y << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
	long long val;
	long long id;
	long long kk;
}a[5];
long long ans;
long long n;
bool cmp(node x,node y)
{
	return x.val<y.val;
}
int main()
{
	scanf("%lld%lld%lld%lld",&a[1].val,&a[2].val,&a[3].val,&a[4].val);
	scanf("%lld",&n);
	a[1].kk=a[1].val;a[2].kk=a[2].val;a[3].kk=a[3].val;a[4].kk=a[4].val;
	a[3].val*=2;a[2].val*=4;a[1].val*=8;
	a[1].id=25;a[2].id=50;a[3].id=100;a[4].id=200;
	sort(a+1,a+4+1,cmp);n*=100;
	while (n!=0)
	{
		if ((n-a[1].id)>=0)	{ans+=(n/a[1].id)*a[1].kk;n=(n%a[1].id);}
		else if ((n-a[2].id)>=0)	{ans+=(n/a[2].id)*a[2].kk;n=(n%a[2].id);}
		else if ((n-a[3].id)>=0)	{ans+=(n/a[3].id)*a[3].kk;n=(n%a[3].id);}
		else if ((n-a[4].id)>=0)	{ans+=(n/a[4].id)*a[4].kk;n=(n%a[4].id);}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct Union{
  vector<int> r,p;
  Union(int size){init(size);}
  void init(int size){
    r.resize(size);
    p.resize(size);
    for(int i=0;i<size;i++) r[i]=1,p[i]=i;
  }
  int find(int x){
    if(x!=p[x]) p[x]=find(p[x]);
    return p[x];
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
typedef pair<int,int> P;
int main(){
  int n,k,l,i,j,p,q;
  cin>>n>>k>>l;
  Union u1(n+1),u2(n+1);
  vector<P> v;
  for(i=0;i<k;i++){
    cin>>p>>q;
    v.push_back(P(p,q));
    u1.unite(p,q);
  }
  for(i=0;i<l;i++){
    cin>>p>>q;
    v.push_back(P(p,q));
    u2.unite(p,q);
  }
  map<P,int> mp;
  for(i=1;i<=n;i++){
    mp[P(u1.find(i),u2.find(i))]++;
  }
  for(i=1;i<=n;i++) cout << mp[P(u1.find(i),u2.find(i))] << " \n"[i==n];
  return 0;
}


Measured memory_bytes: 16624
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	string s;
	cin>>s;
	if(s[2] == s[3]){
		
		if(s[4]==s[5]){
			
			cout<<"Yes"<<endl;
			}
		else cout<<"No"<<endl;
		
		
		}
	else cout<<"No\n"<<endl;
	
	
	
	}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
#define SENTINEL 99999999

typedef struct{
  char suit;
  int value;
} Card;

Card L[MAX/2+2],R[MAX/2+2];

void merge(Card A[],int n,int left,int mid,int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;

  for(i=0;i<n1;i++){L[i]=A[left+i];}
  for(i=0;i<n2;i++){R[i]=A[mid+i];}

  L[n1].value=SENTINEL;
  R[n2].value=SENTINEL;

  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value){A[k]=L[i++];}
    else{A[k]=R[j++];}
  }
}

void mergeSort(Card *A,int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(Card A[],int n,int p,int r){
  int i,j;
  Card t,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

void quickSort(Card *A,int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(){
  int n,i,v;
  Card A[MAX],B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=v;
    B[i].value=v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit!=B[i].suit) stable=0;
  }
  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) printf("%c %d\n",B[i].suit,B[i].value);
  return 0;
}


Measured memory_bytes: 4056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		sc.close();

		if(a.equals(b)) {
			System.out.println("H");
		}else {
			System.out.println("D");
		}
	}
}

Measured memory_bytes: 21588
from math import factorial
from itertools import permutations
N = int(input())
Points = [list(map(int, input().split())) for i in range(N)]


def dist(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5


ans = 0
for perm in permutations(range(N)):
    for i in range(N - 1):
        x1, y1 = Points[perm[i]]
        x2, y2 = Points[perm[i + 1]]
        ans += dist(x1, y1, x2, y2)

print(ans / factorial(N))


Measured memory_bytes: 3188
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = int(input())
    b = [int(i) for i in input().split()]

    count =Decimal(0)

    for i in b:
        count = count +(Decimal(1) / Decimal(i))

    print(Decimal(1) / Decimal(count))

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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;
typedef complex<double> P;


void solve(ll N, vector<ll> x, vector<ll> y) {
    vector<P> ps;
    for (int i = 0; i < N; i++) {
        ps.push_back(P(x[i], y[i]));
    }
    for (int i = 0; i < N; i++) {
        vector<pair<double, double> > seg;
        for (int j = 0; j < N; j++) {
            if (i != j) {
                P v = ps[j] - ps[i];
                P s = v * P(0, 1);
                P t = v / P(0, 1);

                seg.push_back({atan2(s.imag(), s.real()), atan2(t.imag(), t.real())});
            }
        }
        vector<pair<double, int> > add;
        for (auto &s : seg) {
            if (s.second < s.first) s.second += 2 * M_PI;
            if (s.first < 0) {
                if (s.second > 0) {
                    add.push_back({0, 1});
                    add.push_back({s.second, -1});
                    add.push_back({s.first + 2 * M_PI, 1});
                } else {
                    add.push_back({s.first + 2 * M_PI, 1});
                    add.push_back({s.second + 2 * M_PI, 1});
                }
            } else {
                add.push_back({s.first, 1});
                add.push_back({s.second, -1});
            }
        }
        for (int i = add.size() - 1; i >= 0; i--) {
            add.push_back({add[i].first + 1e-9, 0});
            add.push_back({add[i].first - 1e-9, 0});
        }
        add.push_back({0, 0});
        add.push_back({2 * M_PI, 0});
        sort(add.begin(), add.end());

        double prv = 0;

        int ans = 0;
        double tot = 0;
        for (auto a : add) {
            if (ans > 0) tot += a.first - prv;
            ans += a.second;
            prv = a.first;
        }
        printf("%.15lf\n", 1 - tot / (2 * M_PI));

    }
}

int main() {
    ll N;
    scanf("%lld", &N);
    vector<ll> y(N - 1 + 1);
    vector<ll> x(N - 1 + 1);
    for (int i = 0; i <= N - 1; i++) {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
    }
    solve(N, x, y);
    return 0;
}



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

#define N 1000

int max(int x, int y) {return ((x>y)? x:y);}

int lcs(char *s1, char *s2){
  int i, j, k, l;
  char space[N+1]=" ";
  int c[N+1][N+1];
  int m=strlen(s1); 
  int n=strlen(s2);
  int maxl=0;
  for(i=1;i<m;i++) c[i][0]=0;
  for(j=1;j<n;j++) c[0][j]=0;

  for(i=1;i<m;i++){
    for(j=1;j<n;j++){
      if(s1[i]==s2[j]) c[i][j]=c[i-1][j-1]+1;
      else c[i][j]=max(c[i-1][j], c[i][j-1]);
      maxl=max(maxl, c[i][j]);
    }
  }return maxl;
}

int main(){
  char s1[N+1], s2[N+1], space[N+1]=" ";
  int i, j, n;
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%s", s1+1);
    scanf("%s", s2+1);
    s1[0]=' ',s2[0]=' ';

    printf("%d\n", lcs(s1,s2));

  }
  return 0;
}
    



Measured memory_bytes: 5636
#include <stdio.h>

int main(void) {
	int A,B,N;
	char a[256];

	fgets(a, 256, stdin);
	sscanf(a, "%d %d %d", &N, &A, &B);
	
	if (A*N < B) {
		printf("%d\n", A*N);
	}
	else if(A*N > B) {
		printf("%d\n", B);
	}
	else{
		printf("%d\n", B);
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int p[100010];
using Graph = vector<vector<int>>;
int ans = 0;


void dfs(Graph &g, int v, int num, int pre) {
  if(p[v] == num){
    ans++;
  }
  else {
    for(auto next_v : g[v]) {
      if(next_v==pre) continue;
      dfs(g,next_v,num,v);
    }
  }
}


int main() {
  string s;
  cin >> s;
  bool f = false;
  if(s[2] == s[3] && s[4] == s[5]) f = true;
  cans(f);
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

int N;
vector<int> ans;
void solve(int x) {
  if(x == 1 || x == 0) {
    ans.push_back(x);
    return;
  }
  int s;
  if(x > 0) {
    ans.push_back(x % 2);
    s = -(x / 2);
  } else {
    if((-x) % 2 == 0) {
      ans.push_back(0);
      s = (-x) / 2;
    } else {
      ans.push_back(1);
      s = (-x) / 2 + 1;
    }
  }
  solve(s);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  solve(N);
  for(auto it = ans.rbegin(); it != ans.rend(); it++) {
    cout << *it;
  }

  return 0;
}

Measured memory_bytes: 256
n,m=gets.split.map(&:to_i)
s=[]
p=0
n.times{s<<gets.split.map(&:to_i)}
s.sort!{|a,b|a[0]<=>b[0]}
s.each{|x|
  if x[1]>=m
    p+=x[0]*m;break
  else
    p+=x[0]*x[1];m-=x[1]
  end
  }
puts p

Measured memory_bytes: 10488
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] L = new int[2*N];
    for (int i = 0 ; i < 2*N; i++) {
      L[i] = sc.nextInt();
    }
    Arrays.sort(L);
    int ans = 0;
    for (int i = 0; i < 2*N; i+=2) {
      ans += L[i];
    }
    System.out.println(ans);
  }
}

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

using namespace std;

typedef long long ll;
 
const int maxn = 1e5 + 10;

vector<pair<int, int> > t[maxn];
int c[maxn];

void dfs(int v, int par = -1){
	for (auto it : t[v]){
		int u = it.first, w = it.second % 2;
		if (u != par){
			c[u] = c[v] ^ w;
			dfs(u, v);
		}
	}
}

int main(){
	ios_base::sync_with_stdio (false);
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++){
		int v, u, w;
		cin >> v >> u >> w;
		t[v].push_back({u, w});
		t[u].push_back({v, w});
	}
	dfs(1);
	for (int i = 1; i <= n; i++)
		cout << c[i] << '\n';
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

void str_replace(string &s, string target, string replacement) {
    if (!target.empty()) {
        string::size_type pos = 0;
        while ((pos = s.find(target, pos)) != string::npos) {
            s.replace(pos, target.length(), replacement);
            pos += replacement.length();
        }
    }
}

int main() {
    string s;
    cin >> s;
    str_replace(s, "?", "D");
    int ans = 0;
    int n = s.size();
    rep(i,n) {
        if (s[i] == 'D') ans++;
        if (i <= n-2 && s[i] == 'P' && s[i+1] == 'D') ans++;
    }
    cout << s << endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    map<int,int> m;
    vector<vl> dp(200010,vl(2,0));
    rep(i,n){
        m[a[i]]++;
    }
    ll all = 0;
    for(auto t : m){
        int x = t.first,y = t.second;
        all += dp[x][0] = (ll)(y-1)*y/2;
        if(y-2>0) dp[x][1] = (ll)(y-2)*(y-1)/2;
    }
    rep(i,n){
        //cout << a[i] << " " << all << " -" << dp[a[i]][0] << " +" << dp[a[i]][1] << endl;
        ll ans = all - dp[a[i]][0] + dp[a[i]][1];
        cout << ans << endl;
    }
}

Measured memory_bytes: 31232
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
    return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
        in >> x;
    return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
    for (const vector<T> &x : v)
        out << x << '\n';
    return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
        out << x << ' ';
    return out;
}

long long gcd (long long a, long long b)
{
    if (b > a)
        swap(a, b);
    return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    #ifdef ONLINE_JUDGE
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.setstate(ios::failbit);
    #endif

    string t;
    cin >> t;
    string s;
    ll ans = 0;
    int len = t.size();
    for(char c : t)
    {
        if(c == '1' and !s.empty() and s.back() == '1')
        {
            s.pop_back();
            ans += len;
            len -= 2;
        }
        else
            s.push_back(c);
    }

    int z = 0, one_cnt = 0;
    rep(i,0,s.size())
    {
        if(s[i] == '0')
            z++;
        if(s[i] == '1')
        {
            if(one_cnt)
                z--;
            ans += len - 2 * one_cnt - (z + 1) / 2;
            one_cnt++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3872
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	ll N;
	cin >> N;
	vector<ll> h(N);
	REP(i, N)cin >> h[i];

	
	vector<ll> dp(N + 5, INF);

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);

	REP(i, N) {dp[i + 2] = min( dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs( h[i + 2] - h[i + 1]));}

	cout << dp[N - 1] << endl;



	return 0;
}


Measured memory_bytes: 4708
while True:
    H,W=map(int,input().split())
    
    if H==0 and W==0:
        break
    
    else:
        for i in range(H):
            if i==0 or i==H-1:
                for j in range(W):
                    print("#",end="")
            else:
                for j in range(W):
                    if j==0 or j==W-1:
                        print("#",end="")
                    else:
                        print(".",end="")
            print()
        
    print()


Measured memory_bytes: 7008
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[i][j] - length of the longest common subsequence
    OPT[i][j] = max(OPT[i-1][j-1]+(1 if s[i] == t[j] else 0),
                    OPT[i-1][j],
                    OPT[i][j-1])
    """
    s = input().strip()
    t = input().strip()
    OPT = [[0]*(len(t)+1) for _ in range(len(s)+1)]
    for i in range(1, len(s)+1):
        for j in range(1, len(t)+1):
            OPT[i][j] = max(OPT[i-1][j-1]+(1 if s[i-1] == t[j-1] else 0),
                            OPT[i-1][j],
                            OPT[i][j-1])
    i, j = len(s), len(t)
    ans = []
    while i != 0 and j != 0:
        if OPT[i][j] == OPT[i-1][j]:
            i -= 1
        elif OPT[i][j] == OPT[i][j-1]:
            j -= 1
        else:
            ans.append(s[i-1])
            i -= 1
            j -= 1
    return ''.join(ans[::-1])


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 111964
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll h, w, k;
	cin >> h >> w >> k;
	VecS s(h);
	rep(i, h) cin >> s[i];

	ll ans = LINF;
	rep(bit, pow2(h - 1)){
		bitset<10> bits(bit);
		ll m = bits.count();
		Vec group(h);
		rep(i, h - 1) group[i + 1] = group[i] + bits[i];

		ll line = m;
		Vec cs(m + 1);
		rep(j, w){
			bool flg = true;
			Vec sum(m + 1);
			rep(i, h) sum[group[i]] += s[i][j] - '0';
			rep(i, m + 1) if(sum[i] > k) line += INF;
			rep(i, m + 1) flg &= (cs[i] + sum[i] <= k);
			if(flg){
				rep(i, m + 1) cs[i] += sum[i];
			}else{
				line++;
				rep(i, m + 1) cs[i] = sum[i];
			}
		}
		//co({bit, line});
		chmin(ans, line);
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <tuple>
#include <map>
#include <algorithm>
using Int = long long;
using namespace std;

int main()
{
    int A, B, C; cin >> A >> B >> C;
    if (C >= A && C <= B) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main()
{
  char c;
  cin>>c;
  if(c=='A')cout<<"T"<<endl;
  else if(c=='T')cout<<"A"<<endl;
  else if(c=='C')cout<<"G"<<endl;
  else cout<<"C"<<endl;
  return 0;
}

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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

#define MAX_COST (10000000000)


int main(int argc, char **argv){
	int n, m;
	std::vector<std::vector<long long> > min_cost;
	bool is_there_negative_cycle = false;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	ifs >> n >> m;
#else
	std::cin >> n >> m;
#endif


	min_cost.resize(n);
	for(int i = 0; i < n; i++){
		min_cost[i].resize(n, MAX_COST);
		min_cost[i][i] = 0;
	}
	for(int i = 0; i < m; i++){
		int s, t, d;

#if INPUT_FROM_FILE
		ifs >> s >> t >> d;
#else
		std::cin >> s >> t >> d;
#endif
		min_cost[s][t] = d;
	}

	for(int k = 0; k < n; k++){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(min_cost[i][j] == MAX_COST){
					if(min_cost[i][k] == MAX_COST || min_cost[k][j] == MAX_COST){
						min_cost[i][j] = MAX_COST;
					}
					else{
						min_cost[i][j] = min_cost[i][k] + min_cost[k][j];
					}
				}
				else{
					min_cost[i][j] = std::min(min_cost[i][j], min_cost[i][k] + min_cost[k][j]);
				}
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		if(min_cost[i][i] < 0){
			is_there_negative_cycle = true;
			break;
		}
	}
	

	if(is_there_negative_cycle){
		std::cout << "NEGATIVE CYCLE" << std::endl;
	}
	else{
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(min_cost[i][j] == MAX_COST){
					std::cout << "INF";
				}
				else{
					std::cout << min_cost[i][j];
				}
				if(j < n - 1){
					std::cout << " ";
				}
			}
			std::cout << std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() { 

    string s, t;
    cin >> s >> t;
    int tt = t.size(), ss = s.size();
    int res = tt;
    for (int i = 0; i + tt - 1 < ss; i++) {
        int c = 0;
        for (int j = 0; j < tt; j++) {
            if (t[j] != s[j + i]) {
                c++;
            }
        }
        res = min(res, c);
    }
    cout << res << endl;
}




Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

vector<int> pri;
int isprime(int x){
  for(int i=0;i<pri.size();i++){
    if(x == pri[i])return 1;
    if(!(x % pri[i]))return 0;
  }
  return 1;
} 

void primecal(int x){
  bool ip;

  for(int i=2;i<=floor(sqrt(x));i++){
    ip = true;
    for(int j=0;j<pri.size();j++){
      if(!i%pri[j]){
	ip = false;
	break;
      }
    }
    if(ip)pri.push_back(i);
  }
}

int  main(){
  int mx,N,tmp;
  vector<int> a;
  cin >> N;
  mx = 0;
  for(int i=0;i<N;i++){
    cin >> tmp;
    a.push_back(tmp);
    mx = max(mx,tmp);
  }
  primecal(mx);
  int c=0;
  for(int i=0;i<N;i++)
    c += isprime(a[i]);

  cout << c << endl;
  
  return 0;
}

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

const int INF = 1e9 + 5;
const int ALPHABET = 26;

int main() {
    int N;
    cin >> N;
    vector<int> min_freq(ALPHABET, INF);

    for (int i = 0; i < N; i++) {
        string str;
        cin >> str;
        vector<int> freq(ALPHABET, 0);

        for (char c : str)
            freq[c - 'a']++;

        for (int x = 0; x < ALPHABET; x++)
            min_freq[x] = min(min_freq[x], freq[x]);
    }

    for (int x = 0; x < ALPHABET; x++)
        for (int i = 0; i < min_freq[x]; i++)
            cout << (char) ('a' + x);

    cout << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		if (K==1) {
			System.out.println(0);
			return;
		}
		System.out.println(N-K);
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define f(p,n) for(ll i=p;i<n;i++)
ll exp(ll a,ll b,ll m);

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

	ll n;
	cin>>n;
	ll a[n];
	f(0,n) cin>>a[i];
	ll b[n];
	f(0,n) cin>>b[i];

	vector<ll> zyada;
	ll sum=0;
	ll co=0;
	f(0,n)
	{
		if(a[i]<b[i])
		{
			sum+=(b[i]-a[i]);
			co++;
		}
		else if(a[i]>b[i])
		{
			zyada.pb(a[i]-b[i]);
		}
	}

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

	ll l=zyada.size();

	for(ll j=l-1;j>=0;j--)
	{
		if(sum<=0) break;
		sum-=zyada[j];
		co++;
	}
	if(sum>0)
	{
		cout<<-1<<endl;
	}
	else cout<<co<<endl;
return 0;
}

ll exp(ll a,ll b,ll m)
{
	if(b==0)
	{
		return 1;
	}
	ll temp =exp(a,b/2,m);
	temp=(temp*temp)%m;
	if(b&1)
	{
		return (temp*(a%m))%m;
	}
	return temp;
}



Measured memory_bytes: 2428
#include<cstdio>
#include<vector>

using namespace std;

bool h[10];

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < k; i++){
		int t;
		scanf("%d", &t);
		h[t] = true;
	}
	int ans = n;
	bool f = true;
	while(f){
		int x = 1;
		while(x <= ans){
			if(h[(ans / x) % 10]) break;
			x *= 10;
			if(x > ans) f = false;
		}
		if(f) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

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

Measured memory_bytes: 128
"""Boot-camp-for-Beginners_Easy013_A_Candy-Distribution-Again_30-August-2020.py"""

A, B, C = map(int, input().split())
a, b, c = A, B, C
i = 0
while True:
    if (A % 2 == 0 and B % 2 == 0 and C % 2 == 0):
        i += 1
        a, b, c = A, B, C
        A = (b+c)/2
        B = (c+a)/2
        C = (a+b)/2
        #print(A,B,C)
        if(A == a and B == b and C == c):
            print(-1)
            break
    else:
        print(i)
        break


Measured memory_bytes: 9168
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
int P[1010];
int X[1010];
vector<int> children[1010];

typedef pair<int, int> fruit;
fruit F[1010];
fruit empty = fruit(-1, -1);

bool judged = false;

fruit calc(int v) {
  if (F[v] != empty) return F[v];
  if (children[v].empty()) {
    F[v] = fruit(X[v], 0);
    // cerr << "F[" << v << "] = " << F[v].first << " " << F[v].second << endl;
    return F[v];
  }
  // cerr << "now = " << v << endl;
  int sum = 0;
  int allsum = 0;
  for (auto x : children[v]) {
    if (calc(x) == empty) return F[v] = empty;
    sum += calc(x).second;
    allsum += calc(x).first + calc(x).second;
  }
  if (sum > X[v]) {
    judged = true;
    return F[v] = empty;
  }
  int s = children[v].size();
  vector< set<int> > S(s+1);
  S[0].insert(0);
  for (auto i = 0; i < s; ++i) {
    int fir = calc(children[v][i]).first;
    int sec = calc(children[v][i]).second;
    for (auto x : S[i]) {
      if (x > X[v]) break;
      S[i+1].insert(x + fir);
      S[i+1].insert(x + sec);
    }
  }
  /*
  for (auto x : S[s]) {
    cerr << x << " ";
  }
  */
  auto it = S[s].upper_bound(X[v]);
  it--;
  F[v] = fruit(X[v], allsum-*it);
  if (F[v].first < F[v].second) swap(F[v].first, F[v].second);
  // cerr << "F[" << v << "] = " << F[v].first << " " << F[v].second << endl;
  return F[v];
}

int main () {
  cin >> N;
  for (auto i = 0; i < N-1; ++i) {
    cin >> P[i];
    P[i]--;
    children[P[i]].push_back(i+1);
  }
  /*
  for (auto i = 0; i < N; ++i) {
    cerr << "children[" << i << "] : ";
    for (auto x : children[i]) {
      cerr << x << " ";
    }
    cerr << endl;
  }
  */
  for (auto i = 0; i < N; ++i) {
    cin >> X[i];
  }
  for (auto i = 0; i < N; ++i) {
    F[i] = empty;
  }
  calc(0);
  if (judged) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << "POSSIBLE" << endl;
  }
}


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

using namespace std;

int main() {
  int R;
  cin >> R;
  if (R < 1200) {
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,x,b,n,t,ans;
int main()
{
	cin>>n>>x;
	cin>>a;
	if(a>x){ans+=a-x;a=x;}
	for(int i=2;i<=n;i++)
	{
		cin>>b;
		if(a+b>x){t=a+b-x;ans+=t;b=b-t;}
		a=b;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n; cin >> n;
  vector<ll> a(n); rep(i, n) cin >> a[i];
  ll sum = 0, mi = 0xffffffff, neg = 0;
  bool zero = false;

  rep(i, n) {
    zero |= a[i] == 0;
    if (a[i] < 0) neg++;
    sum += abs(a[i]);
    mi = min(mi, abs(a[i]));
  }
  debug2(neg, zero);
  debug2(sum, mi);
  if (neg % 2 == 0 || zero) outl(sum);
  else outl(sum - 2*mi);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;


int main()
{
    int N;
    vector<int> s;
    //map<int, int> s;
    cin >> N; 
    int s_orig[N];

    rep(i,0,N) {
        cin >> s_orig[i];
        s.push_back(s_orig[i]);
    }

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

    int max_1 = s[N-1];
    int max_2 = s[N-2];

    //cout << max_1 << "," << max_2 << endl;

    rep(i, 0, N){
        if(max_1 == s_orig[i]) {
            cout << max_2 << endl;
        } else {
            cout << max_1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <limits.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	if (2 * m > n) cout << 0 << endl;
	else cout << n - 2 * m << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    string s;
    cin>>s;
    int len = (int)s.length();
    /*vector<int >a(len,0);
    if(s[0]=='B')a[0]=1;
    else a[0]=0;
    for(int i=1;i<len;i++){
        if(s[i]=='B')a[i]=a[i-1]+1;
        else a[i]=a[i-1];
    }
    */
    long long count=0;int cb=0;
    for(int i=0;i<len;i++){
        if(s[i]=='B')cb++;
        if(s[i]=='W')count+=cb;
    }
    cout<<count;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;

map<ll, ll> pf(ll x){
    ll y = x;
    ll a = 2;
    map<ll, ll> m;
    while (a * a <= x) {
        if (y % a == 0) {
            y /= a;
            ++m[a];
        } else {
            ++a;
        }
    }
    if (y != 1) ++m[y];

    return m;
}


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

    long long N;

    cin >> N;

    long long result = 1e16;

    // for(auto &&i : pf(N)){
    //     for (ll j = 1; j <= i.second; ++j)
    //         result =
    //             (result < 0) ?
    //             (N / (ll)pow(i.first, j) + (ll)pow(i.first, j)) :
    //             min(result, N / (ll)pow(i.first, j) + (ll)pow(i.first, j));
    // }

    // cout << result - 2;

    for1(i, sqrt(N) + 1){
        if (N % i == 0) {
            result = min(result, N / i + i);
        }
    }

    cout << result - 2;

    return 0;
}


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

using namespace std;

long n, a, b, c, d, x;

int g(int m) {
  long ma = m * d - (n - m - 1) * c;
  long mi = m * c - (n - m - 1) * d;
  if (mi <= x && x <= ma) return 2;
  return x > ma;
}

bool f() {
  cin >> n >> a >> b >> c >> d;
  x = a - b;
  int ok = -1, ng = n;
  while (ng - ok > 1) {
    int m = (ok+ng) / 2;
    int r = g(m);
    if (r == 2) return true;
    (r ? ok : ng) = m;
  }
  return false;
}

int main() {
  if (f()) cout << "YES" << endl;
  else cout << "NO" << endl;
}
    

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

ll N;

void solve()
{
	map<ll, int> pf;
	ll x = N;
	for(ll i=2;i*i<=x;++i){
		if(x%i==0){
			int cnt=0;
			while(x%i==0){
				cnt++;
				x/=i;
			}
			pf[i]=cnt;
		}
	}
	if(x!=1)pf[x]=1;
	ll ans = 0;
	for(auto p : pf){
		const int L = p.second;
		//cout << L << '\n';
		int ps = 0, nxt = 1;
		while(ps + nxt <= L){
			ans++;
			ps+=nxt++;
		}
	}
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	solve();
	return 0;
}

Measured memory_bytes: 3656
import java.util.*;
import java.util.Map.*;

public class Main {
    private static int[] colors;
    private static Map<Integer, Integer>[] friendship;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n - 1;
        
        colors = new int[n];
        Arrays.fill(colors, -1);
        
        friendship = new HashMap[n];
        Arrays.setAll(friendship, i -> new HashMap<Integer, Integer>());
        
        while (m-- > 0) {
            int me = sc.nextInt() - 1;
            int you = sc.nextInt() - 1;
            int length = sc.nextInt();
            friendship[me].put(you, length);
            friendship[you].put(me, length);
        }
        
        dfs(0, 0);
        
        for (int c : colors) {
            System.out.println(c);
        }
    }
    
    public static void dfs(int p, int length) {
        boolean alreadyKnown = colors[p] != -1;
        if (alreadyKnown) return;
        
        if (length % 2 == 0) {
            colors[p] = 0;
        } else {
            colors[p] = 1;
        }
        
        for (Entry<Integer, Integer> entry : friendship[p].entrySet()) {
            int friend = entry.getKey();
            int length2 = entry.getValue();
            dfs(friend, length + length2);
        }
    }
}

Measured memory_bytes: 124100