akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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


int main() {
    int n, d, x;
    cin >> n >> d >> x;
    
    int sum = 0;
    REP(i, n){
        int a;
        cin >> a;
        
        sum += (d - 1) / a + 1;
    }
    
    cout << sum + x << endl;
}

Measured memory_bytes: 256
#1,入力をちゃんと受け取る
# ex:「2 5] →a=2,b=5 みたいにする
a, b = map(int, input().split())
#print(a)
#print(b)

#2,目的通りの計算
# ex:二つの整数AとBの掛け算をする
answer = a * b

#計算の結果を出力する
print(answer)

Measured memory_bytes: 9104
require 'pp'

def gets_HW_int
  h, w, n= gets.split.map(&:to_i)
  board = n.times.map { gets.split.map(&:to_i) }
  return h, w, n, board
end
W, H, N, xya_list = gets_HW_int

xs = [0, W]
ys = [0, H]

xya_list.each do |x, y, a|
  if a == 1
    xs[0] = [xs[0], x].max
  elsif a == 2
    xs[1] = [xs[1], x].min
  elsif a == 3
    ys[0] = [ys[0], y].max
  elsif a == 4
    ys[1] = [ys[1], y].min
  end
end

# ans = (x_max.min - x_min.max) * (y_max.min - y_min.max)
# puts ans >= 0 ? ans : 0

puts [xs[1] - xs[0], 0].max * [ys[1] - ys[0], 0].max

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


int main(void)
{ 
  int n,a[2000000],i,j,k;
  cin>>n;
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int max1=0,max2=0;
  for(i=0;i<n;i++)
  {
    if(max1<=a[i]){max2=max1;max1=a[i];}
    else if(max2<=a[i]){max2=a[i];}
  }
  for(i=0;i<n;i++)
  {
    if(a[i]==max1){cout<<max2<<endl;}
    else{cout<<max1<<endl;}
  }
  return 0;
}

Measured memory_bytes: 4412
#include <iostream>

using namespace std;

