akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    Parents = None

    def __init__(self, N):
        self.Parents = [-1 for i in range(N + 1)]

    # Aがどのグループにいるのか調べる
    def root(self, A):
        if self.Parents[A] < 0:
            return A
        else:
            self.Parents[A] = self.root(self.Parents[A])
            return self.Parents[A]

    # Aが所属しているグループのサイズを返す
    def size(self, A):
        return -self.Parents[self.root(A)]

    # AとBをくっつける
    def Connect(self, A, B):
        if self.root(A) == self.root(B):
            return False
        if self.size(A) < self.size(B):
            self.Parents[self.root(B)] += self.Parents[self.root(A)]
            self.Parents[self.root(A)] = B
        else:
            self.Parents[self.root(A)] += self.Parents[self.root(B)]
            self.Parents[self.root(B)] = A
        return True


n, m = map(int, input().split())
a = [input().split() for i in range(m)]
a = [(int(i[0]), int(i[1])) for i in a]
ans = [int(n * (n - 1) / 2) for i in range(m)]
uni = UnionFind(n)

for i in range(m):
    if i == 0:
        continue
    A = a[-i][0]
    B = a[-i][1]

    if uni.root(A) != uni.root(B):
        ans[i] = ans[i-1] - uni.size(A) * uni.size(B)
        uni.Connect(A, B)
    else:
        ans[i] = ans[i-1]


for i in range(1, m+1):
    print(ans[-i])


Measured memory_bytes: 45800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}



	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int f[][] = new int[n][10];
		for(int i=0; i<n; i++) {
			for(int j=0; j<10; j++) {
				f[i][j]=sc.nextInt();
			}
		}
		int p[][] = new int[n][11];
		for(int i=0; i<n; i++) {
			for(int j=0; j<11; j++) {
				p[i][j]=sc.nextInt();
			}
		}
		int ans = Integer.MIN_VALUE;
		for(int i=1; i<(1<<10); i++) {
			int sum=0;
			for(int j=0; j<n; j++) {
				int c=0;
				for(int k=0; k<10; k++) {
					if(f[j][k]==1 && ((i>>k)&1)==1) {
						c++;
					}
				}
				sum+=p[j][c];
			}
			ans = Math.max(ans, sum);
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 26276
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
#define pb(x) push_back(x);
typedef long long  int ll;
ll mod = 998244353;
ll hmaxii=0;
vector<ll>values[2*100000+1];
ll MAXN = 2*100000+1;
ll spf[2*100000+1];
//vector<ll>values[];
ll diff,x,y,z;
ll flag=1;ll price[1001][1001];

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }


void solution(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int ans[n];
    ans[0]=0;
    ans[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<=k&&i<n;i++){
        ans[i] = abs(arr[0]-arr[i]);
        for(int j=i-1;j>=1;j--){
            ans[i] = min(ans[i],ans[j]+abs(arr[i]-arr[j]));
        }
    }
    for(int i=k+1;i<n;i++){
        ans[i]=INT_MAX;
        for(int j=1;j<=k;j++){
            ans[i]=min(ans[i],ans[i-j]+abs(arr[i]-arr[i-j]));
        }
    }
    cout<<ans[n-1]<<endl;
}


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //sieve();
    /*ll powe[64];
    powe[0]=1;
    ll i=1;
    while(i<64){
        powe[i] = powe[i-1]*2;
        i++;
    }*/
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solution();
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        int a,b; cin>>a>>b;
        if(b%a==0)cout<<a+b<<endl;
        else cout<<b-a<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a;
    char b;
    bool c[4] = {false, false, false, false};
    cin >> a;
    for (int i = 0; i < a; i++) {
        cin >> b;
        if(b == 'Y'){
            printf("%s\n", "Four");
            return 0;
        }
    }
    printf("%s\n","Three");
    return 0;
}

Measured memory_bytes: 256
'''
2で割った余り == p
p:0
1を偶数個と0を任意の数
p:1
1を奇数個と0を任意の数
'''

def comb(n, r):
    ret = 1
    if (n == r) or (n == 0) or (r == 0):
        ret = 1
    else:
        for i in range(1, n + 1):
            ret *= i
        for i in range(1, r + 1):
            ret //= i
        for i in range(1, n - r + 1):
            ret //= i
##    print('comb', n, r, ret)
    return ret

if __name__ == '__main__':
    n, p = map(int, input().split())
    a = list(map(int, input().split()))
    a_mod2 = list(map(lambda x: x % 2, a))
    cnt_0 = a_mod2.count(0)
    cnt_1 = a_mod2.count(1)
    cnt_odd_1 = cnt_1 if cnt_1 % 2 == 1 else cnt_1 - 1
    cnt_even_1 = cnt_1 if cnt_1 % 2 == 0 else cnt_1 - 1

