akhauriyash/Code-Regression huggingface dataset:
// 🐋💭
import Foundation

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

func readInt() -> Int {
    return Int(readLine()!)!
}

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

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}
///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let nm = readInts()
    let (n, m) = (nm[0], nm[1])
    var aryAB = [[Int]]()
    
    for _ in 0..<n {
        aryAB.append(readInts())
    }
    
    aryAB.sort { $0[0] < $1[0] }
    
    var value = 0
    var drinkCounter = 0
    var i = 0
    while drinkCounter <= m && i < n{
        value += aryAB[i][0] * aryAB[i][1]
        drinkCounter += aryAB[i][1]
        i += 1
    }
    value -= (drinkCounter - m) * aryAB[i - 1][0]
    print(value)
}
main()


Measured memory_bytes: 20516
//おまじない
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
//#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 300;

int main(){
    
    char g[maxn+10][maxn+10];
    int ans[maxn+10][maxn+10] = {0};
    int cnt=0;
    int h,w,k;
    
    cin >> h>>w>>k;
    
    rep(i,h){
        rep(j,w){
            char c;cin >> c;
            if(c=='#'){
                ans[i][j]=cnt+1;
                cnt++;
            }
        }
    }
    
    
//    if(h==1){
//        for(int j=0;j<w-1;j++){
//            if(ans[0][j+1]==0)ans[0][j+1]=ans[0][j];
//        }
//        for(int j=w-1;j>=1;j--){
//            if(ans[0][j-1]==0)ans[0][j-1]=ans[0][j];
//        }
//    }else if(w==1){
//        for(int i=0;i<h-1;i++){
//            if(ans[i+1][0]==0)ans[i+1][0]=ans[i][0];
//        }
//        for(int i=h-1;i>=1;i--){
//            if(ans[i-1][0]==0)ans[i-1][0]=ans[i][0];
//        }
//    }else{
//
        for(int i=0;i<h;i++){
            for(int j=0;j<=w-2;j++){
                if(ans[i][j+1]==0)ans[i][j+1]=ans[i][j];
            }
        }
        
        for(int i=0;i<h;i++){
            for(int j=w-1;j>=1;j--){
                if(ans[i][j-1]==0)ans[i][j-1]=ans[i][j];
            }
        }
        
        rep(i,h){
            bool key=false;
            rep(j,w){
                if(ans[i][j]==0){
                    key=true;
                    break;
                }
            }
            if(key){
                rep(j,w){
                    if(ans[i][j]==0){
                        if(i==0)ans[i][j]=ans[i+1][j];
                        else ans[i][j]=ans[i-1][j];
                    }
                }
            }
        }
    
    for(int i=h-1;i>=0;i--){
        bool key=false;
        rep(j,w){
            if(ans[i][j]==0){
                key=true;
                break;
            }
        }
        if(key){
            rep(j,w){
                if(ans[i][j]==0){
                    if(i==h-1)ans[i][j]=ans[i-1][j];
                    else ans[i][j]=ans[i+1][j];
                }
            }
        }
    }
    
    
  //  }
    
    rep(i,h){
        rep(j,w){
            cout << ans[i][j]<<space;
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10**9)

n,x = map(int,input().split())

def f(n):
	if n == 0:
		return 1
	return 2 * f(n-1) + 3

def f2(n):
	if n == 0:
		return 'P'
	return 'B' + f2(n-1) + 'P' + f2(n-1) + 'B'

def p(n):
	if n == 0:
		return 1
	return 2 * p(n-1) + 1

num = f(n)

ans = 0
while True:
	if num < 10 ** 5:
		break
	tmp = num // 2 + 1

	if x > tmp:
		ans += p(n) // 2 + 1
		x -= tmp
		num -= tmp + 1
	elif x < tmp:
		num -= tmp + 1
		x -= 1
	else:
		print(p(n-1)+1)
		sys.exit()
	n -= 1

string = f2(n)
if len(string) <= x:
	print(p(n)+ans)
else:
	for i in range(x):
		if string[i] == 'P':
			ans += 1
	print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
  int m = inputValue();
  int d = inputValue();
  int count = 0;
  repd(i,1,m + 1)
  {
    repd(j,1,d + 1)
    {
      int a = j/10;
      int b = j%10;
      if ( a >= 2 && b >= 2 && i == a*b)
      {
        count++;
      }
    }
  }
  cout << count;
    return 0;
}


Measured memory_bytes: 256
// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll M = 1e9 + 7, N = 1e6 + 5;

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, x, y, minsum = M * M, maxsum = -(M * M), mindiff = M * M, maxdiff = -(M * M);
    cin >> n;
    for (ll i = 0; i < n; i++)
    {
        cin >> x >> y;
        maxsum = max(maxsum, x + y);
        minsum = min(minsum, x + y);
        maxdiff = max(maxdiff, x - y);
        mindiff = min(mindiff, x - y);
    }
    cout << max(maxsum - minsum, maxdiff - mindiff);
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

ll N, M, K, Q;
string S;

int main() {
    cin >> K;
    N = 50;
    vector<ll> a(N);

    for (int i = 0; i < K % N; i++) {
        a[i] += N;
    }
    for (int i = K % N; i < N; i++) {
        a[i] += N - K % N - 1;
    }

    if (K >= N) {
        for (int i = 0; i < N; i++) {
            a[i] += ((K - (K % N)) / N);
        }
        //
    }

    cout << N << endl;
    for (int i = 0; i < N; i++) {
        cout << a[i];
        if (i != N - 1) cout << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A_1_Ns = list(map(int,input().split()))
A_2_Ns = list(map(int,input().split()))
candies = []

for i in range(1,N+1):
    candies.append(sum(A_1_Ns[0:i]) + sum(A_2_Ns[i-1:N]))

print(max(candies))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n;
vector<int> g[55];
int m;
int dis[55][55];
int ooo[55];
map<pii,int> vtoe;
void dfs(int now,int v,int lst){
    if(dis[now][v]) return;
    dis[now][v]=dis[now][lst]+1;
    for(int i=0;i<g[v].size();i++)
        dfs(now,g[v][i],v);
}
void tofind(int v,int dest,int num){
    if(v==dest) return;
    for(int i=0;i<g[v].size();i++)
        if(dis[dest][g[v][i]]<dis[dest][v]){
            ooo[vtoe[mp(v,g[v][i])]]|=(1<<num);
            tofind(g[v][i],dest,num);
        }
}
ll dp[55][1<<20+1];
int main(){
    cin>>n;
    for(int i=1;i<=n-1;i++){
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
        vtoe[mp(a,b)]=i;
        vtoe[mp(b,a)]=i;
    }
    for(int i=1;i<=n;i++)
        dfs(i,i,0);
    cin>>m;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        tofind(u,v,i);
    }
    dp[0][0]=1;
    for(int i=0;i<=n-2;i++)
        for(int j=0;j<(1<<m);j++){
            if(dp[i][j]==0) continue;
            dp[i+1][j|ooo[i+1]]+=dp[i][j];
            dp[i+1][j]+=dp[i][j];
        }
    cout<<dp[n-1][(1<<m)-1]<<endl;
    return 0;
}

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

using namespace std;

int main(void){
  int n,m,s[400],l[400],p[400],w[400],dp[400];
  
  cin >> n;
  for(int i=0;i<n;i++)
    cin >> s[i] >> l[i] >> p[i];
  
  cin >> m;
  for(int i=0;i<m;i++)cin >> w[i];
  
  fill(dp,dp+400,-1);
  dp[0]=0;

  for(int i=1;i<400;i++)
    for(int j=0;j<n;j++)
      for(int k=s[j];k<=l[j];k++)
	if(i-k>=0)dp[i]=max(dp[i],dp[i-k]+p[j]);
  
  for(int i=0;i<m;i++){
    if(dp[w[i]]<0){
      cout << -1 << endl;
      return 0;
    }
  }
    
  for(int i=0;i<m;i++)
    cout << dp[w[i]] << endl;
  
  return 0;
}


Measured memory_bytes: 3116
from collections import Counter


def comb(n, r):
    ans = 1
    for i in range(1, r+1):
        ans = ans * ((n + 1 - i) / i)

    return int(ans)


N = int(input())
A = list(map(int, input().split()))
c = [0]*(N+1)

for A_i in A:
    c[A_i] += 1

gsum = 0
for i in range(1, N + 1):
    if (c[i] != 0):
        gsum += comb(c[i], 2)

for i in A:
    print(gsum-(c[i]-1))


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

bool invite[500];
bool are_friend[500][500];

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		memset(invite,false,sizeof(invite));
		memset(are_friend,false,sizeof(are_friend));
		for(int i=0;i<m;i++){
			int a,b;
			cin>>a>>b;
			a--;b--;
			are_friend[a][b]=are_friend[b][a]=true;
		}
		for(int i=1;i<n;i++){
			if(are_friend[0][i]){
				invite[i]=true;
				for(int j=1;j<n;j++){
					if(are_friend[i][j]){
						invite[j]=true;
					}
				}
			}
		}
		cout<<count(invite,invite+n,true)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1412
public class Main {

    /**
     * ????????????????????????
     *
     * @param args
     */
    public static void main(String[] args) {
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                System.out.println(i + "x" + j + "=" + i * j);
            }
        }
    }
}

