akhauriyash/Code-Regression huggingface dataset:
pub fn main() {
    use std::collections::HashSet;
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let mut t: Vec<usize> = vec![0;n];
    let mut d: Vec<u64> = vec![0;n];
    for i in 0..n {
        t[i] = iter.next().unwrap().parse().unwrap();
        d[i] = iter.next().unwrap().parse().unwrap();
    }
    let mut sushi: Vec<(u64, usize)> = (0..n).map(|i| (d[i], t[i])).collect();
    sushi.sort();
    sushi.reverse();

    let mut tier1: Vec<(u64, usize)> = Vec::new();
    let mut tier2: Vec<(u64, usize)> = Vec::new();
    let mut kinds: HashSet<usize> = HashSet::new();
    for i in 0..n {
        let (value, key) = sushi[i];
        if kinds.contains(&key) {
            tier2.push((value, key));
        } else {
            kinds.insert(key);
            tier1.push((value, key));
        }
    }

    let mut tier1_vsums: Vec<u64> = vec![0;tier1.len()+1];
    for i in 0..tier1.len() {
        tier1_vsums[i+1] = tier1_vsums[i] + tier1[i].0;
    }
    let mut tier2_vsums: Vec<u64> = vec![0;tier2.len()+1];
    for i in 0..tier2.len() {
        tier2_vsums[i+1] = tier2_vsums[i] + tier2[i].0;
    }

    let mut ret: u64 = 0;
    for i in 0..k+1 {
        let from_tier1 = i;
        let from_tier2 = k - i;
        if tier1_vsums.len() <= from_tier1 || tier2_vsums.len() <= from_tier2 {continue;}
        ret = std::cmp::max(ret, tier1_vsums[from_tier1] + tier2_vsums[from_tier2] + from_tier1 as u64 * from_tier1 as u64);
    }
    println!("{}", ret);
}

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

if N < 2:
    ans = 1
elif N < 4:
    ans = 2
elif N < 8:
    ans = 4
elif N < 16:
    ans = 8
elif N < 32:
    ans = 16
elif N < 64:
    ans = 32
else:
    ans = 64

print(ans)

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

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

int main() {
    int s,r;
    vector<int> a;
    set<int> t;
    cin >> s;

    a.push_back(s);
    t.insert(s);
    rep(i,1e6+10) {
        if(a.at(i)%2)
            a.push_back(3*a.at(i)+1);
        else
            a.push_back(a.at(i)/2);

        if(!t.count(a.at(i+1)))
            t.insert(a.at(i+1));
        else {
            r = i+2;
            break;
        }
    }

    cout << r << endl;
}

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

int main() {
   int H, N,sum=0;
   cin >> H >> N;
   vector<int> A(N);

   for(int i=0; i<N; i++) {
      cin >> A[i];
      sum += A[i];
   }
   if(sum >= H) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3744
#include<stdio.h>
int mat[50][1000];
int main(void){
    while(1){
        int n, m;
        scanf("%d%d",&n,&m);
        if(n==0) break;
        int max = 0;
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                scanf("%d",&mat[i][j]);
                
            }
        }
        for(int i=0;i<n;i++){
            int tmp=0;
            for(int j=0;j<m;j++){
                tmp += mat[j][i];
            }
            if(max<tmp) max = tmp;
        }
        printf("%d\n",max);
    }
}



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

int main() {
  string a,b;
  cin >> a;
  cin >> b;
  cout << b << a << endl;

  // cout << "Hello world!" << endl;
}


Measured memory_bytes: 256
import sys
N, M, P = map(int, input().split())
Edge = []
G = [[] for i in range(N)]
G_rev = [[] for i in range(N)]
for i in range(M):
    a, b, c = map(int, sys.stdin.readline().split())
    a, b = a - 1, b - 1
    c = -(c - P)
    Edge.append([a, b, c])
    G[a].append(b)
    G_rev[b].append(a)


# 0とNの両方から辿れない頂点を削除
def dfs(g, stack):
    can_reach = set()
    while stack:
        n = stack.pop()
        can_reach.add(n)
        for to in g[n]:
            if to in can_reach:
                continue
            stack.append(to)
    return can_reach


can_reach_from_0 = dfs(G, [0])
can_reach_from_N = dfs(G_rev, [N - 1])

can_reach_from_0_and_N = can_reach_from_0 & can_reach_from_N
EdgeShifted = []
for a, b, c in Edge:
    if (a in can_reach_from_0_and_N) and (b in can_reach_from_0_and_N):
        EdgeShifted.append([a, b, c])


# ベルマンフォード
dist = [float('inf')] * N
dist[0] = 0

for n in range(len(can_reach_from_0_and_N)):
    for fr, to, cost in EdgeShifted:
        if dist[to] > dist[fr] + cost:
            dist[to] = dist[fr] + cost
            # 負閉路検出
            if n == len(can_reach_from_0_and_N) - 1:
                print(-1)
                exit()

print(max(0, -dist[N - 1]))


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

using namespace std;
typedef long long ll;
const int m= 1e9 + 7;
 