##    print('a', a)
##    print('a_mod2', a_mod2)
##    print('cnt_0', cnt_0)
##    print('cnt_1', cnt_1)
##    print('cnt_odd_1', cnt_odd_1)
##    print('cnt_even_1', cnt_even_1)

    ans = 0
    if p == 0:
        rng = list(range(0, cnt_even_1 + 1))[::2]
        for i in rng:
            ans += comb(cnt_1, i)
        ans *= (2 ** cnt_0)
    elif p == 1:
        rng = list(range(1, cnt_odd_1 + 1))[::2]
        for i in rng:
            ans += comb(cnt_1, i)
        ans *= (2 ** cnt_0)
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main()
{
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int ans;
    int d=2*max(x,y)+1;
    vin sum(d);
    rep(l,d){
        if(l<=x&&l<=y)sum[l]=a*x+b*y+(2*c-a-b)*l;
        else if(l>x&&l<=y)sum[l]=b*y+(2*c-b)*l;
        else if(l<=x&&l>y)sum[l]=a*x+(2*c-a)*l;
        else if(l>x&&l>y)sum[l]=2*c*l;
    }
    sort(all(sum));
    cout<<sum[0]<<endl;
}

Measured memory_bytes: 1024
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Fenwick Tree
struct FenwickTree {
    int length;
    vector<ll> node;
    FenwickTree (int N) : length(N), node(length + 1, 0) {}
    void add(int idx, ll val) {
        ++idx;
        while (idx <= length) {
            node[idx] += val;
            idx += (idx & (-idx));
        }
    }
    ll getsum(int idx) {
        ll ans = 0;
        while (idx) {
            ans += node[idx];
            idx -= (idx & (-idx));
        }
        return ans;
    }
};

// Main
int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(3, vector<int>(n));
    rep(i, 3) rep(j, n) {
        cin >> a[i][j];
        --a[i][j];
    }
    
    rep(i, n) {
        if (a[0][i] / 3 != a[1][i] / 3 || a[1][i] / 3 != a[2][i] / 3 || a[2][i] / 3 != a[0][i] / 3) {
            cout << "No\n";
            return 0;
        }
        if (a[1][i] % 3 != 1) {
            cout << "No\n";
            return 0;
        }
        if ((a[1][i] / 3 - i) % 2) {
            cout << "No\n";
            return 0;
        }
    }
    
    ll b0 = 0, b1 = 0;
    FenwickTree ft0(n), ft1(n);
    for (int i = 0; i < n; i += 2) {
        b0 += (i / 2 - ft0.getsum(a[0][i] / 3 + 1));
        ft0.add(a[0][i] / 3, 1);
    }
    for (int i = 1; i < n; i += 2) {
        b1 += (i / 2 - ft1.getsum(a[0][i] / 3 + 1));
        ft1.add(a[0][i] / 3, 1);
    }
    ll r0 = 0, r1 = 0;
    for (int i = 0; i < n; i += 2) {
        if (a[0][i] % 3) ++r0;
    }
    for (int i = 1; i < n; i += 2) {
        if (a[0][i] % 3) ++r1;
    }
    
    if (b0 % 2 == r1 % 2 && b1 % 2 == r0 % 2) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 5820
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;

int n,a[N];