Measured memory_bytes: 24024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] line = br.readLine().split(" ");
		
		int num1 = Integer.parseInt(line[0]);
		int num2 = Integer.parseInt(line[1]);
		int num3 = Integer.parseInt(line[2]);
		
		
		if(num1 == 5 && num2 == 5 && num3 == 7){
			System.out.println("YES");
		}
		else if(num1 == 5 && num2 == 7 && num3 == 5){
			System.out.println("YES");
		}
		else if(num1 == 7 && num2 == 5 && num3 == 5){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	
	}

}


Measured memory_bytes: 8148
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<deque>
#include<cstdio>
#include<ctime>
#include<bitset>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define ULL unsigned long long
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int a[MAXN+5];
int main(){
	int n=read();
	for(int i=1;i<=n+1;i++)
		a[i]=read();
	LL ans=0;
	for(int i=1;i<=n;i++){
		int b=read();
		int t=min(a[i],b);
		a[i]-=t,b-=t;
		ans+=t;
		if(b>=0){
			int p=min(a[i+1],b);
			a[i+1]-=p,b-=p;
			ans+=p;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair <long long, long long>, null_type, less<pair <long long, long long> >, rb_tree_tag, tree_order_statistics_node_update>

const int N = 200 * 1000 + 7;

long long a[N];
int dp[N];
long long ps[N];
ordered_set s;
int32_t main() {
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		ps[i] = ps[i - 1] + a[i];
		ps[i] -= k;
	}
	long long ans = 0;
	for (int i = n; i; i--) {
		pair <long long, long long> p = {ps[i], i};
		s.insert(p);
		pair <long long, long long> p2 = {ps[i - 1], i - 1};
		int x = s.order_of_key(p2);
		ans += n - i - x + 1;
	//	cout << i << " " << x << " " << p.first << " " << p2.first << endl;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int NO = 11;

int main(){
	int n;
	string s;
	cin >> n >> s;
	ll dp[12][12][12];
	for(int i=0;i<=11;i++) {
		for(int j=0;j<=11;j++) {
			for(int k=0;k<=11;k++) {
				dp[i][j][k] = 0;
			}
		}
	}
	dp[NO][NO][NO] = 1;
	for(int i=0;i<s.size();i++) {
		int key = (int)(s[i]-'0');
		for(int one=0;one<10;one++) {
			for(int two=0;two<10;two++) {
				if(dp[one][two][key] > 0) continue;
				else dp[one][two][key] += dp[one][two][NO];
			}
			if(dp[one][key][NO] > 0) continue;
			else dp[one][key][NO] += dp[one][NO][NO];
		}
		if(dp[key][NO][NO] > 0) continue;
		else dp[key][NO][NO] += dp[NO][NO][NO];
	}
	ll ans = 0;
	for(int i=0;i<=9;i++) {
		for(int j=0;j<=9;j++) {
			for(int k=0;k<=9;k++) {
				ans += dp[i][j][k];
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<int> w(N+1, 0);
    vector<int> e(N+1, 0);
    rep(i, N) {
        if(S[i]=='W') {
            w[i+1] = w[i] + 1;
            e[i+1] = e[i];
        } else {
            w[i+1] = w[i];
            e[i+1] = e[i] + 1;
        }
    }
    int cnt = 10000000;
    for(int i = 0; i < N; i++) {
        int cw, ce;
        cw = w[i] - w[0];
        ce = e[N] - e[i+1];
        cnt = min(cnt, cw+ce);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define LL long long
#define max 1e5

using namespace std;

int main()
{
 /* LL k;
    cin>>k;
    if(k%2==0)
        cout<<"-1"<<endl;
    else
    {

    }  */
  int n;
    cin>>n;
    char ch[n+5];
    scanf("%s",ch);
    int ans=0;
    for(int i=0,j=n-1;;)
    {
        if(i>=j)
            break;
        if(ch[i]=='R')
            i++;
        if(ch[j]=='W')
            j--;
        if(ch[i]=='W'&&ch[j]=='R')
        {
            ans++;
            ch[j]='W';
            ch[i]='R';
            i++,j--;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3924
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if ( A<=8 &&  B<=8) System.out.println("Yay!");
		else System.out.println(":(");
	}
}


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

int main(){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)toupper(s1[0]) 
         << (char)toupper(s2[0]) 
         << (char)toupper(s3[0]) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a, b, c;

	scanf("%d %d %d\n", &a, &b, &c);

	if(a <= b){
		if(b <= c){
			printf("%d %d %d\n", a, b, c);
		}else{
			if(a <= c){
				printf("%d %d %d\n", a, c, b);
			}else{
				printf("%d %d %d\n", c, a, b);
			}
		}
	}else{
		if(c <= b){
			printf("%d %d %d\n", c, b, a);
		}else{
			if(a <= c){
				printf("%d %d %d\n", b, a, c);
			}else{
				printf("%d %d %d\n", b, c, a);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 600
<?php
/**
 * ABC132
 * B - Ordinary Number
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d", $n);
$p = array_map('intval', explode(' ', trim(fgets(STDIN))));

$count = 0;
for ($i = 0; $i < $n - 2; $i++) {
    if ($p[$i] < $p[$i + 1] and $p[$i + 1] < $p[$i + 2]) {
        $count++;
    } elseif ($p[$i + 2] < $p[$i + 1] and $p[$i + 1] < $p[$i]) {
        $count++;
    }
}

echo $count, PHP_EOL;


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

int main() {

  int N, K;
  cin >> N >> K;

  vector<string> D(K);
  for (int i = 0; i < K; i++) {
    cin >> D[i];
  }
  
  for (int i = N; i < 100000; i++) {
    
    string s = to_string(i);

    bool res = true;

    for (int j = 0; j < K; j++) {
      if (s.find(D[j]) != std::string::npos) {
        res = false;
        break;
      }
    }

    if (res) {
      cout << i << endl;
      break;
    }

  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int now[3] = {0, 0, 0}, before=0;
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  while(true){
    now[before]++;
    if(now[0] == s[0].size()+1) {
      cout << "A" << endl;
      break;
    }else if(now[1] == s[1].size()+1) {
      cout << "B" << endl;
      break;
    }else if(now[2] == s[2].size()+1) {
      cout << "C" << endl;
      break;
    }
    if(s[before][now[before]-1] == 'a') {
      before = 0;
    }
    else if(s[before][now[before]-1] == 'b') {
      before = 1;
    }
    else {
      before = 2;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b; cin>>a>>b;
  int c=a/0.08,d=b/0.1;
  if(c>d) swap(c,d); --c; ++d;
  while(c<=d){
    if(floor(c*0.08)==a&&floor(c*0.1)==b) break; 
    else ++c;
  }
  if(c>d) cout<<-1; else cout<<c;
  return 0;
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;
const int INF=1e9;

signed main(){
  int n,W;
  cin>>n>>W;
  vector<int> w(n);
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>w[i]>>v[i];
  vector<vector<int> > dp(n+1,vector<int>(1e5+1001,1e13));
  dp[0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<1e5+1;j++){
      dp[i+1][j+v[i]]=min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
      dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
    }
  }
  int ans=0;
  for(int i=0;i<1e5+1;i++){
    if(dp[n][i]<=W)ans=max(ans,i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 81024
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if(T[u].p == NIL) cout << "root, ";
  else if(T[u].l == NIL) cout << "leaf, ";
  else cout <<"internal node, ";

  cout << "[";

  for (i=0, c=T[u].l; c!=NIL; i++, c=T[c].r){
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;

}

int rec(int u, int p) {
  D[u]=p;
  if(T[u].r!=NIL) rec(T[u].r, p);
  if(T[u].l!=NIL) rec(T[u].l, p+1);
  return 0;
}

int main(){
  int i, j, d, v, c, l, r;
  cin >> n;
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0; i<n; i++){
    cin >> v >> d;
    for(j=0; j<d; j++){
      cin >> c;
      if(j==0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0; i<n; i++){
    if(T[i].p==NIL) r = i;
  }

  rec(r,0);

  for(i=0; i<n; i++) print(i);

  return 0;
}



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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> C (H,vector<char>(W));
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cin >> C.at(i).at(j);
      }
    }
  
    for(int i=0;i<H;i++){
      for(int cnt=0;cnt<2;cnt++){
        for(int j=0;j<W;j++){
          cout << C.at(i).at(j);
        }
        cout << endl;
      }
    }
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

input_line = sys.stdin.readline()
n = int(input_line)
input_line = sys.stdin.readline()
a = [int(v) for v in input_line.split()]

x = 1
bd = 0
skip = False
UP = 1
DOWN = -1
stat = 0
for i in range(1, n):
	diff = a[i] - a[i - 1]
	if diff == 0:
		continue

	if stat == 0:
		if diff > 0:
			stat = UP
		else :
			stat = DOWN

		continue

	if stat == UP and diff < 0:
		x += 1
		stat = 0
		continue

	if stat == DOWN and diff > 0:
		x += 1
		stat = 0

print(str(x))


Measured memory_bytes: 15988
H, W = map(int, input().split())
S = [input() for h in range(H)]
ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            continue

        # h,w
        record = [[[h, w]]]
        count = 0
        while True:
            if record[count] == []:
                break
            li = []
            for p in record[count]:
                h = p[0]
                w = p[1]
                next_to_p = []
                if h > 0 and S[h - 1][w] == "." and [h - 1, w] not in record[count - 1] + li:
                    next_to_p.append([h - 1, w])
                if w > 0 and S[h][w - 1] == "." and [h, w - 1] not in record[count - 1] + li:
                    next_to_p.append([h, w - 1])
                if h < H - 1 and S[h + 1][w] == "." and [h + 1, w] not in record[count - 1] + li:
                    next_to_p.append([h + 1, w])
                if w < W - 1 and S[h][w + 1] == "." and [h, w + 1] not in record[count - 1] + li:
                    next_to_p.append([h, w + 1])
                li = li + next_to_p
            record.append(li)
            count += 1

        ans = max(ans, count - 1)

print(ans)

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder("Christmas");

		int n = 25 - sc.nextInt();

		for(int i = 0; i < n; i++) {
			sb.append(" Eve");
		}

		System.out.println(sb);
	}
}

Measured memory_bytes: 35720
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    int n,k; cin >> n >> k;
    int ans = 0;
    if(k == 0){cout << n*n<<endl;return 0;}
    rep(i,n+1){
        if(i-1 >= k) {
            ans += n/i*(i-k);
            ans += max(0LL, (n%i) - k + 1);
        }
    }
    cout << ans << endl;
    return 0;
}






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

using namespace std;


int main() {
    int n,k,x,y,res;
    res = 0;
    cin >> n >> k >> x >> y;
    
    for (int i = 0 ; i < min(n,k) ; i++){
        res = res + x;
    }
    for (int i = k ; i < n ; i++){
        res = res + y;
    }
    
    cout << res << endl;
    
    
    
	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	M := getInt()
	D := getInt()

	cnt := 0
	for i := 22; i <= D; i++ {
		d1 := i % 10
		d10 := i / 10

		if d1 <= 1 || d10 <= 1 {
			continue
		}

		if d1 * d10 <= M {
			cnt++
		}
	}

	fmt.Println(cnt)
}

func getInt() int {
	sc.Scan()
	str := sc.Text()
	value, _ := strconv.Atoi(str)
	return value
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}


Measured memory_bytes: 640
import sys
n, a, b, c, d = map(int, sys.stdin.readline().split())
s = sys.stdin.readline().rstrip()

def can_reach(start, end):
    for i in range(start-1, end-1):
        if s[i] == '#' and s[i+1] == '#':
            return False
    return True

if can_reach(a, c) and can_reach(b, d):
    if c < d:
        print('Yes')
    else:
        flag = False
        for i in range(b-1, d):
            if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
                flag = True
        print('Yes' if flag else 'No')
else:
    print('No')


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

int main() {
  
  int n;
  cin >> n;
  int m;
  cin >> m;
  int x;
  cin >> x;
  
  vector<int> vec(n, 0);
  for (int i=0; i<m; i++) {
    int a;
    cin >> a;
    vec.at(a-1)=1;
  }
  
  int s=0;
  for (int i=0; i<x-1; i++) s+=vec.at(i);
  
  int t=0;
  for (int i=0; i<n-x; i++) t+=vec.at(x+i);
  
  cout << min(s, t) << endl;
}

Measured memory_bytes: 256
from collections import deque


def solve(tree, root):
    def dfs1():
        """各頂点の部分木内で最も遠い頂点(葉)までの距離を求める"""
        q1 = deque([root])
        q2 = deque([root])
        while q1:
            v = q1.pop()
            for nxt_v, cost in tree[v]:
                if nxt_v in par:
                    continue
                else:
                    par[nxt_v] = v
                    q1.append(nxt_v)
                    q2.append(nxt_v)
        while q2:
            v = q2.pop()
            for nxt_v, cost in tree[v]:
                if nxt_v == par[v]:
                    continue
                else:
                    dist1[v] = max(dist1[v], dist1[nxt_v] + cost)
    
    def dfs2():
        """全方位木DPで各頂点の最も遠い頂点(葉)までの距離を求める"""
        q = deque([(root, 0)])
        while q:
            v, par_d = q.pop()
            tmp = [(0, -1)]
            for nxt_v, cost in tree[v]:
                if nxt_v == par[v]:
                    tmp.append((par_d + cost, nxt_v))
                else:
                    tmp.append((cost + dist1[nxt_v], nxt_v))
            tmp = sorted(tmp, reverse=True)
            dist2[v] = tmp[0][0]
            for nxt_v, cost in tree[v]:
                if nxt_v == par[v]:
                    continue
                if tmp[0][1] != nxt_v:
                    q.append((nxt_v, tmp[0][0]))
                else:
                    q.append((nxt_v, tmp[1][0]))

    par = {root: -1}
    dist1 = [0] * n
    dist2 = [0] * n
    dfs1()
    dfs2()
    return dist2
    
    
n = int(input())
info = [list(map(int, input().split())) for i in range(n - 1)]
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b, cost = info[i]
    tree[a].append((b, cost))
    tree[b].append((a, cost))
root = 0

ans = solve(tree, root)
for res in ans:
    print(res)


Measured memory_bytes: 12360
from math import sqrt, factorial
from itertools import permutations
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
order = [i for i in range(N)]
s = 0
for a in permutations(order, N):
    for b in range(N-1):
        s += sqrt((xy[a[b]][0]-xy[a[b+1]][0])**2+(xy[a[b]][1]-xy[a[b+1]][1])**2)
print(s/factorial(N))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    char a, b; cin >> a >> b;
    vector<char> c = {'A', 'B', 'C', 'D', 'E', 'F'};
    int locA, locB;
    REP(i, 6) {
        if(c[i] == a) locA = i;
        if(c[i] == b) locB = i;
    }
    if(locA == locB) cout << "=" << endl;
    else cout << (locA < locB ? "<" : ">") << endl;
}

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

int main(){
  char c;
  cin >> c;
  switch(c){
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
      cout << "vowel" << endl;
      break;
    default:
      cout << "consonant" << endl;
      break;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] ab = new int[n][2];
		for(int i = 0; i < n; i++){
			ab[i][0] = sc.nextInt();
			ab[i][1] = sc.nextInt();
		}
		Arrays.sort(ab,(a,b) -> Integer.compare(a[0],b[0]));
		long ans = 0;
		int ans2 = 0;
		int i = 0;
		while(ans2 != m){
			for(int j = 0; j < ab[i][1] && ans2!=m; j++){
				ans+=ab[i][0];
				ans2++;
			}
			i++;
		}
		System.out.print(ans);
	}
}


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

int main(){
  int N;
  cin >> N;
  string W[N];
  for (int i = 0; i < N; i++) {
    cin >> W[i];
    if (i > 0) {
      for (int j = 0; j < i; j++) {
        if (W[i] == W[j]) {
          cout << "No" << endl;
          return 0;
        }
      }
      if (W[i][0] != W[i - 1][W[i - 1].length() - 1]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

typedef long long int64;

const int mod = 1e9 + 7;


struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int64 lcm(int64 a, int64 b)
{
  return (a / __gcd(a, b) * b);
}


struct SegmentTree
{
  vector< int64 > latte, malta;
  int sz;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    latte.assign(2 * sz - 1, 1);
    malta.assign(2 * sz - 1, 0);
  }

  void set(int k, int x, int y)
  {
    latte[k + sz - 1] = x;
    malta[k + sz - 1] = y;
  }

  void build()
  {
    for(int k = sz - 2; k >= 0; k--) {
      latte[k] = lcm(latte[2 * k + 1], latte[2 * k + 2]);
      (malta[k] += latte[k] / latte[2 * k + 1] % mod * malta[2 * k + 1] % mod) %= mod;
      (malta[k] += latte[k] / latte[2 * k + 2] % mod * malta[2 * k + 2] % mod) %= mod;
    }
  }

  pair< int64, int64 > query(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return {1LL, 0LL};
    if(a <= l && r <= b) return {latte[k], malta[k]};
    auto L = query(a, b, 2 * k + 1, l, (l + r) >> 1);
    auto R = query(a, b, 2 * k + 2, (l + r) >> 1, r);
    int64 LCM = lcm(L.first, R.first);
    int64 aaa = LCM / L.first % mod * L.second % mod;
    int64 bbb = LCM / R.first % mod * R.second % mod;
    return {LCM, (aaa + bbb) % mod};
  }

  int64 query(int a, int b)
  {
    return (query(a, b, 0, 0, sz).second);
  }
};

int main()
{
  int N, Q, P[100000];
  scanf("%d %d", &N, &Q);
  for(int i = 0; i < N; i++) scanf("%d", &P[i]);
  UnionFind tree(N);
  for(int i = 0; i < N; i++) tree.unite(i, P[i] - 1);
  vector< int > sum(N, 0);
  for(int i = 0; i < N; i++) (sum[tree.find(i)] += P[i]) %= mod;
  SegmentTree seg(N);
  for(int i = 0; i < N; i++) seg.set(i, tree.size(i), sum[tree.find(i)]);
  seg.build();
  while(Q--) {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", seg.query(--a, b));
  }
}

Measured memory_bytes: 8128
n, k = map(int, input().split())
netas_oishisas = []
for _ in range(n):
    netas_oishisas.append(tuple(map(int, input().split())))
netas_oishisas.sort(key = lambda no: no[1], reverse = True)
tabetaneta = set()
second = []
greedyscore = 0
for i in range(k):
    neta, oishisa = netas_oishisas[i]
    if neta in tabetaneta:
        second.append(oishisa)
    else:
        tabetaneta.add(neta)
    greedyscore += oishisa
greedyscore += len(tabetaneta) ** 2
maxscore = greedyscore
currentscore = greedyscore
second.reverse()
secondpointer = 0
secondn = len(second)
for i in range(k, n):
    if secondpointer >= secondn:
        break
    neta, oishisa = netas_oishisas[i]
    if neta not in tabetaneta:
        currentscore = currentscore - second[secondpointer] + 2*len(tabetaneta) + 1 + oishisa
        maxscore = max(maxscore, currentscore)
        secondpointer += 1
        tabetaneta.add(neta)
print(maxscore)


Measured memory_bytes: 19240
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,n,k;
  cin>>x>>n;
  set<int> s;
  for(int i=0;i<n;i++){
    cin>>k;
    s.insert(k);
  }
  int index;
  int mm=INT_MAX;
  for(int i=x;i>=-1000;i--){
    if(s.count(i)==0){
      if(mm>abs(x-i)){
        mm=abs(x-i);
        index=i;
        break;
      }
    }
  }
  for(int i=x;i<=1000;i++){
    if(s.count(i)==0){
      if(mm>abs(x-i)){
        mm=abs(x-i);
        index=i;
        break;
      }
    }
  }
  cout<<index;
  return 0;
}

Measured memory_bytes: 3572
# 桁DP

n = gets.to_i
n_array = n.to_s.split("").map(&:to_i)
k = gets.to_i
# # dp[上から i 桁まで][smaller][0 でない数]の出現回数
length = n_array.size
dp = (length + 1).times.map { 2.times.map { Array.new(k + 1, 0) } }
# 初期化
# dp[0 桁目まで][桁は不自由][0 でない数は 0 個]の出現回数は 1
dp[0][0][0] = 1

# 桁数分ループする（i は遷移元の桁）
length.times do |i|
  # 最適化のため、事前に 1 行分だけ参照渡しをする
  dp_current = dp[i]
  dp_next = dp[i + 1]
  next_digit = n_array[i]
  # smaller == 1 の場合、以下の桁は自由
  2.times do |smaller|
    (k + 1).times do |nonzero|
      next if dp_current[smaller][nonzero] == 0
      limit = smaller == 1 ? 10 : next_digit + 1
      limit.times do |digit|
        # smaller == 0 且つ digit == next_digit（上限）の時のみ、0 のまま遷移する
        next_smaller = smaller == 0 && digit == next_digit ? 0 : 1
        next_nonzero = digit == 0 ? nonzero : nonzero + 1
        next if next_nonzero > k
        # 次の桁に遷移する
        dp_next[next_smaller][next_nonzero] += dp_current[smaller][nonzero]
      end
    end
  end
end

puts dp.last[0][k] + dp.last[1][k]


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

int main() {
  int n;
  scanf("%d", &n);

  unordered_set<int> s;
  bool b = true;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    
    if (s.count(a)) {
      b = false;
      break;
    }
    s.insert(a);
  }

  if (b)
    printf("YES\n");
  else
    printf("NO\n");

  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int a,b;
	scanf("%lld%lld",&a,&b);
	cout<<max(max(a+b,a-b),a*b)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{   
    ll N, A, B; 
    cin >> N >> A >> B;
    cout<<min(A,B)<<" "<<max((ll)0, A+B-N)<<endl;

    return 0;
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define MOD 1000000007

using namespace std;

using ll = long long;

ll solve() {
    int N;
    cin >> N;
    vector<int> T(N + 2), A(N + 2);
    T[0] = 0;
    T[N + 1] = T[N];
    A[0] = 0;
    A[N + 1] = A[N];
    FOR(i, 1, N + 1) cin >> T[i];
    FOR(i, 1, N + 1) cin >> A[i];

    ll result = 1;
    FOR(i, 1, N + 1) {
        if (T[i - 1] < T[i] && A[i] > A[i + 1]) {
            if (T[i] != A[i]) {
                return 0;
            }
        } else if (T[i - 1] < T[i]) {
            if (T[i] > A[i]) {
                return 0;
            }
        } else if (A[i] > A[i + 1]) {
            if (A[i] > T[i]) {
                return 0;
            }
        } else {
            result = (result * min(T[i], A[i])) % MOD;
        }
    }
    return result;
}

int main() {
    cout << solve() << endl;
    return 0;
}

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

int main() {
    int N, K; cin >> N >> K;
    map<int, int> m;
    rep(i, N){
        int a; cin >> a;
        m[a]++;
    }
    priority_queue<int> pq;
    for (auto p : m){
        auto value = p.second;
        pq.push(value);
    }

    int n = 0;
    rep(i, K){
        int x = pq.top(); pq.pop();
        n += x;
        if(pq.empty())break;
    }
    if(pq.empty()){
        cout << 0 << endl;
    } else {
        cout << N - n << endl;
    }

    return 0;
}

Measured memory_bytes: 13680
#include <algorithm> // std::sort(begin,end)
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;

void mySet(vector<vector<int>> &tree,
           priority_queue<int, vector<int>, greater<int>> &q, vector<int> &cc,
           int prev, int now) {

  for (int next : tree[now]) {
    if (next != prev)
      mySet(tree, q, cc, now, next);
  }
  cc[now] = q.top();
  q.pop();
}

int main(int argc, char const *argv[]) {
  int n, a, b;
  priority_queue<int, vector<int>, greater<int>> q;
  cin >> n;
  vector<vector<int>> tree(n);
  vector<int> c(n), c_result(n, 0);

  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  for (int i = 0; i < n; i++) {
    cin >> c[i];
    q.push(c[i]);
  }

  sort(c.begin(), c.end());
  ll sum = 0;
  for (int i = 0; i < n - 1; i++) {
    sum += c[i];
  }

  int no_leaf = -1;
  for (int i = 0; i < n; i++) {
    if (tree[i].size() != 1) {
      no_leaf = i;
      break;
    }
  }
  mySet(tree, q, c_result, -1, no_leaf);

  cout << sum << endl;
  for (int i = 0; i < n; i++) {
    cout << c_result[i] << " \n"[i == n - 1];
  }

  return 0;
}


Measured memory_bytes: 1536
import kotlin.comparisons.compareValues

fun main(arg: Array<String>) {
    val (N, X) = listOfInt()
    var A = listOfLong().toLongArray()
    var ans = 0L
    for (n in 1 until N) {
        val s = (A[n - 1] + A[n]) - X
        if (s <= 0) continue
        if (A[n] >= s) {
            ans += s
            A[n] -= s
        } else {
            ans += s
            A[n - 1] -= s - A[n]
            A[n] = 0
        }
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 71732
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int N,K;
	cin>>N>>K;
	int ans=1;
	for(int i=0;i<N;i++){
		ans=min(ans*2,ans+K);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// AOJ DSL_2_D Range Update Query (RUQ)
// 2018.5.18 bal4u

#include <stdio.h>

#define INF 0x7fffffff

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char *inf = "2147483647";

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else if (n == INF) for (i = 0; i < 10; i++) pc(inf[i]);
	else {
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

#define MAX_N 100005
#define INF 0x7fffffff

int node[MAX_N << 2];


int find(int t, int l, int r, int x)
{
	int m;

	if (~node[t]) return node[t];
	m = (l + r) >> 1;
	if (x <= m) return find( t<<1, l, m, x);
	else        return find((t<<1)|1, m + 1, r, x);
}

void update(int t, int l, int r, int x, int y, int k)
{
	int m;

	if (l == x && r == y) { node[t] = k; return; }
	m = (l + r) >> 1;
	if (~node[t]) {
		node[t<<1] = node[(t<<1)|1] = node[t];
		node[t] = -1;
	}
	if (y <= m)	update(t<<1, l, m, x, y, k);
	else if (x > m)	update((t<<1)|1, m+1, r, x, y, k);
	else {
		update(t<<1, l, m, x, m, k);
		update((t<<1)|1, m+1, r, m+1, y, k);
	}
}

signed main(void)
{
	int n, q, sz;
	int op, s, t, x;

	n = in(), q = in();
	sz = n << 2;
	for (s = 0; s < sz; s++) node[s] = INF;

	while (q--) {
		op = gc() & 1, gc();
		if (op) out(find(1, 1, n, in()+1));
		else {
			s = in()+1, t = in()+1, x = in();
			update(1, 1, n, s, t, x);
		}
	}
	return 0;
}


Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

	
			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long K = inputArray[1];

			var xArray = retreiveLongArray();

			var minDistance = long.MaxValue;

			//マイナスに往復する場合
			var minusPattern = new Dictionary<long, long>();

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

				if (xArray[i]<0) {
					minusPattern.Add(i, xArray[i] * 2);
				}
				else {
					minusPattern.Add(i, xArray[i] );
				}
			}

			//プラスに往復する場合
			var plusPattern = new Dictionary<long, long>();

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

				if (xArray[i] > 0) {
					plusPattern.Add(i, xArray[i] * 2);
				}
				else {
					plusPattern.Add(i, xArray[i]);
				}
			}


			//マイナスに往復する場合
			for (int i = 0; i < N-K+1; i++) {

				var distance =  minusPattern[i + K - 1]- minusPattern[i];

				if(minusPattern[i] * minusPattern[i + K - 1] > 0) {
					distance += Math.Min(Math.Abs(minusPattern[i]), Math.Abs(minusPattern[i + K - 1]));
				}

				minDistance = Math.Min(minDistance, distance);
			}

			//プラスに往復する場合
			for (int i = 0; i < N - K + 1; i++) {

				var distance =  plusPattern[i + K - 1]- plusPattern[i];

				//どちらも同じ側にあるときは、原点からの移動距離を追加する
				if (plusPattern[i] * plusPattern[i + K - 1] > 0) {
					distance += Math.Min(Math.Abs(plusPattern[i]), Math.Abs(plusPattern[i + K - 1]));
				}

				minDistance = Math.Min(minDistance, distance);
			}



			//答えの出力
			var ans = minDistance;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


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

using namespace std;

int main()
{
   string s;
   cin >> s;
	bool bJudge = true;
	int i=0;
	for(i=0; i<s.size(); i++){
      if ((i+1)%2==0){
      	if('R'==s[i]){
        	cout << "No";
          	return 0;
        }
      }
      else{
      	if('L'==s[i]){
        	cout << "No";
          	return 0;
        }
      }
    }
    cout << "Yes";
    return 0;
}

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

int main() {
	string a,b,c;
	string ans="aaa";
	cin >> a>> b>>c;
	ans[0] = toupper(a[0]);
	ans[1] = toupper(b[0]);
	ans[2] = toupper(c[0]);
	cout << ans << endl;
}

Measured memory_bytes: 256