akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll N,P;
vector<pair<ll, ll>> prime_factor(ll n) {
    vector<pair<ll, ll>> vp;

    // iがsqrt(n)となるまで繰り返す
    for (ll i = 2; i*i <= n; i++) {
        if (n%i == 0) {  // iが素因数
            vp.emplace_back(i, 0);

            // 素因数の数を求める
            do {
                vp[vp.size() - 1].second++;
                n /= i;
            } while (n%i == 0);
        }
    }

    if (n != 1) vp.emplace_back(n, 1);
    return vp;
}
ll ans;
int main() {
    cin>>N>>P;

    ans=1;
    auto pm = prime_factor(P);
    for(auto m: pm){
//        p2(m.first, m.second);
        if(m.second<N) continue;

        ans*=pow(m.first,(m.second/N));
    }
    p(ans);
    return 0;
}


Measured memory_bytes: 256
# Contest No.: ABC173
# Problem No.: C
# Solver:      JEMINI
# Date:        20200705

import sys
import heapq

def main():
    h, w, K = map(int, input().split())
    table = []
    for _ in range(h):
        temp = input()
        table.append([])
        for i in temp:
            table[-1].append(i)    
    ans = 0
    for i in range(2 ** (w + h)):
        cnt = 0
        tempTable = [_[:] for _ in table]

        rowNum = i % (2 ** h)
        colNum = i // (2 ** h)
        cntRow = 0
        cntCol = 0

        while rowNum:
            if rowNum % 2:
                tempTable[cntRow] = ["R"] * w
            rowNum = rowNum // 2
            cntRow += 1
        while colNum:
            if colNum % 2:
                for j in range(h):
                    tempTable[j][cntCol] = "R"
            colNum = colNum // 2
            cntCol += 1
        for j in range(h):
            for k in range(w):
                if tempTable[j][k] == "#":
                    cnt += 1
        #print(i, cnt, K, tempTable)
        if cnt == K:
            ans += 1

    print(ans)


    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 68904
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            count += (d - 1) / sc.nextInt() + 1;
        }
        System.out.println(count + x);
    }
}


Measured memory_bytes: 22228
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//using ll = long long;
//void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}
int f(int n){
    int sum = 0;
    while (n != 0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n, a, b, cnt = 0;
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++){
        int sum = f(i);
        //cout << sum << "\n";
        if(sum >= a && sum <= b)cnt += i;
    }
    cout << cnt;
}

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

#define N 36

int main(){
  int n,i,j,minj;
  char tmp[3],A[N][3],B[N][3],S[N][3];
  
  scanf("%d",&n);
   
  for(i=0;i<n;i++){
    scanf("%s",A[i]);
  }
  
  for(i=0;i<n;i++){
    strcpy(B[i],A[i]);
    strcpy(S[i],A[i]);
  }
  
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(B[j][1]<B[j-1][1]){
	strcpy(tmp,B[j]);
	strcpy(B[j],B[j-1]);
	strcpy(B[j-1],tmp);
      }
    }
  }

  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(S[j][1]<S[minj][1]){
	minj = j;
      }
      
    }
    strcpy(tmp,S[i]);
    strcpy(S[i],S[minj]);
    strcpy(S[minj],tmp);
  }

  for(i=0;i<n;i++){
    printf("%s",B[i]);
    if(i<n-1){
      printf(" ");
    }else{
      printf("\nStable\n");
    }
  }

  for(i=0;i<n;i++){
    printf("%s",S[i]);
    if(i<n-1){
      printf(" ");
    }else{
      printf("\n");
    }
  }
  j=0;
  for(i=0;i<n;i++){
    if(strcmp(B[i],S[i])!=0){
      j=1;
    }
  }
  
  if(j==0){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }
  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=0,t1,t2,a,b,c,d;
int main(){
    scanf("%lld %lld %lld %lld %lld %lld",&t1,&t2,&a,&b,&c,&d);
    a-=c; b-=d; a*=t1; b*=t2;
    if(a+b==0) printf("infinity\n");
    else if(a>0&&a+b>0) printf("0\n");
    else if(a<0&&a+b<0) printf("0\n");
    else{
        b=fabs(b+a); a=fabs(a);
        ans=a/b*2;
        if(a%b!=0) ans++;
        printf("%lld\n",ans);
    }
}


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

int main()
{
	
	int a[3],i,sum=0;
	for(i=0;i<3;i++)
	{
		cin>>a[i];
	}
	sort(a,a+3);
	int k;
	cin>>k;
	while(k--)
	{
		a[2]=a[2]*2;
	}
	for(int j=0;j<3;j++)
	{
		sum=sum+a[j];
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int S = sc.nextInt();
        
        int h = S / 3600;
        S -= (h * 3600);
        int m = S / 60;
        S -= (m * 60);
        int s = S;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26272
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h,w;
  cin>>h>>w;
  vector<string> c(h);
  rep(i,h)cin>>c[i];
  vector<string> ans(2*h);
  rep(i,h){
    if(i==0){
      ans[0]=c[0];
      ans[1]=c[0];
      continue;
    }
    ans[2*i]=c[i];
    ans[2*i+1]=c[i];
  }
  rep(i,2*h){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 3696
def cmb(n,r,mod):
    if r<0 or r>n:return 0
    r=min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod


mod=998244353
n,m,k=map(int,input().split())
g1=[1,1]
g2=[1,1]
inverse=[0,1]

for i in range(2,n):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1]%mod))