int main(){
   
    ll h, w;
    cin>>h>>w;
 
    vector<vector<char>> mat(h, vector<char>(w));
    vector<vector<ll>> dp(h, vector<ll>(w));
 
    for(ll i = 0; i < h; i++)
        for(ll j = 0; j < w; j++)
            cin>>mat[i][j];
 
    dp[0][0] = 1;
 
    for(ll i = 1; i < h; i++)
        if(dp[i-1][0] != 0 && mat[i][0] == '.')
            dp[i][0] = 1;
 
    for(ll i = 1; i < w; i++)
        if(dp[0][i-1] != 0 && mat[0][i] == '.')
            dp[0][i] = 1;
 
    for(ll i = 1; i < h; i++){
        for(ll j = 1; j < w; j++){
            if(mat[i][j] == '#'){
                dp[i][j] = 0;
                continue;
            }
 
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % m;
        }
    }
 
    cout<<dp[h-1][w-1]<<endl;
 
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>                                       
using namespace std;                                      
                                                          
int main(){                                               
        int a[3];                                         
        for (int i = 0; i < 3; i++){                      
                cin >> a[i];                              
        }                                                 
        int five=0;                                       
        int seven =0;                                     
        for (int i = 0; i < 3; i++){                      
                if (a[i] == 5 ) five++;                   
                else if (a[i] == 7 ) seven++;             
        }                                                 
        if (five == 2 && seven ==1) cout << "YES" << endl;
        else cout << "NO" << endl;                        
                                                          
}                                                         

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)

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

int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;

const int MAX_Q=100001;
bool isPrime[MAX_Q];
bool isPrimeSmall[MAX_Q];
int prime[MAX_Q];

int sieve(int n){
	int p=0;
	for(int i=0;i<=n;i++)isPrime[i]=true;
	isPrime[0]=isPrime[1]=false;
	for(int i=2;i<=n;i++){
		if(isPrime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i)isPrime[j]=false;
		}
	}
	return p;
}