int main() {
    int a, b, c;
    int x;
    cin >> a >> b >> c >> x;
    int count = 0;
    int i, j, k;
    for (i = 0; i <= a; i++) {
        for (j = 0; j <= b; j++) {
            for (k = 0; k <= c; k++) {
                if (x == 500 * i + 100 * j + 50 * k)
                    count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
H,W = (int(i) for i in input().split())  
df = [input() for i in range(H)] 
s="." * W
df.insert(0,s)
df.append(s)
for i in range(H+2):
    df[i] = "." + df[i] + "."


ans = True
for h in range(1,H-1):
    for w in range(1,W-1):
        if df[h][w]=="#":
            if df[h][w-1]=="." and df[h][w+1]=="." and df[h+1][w]=="." and df[h-1][w]==".":
                ans = False
                break
    if ans is False:
        break

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
  int i,fives=0,seven=0;
  for (i=0;i<3;i++)
{
  int temp;
 scanf("%d",&temp);
 if (temp==5)
fives++;
  if (temp==7)
  seven++;
}
if (fives==2 && seven==1)
  printf("YES");
else
  printf("NO");
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        
        int cnt = 0;
        boolean isAns = true;
        while (isAns) {
            for (int i = 0; i < n; i++) {
                if (a[i] % 2 != 0) {
                    isAns = false;
                    break;
                }
                a[i] /= 2;
            }
            cnt++;
        }

        System.out.println(cnt-1);
    }
}


Measured memory_bytes: 21716
n = int(input())
ans = 10**12
for i in range(1, int(n**0.5)+1):
  if n%i == 0:
    l = (i+(n/i)-2) #-2は(0,0)->(1,1)の分
    ans = min(ans, l)
print(int(ans))

'''
10^12 以下の 正整数 N が与えられます。
この整数を i×j (i,j∈N) と表したとき，i+j−2 の最小値を求める問題です。
まず，愚直に考えると [1, N] の範囲で 2 重ループを回し，ij=N となる 2 整数の和の最小値を更新すればよいです。しかし，これは O(N2) となり，到底間に合いません。
ここで，約数 (つまり，ij=N, i≤j となる i,j すべて) を列挙する際，一方の約数 i は N−−√ 以下であることを利用します。もう一方の約数 j は N÷i から求まるので，すべての約数は O(N−−√) で求まることがわかります。
あとは，すべての i,j の組を列挙し，i+j−2 の最小値を求めれば良いです。1×N=N であることは自明なので，1+N–2=N–1 を初期値にしておきましょう。

計算量 O(N−−√)
'''


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

struct UnionFind{
	std::vector<int> data;
	
	UnionFind(int n){
		data.assign(n, -1);
	}
	
	void unite(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return;
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}
	
	int find(int k){
		if(data[k] < 0) return k;
		return data[k] = find(data[k]);
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(){
	int n, m; cin >> n >> m; std::vector<int> vec(n), a(m), b(m);
	for(int i = 0; i < n; i++) cin >> vec[i]; UnionFind uf(n);
	std::map<int, int> mp;
	for(int i = 0; i < n; i++) mp[vec[i]] = i;
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i];
		
		uf.unite(--a[i], --b[i]);
	}
	
	int count = 0;
	for(int i = 0; i < n; i++){
		if(uf.same(mp[i + 1], i)) count++;
	}
	
	cout << count << endl;
	return 0;
}


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

int LCS(string str1, string str2)
{
  int n1, n2;
  n1 = (int)(str1.length());
  n2 = (int)(str2.length());
  int dp[n1+1][n2+1];

  for(int i = 0; i < n1 + 1; i++) {
    for(int j = 0; j < n2 + 1; j++) {
      dp[i][j] = 0;
    }
  }


  int maxi, s, t;
  for(int i = 1; i < n1 + 1; i++) {
    for(int j = 1; j < n2 + 1; j++) {
      if(str1[i-1] != str2[j-1]) {
	dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      }
      else {
	dp[i][j] = dp[i-1][j-1] + 1; //(i-1,j)と(i,j-1)の場合はstr1[i]とstr2[j]が考慮されているので斜め移動のみ
      }
    }
  }
  /*
  for(int i = 0; i < n1 + 1; i++) {
    for(int j = 0; j < n2 + 1; j++) {
      cout << dp[i][j] << " ";
    }
    cout << "\n";
  }
  */
  maxi = 0;
  for(int i = 0; i < n1 + 1; i++) {
    for(int j = 0; j < n2 + 1; j++) {
      if(maxi < dp[i][j]) {
	maxi = dp[i][j];
      }
    }
  }
  

  return maxi;
}

int main()
{
  int q;
  cin >> q;
  string str1[q], str2[q];
  for(int i = 0; i < q; i++) {
    cin >> str1[i];
    cin >> str2[i];
  }

  for(int i = 0; i < q; i++) {
    cout << LCS(str1[i], str2[i]) << "\n";
  }

  return 0;
}


Measured memory_bytes: 7116
import java.awt.*;
import java.io.*;
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new TestB().doIt();
	}
	class TestB{
		void doIt() {
			int H = sc.nextInt();
			int W = sc.nextInt();
			int ch = sc.nextInt() - 1;
			int cw = sc.nextInt() - 1;
			int dh = sc.nextInt() - 1;
			int dw = sc.nextInt() - 1;
			
			int count[][] = new int[H][W];
			boolean map[][] = new boolean[H][W];
			
			PriorityQueue<Pos> array = new PriorityQueue<Pos>();
			
			for(int h = 0;h < H;h++) {
				String str = sc.next();
				for(int w = 0;w < W;w++) {
					count[h][w] = 10000000;
					if(h == ch && w == cw) {
						count[h][w] = 0;
						array.add(new Pos(h,w,0));
					}
					if(str.substring(w, w+1).equals("#")) {
						map[h][w] = false;
					}else {
						map[h][w] = true;
					}
				}
			}
			
			int mh[] = {1,-1,0,0};
			int mw[] = {0,0,1,-1};
			int mmh[] = {-2,-2,-2,-2,-2,
					-1,-1,-1,-1,-1,
					0,0,0,0,
					1,1,1,1,1,
					2,2,2,2,2};
			int mmw[] = {-2,-1,0,1,2,
					-2,-1,0,1,2,
					-2,-1,1,2,
					-2,-1,0,1,2,
					-2,-1,0,1,2};
			int lengthm = 4;
			int lengthmm = 24;
			int cc = 0;
			
			while(array.size() > 0) {
				Pos p = array.poll();
//				System.out.println(p.c+" "+p.h+" "+p.w);
				for(int i = 0;i < lengthm;i++) {
					ch = p.h + mh[i];
					cw = p.w + mw[i];
					cc = p.c;
					if(ch >= 0 && cw >= 0 && ch < H && cw < W) {
						if(map[ch][cw]) {
							if(count[ch][cw] > cc) {
								count[ch][cw] = cc;
								array.add(new Pos(ch,cw,cc));
							}
						}
					}
				}
				for(int i = 0;i < lengthmm;i++) {
					ch = p.h + mmh[i];
					cw = p.w + mmw[i];
					cc = p.c + 1;
					if(ch >= 0 && cw >= 0 && ch < H && cw < W) {
						if(map[ch][cw]) {
							if(count[ch][cw] > cc) {
								count[ch][cw] = cc;
								array.add(new Pos(ch,cw,cc));
							}
						}
					}
				}
				
			}
			
			if(count[dh][dw] > 5000000) {
				System.out.println(-1);
			}else {
				System.out.println(count[dh][dw]);
			}
		}
	}
	
//	class Pos{
	class Pos implements Comparable<Pos> {
		int h,w,c;
		public Pos(int h,int w,int c) {
			this.h = h;
			this.w = w;
			this.c = c;
		}
		public int compareTo(Pos other) {
            return this.c - other.c;
        }
	}
}