ans=m*(m-1)**(n-1)
for i in range(k):
    ans +=(m*pow(m-1,n-2-i,mod))*cmb(n-1,i+1,mod)
    ans %=mod

print(ans%mod)

Measured memory_bytes: 112544
#include <iostream>
#include <string>
#include <sstream>
#include<algorithm>
using namespace std;

int main(){

    while(true){
        
        string n;
        cin>>n;
        
        if(n[0]=='0'&&n.size()==1)break;
        
        int ans=0;
        
        for(int i=n.size()-1;i>=0;i--){
            
            int num=n[i]-'0';
            
            ans=ans+num;
        }
        
        cout<<ans<<endl;
    }
	
	return 0;
	
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,d,p[1000]={},f=0,ans=0;
  cin>>N>>d;
  for(int i=0;i<N;i++)cin>>p[i];
  for(int i=0;i<N;i++)if(p[i]>d)ans+=p[i]-d;
  if(ans>0)cout<<ans<<endl;
  else cout<<"kusoge"<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

const int N=5e5+10;
int n,m,B,re,col[N],cnt[N],ans[N];
void add(int x)
{
    re+=!(cnt[x]++);
}

void del(int x)
{
    re-=!(--cnt[x]);
}

struct Query
{
    int l,r,id;
    bool operator<(Query& b)
    {
        return l/B==b.l/B?r<b.r:l<b.l;
    }
} q[N];

int main()
{
    int i,l=1,r=0;
    
    cin>>n>>m;
    
    B=n/sqrt(m);
    
    for (i=1;i<=n;++i)
    {
        cin>>col[i];
    }
    
    for (i=0;i<m;++i)
    {
        cin>>q[i].l>>q[i].r;
        q[i].id=i;
    }
    
    sort(q,q+m);
    
    for (i=0;i<m;++i)
    {
        if (q[i].l==q[i].r)
        {
            ans[q[i].id]=1;
            continue;
        }
        while (l>q[i].l) add(col[--l]);
        while (r<q[i].r) add(col[++r]);
        while (l<q[i].l) del(col[l++]);
        while (r>q[i].r) del(col[r--]);
        ans[q[i].id]=re;
    }
    
    for (i=0;i<m;++i)
        printf("%d\n",ans[i]);

    return 0;
}


Measured memory_bytes: 15376
n = int(input())

if n == 1:
    print(0)
    exit()

def is_prime(n):
    if n <= 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n%i == 0: return False
    return True

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors


ans = []
cnt = 0
X = make_divisors(n)[1:]
for x in X:
    if is_prime(x):
        ans.append(x)
        n //= x
        cnt += 1
        e = 2
        while x**e < n:
            ans.append(x**e)
            e += 1
    elif x in ans:
        if n%x==0:
            n //= x
            cnt += 1
print(cnt)

Measured memory_bytes: 9268
m,n = map(int,input().split())
k = int(input())
c = [[] for i in range(m)]
for i in range(m):
    c[i] = input()
x = ["J","O","I"]

da = [[[0]*n for _ in range(m)] for _ in range(3)]

for l in range(3):
    if c[0][0] == x[l]:
        da[l][0][0] = 1
    else:
        da[l][0][0] = 0
        
    for i in range(1,n):
        if c[0][i] == x[l]:
            da[l][0][i] = da[l][0][i-1] + 1
        else:
            da[l][0][i] = da[l][0][i-1]
            
    for i in range(1,m):
        co = 0
        for j in range(n):
            if c[i][j] == x[l]:
                co += 1
            da[l][i][j] = da[l][i-1][j] + co
            
for i in range(k):
    p,q,x,y = map(int,input().split())
    p -= 1
    q -= 1
    x -= 1
    y -= 1
    ans = [0] * 3
    for j in range(3):
        if p == 0 and q == 0:
            ans[j] = da[j][x][y]
        elif p == 0:
            ans[j] = da[j][x][y] - da[j][x][q-1]
        elif q == 0:
            ans[j] = da[j][x][y] - da[j][p-1][y]
        else:
            ans[j] = da[j][x][y] - da[j][p-1][y] - da[j][x][q-1] + da[j][p-1][q-1]
            
    print(*ans)


Measured memory_bytes: 123872
M=10**9+7
n=int(input())
a=list(map(int, input().split()))
def f(x, y):
  while y: x,y=y,x%y
  return x
l,r=a[0],1
for i in range(1,n):
  g=f(l,a[i])
  s,t=l//g,a[i]//g
  l,r=s*t*g,(r*t+s)%M
print(r)

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

int main() {
    int A, B, count;
    cin >> A >> B;
    count = 0;
    for(int i = A; i <= B; i ++){
        if(i/10000 == i%10){
            int j = (i%10000)/10;
            if(j/100 == j%10){
                count++;
            }
        }
    }
    cout << count << endl; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Graph vector<vector<ll>>
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
int main(){
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    for(ll i=k;i<n;i++){
        if(a[i]>a[i-k]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4840
import java.io.*;
import java.lang.Integer;
public class Main {
	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String in  = br.readLine() ;
			String[] numStr = in.split(" ");
			int[] num = new int[2];
			num[0] = Integer.parseInt(numStr[0]);
			num[1] = Integer.parseInt(numStr[1]);
			int a1 = num[0]/num[1];
			int a2 = num[0]%num[1];
			double f1 = num[1];
			f1 = num[0]/f1;
			System.out.printf("%d %d %9.5f" , a1, a2, f1);
		} catch ( IOException e ) {
			System.out.println("??¨??????????????????????????????");
		}
	}
}

Measured memory_bytes: 24820
import Data.List
  ( findIndex, minimumBy )

main = do
  _ <- getLine
  [t,a] <- map read . words <$> getLine
  hs <- map read . words <$> getLine
  
  print . findIndex4Minimum $ map (f t a) hs

-- f :: Int -> Int -> Int -> Int
f :: Double -> Double -> Double -> Double
f t a h = abs( (t-h*0.006) - a )

findIndex4Minimum :: [Double] -> Int
findIndex4Minimum ws = snd . minimumBy c . zip ws $ [1..]
  where
    c x y = compare (fst x) (fst y)

Measured memory_bytes: 1276
using System;
using System.Collections.Generic;
using System.Linq;

namespace NextAlphabet
{
    class Program
    {

        static void Main(string[] args)
        {
            var input = Char.Parse(Console.ReadLine());

            char[] alphabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'w', 'x', 'y', 'z' };

            List<char> lettersList = new List<char>();

            for(int i = 0; i < alphabet.Count(); i++)
            {
                lettersList.Add(alphabet[i]);
            }

            var output = lettersList.FindIndex(x => x == input);

            Console.WriteLine(alphabet[output+1]);
        }
    }
}

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

int block[101][101];
int oblock[101][101];
int xg,yg,w,h;

int go (int xs, int ys) {
	//cout << xs << " " << ys << endl;
	oblock[xs][ys] = 1;
	if ( xs > w && ys > h ) {
		return 0;
	}
//	else if ( xs == w && ys == h ) {cout >> "NG" >> endl; return 0;}
	if ( xs > 1 && block[xs-1][ys] == block[xs][ys] && !oblock[xs-1][ys] ){ go( xs-1,ys ); }
	if ( ys > 1 && block[xs][ys-1] == block[xs][ys] && !oblock[xs][ys-1] ){ go( xs,ys-1 ); }
	if ( xs < w && block[xs+1][ys] == block[xs][ys] && !oblock[xs+1][ys] ){ go( xs+1,ys ); }
	if ( ys < h && block[xs][ys+1] == block[xs][ys] && !oblock[xs][ys+1] ){ go( xs,ys+1 ); }
}

int main() {
	while ( cin >> w && cin >> h ) {
		if ( !(w + h) )	break;
		//各ブロックの初期化
		for ( int i = 0; i < w; i++ ) {
			for ( int j = 0; j < h; j++ ) {
				block[i][j] = 0;
				oblock[i][j] = 0;
			}
		}
		int n,xs,ys;
		cin >> xs >> ys;
		cin >> xg >> yg;
		cin >> n;
		//各ブロックの情報の入力
		for ( int i = 0; i < n; i++ ) {
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			int tate,yoko;
			if ( d ) {yoko=2;tate=4;}
			else {yoko=4;tate=2;}
			//カラーの入力
			for ( int j = x; j < x + yoko; j++ ) {
				for ( int k = y; k < y + tate; k++ ) {
					block[j][k] = c;
				}
			}
		}
		/*for ( int i = 0; i < w; i++ ) {
			for ( int j = 0; j < h; j++ ) {
				cout << block[i][j] << " ";
			}
			cout << endl;
		}
		cout << endl;*/
		//経路探索
		if ( block[xs][ys] )	go ( xs, ys );
		if ( oblock[xg][yg] )	cout << "OK" << endl;
		else	cout << "NG" << endl;
		/*for ( int i = 0; i < w; i++ ) {
			for ( int j = 0; j < h; j++ ) {
				cout << oblock[i][j] << " ";
			}
			cout << endl;
		}*/
	}
}

Measured memory_bytes: 1236
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(){
	string s1,s2;
	double d1,d2;
	double l1,l2;
	cin >> s1 >> d1 >> l1;
	cin >> s2 >> d2 >> l2;
	if(s1=="CD"){
		d1 += 60.0;
	}
	if(s2=="CD"){
		d2 += 60.0;
	}
	if(s1=="DB"){
		d1 += 120.0;
	}
	if(s2=="DB"){
		d2 += 120.0;
	}
	double x1,x2,y1,y2;
	x1 = l1 * cos(d1/180.0*M_PI);
	x2 = l2 * cos(d2/180.0*M_PI);
	y1 = l1 * sin(d1/180.0*M_PI);
	y2 = l2 * sin(d2/180.0*M_PI);
	double p1,p2,q1,q2;
	q1 = 2*y1/sqrt(3);
	q2 = 2*y2/sqrt(3);
	p1 = x1-q1/2;
	p2 = x2-q2/2;
	while(!(0<=q1&&q1<=2)){
		if(q1<0){
			q1 +=2;
		}else{
			q1 -=2;
		}
	}
	while(!(0<=q2&&q2<=2)){
		if(q2<0){
			q2 +=2;
		}else{
			q2 -=2;
		}
	}
	while(!(0<=p1&&p1<=2)){
		if(p1<0){
			p1 +=2;
		}else{
			p1 -=2;
		}
	}
	while(!(0<=p2&&p2<=2)){
		if(p2<0){
			p2 +=2;
		}else{
			p2 -=2;
		}
	}
	if(p1+q1>2){
		p1 = 2.0-p1;
		q1 = 2.0-q1;
	}
	if(p2+q2>2){
		p2 = 2.0-p2;
		q2 = 2.0-q2;
	}
	int label1=0;int label2=0;
	if(p1+q1<1){
		label1 =1;
	}
	if(q1>1){
		label1 =2;
	}
	if(p1>1){
		label1 = 3;
	}
	if(p2+q2<1){
		label2 =1;
	}
	if(q2>1){
		label2 =2;
	}
	if(p2>1){
		label2 = 3;
	}
	//cout << p1 << " " << q1 << " " << p2 << " " << q2 << endl;
	if(label1==label2){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#要素の根を探す関数
def find_root(n):
    while(parts[n-1][0]!=n-1):
        n=parts[n-1][0]+1
    return tuple(parts[n-1])

#入力を受け取る
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]

#partsの1つ目は根の番号、2つ目は深さ、3つ目は接続されている要素数
parts=[[i,1,1] for i in range(N)]
#全部壊れた時の不便度はN(N-1)
ans=[N*(N-1)//2]

#橋の数-1だけ処理を行う（橋が全部かかっているときは不便度0なので）
for i in range(M-1):
#一番最後に壊れた橋を探す
    ab=AB.pop()
#それぞれの要素の根を探す
    a=find_root(ab[0])
    b=find_root(ab[1])
#木構造が深い方をaとする
    if a[1]>=b[1]:
        a,b=a,b
    else:
        b,a=a,b
#根が同一ならば処理不要
    if a[0]==b[0]:
        ans.append(ans[-1])
#根が違うのであれば、以後木をくっつける処理を行う
    else:
#要素x個の木と要素y個の木が繋がれば不便度はxyだけ減る
        ans.append(ans[-1]-a[2]*b[2])
#bの根にaを接続する
        parts[b[0]][0]=parts[a[0]][0]
#接続後のaの深さは(aの深さ)と(bの深さ+1)の大きい方
        parts[a[0]][1]=max(parts[a[0]][1],parts[b[0]][1]+1)
#aの要素数+bの要素数が接続後のaの要素数
        parts[a[0]][2]+=parts[b[0]][2]
#答えを出力
for i in reversed(ans):
    print(i)

Measured memory_bytes: 38248
#include <iostream>
#include <queue>
#include <map>

using namespace std;

typedef pair<int, int> P;

void init_minutes(int h, int w, int minutes[1000][1000]) {
    for (int y=0; y<h; y++) {
        for (int x=0; x<w; x++) {
            minutes[x][y] = -1;
        }
    }
}

int main() {
    int h, w, n;
    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};
    int minutes[1000][1000];
    char area[1000][1000];
    P start;

    cin >> h >> w >> n;
    for (int y=0; y<h; y++) {
        for (int x=0; x<w; x++) {
            cin >> area[x][y];
            if (area[x][y] == 'S') {
                start.first = x;
                start.second = y;
            }
        }
        cin.ignore();
    }
    minutes[start.first][start.second] = 0;
    for (int m=1; m<=9; m++) {
        queue<P> q;
        q.push(start);
        int min = minutes[start.first][start.second];
        init_minutes(h, w, minutes);
        minutes[start.first][start.second] = min;
        while (q.size() > 0) {
            int x = q.front().first;
            int y = q.front().second;
            q.pop();
            for (int i=0; i<4; i++) {
                int nx = x+dx[i];
                int ny = y+dy[i];
                if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                    continue;
                }
                if (minutes[nx][ny] >= 0 || area[nx][ny] == 'X') {
                    continue;
                }
                minutes[nx][ny] = minutes[x][y]+1;
                if (area[nx][ny] == '0'+m) {
                    start.first = nx;
                    start.second = ny;
                    break;
                }
                q.push(P(nx, ny));
            }
        }
    }
    cout << minutes[start.first][start.second] << endl;
    return 0;
}

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

int main() {
	int n;cin>>n;
	vector<int> u(n-1),v(n-1),w(n-1);
	vector<int> color(n+1,-1);
	vector<vector<pair<int,int>>> next(n+1,vector<pair<int,int>>(0));
	for(int i=0;i<n-1;i++){
		cin>>u[i]>>v[i]>>w[i];
		next[u[i]].push_back(make_pair(v[i],w[i]));
		next[v[i]].push_back(make_pair(u[i],w[i]));

	}
	color[1]=0;
	vector<int> list;
	list.push_back(1);
	while(list.size()){
		int num=list.back();
		list.pop_back();
		for(auto x:next[num]){
			if(color[x.first]==-1){
				list.push_back(x.first);
				if(x.second%2){
					color[x.first]=1-color[num];
				}else{
					color[x.first]=color[num];
				}
//				cout<<num<<' '<<color[num]<<' '<<x.first<<' '<<color[x.first]<<endl;
			}
		}

	}
	for(int i=1;i<=n;i++){
		cout<<color[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 7936
#include <iostream>

using namespace std;

int main()
{
    int K, S, res = 0;
    cin >> K >> S;
    for (int X = 0; X <= K; X++) {
        for (int Y = 0; Y <= K; Y++) {
            int Z = S - (X + Y);
            if (0 <= Z && Z <= K) {
                ++res;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;

const int N_MAX = 100000;

int N;
ll K;
P ps[N_MAX];

void solve() {
  sort(ps, ps + N);
  ll ans = 0;
  REP(i, N) {
    if (K <= ps[i].second) {
      ans = ps[i].first;
      break;
    }
    K -= ps[i].second;
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d%lld", &N, &K);
  REP(i, N) {
    int a, b;
    scanf("%d%d", &a, &b);
    ps[i] = P(a, b);
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 896
#! /usr/bin/env python3

n, m = map(int, input().split())
data = [[int(i) for i in input().split()] for _ in range(n)]

res = -1000000

for x in [1,-1]:
    for y in [1,-1]:
        for z in [1,-1]:
            s = 0
            ss = []
            for row in data:
                ss.append(row[0] * x + row[1] * y + row[2] * z)
            ss.sort()
            ss.reverse()
            for i in range(m):
                s += ss[i]
            if s > res:
                res = s

print(res)


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

struct	ModCombi
{
	int64_t	sup, mod;
	vector<int64_t>	fact_vec, inv_vec, if_vec;
	ModCombi(int64_t sup, int64_t mod): sup(sup), mod(mod)
	{
		fact_vec.resize(sup + 1);
		inv_vec.resize(sup + 1);
		if_vec.resize(sup + 1);
		fact_vec.at(0) = fact_vec.at(1) = 1;
		inv_vec.at(1) = 1;
		if_vec.at(0) = if_vec.at(1) = 1;
		for (int64_t i = 2; i <= sup; ++i) {
			fact_vec.at(i) = fact_vec.at(i - 1) * i % mod;
			inv_vec.at(i) = mod - mod / i * inv_vec.at(mod % i) % mod;
			if_vec.at(i) = if_vec.at(i - 1) * inv_vec.at(i) % mod;
		}
	}
	int64_t	calc(int64_t n, int64_t k)
	{
		if (n < 0 || sup < n) return 0;
		if (k < 0 || n < k) return 0;
		return fact_vec.at(n) * if_vec.at(k) % mod * if_vec.at(n - k) % mod;
	}
};

int	main()
{
	const static int64_t	mod = static_cast<int64_t>(1e+9) + 7;
	int	X, Y;
	cin >> X >> Y;
	int num_move0 = 2 * Y - X, num_move1 = 2 * X - Y;
	if ((num_move0 % 3 != 0) || (num_move1 % 3 != 0)) {
		cout << 0 << endl;
		return 0;
	}
	if (num_move0 < 0 || num_move1 < 0) {
		cout << 0 << endl;
		return 0;
	}
	num_move0 /= 3;
	num_move1 /= 3;
	ModCombi	mc(num_move0 + num_move1, mod);
	cout << mc.calc(num_move0 + num_move1, num_move0) << endl;
}
	




Measured memory_bytes: 15872
import bisect
n=int(input())
a = list(map(int,input().split()))
a.sort()
 
c = 0
d = 0 #i
 
while d <= n-1:
    s2 = bisect.bisect_right(a,a[d])
    s = s2-d
    if a[d] > s:
        c += s
    else:
        c += s-a[d]
    d = d + s
    
print(c)

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

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



Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int64_t n;
  cin >> n;
  vector<int> p;
  int64_t N=n;
  int count_sum=0;
  int ans=0;
  if(n==1){
    cout << 0 << endl;
  }else{
  for(int i=2;i<=sqrt(N);i++){
    int count =0;
    if(n%i==0){
      do{
        count++;
        n=n/i;
      }while(n%i==0);
      count_sum+=count;
      p.push_back(count);
    }    
  }
    if(n>sqrt(N)){
            p.push_back(1);
    }
    
  if(count_sum!=0){
  for(int j=0;j<p.size();j++){
    if(p.at(j)>35){
      p.at(j)=8;
    }else if(p.at(j)>27){
      p.at(j)=7;
    }else if(p.at(j)>20){
      p.at(j)=6;
    }else if(p.at(j)>14){
      p.at(j)=5;
    }else if(p.at(j)>9){
      p.at(j)=4;
    }else if(p.at(j)>5){
      p.at(j)=3;
    }else if(p.at(j)>2){
      p.at(j)=2;
    }else{
      p.at(j)=1;
    }

   ans+=p.at(j); 
  }}else{
    ans=1;
  }
  
  cout << ans <<endl;
}
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll mod=(1e+9)+7;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

bool check(string &res, string &s, char zero, char one){
  ll n=s.size();
  rep(i,0,n) res[i]='?';
  res[0]=zero;
  res[1]=one;
  
  if(!((s[0]=='o')^(res[0]=='S'))) res[res.size()-1]=one;
  else res[res.size()-1]=(res[1]=='S'?'W':'S');
 
  rep(i,2,n-1){
   if(!((s[i-1]=='o')^(res[i-1]=='S'))) res[i]=res[i-2];
   else res[i]= (res[i-2]=='S'?'W':'S');
  }
  
  char flag;
  
  if(!((s[n-2]=='o')^(res[n-2]=='S'))) flag=res[n-3];
  else flag = (res[n-3]=='S'?'W':'S');

  return (res[n-1]==flag)&&((res[n-1]=='S')^(s[n-1]=='o')^(res[n-2]==res[0]));

}

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

 ll n;
 string s;
  cin >> n >> s;
 string res=s;
 
 if(check(res,s,'S','S')) {
   cout << res << endl;
   return 0;
 }
 if(check(res,s,'S','W')) {
   cout << res << endl;
   return 0;
 }
 if(check(res,s,'W','W')) {
   cout << res << endl;
   return 0;
 }
 if(check(res,s,'W','S')) {
   cout << res << endl;
   return 0;
 }
  cout << -1 << endl;
 
  
}


Measured memory_bytes: 640
import Data.List -- sort
import Control.Monad -- replicateM

readInt = read <$> getLine :: IO Integer
arrayInt = map read . words <$> getLine :: IO [Integer]
writeln x = putStrLn $ unwords x :: IO ()

main = do
    [a,b,t] <- arrayInt
    print $ (t `div` a) * b

eval a b = sum $ zipWith (\ x y -> if x == y then 0 else 1) a b


Measured memory_bytes: 508
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int n;
    int ans = 0;
    map<string, int> cards;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (cards.count(s) > 0) {
            cards[s]++;
        } else {
            cards[s] = 1;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19148
using System;
class Program
{
  static void Main(string[] args)
  {
    int N = int.Parse(Console.ReadLine());
    string[] nums = new string[2];
    double Value;
    string Money;
    double Sum = 0;
    for(int i = 0; i < N; i++)
    {
      nums = Console.ReadLine().Split(' ');
      Value = float.Parse(nums[0]);
      Money = nums[1];
      if(Money == "BTC")
      {
        Sum += Value * 380000.0;
      }
      else
      {
        Sum += Value;
      }
    }
    Console.WriteLine(Sum);
  }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int N,upMAX,downMAX,num,tmp,pre;

	scanf("%d",&N);

	for(int i = 0; i < N; i++){
		scanf("%d",&num);
		pre = -1;
		upMAX = 0,downMAX = 0;
		for(int k = 0; k < num; k++){
			scanf("%d",&tmp);
			if(pre == -1){
				//Do nothing
			}else if(pre > tmp){
				downMAX = max(downMAX,pre-tmp);
			}else if(pre < tmp){
				upMAX = max(upMAX,tmp-pre);
			}
			pre = tmp;
		}
		printf("%d %d\n",upMAX,downMAX);
	}

	return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <queue>
#include <stack>

typedef long long ll;
using namespace std;

int main(){
  ll i,j,k;
  ll n,a,b;
  cin >> n >> a >> b;
  cout << min(a,b) << " " << max(a+b-n,0ll) << endl;
  return 0;
}


Measured memory_bytes: 256
program sunuke

implicit none

integer::    n
integer::    x,y,z

read(*,*) n
x=int(n/100)
n=n-100*x
y=int(n/10)
z=n-10*y


if(x==1) then
  x=9
else if(x==9) then
  x=1
endif
if(y==1) then
  y=9
else if(y==9) then
  y=1
endif
if(z==1) then
  z=9
else if(z==9) then
  z=1
endif

n=100*x+10*y+z

write(*,*) n

end program sunuke


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if (A == B && B == C && A % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }

    int ans = 0;
    while (1) {
        if (A % 2 || B % 2 || C % 2) {
            cout << ans << endl;
            return 0;
        }

        int a = A, b = B, c = C;
        A = (b + c) / 2;
        B = (a + c) / 2;
        C = (a + b) / 2;

        ++ans;
    }

    return 0;
}

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

int A[200010], B[200010];
bool AC[200010], CB[200010];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++)
    cin >> A[i] >> B[i];
  
  for (int i = 0; i < M; i++) {
    if (A[i] == 1)
      AC[B[i] - 1] = true;
    else if (B[i] == N)
      CB[A[i] - 1] = true;
  }
  
  for (int i = 0; i < M; i++) {
    if (AC[i] && CB[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
//#define int ll
#define el '\n'
typedef long long ll; typedef long double ld; typedef double dd;typedef vector<int> vi; typedef pair<int, int> pii;typedef pair<ll,ll> pll;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;
///if(///////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vi vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}



///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n, sum=0; cin>>n;
vi v(n); for(int i=0;i<n;++i){
	cin>>v[i];
	sum+=v[i];
}
bool ok=true;
for(int i=0;i<n;++i){
	if(v[i]>=sum-v[i] || v[i]<1) ok=false;
}
cout<<(ok?"Yes":"No")<<el;

return 0;
}


Measured memory_bytes: 256
N,M,V,P,*A = $<.read.split.map &:to_i
I,c = [[]]
A.sort!.each_with_index {|n,i| I<<i if c!=n; c=n}
x,y = [A[-P]-M,A[-P]].map {|n| I.bsearch_index {|i| A[i]>=n} }
c = I[x]
v = V-P-c+1
t = A[c]+M
T = I[y+1]=N-P+1
w = (x..y).inject(0) {|s,i| a,b=I[i,2]; s+(t-A[a])*(b-a)}
while M*v > w
	a,b = I[x,2]
	c += b-a
	w += (A[b]-A[a])*(T-b)
	x += 1
end
p N-c

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

Measured memory_bytes: 48328
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
main(){
  int n,y;
  cin>>n>>y;
  for(int i=0;i<10000;i++){
    for(int j=0;j<10000;j++){
      int x=y-(i*10000)-(j*5000);
      if(x>=0&&x%1000==0){
        int k=x/1000;
        if(i+j+k==n){
          cout<<i<<' '<<j<<' '<<x/1000<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>

using namespace std;

long long n, x, y;
const long long N = 2e5 + 5;
const long long mod = 1e9 + 7;
long long mini1 = 1000 * 1000 * 1000 + 7;
long long mini2 = 1000 * 1000 * 1000 + 7;
long long color1 = 0;
long long color2 = -1;
long long ind1;
long long ind2;
long long cnt = 0;
long long c[N];
long long fac[N];
vector<long long> v;
long long w[N];
map<long long, long long> mp;
bool mark[N];
map<long long, long long > mn;
vector<int> graph[N];

long long power(long long a, long long b)
{
	if (b == 0)
	{
		return 1;
	}
	long long ans = power(a, b / 2);
	ans = ans % mod;
	ans = ans * ans;
	ans = ans % mod;
	if (b % 2 == 1)
	{
		ans = ans * a;
		ans = ans % mod;
	}
	return ans;
}

long long choose(long long a, long long b) 
{
	long long t = fac[b];
	t = (t * power(fac[a], mod - 2)) % mod;
	t = (t * power(fac[b - a], mod - 2)) % mod;
	return t;
}


int main() 
{
	fac[0] = 1;
	for (long long i = 1; i < N; i++)
	{
		fac[i] = (fac[i - 1] * i) % mod;
	}
	cin >> n >> x >> y;
	for (long long i = 0; i < n; i++)
	{
		cin >> c[i] >> w[i];
		if (mn[c[i]] > w[i] || mn[c[i]] == 0)
		{
			mn[c[i]] = w[i];
		}
		if (w[i] < mini1)
		{
			if (c[i] == color1)
			{
				mini1 = w[i];
				ind1 = i;
			}
			else
			{
				mini2 = mini1;
				color2 = color1;
				ind2 = ind1;
				mini1 = w[i];
				color1 = c[i];
				ind1 = i;
			}
			continue;
		}
		if (c[i] != color1 && mini2 > w[i])
		{
			mini2 = w[i];
			color2 = c[i];
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (w[i] + mn[c[i]] <= x)
		{
			w[i] = mn[c[i]];
		}
	}
	for (long long i = 0; i < n; i++)
	{
		if (c[i] != color1)
		{
			if (w[i] + mini1 <= y)
			{
				mp[c[i]]++;
				cnt++;
			}
		}
		if (c[i] == color1)
		{
			if (w[i] + mini2 <= y || w[i] + mini1 <= x)
			{
				mp[c[i]]++;
				cnt++;
			}
		}
	}
	for (long long i = 0; i < n; i++)
	{
		if (mp[c[i]])
		{
			v.push_back(mp[c[i]]);
			mp[c[i]] = 0;
		}
	}
	long long ans = 1;
	for (long long i = 0; i < v.size(); i++)
	{
		long long tmp = v[i];
		ans = ans * max(1ll, choose(tmp, cnt));
		ans = ans % mod;
		cnt = cnt - tmp;
	}
	cout << ans << endl;



}


Measured memory_bytes: 28148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n, m;
    cin >> n >> m;
    int a[m], b[m], cnt[n] = {};
    rep (i, m) {
        cin >> a[i] >> b[i];
        cnt[a[i] - 1]++;
        cnt[b[i] - 1]++;
    }
    rep (i, n) {
        if (cnt[i] % 2 != 0) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    VI p(N),n2id(N);
    REP(i,N){
        cin >> p[i]; p[i]--;
        n2id[p[i]] = i;
    }
    VI a(N), b(N);
    REP(i,N) a[i] = 30000 + i*30000;
    RREP(i,N) b[i] = 30000 + (N-1-i)*30000;
    REP(i,N){
        a[p[i]] += i;
        b[p[i]] += i;
    }
    REP(i,N) cout << a[i] << " ";
    cout << en;
    REP(i,N) cout << b[i] << " ";
    cout << en;
    return 0;
}

Measured memory_bytes: 896
def insertion_sort(a, n)
  n.times do |i|
    v = a[i]
    j = i - 1
    while j >= 0 && a[j] > v
      a[j + 1] = a[j]
      j -= 1
    end

    a[j + 1] = v
    puts a.join(' ')
  end
end

n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)

insertion_sort(a, n)

Measured memory_bytes: 8732
N, M = map(int, input().split())
edges = [[] for _ in range(N + 1)]
res = 0
passed_nodes = set()

for _ in range(M):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

def recur(i, tot, pns):
    global res
    pns = pns.copy()

    if tot == N:
        res += 1
        return

    flag = False
    pns.add(i)

    for e in edges[i]:
        if e not in pns:
            recur(e, tot + 1, pns)
            flag = True

    if not flag:
        return

recur(1, 1, passed_nodes.copy())

print(res)



Measured memory_bytes: 3064
//コンパイラ最適化用
#pragma GCC optimize("O3")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

signed main(){
  ll N, D;
  cin >> N >> D;
  ll point[N][2];
  long double distance;
  long double sum;
  int numP=0;
  for (int i=0; i < N; i++){
    cin >> point[i][1] >> point[i][2];
  }
  
  for(int i = 0; i< N ; i++){
distance = sqrt((pow(point[i][1], 2) + pow(point[i][2], 2)));
    //cout << point1[i]*point1[i] << endl;
    //cout << sum << ", " << distance << endl;
    if(D >= distance){
      numP++;
    }
  }
  cout << numP;
}



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

#define fi first
#define se second

const int N = 6006;
const long long mod = 1e9 + 7;

using namespace std;


int main()
{
        ios_base::sync_with_stdio(false);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        string s;
        cin >> s;
        int n = s.size();
        bool bad = false;
        if(s[n - 1] == '1'){
                bad = true;
        }
        if(s[0] == '0' || s[n - 2] == '0'){
                bad = true;
        }
        for(int i = 1; i < n; i++){
                if(s[i - 1] != s[n - i - 1]){
                        bad = true;
                }
        }
        if(bad){
                cout << -1 << "\n";
                return 0;
        }

        int x = 2;
        cout << 1 << " " << 2 << "\n";
        for(int i = 2; i < n; i++){
                cout << x << " " << i + 1 << "\n";
                if(s[i - 1] == '1'){
                        x = i + 1;
                }
        }
}


Measured memory_bytes: 1616
import java.util.Scanner;
 
class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
 
double a = scanner.nextDouble();
double b = scanner.nextDouble();
 
if(a > b) {
    System.out.println("GREATER");
} else if(a < b) {
    System.out.println("LESS");
} else {
    System.out.println("EQUAL");
}
}
}

Measured memory_bytes: 24532
#include <stdio.h>

int main(void) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a < b) {
        if(b < c) {
            puts("Yes");
        } else {
            puts("No");
        }
    } else {
        puts("No");
    }
}


Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  string n;
  cin >> n;
  int sum = 0;
  for (char c : n) {
    int ni = c - '0';
    sum += ni;
    sum %= 9;
  }
  if (sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(){
    int go = 0;
    int shiti = 0;
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    for(int i=0;i<3;i++){
        if(a[i]==5){
            go++;
        }
        else if(a[i]==7){
            shiti++;
        }
    }

    if(go==2 &&shiti==1){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
        
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 200000000000000ll
using namespace std;
map<ll,ll>mp;
ll a[400005],sum[400005],ans;int n;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	mp[N]++;
	for (int i=1;i<=n;i++){
		ans=ans+mp[sum[i]+N];
		mp[sum[i]+N]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 18432
#include <stdio.h>

int	main(void)
{
  	int	n;
  	int a[200002];
  	int	i;
  	int	t[200002];
 
  	scanf("%d\n", &n);
  	for(i=1; i<=n; i++)
    {
      	t[i] = 0;
    }
  	a[0] = 0;
  	for(i=2; i<=n; i++)
    {
      	scanf("%d", &a[i]);
      	t[a[i]]++;
    }
  
 	for(i=1; i<=n; i++)
    {
      	printf("%d\n", t[i]);
    }
  	return (0);
}

Measured memory_bytes: 3288
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define V vector<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N;  cin >> N;
    string s;  cin >> s;

    int kp[3][4000];
    REP(i, 3)  REP(j, 4000)  kp[i][j] = 0;  //RGB
    if(s[0] == 'R')       kp[0][0]++;
    else if(s[0] == 'G')  kp[1][0]++;
    else if(s[0] == 'B')  kp[2][0]++;
    
    REP(i, N){
      kp[0][i] = kp[0][i - 1];
      kp[1][i] = kp[1][i - 1];
      kp[2][i] = kp[2][i - 1];
      if(s[i] == 'R')       kp[0][i]++;
      else if(s[i] == 'G')  kp[1][i]++;
      else if(s[i] == 'B')  kp[2][i]++;
      
    }


    ll ans = 0;
    for(int i = 1 ;  i < N-1 ; i++){
      if(s[i] == 'R')      ans += kp[1][i-1]*(kp[2][N-1]-kp[2][i]) + kp[2][i-1]*(kp[1][N-1]-kp[1][i]);
      else if(s[i] == 'G') ans += kp[0][i-1]*(kp[2][N-1]-kp[2][i]) + kp[2][i-1]*(kp[0][N-1]-kp[0][i]);
 	  else if(s[i] == 'B') ans += kp[0][i-1]*(kp[1][N-1]-kp[1][i]) + kp[1][i-1]*(kp[0][N-1]-kp[0][i]);
      
      for(int side = 1 ; side <= min(i, N-i-1) ; side++){
        if(s[i] != s[i-side] && s[i] != s[i+side] && s[i+side] != s[i-side])  ans--;
      }
    }

    cout << ans << endl;
  	return 0;
}


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

int main()
{
	long long n,i,ara[200010],sum,sss,w,mm;
	while(scanf("%lld",&n)==1)
	{
		sum = 0;
		sss = 0;
		for(i=0;i<n;i++)
		{
			scanf("%lld",&ara[i]);
			if(i!=n-1)
				sum = sum + ara[i];
			//else
				//sss = sss + ara[i];
		}
		//printf("%d %d\n",sum,sss);
		sss = ara[n-1];
		mm = 99999999999999;
		w = abs(sss-sum);
		mm = min(mm,w);
		for(i=n-2;i>0;i--)
		{
			sum = sum - ara[i];
			sss = sss + ara[i];
			w = abs(sum-sss);
			mm = min(mm,w);
		}
//		mm = abs(sum-sss);
//		if(sum>sss)
//		{
//			for(i=n/2-1;i>0;i--)
//			{
//				sss = sss + ara[i];
//				sum = sum - ara[i];
//				w = abs(sum-sss);
//				mm = min(mm,w);
//			}
//		}
//		else if(sum<sss)
//		{
//			for(i=n/2;i<n-1;i++)
//			{
//				sss = sss - ara[i];
//				sum = sum + ara[i];
//				w = abs(sum-sss);
//				mm = min(mm,w);
//			}
//		}
//		else
//			mm = 0;
		printf("%lld\n",mm);
	}
    return 0;
}


Measured memory_bytes: 1792