int main(){
	int q;
	cin>>q;
	int l[q];
	int r[q];
	REP(i,q)cin>>l[i]>>r[i];
	int res=sieve(MAX_Q);
	int cnt[MAX_Q];
	cnt[0]=0;
	for(int i=1;i<MAX_Q;i++){
		if(i%2==1 && isPrime[i] && isPrime[(i+1)/2]){
			cnt[i]=cnt[i-1]+1;
		}else{
			cnt[i]=cnt[i-1];
		}
	}
	REP(i,q){
		cout<<cnt[r[i]]-cnt[l[i]-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>

int main(void){
    int a, b, c, ans=0;
    std::cin >> a >> b >> c;
    for (int i = 0; i < 2; ++i){
        if (a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if (b < c){
            int tmp = b;
            b = c;
            c = tmp;
        }
    }

    int d1 = a - b;
    int d2 = a - c;
    ans += d1;
    d2 -= d1;
    if (d2 % 2 == 0){
        ans += d2 / 2;
    } else {
        ans += d2 / 2 + 2;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3560
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int A[][] = new int[n][m];
        int b[] = new int[m];
        int i,j,c;
        
        for(i=0; i<n; i++){
            for(j=0; j<m; j++){
                A[i][j] = sc.nextInt();
            }
        }
        
        for(j=0; j<m; j++){
            b[j] = sc.nextInt();
        }
        
        for(i=0; i<n; i++){
            c = 0;
            for(j=0; j<m; j++){
                c += ( A[i][j] * b[j] );
            }
            System.out.println(c);
        }
    }
}



Measured memory_bytes: 40880
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;


void solve(){
    map<int,int> counter;
    for(int i = 1; i < 100; i++){
        for(int j = 1; j < 100; j++){
            for(int k = 1; k < 100; k++){
                int v = i*i + j*j + k*k + i*j + j*k +k*i;
                counter[v]++;
            }
        }
    }
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cout << counter[i] << endl;
    }
}

int main(){
    int T;
    T = 1;
    //cin >> T;
    while(T--){
        solve();
        cout << endl;
    }
}






Measured memory_bytes: 5324
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input();//.ToInt();
		var n = p[0].ToInt();
		var m = p[1].ToLong();
		var ac = new bool[n];
		var pens = new int[n];
		int seitou = 0;
		int pen = 0;
		for(int i = 0; i < m; i++)
		{
			var q = Input();
			var index = q[0].ToInt() - 1;
			if(!ac[index] && q[1] == "AC")
			{
				ac[index] = true;
				seitou++;
				pen += pens[index];
				continue;
			}
			if(!ac[index] && q[1] == "WA")
			{
				pens[index]++;
			}
		}
		Console.WriteLine("{0} {1}", seitou, pen);
		
	}
	

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


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

using namespace std;
int main() {
    vector <int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if (a[0] == a[2])
        return cout << "No", 0;
    if (a[0] == a[1] || a[1] == a[2])
        return cout << "Yes", 0;
    cout << "No";
}


Measured memory_bytes: 256
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cum_A=[0]
cum_B=[0]
for i in range(N):
  cum_A.append(cum_A[-1]+A[i])
for i in range(M):
  cum_B.append(cum_B[-1]+B[i])
ans, j = 0,M
for i in range(N+1):
  if cum_A[i] > K:
    break
  while cum_B[j] > K-cum_A[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)

Measured memory_bytes: 126820
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
count = 0
for i in range(1, n+1):
    s = str(i)
    s = list(s)
    # print(s)
    if len(s) % 2 != 0:
        count += 1
print(count)




Measured memory_bytes: 5572
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;

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

    int n;
    cin>>n;
    int a[n];
    rep(i, n){
        cin>>a[i];
    }
    int q;
    cin>>q;
    int m[q];
    rep(i, q){
        cin>>m[i];
    }
    vector<int> s;
    
    //ビット全探索
    vector<int> sum;

    for (int bit = 0; bit < (1<<n); ++bit){
        sum.pb(0); // 部分集合の和
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が S に入っているなら足す
                sum[bit] += a[i];
            }
        }
    }

    for(int j = 0; j < q; j++){
        bool exist = false;
        // sum が m[j] に一致するか
        for(int i = 0; i < sum.size(); i++){
            if(sum[i] == m[j]){
                exist = true;
                break;
            }
        }
        if(exist){
            cout << "yes" << endl;
        }
        else{
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6916
using System;
using System.Collections.Generic;
public class ABC128A {
    public static void Main() {
        int A, P;
        string[] str = System.Console.ReadLine().Split(' ');
        A = int.Parse(str[0]);
        P = int.Parse(str[1]);
        P += A * 3;
        System.Console.WriteLine(P / 2);
    }
}


Measured memory_bytes: 11092
def main():
    X = int(input())
    maxi = 1
    if X <= 2:
        print(1)
        return
    for b in range(2, X):
        for p in range(2, X):
            if b**p > X:
                break
            else:
                maxi = max(maxi, b**p)
    print(maxi)
main()

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

using namespace std;

#define rep(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define drep(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define debug(x) cout << #x << " = " << x << endl

int n;

int a[25];
int main () {
	scanf ("%d", &n);
	int ans = 0;
	rep(i, 1, n) {
		scanf ("%d", a + i);
	}
	rep(i, 2, n - 1) if (a[i] == a[i] + a[i - 1] + a[i + 1] - max(a[i], max(a[i + 1], a[i - 1])) - min(a[i], min(a[i + 1], a[i - 1]))) {
		++ans;
	}
	printf ("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
import itertools

inp = input()
split = inp.split()
h = int(split[0])
w = int(split[1])
k = int(split[2])
lines=[]
result = 0
for i in range(h):
    lines.append(input())
hList = list(range(h+1))[1:]
wList = list(range(w+1))[1:]
hResult = [[]]
wResult = [[]]
for n in range(1,len(hList)+1):
    for conb in itertools.combinations(hList, n):
        hResult.append(list(conb)) #タプルをリスト型に変換
for n in range(1,len(wList)+1):
    for conb in itertools.combinations(wList, n):
        wResult.append(list(conb)) #タプルをリスト型に変換
def check(hBanish, wBanish):
    result = 0
    for hNum in range(1, h + 1):
        if hNum in hBanish:
            continue
        else:
            for wNum in range(1, w + 1):
                if wNum in wBanish:
                    result += 0
                elif lines[hNum-1][wNum-1] == "#":
                    result += 1
                else:
                    result += 0
    return result

for hBanish in hResult:
    for wBanish in wResult:
        if check(hBanish, wBanish) == k:
            result  += 1
print(result)
    



Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#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++)
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    int cnt = 0;
    vector<int> a(n+1);
    vector<int> b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    int ans = 0;
    rep(i,n) {
        if (a[i] >= b[i]) {
            ans += b[i];
        }
        else {
            ans += a[i];
            b[i] -= a[i];
            if (a[i+1] - b[i] <= 0) {
                ans += a[i+1];
                a[i+1] = 0;
            }
            else {
                a[i+1] -= b[i];
                ans += b[i];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <string>
#include <sstream>
#include  <list>
//#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
/*
int cmp(shi a,shi b)
{
    return a.x<b.x;
}
long long cmd(long long a, long long  b)
{
    return a > b;
}*/

int cmd(int a, int b)
{
    return abs(a)<abs(b);
}
int main()
{
    int one[]={0,1,0,3,0,5,0,7,8,0,10,0,12};
    int two[]={0,0,0,0,4,0,6,0,0,9,0,11,0};
    int t = 2;
    int a ,b;
    while(cin >>a >>b){
        if(one[a]){
            if(one[b])
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        else if(two[a]){
            if(two[b])
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        else
            cout<<"No"<<endl;

    }
    return 0;

}


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

int main(void) {
	int N,a;
	scanf("%d",&N);

	if(N<=1000){
		a = 1000 - N;
	}else if(1000<N && N<=2000){
		a = 2000 - N;
	}else if(2000<N && N<=3000){
		a = 3000 - N;
	}else if(3000<N && N<=4000){
		a = 4000 - N;
	}else if(4000<N && N<=5000){
		a = 5000 - N;
	}else if(5000<N && N<=6000){
		a = 6000 - N;
	}else if(6000<N && N<=7000){
		a = 7000 - N;
	}else if(7000<N && N<=8000){
		a = 8000 - N;
	}else if(8000<N && N<=9000){
		a = 9000 - N;
	}else{
		a = 10000 - N;
	}
	printf("%d",a);

	return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    int N, Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    stack<char> S;
    vector<int> a(N+1),l(Q),r(Q);
    int tmp = 0;
    for(int i=0;i<Q;i++) cin >> l[i] >> r[i];
    for(int i=0;i<N;i++){
        if(!(i>0 && s[i-1] == 'A' && s[i] == 'C')){
            a[i+1] = tmp;
            S.push(s[i]);
        }
        else{
            a[i+1] = ++tmp;
            S.pop();
        }
    }
    for(int i=0;i<Q;i++){
        cout << a[r[i]]-a[l[i]] << endl;
    }
    return 0;
    
}

Measured memory_bytes: 2176
using System;
using System.Collections.Generic;

namespace ABC091_A_Two_Colors_Card_Game
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			List<string> sList = new List<string>();
			for (int i = 0; i < n; i++) {
				sList.Add(Console.ReadLine());
			}

			int m = int.Parse(Console.ReadLine());
			List<string> tList = new List<string>();
			for (int i = 0; i < m; i++) {
				tList.Add(Console.ReadLine());
			}

			int money = 0;

			for (int i = 0; i < n; i++)
			{
				int moneyValue = 0;
				for (int j = 0; j < n; j++) {
					if (sList[i] == sList[j])
					{
						moneyValue++;
					}
				}

				for (int j = 0; j < m; j++) {
					if(sList[i] == tList[j])
					{
						moneyValue--;
					}
				}

				if (moneyValue > money)
				{
					money = moneyValue;
				}
			}
			
			Console.WriteLine(money);
		}
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 100;

int main() {
    int A[MAX], N;
    int key;
    cin >> N;
    for ( int i = 0; i < N; ++i ) cin >> A[i];

    for ( int i = 0; i < N; ++i ) {
        key = A[i];
        int j = i - 1;
        while ( j >= 0 && A[j] > key ) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = key;
        for ( int k = 0; k < N-1; ++k ) cout << A[k] << ' ';
        cout << A[N-1];
        //cout << '\b';
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

#define debug(x) cerr<<#x<<'='<<x<<'\n' 

int a[1234567];

void nxt(int &j) {
	int k=a[j];
	while (a[j]==k) j++;
}
int num(int j) {
	int k=j;
	while (a[j+1]==a[k]) j++;
//	debug(j);
	return j-k+1;
}

int main(void) {
	int n;
	cin>>n;
	for (int i=1; i<=n; i++) {
		scanf("%d", a+i);
	}
	sort(a+1, a+1+n);
	int ans=0;
	int i=1;
	while (i<=n) {
		int k=num(i);
		if (k>=a[i]) {
			ans+=k-a[i];
			nxt(i);
		} else {
			if (k<a[i]) {
				ans+=k;
				nxt(i);
			}
		}
	}
	cout<<ans;
	return 0;
}


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

int main(){
    char c;
    cin >> c;
    if(islower(c)) cout << "a" << endl;
    else cout << "A" << endl;
    return 0;
}

Measured memory_bytes: 3576
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = input()
    cur = 0

    for x in n:
        cur += int(x)

    if cur % 9 == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 68124
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a,b] <- getIntList
    print $ (a-1) * (b-1)

Measured memory_bytes: 380
import math
a,b,h,m = map(int, input().split())
h += m/60

deg = max((h/12)*360, (m/60)*360) - min((h/12)*360, (m/60)*360)

if deg > 180:
    deg = 360 - deg

print((a**2 + b**2 - 2*a*b*math.cos(math.radians(deg)))**(0.5))

Measured memory_bytes: 9580
main = do
  n:m:_ <- map read . words <$> getLine :: IO [Int]
  as <- map read . words <$> getLine :: IO [Int]
  putStrLn $ show $ count m as

count m as | foldl step False bs = 0
           | otherwise = (div m k + 1) `div` 2
    where bs = map (\x -> div x 2) as
          k = foldl lcm 1 bs
          step a x = a || even (div k x)


Measured memory_bytes: 85372
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct Tile {
	int row,
		col;
};

int main()
{
	int x, y, row, col, c;
	vector<string> v(20);
	queue<Tile> t;

	while (cin >> x >> y, x != 0 && y != 0) {
		c = 1;

		for (int i = 0; i < y; i++) {
			cin >> v.at(i);
			for (int j = 0; j < x; j++) {
				if (v.at(i).at(j) == '@') {
					t.push({ i,j });
					v.at(i).at(j) = '#';
					break;
				}
			}
		}

		while (!t.empty()) {
			row = t.front().row;
			col = t.front().col;
			t.pop();

			if (row - 1 >= 0 && v.at(row-1).at(col) == '.') {
				v.at(row-1).at(col) = '#';
				t.push({row-1,col});
				c++;
			}

			if (row + 1 < y && v.at(row+1).at(col) == '.') {
				v.at(row+1).at(col) = '#';
				t.push({ row+1,col });
				c++;
			}

			if (col - 1 >= 0 && v.at(row).at(col-1) == '.') {
				v.at(row).at(col-1) = '#';
				t.push({ row,col-1 });
				c++;
			}

			if (col + 1 < x && v.at(row).at(col+1) == '.') {
				v.at(row).at(col+1) = '#';
				t.push({ row,col+1 });
				c++;
			}
		}

		cout << c << endl;
	}
}


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

vector<vector<int>> g;
vector<ll> ans;

void dfs(int par, int crt)
{
  ans[crt] += ans[par];
  for (auto& nxt : g[crt])
    if (nxt != par)
      dfs(crt, nxt);
}

int main()
{
  int n, q;
  cin >> n >> q;
  g.resize(n);
  rep(i, n - 1)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans.resize(n);
  rep(i, q)
  {
    int p, x;
    cin >> p >> x;
    ans[p-1] += x;
  }
  for (auto& nxt : g[0])
    dfs(0, nxt);
  rep(i, n)
    printf("%lld%c", ans[i], i == n - 1 ? '\n' : ' ');
  return 0;
}

Measured memory_bytes: 24320
n = int(input())
a = list(map(int,input().split()))
b = {0:0}
c = 0
for i in range(n):
    c = c+a[i]
    if c in b:
        b[c] += 1
    else:
        b[c] = 0
d = list(b.values())
ans = 0
for i in d:
    ans+= ((i+1)*i)//2
print(ans)

Measured memory_bytes: 39532
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Main m = new Main();
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(b % a == 0 ? a+b : b-a);
    }
}

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

int N,A,B,C,X;
int Y[100];

int solve()
{
  int ans=0;
  int i=0;

  while(1){
    if(X == Y[i]) i++;
    if(i == N) break;
    X = (A*X+B)%C;
    ans++;
    if(ans > 10000) return -1;
  }
  return ans;
}

int main(){
  
  while(1){  
    cin >> N >> A >> B >> C >> X;
    if(N+A+B+C+X == 0) break;
    
    for(int i=0;i < N;i++){
      cin >> Y[i];
    }
    cout << solve() << endl;
  }
  return 0;
}



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

int main () {
  int n , m , l ;
  cin >> n >> m >> l ;
  int A[n][m] = {} , B[m][l]  ={} ;
  for(int i = 0 ; i < n ; i++ ){
    for(int j = 0 ; j < m ; j++ ){
      cin >> A[i][j] ;
    }
  }
  for(int i = 0 ; i < m ; i++ ){
    for(int j = 0 ; j < l ; j++ ){
      cin >> B[i][j] ;
    }
  }
  for(int i = 0 ; i < n ; i++ ){
    for(int j = 0 ; j < l ; j++ ){
      long long pre = 0 ;
      for(int k = 0 ; k < m ; k++ ){
        pre += A[i][k] * B[k][j] ;
      }
      cout << pre ;
      if(j!=l-1) cout << ' ' ;
    }
    cout << endl ;
  }
}


Measured memory_bytes: 3136
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<double,double>P;
#define X first
#define Y second
#define pb push_back

double mag(P p){
	//2次元ベクトルの大きさ
	return sqrt(p.X*p.X+p.Y*p.Y);
}

double inner(P a,P b){
	//2次元ベクトルの内積
	return a.X*b.X+a.Y*b.Y;
}

double inner_rad(P a,P b){
	//2つのベクトル間の角度
	return acos(inner(a,b)/mag(a)/mag(b));
}

int main(){
	int n;
	while(cin>>n,n){
		vector<P>V;
		for(int i=0;i<n;i++){
			double x,y;
			scanf("%lf,%lf",&x,&y);
			V.pb(P(x,y));
			
			//cout<<"# "<<x<<","<<y<<endl;
		}
		
		
		
		int st=0;
		for(int i=1;i<V.size();i++){
			if(V[i].Y<V[st].Y ||( V[i].Y==V[st].Y && V[i].X>V[st].X))st=i;
		}
		int use=1;
		int now=st;
		P last=P(-10000,V[st].Y);
		
		while(true){
			//if(use>7)break;
			//cout<<last.X<<","<<last.Y<<" : "<<V[now].X<<","<<V[now].Y<<" : ";
			int next=now;
			double rad=0;
			for(int i=0;i<V.size();i++){
				if(i!=now){
					//cout<<"# "<<last.X<<","<<last.Y<<" : "<<V[now].X<<","<<V[now].Y<<" : "<<V[i].X<<","<<V[i].Y<<" : "<<inner_rad(P(last.X-V[now].X,last.Y-V[now].Y),P(V[i].X-V[now].X,V[i].Y-V[now].Y))<<endl;
					if(inner_rad(P(last.X-V[now].X,last.Y-V[now].Y),P(V[i].X-V[now].X,V[i].Y-V[now].Y))>rad){
						next=i;
						rad=inner_rad(P(last.X-V[now].X,last.Y-V[now].Y),P(V[i].X-V[now].X,V[i].Y-V[now].Y));
					}
				}
			}
			//cout<<V[next].X<<","<<V[next].Y<<endl;
			if(next==st){
				break;
			}
			use++;
			last=V[now];
			now=next;
		}
		
		cout<<n-use<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1336
#include<bits/stdc++.h>
using namespace std;
//map<int,int> mp;
const int maxn = 3e5 + 10;
int a[maxn], ans[maxn], b[maxn];
priority_queue<int> Q;
int n, m;
void solve() {
	scanf("%d", &n);
	for (int i = 1, x; i <= n; ++i) {
		scanf("%d", &x);
		++a[x];
	}
	for (int i = 1; i <= n; ++i) {
		++b[a[i]];
	}
	for (int i = n; i > 1; --i) {
		b[i - 1] = b[i - 1] + b[i];
	}
	for (int i = 1, sum; i <= n; ++i) {
		sum = 0;
		for (int j = 1; j <= n / i; ++j) {
			sum += b[j];
			if (sum >= j * i)ans[i] = j;
		}
	}
	for (int i = 1; i <= n; ++i)
		printf("%d\n", ans[i]);
}
int main() {
	solve();

	return 0;
}

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

using namespace std;

bool LinearSearch(vector<int> A, int n, int num)
{
	int i = 0;

	A.push_back(num);
	while (A[i] != num)
		i++;

	return (i != n);
}

int main()
{
	int N, Q, t;
	int sum = 0;
	cin >> N;

	vector<int> S(N);
	for (int i = 0;i < N;i++)
		cin >> S[i];

	cin >> Q;

	for (int i = 0;i < Q;i++)
	{
		cin >> t;

		if (LinearSearch(S, N, t))
			sum++;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3148
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  string s;
  while (cin >> s) {
    string t = "";
    for (char c : s) {
      if (c != 'x') t += c;
    }
    if (t != string(t.rbegin(), t.rend())) {
      cout << -1 << endl;
      continue;
    }
    vector<int> xs;
    int x = 0;
    for (char c : s) {
      if (c == 'x') {
        ++x;
      } else {
        xs.push_back(x);
        x = 0;
      }
    }
    xs.push_back(x);
    int res = 0;
    for (int i = 0, n = xs.size(); i < n - i - 1; i++) {
      res += max(xs[i], xs[n - i - 1]) - min(xs[i], xs[n - i - 1]);
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1216
N,W = map(int,input().split())
V = 100*N
Data = []
for _ in range(N):
    v,w = map(int,input().split())
    Data.append([v,w])

INF = 10**12
DP = [[INF]*(V+1) for _ in range(N+1)]
for i in range(N+1):
    DP[i][0] = 0

for n in range(1,N+1):
    for v in range(1,V+1):
        tv,tw = Data[n-1]
        if tv <= v:
            DP[n][v] = min(DP[n][v],DP[n-1][v-tv]+tw)
        DP[n][v] = min(DP[n][v],DP[n-1][v])

res = 0
for v in range(1,V+1):
    w = DP[N][v]
    if w <= W:
        res = v
print(res)


Measured memory_bytes: 17184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n, m;
    cin >> n >> m;
    int a[n + 1];
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] * 4 * m >= sum) {
            cnt++;
        }
    }
    if (cnt >= m) cout << "Yes\n";
    else cout << "No\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false) cin.tie(NULL) cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define f first 
#define s second
#define int long long
using namespace std;

const int nax=1e5+5;
vector<int>adj[nax];
const int mod=1e9+7;
const int inf=1e18+7;
vector<pair<int,int>>v;
signed main(){
	int n;
	cin>>n;

	for(int i=1; i*i<=n; i++){
		if(n%i==0){
			v.pb({i,n/i});
		}
	}
	int ans=inf;
	for(auto u: v){
		ans=min(ans, abs(1-u.f)+abs(1-u.s));
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 2688
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int N,top_M;
    int product[100];
    int total_vote = 0;

    std::cin >> N >> top_M;
    for(int i = 1; i <= N ; i++)
    {
       std::cin >> product[i]; 
       total_vote = total_vote + product[i];
    }


   //int border = total_vote / (4 * top_M); 切り捨てによってボーダーさがっちゃう！
    double border = ceil((double)total_vote / (double)(4 * top_M));


    int count = 0;

    for(int i = 1; i <= N ; i++)
    {
        if(product[i] >= (int)border)  count++;
    }

    if (count >= top_M)
    {   
        std:: cout << "Yes" << endl ;  
    }else{
        std:: cout << "No" << endl ;
    }

}

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

int main() {
  std::string s;
  std::cin >> s;

  int q;
  std::cin >> q;

  s.reserve(q);
  bool isReverse = false;

  for (int i = 0; i < q; ++i) {
    int t;
    std::cin >> t;

    if (t == 1) {
      isReverse = !isReverse;
      continue;
    }

    int f;
    std::string c;
    std::cin >> f >> c;

    if ((f == 1 && !isReverse) || (f == 2 && isReverse)) {
      s.insert(0, c);
    } else {
      s += c;
    }
  }

  if (isReverse) {
    std::reverse(s.begin(), s.end());
  }
  std::cout << s << std::endl;
  return 0;
}


Measured memory_bytes: 920
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;


int main() {
  int h,w;
  int ans = -1;
  cin >> h >> w;
  vector<string> s(h);
  vector< vector<int> > r(h, vector<int> (w));
  vector< vector<int> > l(h, vector<int> (w));
  vector< vector<int> > u(h, vector<int> (w));
  vector< vector<int> > b(h, vector<int> (w));

  for(int i=0; i<h; i++) {
    cin >> s[i];
  }

  for(int i=0; i<h; i++) {
    l[i][0] = (s[i][0]=='#'? 0 : 1);
    r[i][w-1] = (s[i][w-1]=='#'? 0 : 1);
  }

  for (int i=0; i<h; i++) {
    for (int j=1; j<w; j++) {
      if (s[i][j] == '#') l[i][j] = 0;
      else l[i][j] = l[i][j-1] + 1;
    }
  }

  for (int i=0; i<h; i++) {
    for (int j=w-2; j>=0; j--) {
      if (s[i][j] == '#') r[i][j] = 0;
      else r[i][j] = r[i][j+1] + 1;
    }
  }

  for(int i=0; i<w; i++) {
    u[0][i] = (s[0][i]=='#'? 0 : 1);
    b[h-1][i] = (s[h-1][i]=='#'? 0 : 1);
  }

  for (int i=0; i<w; i++) {
    for (int j=1; j<h; j++) {
      if (s[j][i] == '#') u[j][i] = 0;
      else u[j][i] = u[j-1][i] + 1;
    }
  }

  for (int i=0; i<w; i++) {
    for (int j=h-2; j>=0; j--) {
      if (s[j][i] == '#') b[j][i] = 0;
      else b[j][i] = b[j+1][i] + 1;
    }
  }

  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      // cout << l[i][j] << " " << r[i][j] << " " << u[i][j] << " " << b[i][j] << endl;
      ans = max(ans, l[i][j]+r[i][j]+u[i][j]+b[i][j]-3);
    }
    // cout << endl;
  }
  cout << ans << endl;
}

/*
4 6
#..#..
.....#
....#.
#.#...
*/


Measured memory_bytes: 69120
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		const long M = 1000000000000000000;

		long N;
		cin >> N;

		vector<long> A( N );
		for( int i = 0; i < N; ++i ) { cin >> A[i]; }
		sort( A.begin(), A.end() );

		long ans = 1;
		for( int i = 0; i < N; ++i ) {
			long b = A[i];
			if( b == 0 ) {
				cout << 0 << endl;
				return;
			}
			if( ans > M/b ) {
				cout << -1 << endl;
				return;
			}

			ans *= b;
		}

		cout << ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


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

int main() {
	int H,W;
  	cin >> H >> W;
  	vector<vector<char>> data(H, vector<char>(W));
  	for (int i = 0; i < H; i++){
    	for (int j = 0; j < W; j++){
        	cin >> data.at(i).at(j);
        }
    }
  	vector<bool> tatecount(H,false);
  	vector<bool> yokocount(W,false);
  	for (int i = 0; i < H; i++){
    	for (int j = 0; j < W; j++){
        	if (data.at(i).at(j) == '#'){
            	tatecount.at(i) = true;
              	yokocount.at(j) = true;
            }
        }
    }
  	
  	for (int i = 0; i < H; i++){
      if (tatecount.at(i)){
    	for (int j = 0; j < W; j++){
        	if(yokocount.at(j)){
            	cout << data.at(i).at(j);
            }
        }
        cout << endl;
    
      }
    }

}
  

Measured memory_bytes: 256
import java.util.*;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
	
		int range = a;
		int cnt = 0;
		
		while(range <= b) {
			if(c % range == 0) {
				cnt++;
			}
			range++;
		}
		
		System.out.println(cnt);
	}
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

const int INF = 1001001001;

vector<int> to[2505];
vector<int> rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2005];


void dfs(int v) {
    if (reachableFrom1[v])return;
    reachableFrom1[v] = true;
    for (int u :to[v]) {
        dfs(u);
    }
}

void rdfs(int v) {
    if (reachableToN[v])return;
    reachableToN[v] = true;
    for (int u :rto[v]) {
        rdfs(u);
    }
}

int main() {

    int n, m, p;

    cin >> n >> m >> p;

    vector<tuple<int, int, int>> edges;

    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        c -= p;
        c = -c;
        edges.emplace_back(a, b, c);
        to[a].push_back(b);
        rto[b].push_back(a);
    }

    dfs(0);
    rdfs(n - 1);
    rep(i, n)ok[i] = reachableFrom1[i] & reachableToN[i];

    {
        vector<int> d(n, INF);
        d[0] = 0;
        bool upd = true;
        int step = 0;
        while (upd) {
            upd = false;
            rep(i, m) {
                int a, b, c;
                tie(a, b, c) = edges[i];
                if (!ok[a])continue;
                if (!ok[b])continue;
                int newD = d[a] + c;
                if (newD < d[b]) {
                    upd = true;
                    d[b] = newD;
                }
            }
            step++;
            if (step > n) {
                puts("-1");
                return 0;
            }
        }
        int ans = -d[n - 1];
        ans = max(ans, 0);
        cout << ans << endl;

    }

}


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

#define LL long long
#define ULL unsigned long long
LL INF=10000000000001LL;

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

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(false)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define clr(x,y) 	memset(x,y,sizeof (x) )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)
// graph direction array [4]
//LL X[4]={0,0,1,-1};
//LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

bool Check(int N,int pos){return (bool)(N & (1<<pos));} // check bit
int Set(int N,int pos){	return N=N | (1<<pos);}// set bit

LL mod=1000000007;
LL modMul(LL a, LL b){

	return (a%mod * b%mod)%mod;
//    LL ans = 0;
//    a = a % mod;
//    while (b > 0){
//        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
//        a = (a%mod * 2%mod) % mod;
//        b /= 2;
//    }
//    return ans % mod;
}

LL powerMod(LL a,LL b){
	if(b==0)return 1%mod;
	LL x=powerMod(a,b/2);
	x = (x%mod*x%mod)%mod;
//	x = modMul( x,x )%mod;
	if(b%2==1){
		x = (x%mod*a%mod)%mod;
//		x = modMul(x,a)%mod;
	}
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}

const int mx = 100005;
// ----------------------------------------------
// ----------------------------------------------

vl arr[mx];
map<LL,pll> ID;
vl Y;
int main(){
//  READ;
//  WRITE;
//  BOOST;
    LL t,n,m,k,c,a,u,v;

	cin>>n>>m;
	FOR(i,m){
        cin>>u>>v;
        Y.pb(v);
        arr[u].pb(v);
	}
	FOR(i,n+1)SV(arr[i]);
	FOR(i,n+1){
		FOR(j,arr[i].size()){
			ID[arr[i][j]] = pll(i,j+1);
		}
	}

	FOR(i,m){
		u = ID[Y[i]].F;
		v = ID[Y[i]].S;
		if( u<10 )cout<<"00000";
		else if( u<100 )cout<<"0000";
		else if( u<1000 )cout<<"000";
		else if( u<10000 )cout<<"00";
		else if( u<100000 )cout<<"0";
		cout<<u;
		if( v<10 )cout<<"00000";
		else if( v<100 )cout<<"0000";
		else if( v<1000 )cout<<"000";
		else if( v<10000 )cout<<"00";
		else if( v<100000 )cout<<"0";
		cout<<v<<endl;
	}

    return 0;
}




Measured memory_bytes: 13940
#include<stdio.h>
int a[200000],b[200000],c[200000],k,n;
void quicksort(int a[],int s,int t){
  if(s<t){
    int i=s,j=t,p=b[a[(s+t)/2]];
    while(1){
      while(b[a[i]]<p)i++;
      while(p<b[a[j]])j--;
      if(i>=j)break;
      a[i]^=a[j]^=a[i]^=a[j];
      i++;j--;
    }
    quicksort(a,s,i-1);quicksort(a,j+1,t);
  }
}
int main(){
  scanf("%d",&n);
  for(k=0;k<n;k++){scanf("%d",&b[k]);a[k]=k;}
  quicksort(a,0,n-1);
  for(k=0;k<n;k++)c[a[k]]=k<n/2?b[a[n/2]]:b[a[n/2-1]];
  for(k=0;k<n;k++)printf("%d\n",c[k]);
}


Measured memory_bytes: 4596
n,a,b=map(int,input().split())
mod=10**9+7
def combination(p,k):
    a,b=1,1  
    for i in range(k):
        a*=(p-i)
        a%=mod
        b*=(i+1)
        b%=mod
    return (a*pow(b,mod-2,mod))%mod
print((pow(2,n,mod)-1-combination(n,a)-combination(n,b))%mod)


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

int main(){
	int i,no,day;
	int ko1[1000],ko2[1000];
	char buf[256];

	memset(ko1,0,sizeof(ko1));
	memset(ko2,0,sizeof(ko2));

	while(strcmp(fgets(buf,256,stdin),"\n")){
		sscanf(buf,"%d,%d",&no,&day);
		ko1[no-1]++;
	}
	while(scanf("%d,%d",&no,&day) != EOF){
		ko2[no-1]++;
	}

	for(i = 0;i < 1000;i++){
		if(ko1[i] && ko2[i]){
			printf("%d %d\n",i+1,ko1[i]+ko2[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0, cnt2 = 0;
    for( int i = 0; i < n; ++i ) {
        if( s[i] == 'R' ) ++cnt;
        else ++cnt2;

    }
    if( cnt > cnt2 ) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    if (A == B){
        cout << "Draw" << endl;
    }
    else if (A != 1 && B != 1){
        if (A > B){
            cout << "Alice" << endl;
        }
        else if (B > A){
            cout << "Bob" << endl;
        }
    }
    else if (A == 1 && B != 1){
        cout << "Alice" << endl;
    }
    else if (A != 1 && B == 1){
        cout << "Bob" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void) {

	// 1_8-B Sum of Numbers
	// ?????????????????°???????????????????¨??????????????????°??????
	
	char str[1000];
	int i;
	int sum;

	// ???????????¨????????????????????????
	// (x???1000?????\????????°?????§?????????
	//	??°????????§???????????????????????´?????????????????????)
	gets(str);
	
	// 0????????????????????§??°?????????
	while(str[0]!='0'){
		sum=0;
		for(i=0; str[i]!='\0'; i++){
			// ???????????°?????????????????????
			sum += (str[i] - '0');
		}
		printf("%d\n",sum);
		gets(str);
	}
	return 0;
}

Measured memory_bytes: 524
#include<stdio.h>

int n;

void CountingSort(int A[], int B[], int k){
    int i, j;
    int C[k+1];
    for(i = 0; i <= k; i++){
        C[i] = 0;
    }
    /* C[i]にiの出現数を記録する*/
    for(j = 1; j <= n;j++){
        C[A[j]]++;
    }
    /*C[i]にi以下の数の出現数を記録する*/
    for(i = 1; i <= k; i++){
        C[i] = C[i] + C[i-1];
    }
    for( j = n; j > 0;j--){
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }
}

int main(){
    scanf("%d", &n);
    int i;
    int A[n+1], B[n+1];
    for(i = 1; i <= n; i++){
        scanf("%d", &A[i]);
    }
    int k = 10000;
    CountingSort(A, B, k);
    for(i = 1; i <= n; i++){
        if(i != 1) printf(" ");
        printf("%d", B[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 17464
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using static exMath;
using static exReadLine;


class Program
{
    static void Main(string[] args)
    {
        int N, M;
        intReadLine(out N, out M);
        if(N == M)
        {
            WriteLine("Yes");
        }
        else
        {
            WriteLine("No");
        }
    }
}

static class exReadLine
{
    public static void intReadLine(out int a)
    {
        a = int.Parse(ReadLine());
    }
    public static void intReadLine(out int a, out int b)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void intReadLine(out int a, out int b, out int c)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void intReadLine(out int a, out int b, out int c, out int d)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }

    public static void longReadLine(out long a)
    {
        a = long.Parse(ReadLine());
    }
    public static void longReadLine(out long a, out long b)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void longReadLine(out long a, out long b, out long c)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void longReadLine(out long a, out long b, out long c, out long d)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }
}

static class exMath
{
    // 最大公約数
    public static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
    public static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    // 最小公倍数
    public static long Lcm(int a, int b)
    {
        return BigMul(a, b) / Gcd(a, b);
    }
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }
}

Measured memory_bytes: 13396