Measured memory_bytes: 65248
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<(int)(n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;

const ll mod=1e9+7;

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

  int n;
  cin >> n;
  vl a(n);
  ll sum=0;
  rep(i, n){
    cin >> a[i];
    sum+=a[i];
    sum%=mod;
  }

  ll ans=0;
  rep(i, n){
    sum-=a[i]-mod;
    sum%=mod;
    ll x=sum*a[i];
    ans+=x%mod;
    ans%=mod;
  }

  cout << ans%mod << endl;

  return 0;
}

Measured memory_bytes: 4784
import java.util.Scanner;

public class Main{
 public static void main(String[] args) {
   Scanner kbd =new Scanner(System.in);
    int k=kbd.nextInt();
   String s=kbd.next();

   int n=s.length();
   if(n<=k){
     System.out.println(s);
   }else{
     System.out.println(s.substring(0,k)+"...");
   }

 }
}

Measured memory_bytes: 38636
#include<bits/stdc++.h>
using namespace std;
int main(void){
	double n, t;
	cin >> n >> t;
	double x, h, mx = -1;
	for(int i = 0; i < n; i++){
		cin >> x >> h;
		mx = max(mx, t * h / x);
	}
	printf("%lf\n", mx);
	return 0;
}


Measured memory_bytes: 3276
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(C-(A-B)<0) cout<<0;
  else cout<<C-(A-B);
  
  
  
}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
using namespace std;

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

	vector<int> h(n);

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

	string result = "Yes";

	if (n == 1) {
		cout << "Yes" << endl;
		return 0;
	}

	if (n == 2) {
		if (h[0] > h[1] + 1) {
			cout << "No" << endl;
			return 0;
		}
	}

	if (h[0] > h[1] + 1) {
		cout << "No" << endl;
		return 0;
	}
	else if (h[0] == h[1]) {

	}
	else {
		--h[0];
	}

	for (int i = 0; i < n-2; i++) {
		if (h[i] == h[i + 1] && h[i + 1] <= h[i + 2]) {

		}
		else if (h[i] < h[i + 1] && h[i + 1] - 1 <= h[i + 2]){
			--h[i + 1];
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
 cin >> n;
 int m=n%1000;
 //cout<<m<<" ";
 int o=(1000-m);
 //cout<<o<<" ";
 int p=(o%1000);
 cout<<p<<endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int n;
  cin >> n;
  vi a(n-1);
  rep(i, n-1) cin >> a[i];

  vi h(n);
  rep(i, n-1){
    h[a[i]-1]++;
  }

  rep(i, n){
    cout << h[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4848
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
#define N 109
using namespace std;

int n;
int read(){
	int x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
ll readll(){
	ll x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
int main(){
	scanf("%d",&n); int i;
	if (n&1){
		printf("%d\n",n==3?2:4*(n/2));
		printf("%d %d\n",n,1);
		printf("%d %d\n",n,n-1);
		if (n==3) return 0;
		for (i=1; i<=n/2; i++){
			int j=n-i;
			if (i==n/2){
				printf("%d %d\n",i,n);
				printf("%d %d\n",j,n);
			} else{
				printf("%d %d\n",i,i+1);
				printf("%d %d\n",i,j-1);
				printf("%d %d\n",j,i+1);
				printf("%d %d\n",j,j-1);
			}
		}
	} else{
		if (n==4){
			puts("4\n1 2\n1 3\n4 2\n4 3"); return 0;
		}
		printf("%d\n",n*2);
		for (i=1; i<=n/2; i++){
			int j=n+1-i;
			if (i==n/2){
				printf("%d %d\n",i,1);
				printf("%d %d\n",i,n);
				printf("%d %d\n",j,1);
				printf("%d %d\n",j,n);
			} else{
				printf("%d %d\n",i,i+1);
				printf("%d %d\n",i,j-1);
				printf("%d %d\n",j,i+1);
				printf("%d %d\n",j,j-1);
			}
		}	
	}
	return 0;
}

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

int main()
{
	int i, j = 0, a = 7, n = 4, flag = 0, num;
	int arr[10001] = { 0, 2,3,5 }, sum[50] = {0};
	
	while (n <= 10000)
	{
		for (i = 2; i <= sqrt(a); i++)
		{
			if (a%i == 0)
			{
				flag = 1;
				break;
			}
		}
		if (flag)
		{
			flag = 0;
		}
		else
		{
			arr[n] = a;
			++n;
		}
		a += 2;
	}
	
	while (1)
	{
		scanf("%d", &num);
		if (num == 0)
		{
			break;
		}
		for (i = 1; i <= num; i++)
		{
			sum[j] += arr[i];
		}
		++j;
	}
	
	for (i = 0; i < j; i++)
	{
		printf("%d\n",sum[i]);
	}

	return 0;
}


Measured memory_bytes: 644
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			for(int i=0;i<=x;i++) {
				if(2*i+4*(x-i)==y) {
					System.out.println("Yes");
					return;
				}
			}
			
			System.out.println("No");
			
		}
	}


Measured memory_bytes: 35772
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int data[100],cnt=0,n,mini;
  cin >> n;
  for(int i=0;i<n;i++) cin >> data[i];
  for(int i=0;i<n;i++){
    mini = i;
    for(int j=i;j<n;j++){
      if(data[j]<data[mini]){
	mini = j;
      }
    }
    if(mini != i){
      cnt++;
      swap(data[i],data[mini]);
    }
  }
  for(int i=0;i<n;i++){
    cout << (i!=0?" ":"") << data[i];
  }
  cout << endl << cnt << endl;
}

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> B(N-1);
    for(int i = 0; i < N-1; i++) cin >> B[i];
    ll ans = B[0];
    for(int i = 0; i < N-2; i++)
    {
        ans += min(B[i], B[i+1]);
    }
    ans += B[N-2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main {

    def main(args: Array[String]): Unit = {
        val n = StdIn.readLine.toInt
        val vs = StdIn.readLine.split(" ").map(_.toInt)
        val cs = StdIn.readLine.split(" ").map(_.toInt)

        println((0 until n).map(i => List(vs(i) - cs(i), 0).max).sum)
    }
}

Measured memory_bytes: 25416
import math
import re
import copy

a,b,h,m = map(int,input().split())
h1 = a * math.cos(math.radians((h + m/60) * 30))
h2 = b * math.cos(math.radians(m * 6))
w1 = a * math.sin(math.radians((h + m/60) * 30))
w2 = b * math.sin(math.radians(m * 6))
h3 = abs(h1-h2)
w3 = abs(w1-w2)
l = math.sqrt((w3 ** 2) + (h3 ** 2))
print(l)

Measured memory_bytes: 10408
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)
	A := make([]bool, N)
	for i := 0; i < K; i++ {
		var d int
		fmt.Scanf("%d", &d)
		for j := 0; j < d; j++ {
			var a int
			fmt.Scanf("%d", &a)
			A[a-1] = true
		}
	}
	count := 0
	for i := 0; i < N; i++ {
		if !A[i] {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 2476
#include<bits/stdc++.h>
using namespace std;
 
int N,M;
bool G[8][8];
 
bool visited[10];
int dfs(int v,int cnt){
    int ret=0;
    if(cnt==N)return 1;

    
    for (int i=0;i<N;i++){
        if(!visited[i]&&G[v][i]){
            //cout <<i+1<<" "<<cnt+1<<" "<<ret<<endl;
            visited[v]=true;
            ret+=dfs(i,cnt+1);
        }
         visited[v]=false;
    }
    return ret;
}
 
signed main(){
    cin>>N>>M;
    for (int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a][b]=G[b][a]=true;
    }
 
    dfs(0,1);
    cout<<dfs(0,1)<<endl;
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    def subsetall(self):
        a = []
        for i in range(len(self.table)):
            if self.table[i] < 0:
                a.append((i, -self.table[i]))
        return a

def main():
    N = I()
    a = []
    b = []
    for i in range(N):
        x,y = LI()
        a.append((x,i))
        b.append((y,i))
    a.sort()
    b.sort()
    t = []
    for i in range(1,N):
        t.append((a[i][0]-a[i-1][0], a[i][1], a[i-1][1]))
        t.append((b[i][0]-b[i-1][0], b[i][1], b[i-1][1]))
    t.sort()
    r = 0
    uf = UnionFind(N)
    for c,d,e in t:
        if uf.union(d,e):
            r += c

    return r

print(main())








Measured memory_bytes: 54952
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

int main(){
    string s,t; cin >> s >> t;
    int ans = 10e7;
    for(int ind = 0; ind + t.size() <= s.size(); ind++){
        int diff = 0;
        string s_partial = s.substr(ind,t.size());

        for(int j = 0; j < t.size(); j++){
            if(s_partial[j] != t[j]){
                diff++;
            }
        }

        ans = min(ans,diff);
    }

    cout << ans << endl;
    sysp;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,mul,f=0;
    cin>>n;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
           if(i*j==n) f=1;

        }
    }
    if(f==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	string name;
	int value,new_value{0};
};

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

int DFS(ConnectNodeInfo& connect,int parent,int child,vector<Data>& D){
	int sum=0;
	if(connect[child].empty()) return D[child].value;

	for(auto& x:connect[child]){
		sum += DFS(connect,child,x.first,D);
	}
	D[child].value = min(D[child].value,sum);
	return D[child].value;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	while(true){
		int N=in();
		if(!N) break;
		vector<Data> D(N);
		map<string,int> E;
		REP(i,N){
			D[i].name=in<string>();
			D[i].value=in();
			E.emplace(D[i].name,i);
		}
		int M=in();
		ConnectNodeInfo connect(N),connect_inv(N);
		REP(i,M){
			string S=in<string>();
			int K=in();
			REP(j,K){
				string T=in<string>();
				connect.AddDirectionalConnection(E[S],E[T],1);
				connect_inv.AddDirectionalConnection(E[T],E[S],1);
			}
		}
		vector<int> L;
		REP(i,N){
			if(connect_inv[i].empty()) L.push_back(i);
		}
		for(auto& x:L){
			DFS(connect,-1,x,D);
		}
		out(D[E[in<string>()]].value);
	}

	return 0;
}



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

int main()
{
    string str;
    queue<int> q;
    stack<int> s;
    cin>>str;
    int len=str.length(),no=0;
    for(int i=0;i<len;i++){
       q.push(str[i]);
       s.push(str[i]);
    }
    for(int i=0;i<len;i++){
        if(q.front()!=s.top()){
            no++;
        }
        q.pop();
        s.pop();
    }
   cout<<no/2<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	int r = min(n, k);
	int ans = 0;
	rep(a, r + 1)rep(b, r + 1) {
		if (a + b > r) continue;
		int tmp = 0;
		priority_queue<int, vector<int>, greater<int>> que;
		rep(i, a) {
			tmp += v[i];
			if (v[i] < 0) que.push(v[i]);
		}
		rrep(i, b + 1) {
			tmp += v[n - i];
			if (v[n - i] < 0) que.push(v[n - i]);
		}
		rep(i, k - (a + b)) {
			if (que.empty()) break;
			tmp -= que.top();
			que.pop();
		}
		maxs(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a, b; cin >> a >> b;

	cout << max(0, a - 2 * b) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

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

    int n;
    cin >> n;
    vector<int> x(n);
    VCIN(x);

    lint sum = 0;
    lint mmax = numeric_limits<lint>::max();
    for(int i=1; i<=100; i++){
        sum = 0;
        for(int j=0; j<n; j++){
            sum += pow(abs(x[j] - i), 2);
        }
        if(sum < mmax) mmax = sum;
    }

    COUT(mmax);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//解説写し
int main(){
  int n;
  long long k;
  cin>>n>>k;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  vector<int>s;
  vector<int>ord(n+1,-1);
  int c=1,l=0;
  {
    int v=1;
    while(ord[v]==-1){
      ord[v]=s.size();
      s.push_back(v);
      v=a[v-1];
    }
    c=s.size()-ord[v];
    l=ord[v];
  }
  if(k<l)cout<<s[k]<<endl;
  else {
    k-=l;
    k%=c;
    cout<<s[l+k]<<endl;
  }
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  double sum=0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    sum+=(1.0/A.at(i));
  }
  double ans=(1/sum);
  cout << fixed << setprecision(14) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import Foundation

private func readInt() -> [Int]{
    return readLine()!.split(separator: " ").map{Int($0)!}
}

func mainA() {
    let line = readInt()
    let S = line[0]
    let W = line[1]
    
    if W >= S {
        print("unsafe")
    } else {
        print("safe")
    }
    

}

mainA()


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

int dfs(int j) {
    int ret = 0;
    while (j > 0) {
        ret += j % 10;
        j /= 10;
    }
    return ret;
}
int main(void){
    // Your code here!
    int n, a, b, res = 0;
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) {
        int sum = dfs(i);
        if (sum >= a && sum <= b) res += i;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,a,b;
	cin >> x >> a >> b;
	if(abs(x-a) > abs(x-b)){
		cout << "B" << endl;
	}else{
		cout << "A" << endl;
	}
	return 0;
}

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

using namespace std;
const long long MOD = 1000000007;


int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (a[i] > a[j]) {
	ans += k * (k + 1) / 2;
	ans %= MOD;
      } else if (a[i] < a[j]) {
	ans += k * (k - 1) / 2;
	ans %= MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

int K;
int s[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int ans = 0;

void solve(){
	ans = s[K-1];
}
 
int main(){
	cin >> K;
 
	solve();

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

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int ans = 0;
    for (int i = 0; i < 3; i++) {
        char c; cin >> c;
        if (c == '1') ans++;
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];

    vector<int> gp(n), gq(n);
    for (int i = 1; i <= n; i++) {
        gp[i-1] = i;
    }
    gq = gp;

    int cnta = 1;
    while (!(gp == p)) {
        next_permutation(gp.begin(), gp.end());
        cnta++;
    }

    int cntb = 1;
    while (!(gq == q)) {
        next_permutation(gq.begin(), gq.end());
        cntb++;
    }

    cout << abs(cnta - cntb) << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
        string s;
        int n,i,j,k,supNow,supPre=1;
        cin >> s;
        vector<vector<ll>> dp(s.length()+1, vector<ll>(13));
        dp.at(0).at(0) = 1;
        for(i=1;i<s.length()+1;++i){
                n = s[s.length()-i]=='?' ? -1 : s[s.length()-i] - '0';
                supNow = i==1 ? 1 : supPre*10%13;
                if(n!=-1){
                        n = n*supNow%13;
                        for(j=0;j<13;++j){
                                dp.at(i).at((j+n)%13) += dp.at(i-1).at(j);
                        }
                }else{
                        for(k=0;k<10;++k){
                                n = k*supNow%13;
                                for(j=0;j<13;++j){
                                        dp.at(i).at((j+n)%13) += dp.at(i-1).at(j);
                                }
                        }
                }
                supPre = supNow;
                for(j=0;j<13;++j) dp.at(i).at(j) %= MOD;
        }
        cout << dp.at(s.length()).at(5) << endl;
        return 0;
}

Measured memory_bytes: 16668
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

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

}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

using namespace std;
 
int main()
{

 
  string str;
  
  cin>>str;
  
  int len=str.length();
  
  bool flag=0;
  
  
  for(int i=0;i<len;i++)
  {
  	if(str[i]!=str[len-i-1])
  	{
  		flag=1;
  		break;
	  }
  }
  
  if(!flag)
  cout<<"Yes";
  else
  cout<<"No";
 
	return 0;
 
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair


int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(NULL);    cout.tie(NULL);

    string s; cin>>s;
    if (s=="ABC") cout<<"ARC";
    else cout<<"ABC";



}


Measured memory_bytes: 3652
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = sorted(list(mapint()), reverse=True)

alice = 0
bob = 0
for i in range(N):
    if i%2==0:
        alice += As[i]
    else:
        bob += As[i]
print(alice-bob)

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;
typedef vector<int> vi;
const int maxn = 100 + 10;

int main() {
    ll n, p;
    cin >> n >> p;
    if (p == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (n == 1) {
        cout << p << endl;
        return 0;
    }
    ll m = p;
    unordered_map<ll, ll> hashMap;
    for (ll i = 2; i * i <= m; ++i) {
        while (m % i == 0) {
            hashMap[i] += 1;
            m /= i;
        }
    }
    ll ans = 1;
    for (auto it = hashMap.begin(); it != hashMap.end(); ++it) {
        if (it->second >= n) {
            ans *= pow(it->first, it->second / n);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 400 + 10;
const int MOD = 998244353;

inline int inc(int a, int b) { return (a + b >= MOD) ? (a + b - MOD) : (a + b); }
inline int dec(int a, int b) { return (a >= b) ? (a - b) : (a + MOD - b); }
inline int mul(int a, int b) { return 1LL * a * b % MOD; }

inline int power(int x, int k) {
	int tmp = 1;
	while(k) {
		if(k & 1) tmp = mul(tmp,x);
		x = mul(x,x);
		k >>= 1;
	}
	return tmp;
}

inline void updata(int &x, int y) { x = inc(x,y); }

int n, a[maxn], b[maxn], sa, sb, fac[maxn], ifac[maxn], inv[maxn];

inline int C(int n, int m) {
	if(n < 0 || m < 0 || n < m) return 0;
	return mul(fac[n],mul(ifac[m],ifac[n - m]));
}

int f[maxn][maxn], g[maxn], Tmp[maxn];
int main() {
//	freopen("data1.in","r",stdin);
  scanf("%d", &n);
	for(int i = 1;i <= n;i ++) scanf("%d%d", &a[i], &b[i]), sa += a[i], sb += b[i];
	inv[0] = 0; inv[1] = 1;
	for(int i = 2;i <= 400;i ++) inv[i] = mul(dec(MOD,MOD / i),inv[MOD % i]);
	fac[0] = ifac[0] = 1;
	for(int i = 1;i <= 400;i ++) fac[i] = mul(fac[i - 1],i);
	ifac[400] = power(fac[400],MOD - 2);
	for(int i = 399;i >= 1;i --) ifac[i] = mul(ifac[i + 1],i + 1);

	//calc f
	f[0][0] = 1;
	for(int i = 1, sum = 0;i <= n;sum += b[i ++]) {
    memset(g,0,sizeof(g));
		g[0] = 1; int p = mul(a[i],power(sa,MOD - 2));
		for(int j = 1;j <= b[i] - 1;j ++) {
			g[j] = mul(g[j - 1],mul(p,inv[j]));
		}
		for(int j = 0;j <= b[i] - 1;j ++) g[j] = dec(MOD,g[j]);
		for(int j = sa;j >= 0;j --) {
      memset(Tmp,0,sizeof(Tmp));
			for(int k = 0;k <= b[i] - 1;k ++) {
				for(int l = 0;l <= sum;l ++) {
					updata(Tmp[k + l],mul(f[j][l],g[k]));
				}
			}
      memcpy(f[j],Tmp,sizeof(f[j]));
			if(j - a[i] >= 0) {
				for(int k = 0;k <= sum;k ++) updata(f[j][k],f[j - a[i]][k]);
			}
		}
	}

  //calc Ans
	int Ans = 0;
	for(int i = 0;i <= sa;i ++) {
		int p = mul(i,power(sa,MOD - 2));
		int now = mul(f[i][0],power(dec(1,p),MOD - 2));
		updata(Ans,now);
	}
	for(int i = 0;i <= sa;i ++) {
		int p = mul(i,power(sa,MOD - 2));
		memset(g,0,sizeof(g));
		g[0] = power(dec(1,p),MOD - 2);
    for(int j = 1;j <= sb;j ++) {
      int xs = mul(j,g[0]);
			g[j] = mul(g[j - 1],xs);
			int now = mul(f[i][j],g[j]);
			updata(Ans,now);
		}
	}
	Ans = dec(MOD,Ans);
	printf("%d\n", Ans);
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 1;
  while(ans * 2 <= n)ans*=2;
  cout << ans << endl;
}

Measured memory_bytes: 256
// AOJ 3006: Chairs
// 2017.10.4 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX		100003
int p[MAX];
int spool[MAX];
int *q[MAX], hi[MAX], hh[MAX];
int sp[MAX], top;
int ans[MAX];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, a, i;
	int *pt;

	n = in();
	for (i = 1; i <= n; i++) {
		p[i] = a = in();
		hh[a]++;
	}
	pt = spool;
	for (i = 1; i <= n; i++) q[i] = pt, pt += hh[i];
	for (i = 1; i <= n; i++) a = p[i], q[a][hi[a]++] = i;

	top = 0, a = 0;
	while (1) for (i = 1; i <= n; i++) {
		while (hi[i]) sp[top++] = q[i][--hi[i]];
		if (!ans[i] && top) {
			ans[i] = sp[--top];
			if (++a == n) goto done;
		}
    }
done:   
	for (i = 1; i <= n; i++) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 4476
import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int numVote = Integer.parseInt(br.readLine());
    Map<String, Integer> voteMap = new HashMap<>();
    
    for(int i=0; i<numVote; i++){
      String name = br.readLine();
      if(voteMap.containsKey(name)){
         voteMap.put(name, voteMap.get(name) + 1);
      } else {
        voteMap.put(name, 1);
      }
    }
    int max = 0;
    StringBuilder result = new StringBuilder();
    
    for(String key: voteMap.keySet().stream().sorted().toArray(String[]::new)){
      int temp = voteMap.get(key);
      if(temp > max){
        result = new StringBuilder(key);
        max = temp;
      } else if(temp == max) {
        result.append("\n").append(key);
      }
    }
    System.out.println(result);
  }
}

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N);
    ll count4 = 0;
    ll count2 = 0;
    for(ll i = 0; i < N; i++)
    {
        cin >> a[i];
        if(a[i] % 4 == 0 )count4++;
        else
        {
            if(a[i] % 2 == 0)count2++;
        }
        
    }

    if((N / 2) <= count4)
    {
        cout << "Yes" << endl;
    }
    else
    {
        if(N - count4*2 <= count2)cout << "Yes" << endl;
        else
        {
            cout << "No" << endl;
        }
        
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int MAX = 10000;

    // 要素数 10000 の配列
    // 添字が素数なら true, でなければ false を格納する
    vector<bool> isPrime(MAX+1, true); // true で初期化

    isPrime[1] = false;

    for (int i = 2; i <= MAX; i++) {
        for (int j = 2; j*j <= i; j++) {
            if (i%j == 0) isPrime[i] = false;
        }
    }

    int N;
    while (cin >> N) {
        int count = 0;
        for (int i = 1; i <= N; i++) {
            if (isPrime[i] && isPrime[N-i+1]) count++;
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  ll A,V,B,W;
  cin >> A >> V >> B >> W;
  ll t;
  cin >> t;
  if(W>=V) {
    cout << "NO" << endl;
    return 0;
  }
  if(abs(A-B)>t*(V-W)) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;
}

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

int main() {
	int h, w;
	const long long MOD = 1000000007;
    cin >> h >> w;
	char a[h][w];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	long long dp[1010][1010] = { 0 };
	dp[0][0] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			dp[i][j] = dp[i][j] % MOD;
			if (i != h - 1) {
				if (a[i + 1][j] == '.') {
					dp[i + 1][j] += dp[i][j];
				}
			}
			if (j != w - 1) {
				if (a[i][j + 1] == '.') {
					dp[i][j + 1] += dp[i][j];
				}
			}
		}
	}
	cout << dp[h - 1][w - 1] << endl;
}


Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>

using namespace std;

int main(void) {
    int n;
    int max = -1;
    int nextMax = -1;
    scanf("%d", &n);
    int number[n];
    for (int i=0; i<n; i++) {
        scanf("%d", &number[i]);
    }
    for (int i=0; i<n; i++) {
        if (number[i] > max) {
            nextMax = max;
            max = number[i];
        } else if (number[i] > nextMax) {
            nextMax = number[i];
        }
    }
    for (int i=0; i<n; i++) {
        if (number[i] == max) {
            cout << nextMax << endl;
        } else {
            cout << max << endl;
        }
    }
    return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i,a,n) for(int i=(a); i<(n); ++i)
#define reps(i,a,n) for(int i=(a); i<(n); --i)
#define all(x) (x).begin(),(x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(n) fixed << setprecision(n)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
	cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;

    while(n > 0){
        if(n % 10 == 7){
            cout<<"Yes\n";
            return 0;
        }
        n /= 10;
    }

    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
long long int dp[3001][3001]; int arr[3000];
long long int solve(int i,int j)
{  if(i>j)
   return 0;
   if (dp[i][j]!=-1) return dp[i][j];
   dp[i][j]=max(arr[i]-solve(i+1,j),arr[j]-solve(i,j-1));
   return dp[i][j];
}
int main()
{int n;
cin>>n;
for(int i=0;i<n;++i)
cin>>arr[i];
memset(dp,-1,sizeof(dp));
long long int result=solve(0,n-1);
cout<<result;
}

Measured memory_bytes: 70784
#include<iostream>
using namespace std;
int main(){
  int n;
  int k,money;
  money = 100000;
  cin >> n;
  
  for(int i = 0;i < n;i++){
    money = money * 1.05;
  
  k = money % 1000;
  if(k > 0){
    money = money -k +1000;
     } 
  }
  cout << money << endl;
}

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

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define yy(n)    ff(y, n)
#define ii(n)    ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;



const LL  INFLL  = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f;  //Works with memset(..).
 
     




int main() {
    ios_base::sync_with_stdio(false);     cin.tie(NULL);
    //cout << '\n';
    cout.precision(16);
    

    int H, W, N;
    cin >> H >> W >> N;
    vector<pii> painted;
    vector<pii> consider(1, pp(-1, -1));
    ii (N) {
        int y, x;
        cin >> y >> x;
        --x, --y;
        painted.append(pp(x, y));
        kk (5)
        ff (h, 5)
            consider.append(pp(x-2+k,
                               y-2+h));
    }
    sort(all(consider));
    sort(all(painted));

    vector<LL> rr(10, 0);
    iii (1, len(consider)) {
        pii here = consider[i];
        if (here == consider[i-1])
            continue;

        if (here.uu < 0 || here.vv < 0
        ||  here.uu+3 > W || here.vv+3 > H)
            continue;

        int nhere = 0;
        xx (3)
        yy (3) {
            pii cell = pp(here.uu+x, here.vv+y);
            ite(painted) lb = lower_bound(all(painted), cell);
            if (lb == painted.ee)
                continue;
            //printf("u %d v %d x %d y %d lbx %d lby %d\n",
             //       here.uu, here.vv, x, y, lb->uu, lb->vv);
            if (*lb == cell)
                ++nhere;
        }
        //printf("nhere %d\n", nhere);
        rr[nhere]++;
    }

    rr[0] = (W-2)*LL(H-2);
    iii (1, 10)
        rr[0] -= rr[i];

    ii (10)
        cout << rr[i] << '\n';
    

    return 0;
}



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

int main() {
  
  long long n,k;
  cin >> n >> k;
  
  vector<long long> h(n);
  for ( int i = 0; i < n; i++){
    cin >> h[i];
  }
  
  sort(h.begin(),h.end());
  
  long long goukei = 0;
  
  for ( int i = 0; i < n - k; i++){
    goukei += h[i];
  }
  
  cout << goukei << endl; 
  
}

Measured memory_bytes: 4784
#include <iostream>
#include <string.h>
#include <cstdio>
using namespace std;
int main() {
    int a,b,c;
    scanf("%d/%d/%d",&a,&b,&c);
    if(a>2019){
        cout<<"TBD";
    }
    else if(a==2019&&4<b){
        cout<<"TBD";
    }
    else{
        cout<<"Heisei";
    }
    return 0;
}

Measured memory_bytes: 256