int coba(int x){
	int ct=0;
	for (int i=1;i<=n;i++){
		if (a[i]<x){
			ct++;
		}
	}
	if (x-ct){
		return (n-ct)/(x-ct)>1;
	}else{
		return !(n-ct);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	int mn=INT_MAX;
	int mx=INT_MIN;
	for (int i=1;i<=n;i++){
		cin >> a[i];
		mn=min(mn,a[i]);
		mx=max(mx,a[i]);
	}
	if (mx-mn<=1){
		int ans=0;
		if (mx==mn){
			ans=coba(mn);
		}
		ans|=coba(mn+1);
		cout << (ans?"Yes":
		"No") << "\n";
	}else{
		cout << "No\n";
	}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
const ll M = 1e9 + 7;
using namespace std; 

void solve()
{
	ll n;
	cin>>n;
	ll a[n],xo=0;
	for(ll i=0;i<n;i++) 
	{
		cin>>a[i];
		xo=xo^a[i];
	}
	for(ll i=0;i<n;i++)
	{
		cout<<(xo^a[i])<<" ";
	}
}

int main() 
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 5116
#include <iostream>
#include <vector>
#include <utility>
#include<algorithm>
using namespace std;

int main() {
	string s;
	cin >> s;
	vector<int>v(s.size());
	for (int i = 0; i < s.size(); i++) {
		v.at(i) = s.at(i)-'0';
	}
	int ans1=0;
	int ans2 = 0;
	for (int i = 0; i < s.size(); i++) {
		int a  = i % 2;
		if (v.at(i) == a)
			ans1++;
	}
	for (int i = 0; i < s.size(); i++) {
		int a = (i + 1) % 2;
		if (v.at(i) == a)
			ans2++;
	}
		cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 896
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;

namespace 水色コーダーに俺はなった{
    class Inonoa{

        /* ここに書け */
        static void Main(){
            long[] nk = ILongs();
            long n = nk[0];
            long k = nk[1];

            long[] a = ILongs();

            long[] last = new long[n];
            for(int i=0;i<last.Length;i++){
                last[i] = -1;
            }

            long ima_turn = 0;
            long ima_idx = 0;
            long[] rireki = new long[300000];

            while(true){
                long tsugi = a[ima_idx] - 1;
                if(ima_turn==(k-1)){
                    Console.WriteLine(tsugi+1);
                    return;
                }
                else if(tsugi==0){
                    long shuki =  ima_turn + 1;
                    long amari = k % shuki;
                    long ans = amari==0 ? 0 : rireki[amari-1];
                    WriteLine(ans + 1);
                    return;
                }else if(last[tsugi]==-1){
                    last[tsugi] = ima_turn;
                }
                    else{
                    long shuki =  ima_turn - last[tsugi];
                    long amari = (k - (last[tsugi] + 1)) % shuki;
                    long ans = rireki[last[tsugi] + amari];
                    WriteLine(ans + 1);
                    return;
                }
                ima_idx = tsugi;
                rireki[ima_turn] = tsugi;
                ima_turn++;
            }
        }

        static readonly long MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static long[] ILongs(){
            string[] s = ReadLine().Split();
            long[] re = new long[s.Length];
            for(long i=0;i<s.Length;i++){
                re[i] = long.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static long[][] ILongLongs(long n){
            long[][] re = new long[n][];
            for(long i=0;i<n;i++){
                string[] s = ReadLine().Split();
                re[i] = new long[s.Length];
                for(long j=0;j<s.Length;j++){
                    re[i][j] = long.Parse(s[j]);
                }
            }
            return re;
        }

        ///<summary>n行の文字列を取ったり</summary>
        static char[][] ICharsChars(long n){
            char[][] re = new char[n][];
            for(long i=0;i<n;i++){
                re[i] = ReadLine().ToCharArray();
            }
            return re;
        }
    }
}

Measured memory_bytes: 45704
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << # x << "; "<< x << endl


int main() {
	long long N, D, X ,Y;
	cin >> N >> D;
	int count = 0;
	for (int i = 0; i < N; i++) {
		cin >> X >> Y;
		if (X * X + Y * Y <= D * D) {
			count += 1;
		}
	}
	cout << count << endl;
}

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

Measured memory_bytes: 580
#include<stdio.h>
#define N 100
int main()
{
  int i,j,l,v,z,A[N];
  
  scanf("%d",&l);
  
  for(i = 1;i <= l;i++){
    scanf("%d",&A[i]);
  }
  
  for(i = 1;i <= l;i++){
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(z = 1;z < l;z++){
      printf("%d ",A[z]);
    }
    printf("%d",A[z]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
/// @file

#include <iostream>

namespace {

bool run(std::istream& is, std::ostream& os);
}  // unnamed namespace

/// @brief エントリポイント
#ifdef _TEST
static int run()
#else
int main()
#endif
{
  try {
    if (run(std::cin, std::cout) == false) {
      std::cerr << "main funciton error.\n";
      return EXIT_FAILURE;
    }
  } catch (const std::exception& e) {
    std::cerr << "catch exception\n";
    std::cerr << e.what() << "\n";
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

namespace {

/// @brief 実行処理
bool run(std::istream& is, std::ostream& os)
{
  int x;
  int y;
  is >> x >> y;

  const int COST = x + y / 2;
  os << COST << "\n";

  return true;
}
}  // unnamed namespace


Measured memory_bytes: 888
def main():
    S = input()
    Even = []
    Odd = []

    for i in range(len(S)):
        if i % 2 == 0:
            Even.append(S[i])
        else:
            Odd.append(S[i])

    if not Even.__contains__("L") and not Odd.__contains__("R"):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Dec  8 00:45:25 2018
//
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	ans := 0
	base := 1
	for i := 0; N != 0; i++ {
		if N%(base*2) != 0 {
			ans += 1 << uint8(i)
			N -= base
		}
		base *= -2
	}

	fmt.Printf("%b\n", ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, x, n) for(int i = x; i > n; i--)
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

ll XOR(ll a, ll b){
    ll e[40];
    e[0] = 1;
    rep2(i, 1, 40) e[i] = e[i-1] * 2;
    int i = 0;
    ll ans = 0;
    while(a > 0 || b > 0){
        int j = (a%2 + b%2) % 2;
        ans += j*e[i];
        a /= 2, b /= 2;
        i++;
    }
    return ans;
}

int main(){
    int N;
    cin >> N;
    ll a[N];
    ll fac[10];
    int count[10];
    fill_n(count, 10, 0);
    cin >> a[0];
    fac[0] = a[0];
    count[0] = 1;
    int size = 1;
    bool able;
    rep2(i, 1, N){
        cin >> a[i];        
        bool update = true;
        rep(j, size){
            if(a[i] == fac[j]){
                count[j]++;
                update = false;
            }
        }
        if(update){
            fac[size] = a[i];
            count[size]++;
            size++;
            if(size == 4) break; 
        }
    }
    if(size == 1){
        if(fac[0] == 0) able = true;
        else able = false;
    }
    else if(size == 2){
        if(fac[0] == 0 || fac[1] == 0){
            if(count[0] == 2*count[1] || count[1] == 2*count[0]) able = true;
            else able = false;
        }
        else able = false;
    }
    else if(size == 3){
        if(XOR(fac[0], fac[1]) == fac[2]){
            if(count[0] == count[1] && count[1] == count[2]) able = true;
            else able = false;
        }
        else able = false;
    }
    else able = false;
    if(able) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string ans = "";
    for(int i=0; i<n; i++){
        ans += s[i];
        ans += t[i];
    }
    cout << ans;
    return 0;
}

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

using namespace std;

typedef unsigned long long int ll;

const ll MAX_N = 100000;

int main () {
    ll n;
    ll H[MAX_N];
    cin >> n;

    for (ll i = 0; i < n; i++) {
        cin >> H[i];
    }

    H[0] = max(H[0] - 1, ll(1));

    for (ll i = 0; i < n - 1; i++) {
        if (H[i] < H[i + 1]) {
            H[i+1]--;
        }

        if (H[i] > H[i + 1]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 1024
package main

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

func main() {
  n,m := NextInts()
  a := make([][]int,n)
  for i:=0;i<n;i++ { a[i] = NextIntArray() }
  set := make(map[int]struct{})
  for i:=1;i<m+1;i++ { set[i] = struct{}{} }
  min := n
  for len(set) > 0 {
    c := map[int]int{}
    for i:=0;i<n;i++ {
      for j:=0;j<m;j++ {
        if _,ok := set[a[i][j]];ok {
          c[a[i][j]]++
          break
        }
      }
    }
    max := 0
    for _,v := range c {
      if max < v { max = v }
    }
    if min > max { min = max }
    for k,v := range c {
      if v == max { delete(set,k) }
    }
  }
  fmt.Println(min)
}

var reader = bufio.NewReaderSize(os.Stdin,1000000)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInts() (int,int) {
  s := strings.Split(NextLine()," ")
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}
func NextIntArray() []int {
  s := strings.Split(NextLine()," ")
  a := make([]int,len(s))
  for i:=0;i<len(s);i++ { a[i],_ = strconv.Atoi(s[i]) }
  return a
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,x,y,z;
  cin>>n>>x>>y>>z;
  vector<vector<int>> dp(n+1,vector<int>((1<<(x+y+z-1))+10,0));
  int mask=(1ll<<(x+y+z-1))-1;
  int ng=(1<<(x+y+z-1))|(1<<(y+z-1))|(1<<(z-1));
  dp[0][0]=1;
  rep(i,n){
    rep(S,1<<(x+y+z-1)){
      if((S & ng)==ng) continue;
      FOR(j,1,11){
        int T=(S<<j) | (1<<(j-1));
        if((T & ng)==ng) continue;
        T&=mask;
        (dp[i+1][T]+=dp[i][S])%=mod;
      }
    }
  }
  ll ans=1;
  rep(i,n) (ans*=10)%=mod;
  rep(i,1<<(x+y+z-1)) (ans-=dp[n][i])%=mod;
  cout<<(ans+mod)%mod<<endl;
}

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

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt(),H[]=new int[n+1];
		for(int i=1;i<=n;i++)H[i]=Integer.parseInt(in.next());
		
		PrintWriter out=new PrintWriter(System.out);
		for(int i=1;i<=n;i++) {
			out.print("node "+i+": ");
			out.print("key = "+H[i]+", ");
			if(i>1)out.print("parent key = "+H[i/2]+", ");
			if(i*2<=n)out.print("left key = "+H[i*2]+", ");
			if(i*2+1<=n)out.print("right key = "+H[i*2+1]+", ");
			out.println();
			out.flush();
		}
	}

}



Measured memory_bytes: 27000
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 333;
const int inf = 1e9;

char a[MAX][MAX];
int f[MAX][MAX];
int g[MAX][MAX];

int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);
  REP(i, N) scanf("%s", a[i]);

  int ans = 0;
  REP(c, M-1) {
    REP(i, N+1) REP(j, N+1) f[i][j] = 0;
    REP(i, N) REP(j, N)
      if (a[i][c] == a[j][c+1]) {
        // if (i > j) {
        //   for (int k = 0; i-j+k < N && i+k < N && j+k < N; ++k)
        //     f[k][i-j+k]++;
        //  } else {
        //   for (int k = 0; j-i+k < N && i+k < N && j+k < N; ++k)
        //     f[j-i+k][k]++;
        // }
        if (i > j) {
          int k = min(N-(i-j), N-i);
          f[0][i-j]++;
          f[k][i-j+k]--;
        } else {
          int k = min(N-(j-i), N-j);
          f[j-i][0]++;
          f[j-i+k][k]--;
        }
      }
    REP(i, N) REP(j, N) f[i+1][j+1] += f[i][j];

    REP(i, N+1) REP(j, N+1) g[i][j] = inf;
    g[0][0] = 0;
    REP(i, N+1) REP(j, N+1) {
      // f[i][j] = 0;
      // REP(k, N) {
      //   if (k < i || k < j) continue;
      //   if (a[k-i][c] == a[k-j][c+1]) f[i][j]++;
      // }
      if (i < N) g[i+1][j] = min(g[i+1][j], g[i][j] + f[i][j]);
      if (j < N) g[i][j+1] = min(g[i][j+1], g[i][j] + f[i][j]);
    }
    ans += g[N][N];
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1280
#define MAP(x,y)map[31+(x)+(y)*(W+1)+1]
#define MAP2(x,y)map2[31+(x)+(y)*(W+1)+1]
char map[32*31+2],map2[32*31+2],*D="ENWS",*p,c,c2;main(){int W,H;int vx[]={1,0,-1,0},vy[]={0,-1,0,1};int t,x,y,d,i,e;for(;scanf("%d%d%[^0-9]",&W,&H,map+31),W;){e=1;for(t=0;e&&++t<180;){e=0;for(y=0;y<H;y++){for(x=0;x<W;x++){p=strchr(D,MAP(x,y));if(p){e=1;d=p-D-1;for(i=4;i--;){d+=3;d%=4;c=MAP(x+vx[d],y+vy[d]);if(c=='.'||c=='X')MAP(x,y)=D[d];}}}}memcpy(map2,map,sizeof(map));for(y=0;y<H;y++){for(x=0;x<W;x++){c=MAP(x,y);if(c=='.'||c=='X'){for(d=0;d<4;d++){c2=MAP(x+vx[d],y+vy[d]);if(c2==D[d^2]){MAP2(x+vx[d],y+vy[d])='.';if(c=='.')MAP2(x,y)=c2;break;}}}}}memcpy(map,map2,sizeof(map));}printf(e?"NA\n":"%d\n",t-1);}exit(0);}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(100001, 0);
  for (int i = 0; i < n; i++) {
    int input; cin >> input;
    v[input]++;
  }
  long long ans = 0;
  long long cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    ans += min(1, v[i]);
    cnt += max(0, v[i]-1);
  }
  if (cnt % 2 != 0) ans--;
  cout << ans << endl;
}

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

cd = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        cd.append(i)
        if i != n // i:
            cd.append(n//i)
min = float('inf')
if len(cd) % 2 == 0:
    for i in range(0, len(cd) - 1,  2):
        if cd[i] + cd[i+1] < min:
            min = cd[i] + cd[i+1]
    print(min - 2)
else:
    print(cd[len(cd) - 1] * 2 - 2)



Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 101;
int main() {
	int n; cin >> n;
	vi z(MAX);
	vv(int, m, MAX, MAX, 0);
	rep(i, 1, n + 1) {
		cin >> z[i - 1] >> z[i];
	}
	int j;
	rep(l, 2, n + 1) {
		rep(i, 1, n - l + 2) {
			j = i + l - 1;
			m[i][j] = 1e8;
			rep(k, i, j) {
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j]);
			}
		}
	}
	P(m[1][n]);
	return 0;
}

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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 1000;

int n, x, p[MAXN], sol;

int main() {
  scanf("%d %d",&n,&x);
  REP(i, n) scanf("%d",&p[i]);
  sort(p, p + n);
  REP(i, n) {
    if (p[i] <= x) {
      sol++;
      x -= p[i];
    }
  }
  if (x && sol == n) sol--;
  printf("%d\n",max(0, sol));
  return 0;
}

Measured memory_bytes: 384
N = int(input())
S = {}

for _ in range(N):
    s = input()
    if s not in S:
        S[s] = 1
    else:
        S[s] += 1

S = sorted(S.items(), key=lambda x: x[1], reverse=True)

flag = True
k = 0
l = []
for key, val in S:
    if flag:
        l.append(key)
        k = val
        flag = False
    else:
        if k == val:
            l.append(key)
        else:
            break

l.sort()
for ll in l:
    print(ll)


Measured memory_bytes: 43224
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vecl = vector<ll>;
using Vi = vector<int>;
using Graph = vector<vector<int>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  Vi A(N);
  REP(i, N) cin >> A[i];
  REP(j, N) {
    if (A[j] % 2 == 1)
      continue;
    else if (A[j] % 3 != 0 && A[j] % 5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

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


int main(void)
{
  int n, m, count = 0;
  int ans;
  scanf("%d", &n);
  m = n;
  while(m > 0){
    m /= 10;
    count++;
  }
  if(count == 1){
    ans = n;
  }else if(count == 2){
    ans = 9;
  }else if(count == 3){
    ans = 9 + n - 99;
  }else if(count == 4){
    ans = 9 + 900;
  }else if(count == 5){
    ans = 909 + n - 9999;
  }else{
    ans = 9 + 900 + 90000;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int ans=0;

int main(){
    int w,h,n;
    cin >> w >> h >> n;
    int x[110]={0},y[110]={0},a[110]={0};
    int b[110][110]={0};
    for(int i=1;i<=n;i++){
        cin >> x[i] >> y[i] >> a[i];
    }
    for(int i=0;i<110;i++){
        if(a[i]==1){
            for(int j=0;j<x[i];j++){
                for(int k=0;k<110;k++)b[j][k]=1;
            }
        }else if(a[i]==2){
            for(int j=x[i];j<110;j++){
                for(int k=0;k<110;k++)b[j][k]=1;
            }
        }else if(a[i]==3){
            for(int j=0;j<110;j++){
                for(int k=0;k<y[i];k++)b[j][k]=1;
            }
        }else if(a[i]==4){
            for(int j=0;j<110;j++){
                for(int k=y[i];k<110;k++)b[j][k]=1;
            }
        }
    }
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            if(b[i][j]==0){
                ans+=1;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define loop(i,x,y) for(ll i=x;i<y;i++)
#define pb push_back
#define S second
#define F first



void solve(){
	
	string a, b;
	cin >> a >> b;

	int n = a.size() + b.size(), l = 0, m = 0;

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

		if(i & 1 && l < b.size())
			cout << b[l++];
		else
			cout << a[m++];
	
	}



}
	
 
 
int main(){
	    
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	solve();
	 
	return 0;
 
}

	 


Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	A := make([][]int, N)
	for i := 0; i < N; i++ {
		A[i] = make([]int, N)
		for j := 0; j < N; j++ {
			A[i][j] = sc.nextInt()
		}
	}
	B := make([][]int, N)
	// C[i][j]: i,jの経路で他の辺を経由するか
	C := make([][]bool, N)
	for i := 0; i < N; i++ {
		B[i] = make([]int, N)
		C[i] = make([]bool, N)
		for j := 0; j < N; j++ {
			if i != j {
				B[i][j] = INF
			}
		}
	}
	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				if A[i][k]+A[k][j] < B[i][j] {
					B[i][j] = A[i][k] + A[k][j]
				}
			}
		}
	}
	ok := true
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if A[i][j] != B[i][j] {
				ok = false
			}
		}
	}
	if !ok {
		fmt.Fprintln(wtr, -1)
		return
	}
	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				// k経由でもi, jに最短経路で到達可能
				if B[i][k]+B[k][j] == B[i][j] {
					if i != k && k != j {
						//fmt.Fprintln(wtr, "in loop", i, j, k)
						C[i][j] = true
					}
				}
			}
		}
	}
	ans := 0
	for i := 0; i < N; i++ {
		for j := i; j < N; j++ {
			if !C[i][j] {
				ans += B[i][j]
			}
		}
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 3840
(function(input) {
  var p = input.replace(/\n$/, '').split('\n');
  var a;
  while (a = p.shift().split(' ').map(Number)) {
    if (a.every(function(e) {
        return e ===  0;
      })) {
      return;
    }
    //console.log(result(a));
    console.log(conv(result(a)));
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function result(a) {
  for (var i = 0; i < 4; i++) {
    var r = Array(4);
    r[i] = a[0];
    for (var j = 0; j < 4; j++) {
      if (r[j] !== undefined) {
        continue;
      }
      r[j] = a[1];
      for (var k = 0; k < 4; k++) {
        if (r[k] !== undefined) {
          continue;
        }
        r[k] = a[2];
        for (var l = 0; l < 4; l++) {
          if (r[l] !== undefined) {
            continue;
          }
          r[l] = a[3];
          //console.log(r);
          var op = ['+', '-', '*'];
          for (var m = 0; m < 3; m++) {
            for (var n = 0; n < 3; n++) {
              for (var o = 0; o < 3; o++) {
                for (var p = 0; p < 3; p++) {
                  var f = [];
                  if (p == 0) {
                    f = [r[0], r[1], r[2], op[m], op[n], r[3], op[o]];
                  } else if (p == 1) {
                    f = [r[0], r[1], op[m], r[2], op[n], r[3], op[o]];
                  } else {
                    f = [r[0], r[1], op[m], r[2], r[3], op[n], op[o]];
                  }
                  //console.log(d);
                  if (calc(f) == 10) {
                    //console.log(f);
                    return f;
                  }
                }
              }
            }
          }
          r[l] = undefined;
        }
        r[k] = undefined;
      }
      r[j] = undefined;
    }
  }
  return false;
}

function calc(a) {
  var stack = [];
  for (var i = 0; i < a.length; i++) {
    var n = a[i];
    //console.log(n);
    if (isNaN(n)) {
      var str = stack.pop();
      str = stack.pop() + ' ' + n + ' ' + str;
      //console.log(str);
      var acm = eval(str);
      //console.log(acm);
      stack.push(acm);
      continue;
    }
    stack.push(Number(n));
  }
  return stack.pop();
}

function conv(a) {
  if (!a) {
    return '0';
  }
  var stack = [];
  for (var i = 0; i < a.length; i++) {
    var n = a[i];
    //console.log(n);
    if (isNaN(n)) {
      var str = stack.pop();
      str = '(' + stack.pop() + ' ' + n + ' ' + str + ')';
      //console.log(str);
      //var acm = eval(str);
      //console.log(acm);
      stack.push(str);
      continue;
    }
    stack.push(Number(n));
  }
  return stack.pop();
}

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

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ma = max(max(a,b),c);
    int mi = min(min(a,b),c);
    if(a != ma && a != mi){
        cout << mi << " " << a << " " << ma << endl;
    }
    else if(b!= ma && b != mi){
        cout << mi << " " << b << " " << ma << endl;
    }
    else{
        cout << mi << " " << c << " " << ma << endl;
    }
}


Measured memory_bytes: 3112
#include <stdio.h>

#define max(a,b) (a > b ? a : b)

int main(void){
    int x = 0;
    int n;
    char s[100];
    int i;
    int max = 0;
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;i<n;i++){
        if(s[i] == 'I'){
            x++;
            max = max(x,max);
        }
        else if(s[i] == 'D'){
            x--;
            max = max(x,max);
        }
    }
    printf("%d\n",max);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
/*---define tricks---*/
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define revsort(b,e) sort(b,e),reverse(b,e)
/*---define types---*/
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;
/*---define variables---*/
ll n,c,x[100005],v[100005];
ll a[100005],b[100005],ans=0;
/*---define function---*/

/*---main code---*/
int main()
{
	FIO;
	cin>>n>>c;
	for(ll i=1;i<=n;++i)
	{
		cin>>x[i]>>v[i];
	}
	x[n+1]=c;
	for(ll i=1;i<=n;++i)
	{
		a[i]=a[i-1]+v[i]-(x[i]-x[i-1]);
	}
	for(ll i=1;i<=n;++i)
	{
		a[i]=max(a[i-1],a[i]);
	}
	for(ll i=n;i>=1;--i)
	{
		b[i]=b[i+1]+v[i]-(x[i+1]-x[i]);
	}
	for(ll i=n;i>=1;--i)
	{
		b[i]=max(b[i+1],b[i]);
	}
	for(ll i=1;i<=n;++i)
	{
		ans=max(ans,a[i]);
		ans=max(ans,a[i]-x[i]+b[i+1]);
		ans=max(ans,b[i]);
		ans=max(ans,b[i]-(c-x[i])+a[i-1]);
	}
	cout<<ans<<'\n';
	return 0;
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define db double
#define ll long long
#define ev edge[i].v
#define mod 1000000007
#define pir pair<int,int>
#define Rep(i,l,r) for(int i=(l);i<=(r);++i)
#define RepD(i,r,l) for(int i=(r);i>=(l);--i)
#define RepG(i,x) for(int i=head[x];i;i=edge[i].next)
using namespace std;

const int N=2005;

ll f[N][N];
ll fac[N*N],inv[N*N];

ll ksm(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod,b>>=1;
	}
	return res;
}

ll C(ll n,ll m){
    if(n<0||n<m) return 0;
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main(){
	ll n,k;
    scanf("%lld%lld",&n,&k);
    if(k==1){puts("1");return 0;}
    fac[0]=inv[0]=f[0][0]=1;
    Rep(i,1,n*k) fac[i]=fac[i-1]*i%mod;
    inv[n*k]=ksm(fac[n*k],mod-2);
    RepD(i,n*k-1,1) inv[i]=inv[i+1]*(i+1)%mod;
    Rep(i,1,n)
    	Rep(j,0,i){
    		if(i) f[i][j]=(f[i][j]+f[i-1][j])%mod;
			if(j) f[i][j]=(f[i][j]+f[i][j-1]*C(n*k-i-(k-1)*(j-1)-1,k-2)%mod)%mod;
		}
    printf("%lld\n",f[n][n]*fac[n]%mod);
    return 0;
}

Measured memory_bytes: 94464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,dp[100009][2],a[109];
bool best(ll sum,bool b)
{
    ll &r=dp[sum][b];
    if(r!=-1) return r;
    r=b^1;
    for(ll i=0;i<n;i++){
    if(b&&sum>=a[i])
    r|=best(sum-a[i],0);
    if(!b&&sum>=a[i])
    r&=best(sum-a[i],1);
    }
    return r;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(ll i=0;i<n;i++)
cin>>a[i];
memset(dp,-1,sizeof dp);
if(best(k,0))
cout<<"Second";
else cout<<"First";
return 0;
}


Measured memory_bytes: 12984
#include <stdio.h>

int main(){
	char c[101];
	long k;
	scanf("%s\n", &c);
	scanf("%ld\n", &k);
	for(int i=0; i<k; i++){
		if(c[i]!='1') {
			printf("%c\n", c[i]);
			return 0;
		}
	}
	printf("1\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

// ===========Disjoint Set Union================
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};
// =======================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, K, L;
  cin >> N >> K >> L;
  dsu d1(N), d2(N);
  for (ll i = 0; i < K; ++i) {
    ll p, q;
    cin >> p >> q;
    p -= 1, q -= 1;
    d1.merge(p, q);
  }
  for (ll i = 0; i < L; ++i) {
    ll r, s;
    cin >> r >> s;
    r -= 1, s -= 1;
    d2.merge(r, s);
  }
  map<pll, ll> ans;
  for (ll i = 0; i < N; ++i) {
    ll p1 = d1.leader(i);
    ll p2 = d2.leader(i);
    ans[{p1, p2}] += 1;
  }
  for (ll i = 0; i < N; ++i) {
    ll p1 = d1.leader(i);
    ll p2 = d2.leader(i);
    cout << ans[{p1, p2}] << " ";
  }
  cout << "\n";
}


Measured memory_bytes: 16076
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
int calc(vector<int> a) {
   if ((int)a.size() == 0) return 0;
   int tmp = 200;
   for (int i = 0; i < (int)a.size(); i++) {
      tmp = min(tmp, a[i]);
   }
   vector<int> b;
   int ans = tmp;
   for (int i = 0; i < (int)a.size(); i++) {
      a[i] -= tmp;
      if(a[i] == 0) {
         ans += calc(b);
         b.clear();
      } else {
         b.push_back(a[i]);
      }
   }
   ans += calc(b);
   return ans;
}
int main() {
   int N;
   cin >> N;
   vector<int> h;
   int tmp;
   for (int i = 0; i < N; i++) {
      cin >> tmp;
      h.push_back(tmp);
   }
   cout << calc(h) << endl;   
   return 0;
}


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

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

double solution(vector<int>& x, vector<int>& y)
{
    int N = x.size();

    auto dist = [&](double x_c, double y_c){  // 円の中心を選んだときの最遠点との距離
        double d = 0;
        REP(i, N) d = max(d, pow(x[i]-x_c, 2) + pow(y[i]-y_c, 2));
        return sqrt(d);
    };
    auto min_dist = [&](double x_c){  // 円の中心の x 座標を選んだときの最遠点との最小距離
        double y_l = 0, y_r = 1e+3;
        REP(_, 80){  
            double c_l = (2*y_l+y_r)/3;
            double c_r = (y_l+2*y_r)/3;
            if(dist(x_c, c_l) > dist(x_c, c_r)) y_l = c_l;
            else y_r = c_r;
        }
        return dist(x_c, y_l);
    };

    double x_l = 0, x_r = 1e+3;
    REP(_, 80){  // double の探索では while より回数を決めて for を回した方がエラーを避けやすい
        double c_l = (2*x_l+x_r)/3;
        double c_r = (x_l+2*x_r)/3;
        if(min_dist(c_l) > min_dist(c_r)) x_l = c_l;
        else x_r = c_r;
    }
    return min_dist(x_l);
}

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

    cout << fixed << setprecision(7) << solution(x, y) << endl;

    return 0;
}

Measured memory_bytes: 256
n = input()

if n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] =="7" or n[-1] == "9":
    print("hon")
elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
    print("pon")
elif n[-1] == "3":
    print("bon")

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

int		main(void)
{
	ll n;
	cin >> n;
	ll a = 1000000007;

	ll ans = 1;
	for (ll i = 0; i < n; i++)
		ans = ans % a * (i + 1);
	cout << ans % a << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<numeric>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------

int ctoi(char c) {
  if('0'<=c && c <= '9') return c-'0';
  return 0;
}

int main(){
  int N=0,T=0;
  cin >> N >> T;
  vector<int> ct;
  for(int i=0;i<N;++i){
    int TE=0,MP=0;
    cin >> TE >> MP;
    if(MP<=T){
      ct.push_back(TE);
    }
  }
  sort(ct.begin(),ct.end());
  if(ct.size())
  {
    cout << ct[0] << endl;
  }else{
    cout << "TLE" <<endl;
  }
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 1;
    for (int i = 0; i < n; i++) {
        if (k > ans) {
            ans *= 2;
        } else {
            ans += k;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
include Math

d, n, bounce_max = gets.split.map(&:to_i)
all_obs = (1..n).map { gets.split.map(&:to_i) }
min = Float::INFINITY

EPS = 0.00001

(0..bounce_max).each do |bounce|
    bounce_point = (0..bounce+1).map {|k| k * d.to_f / (bounce + 1)}
    next if bounce_point.any? {|x| all_obs.map(&:first).any?{|u| (x - u).abs < EPS}}

    candidates = [sqrt(d.to_f / (2 * (bounce + 1)))]

    bounce_point.each_cons(2) do |x1, x2|
        obs = all_obs.select {|x, y| x1 < x && x < x2}
        obs.each do |u, v|
            a = v.to_f / ((u - x1) * (x2 - u))
            candidates << sqrt(1 / (2 * a))
        end
    end

    candidates.select! do |vx|
        bounce_point.each_cons(2).all? do |x1, x2|
            obs = all_obs.select {|x, y| x1 < x && x < x2}
            if obs.empty?
                true
            else
                obs.all? do |u, v|
                    a = 1 / (2 * vx ** 2)
                    obs.all? {|u, v| v <= a * (u - x1) * (x2 - u) + EPS} 
                end
            end
        end
    end

    next if candidates.empty?

    m = candidates.map {|vx|
        a = 1 / (2 * vx ** 2)
        vy = vx * a * d / (bounce + 1)
        hypot(vx, vy)
    }.min

    min = m if m < min
end

p min

Measured memory_bytes: 8908
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int[] x = new int[4];
	int[] y = new int[4];
	for(int i = 0; i < 2; i++){
	    x[i] = scan.nextInt();
	    y[i] = scan.nextInt();
	}

	x[2] = x[1]-(y[1]-y[0]);
	y[2] = y[1]-(x[0]-x[1]);
	x[3] = x[2]-(y[2]-y[1]);
	y[3] = y[2]-(x[1]-x[2]);

	System.out.println(x[2]+" "+y[2]+" "+x[3]+" "+y[3]);
    }
}
			   


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}
 
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int N, K; cin >> N >> K;
	string s; cin >> s;
	int la = -1;
	int cnt = 0;

	vector<pii> vec;
	rep(i, N) {
		int c = s[i] - '0';
		if (c == la) {
			++cnt;
		} else {
			if (la != -1) {
				vec.eb(la, cnt);
			}
			cnt = 1;
			la = c;
		}
	}
	vec.eb(la, cnt);

	vector<int> acm(vec.size() + 1);
	rep(i, vec.size()) {
		acm[i+1] = acm[i] + vec[i].se;
	}

	int ans = 0;
	rep(i, vec.size()) {
		int r = i + (vec[i].fi == 0 ? K * 2 : K * 2 + 1);
		int t = acm[min(r, (int)vec.size())] - acm[i];
		ans = max(ans, t);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1652
#include <iostream>

using namespace std;

int main() {

  int b,r,g,c,s,t;

  int medals;


  while(cin >> b >> r >> g >> c >> s >> t) {

    if(b==0 && r==0 && g==0 && c==0 && s==0 && t==0) break;

    medals=100;

    //rbO{[iX(1ñÉÂ«v77Ì_ð¾éªÅ«AQ[ð6ñÁï·é)
    medals+=77*b;
    t-=6*b;

    //M[{[iX(1ñÉÂ«v51Ì_ð¾é±ÆªÅ«AQ[ð4ñÁï·é)
    medals+=51*r;
    t-=4*r;

    //ÊíQ[ÉuhEªµ¤(1ñÉÂ«v4Ì_ð¾é±ÆªÅ«AQ[ð1ñÁï·é)
    medals+=4*g;
    t-=g;

    //ÊíQ[É`F[ªµ¤(1ñÉÂ«1_ðæçêAQ[ð1ñÁï·é)
    medals-=c;
    t-=c;

    //X^[ªµ¤(Q[ð1ñÁï·é)
    t-=s;
    
    //cèÌQ[ÍSÄXJ
    medals-=3*t;

    cout << medals << endl;

  }

  return 0;

}
    

Measured memory_bytes: 0