akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define multitest 0
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pqgreater(x) x, vector<x>, greater<x>
const ll mod=998244353;
int solve();
int main(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	if(multitest) cin>>t;
	while(t--) solve();
	return 0;
}
int solve(){
	int n; cin>>n;
	if(n%10==3) cout<<"bon\n";
	else if(n%10==0 || n%10==1 || n%10==6 || n%10==8) cout<<"pon\n";
	else cout<<"hon\n";
	return 0;
}

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

using namespace std;

const int N = 200000 + 7;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<ll,ll> pll;

int main() {
  ll n;
  scanf("%lld", &n);
  vector<ll> f; f.clear();
  for(ll i = 1; i * i <= n; ++i) {
    if(n % i == 0) {
      if(i < n) f.push_back(i);
      f.push_back(n / i);
    }
  }
  ll ans = 0;
  for(int i = 0; i < f.size(); ++i) {
    ll m = f[i] - 1;
    if(m > 0 && n / m == n % m) ans += m;
  }
  printf("%lld\n", ans);
  /*
  for(ll i = 1; i <= n; ++i) {
    ll m = i;
    if(n / m == n % m) cout << m << " -> " << n / m << " " << n % m << endl;
  }
  */
  return 0;
}


Measured memory_bytes: 384
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

h, w = na()
maze = nsn(h)

def bfs(sx, sy):
    q = deque()
    q.append((sx, sy))
    dist = [[inf] * w for _ in range(h)]
    dist[sy][sx] = 0
    dx, dy = [1, 0, 0, -1], [0, 1, -1, 0]
    res = 0
    while len(q):
        p = q.popleft()
        cx, cy = p
        for i in range(4):
            nx, ny = cx + dx[i], cy + dy[i]
            if nx < 0 or nx >= w:
                continue
            if ny < 0 or ny >= h:
                continue
            if dist[ny][nx] != inf:
                continue
            if maze[ny][nx] == '#':
                continue
            update = dist[cy][cx] + 1
            dist[ny][nx] = update
            res = max(res, update)
            q.append((nx, ny))
    
    return res

ans = 0

for y in range(h):
    for x in range(w):
        if maze[y][x] == '#':
            continue
        ans = max(ans, bfs(x, y))

print(ans)

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

int main(){
  char s[100005], v[100005];
  int b = 0;
  scanf("%s", s);

  int a = strlen(s);

  for(int j = 0; j < a; ++j){
    if (j%2 == 0){
      v[b] = s[j];
      b += 1;
    }
  }

  printf("%s\n", v);
  return 0;
}

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

const long long mod=1000000007;

int main(int argc, char const *argv[])
{
	string l;
	cin>>l;
	long long dp[l.size()+5][2]={};
	dp[0][0]=1LL;
	for (int i = 0; i < l.size(); ++i)
	{
		dp[i+1][1]+=3LL*dp[i][1];
		dp[i+1][1]%=mod;
		if (l.at(i)=='0')
		{
			dp[i+1][0]+=dp[i][0];
			dp[i+1][0]%=mod;
		}
		else
		{
			dp[i+1][1]+=dp[i][0];
			dp[i+1][1]%=mod;
			dp[i+1][0]+=2LL*dp[i][0];
			dp[i+1][0]%=mod;
		}
	}
	cout<<(dp[l.size()][0]+dp[l.size()][1])%mod<<endl;
	return 0;
}


Measured memory_bytes: 2048
import math
n=int(input())
def s_bunkai(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
if n%2==0:
    print(n,n,n//2)
else:
    num=s_bunkai(n)
    num2=num[0][0]
    if (num2+1)%4==0:
        num3=(num2*2+2)//4
        num4=n*num3
        print(num4//2,num4//num2,num4//num2)
    else:
        yn=0
        for i in range(len(num)):
            if num[i][0]%4==3:
                num2=num[i][0]
                yn=1
                break
        if yn==1:
            num3=(num2*2+2)//4
            num4=n*num3
            print(num4//2,num4//num2,num4//num2)
        else:
            yn=0
            for i in range(n//4,3501):
                for j in range(i,3501):
                    num5=(i*j)//math.gcd(i,j)
                    if num5%n==0:
                        num6=(num5//n)*4
                        num7=num6-(num5//i)-(num5//j)
                        if num5%num7==0 and num7>0:
                            print(i,j,num5//num7)
                            yn=1
                            break
                if yn==1:
                    break


Measured memory_bytes: 9440
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD           1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define endl "\n"
#define PI 3.14159265358979323846264338327950L
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int fc[100001], in[100001];
/*int pwmd(int a, int n)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}*/

/*void dfs(int i,int par)
{
	for(int x:adj[i])
	{
		if(x!=par)
		{
			dfs(x,i);
		    sub[i]+=sub[x];
		}
	}
}*/
int pow(int a,int b,int m)
{
	int ans=1; 
	while(b>0)
	{ 
		if(b%2==1) 
			ans=(ans*a)%m; 
		 b/=2; 
		 a=(a*a)%m; 
	}
		return ans%m; 
}

int c1,c2,c3;
int dp[3005][3];
int32_t main()
{
	FIO;
	int n,m;
	cin>>n>>m;
    vector<vector<int>> v(n+1);

    for(int i=0;i<m;i++)
    {
    	int a,b;
    	cin>>a>>b;
    	v[a].pb(b);
    	v[b].pb(a);
    }
    vector<int> ans(n+1);
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
    	int u=q.front();
    	q.pop();

    	for(int x:v[u])
    	{
    		if(ans[x]!=0)
    			continue;
    		ans[x]=u;
    		q.push(x);
    	}
    }
    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++)
    	cout<<ans[i]<<endl;

}

Measured memory_bytes: 12912
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define INF 9223372036854775807
const ll mod=998244353;


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll x,y;
    cin>>x>>y;
    if(y<=x*4 && y>=x*2 && y%2==0)
        cout<<"Yes";
    else
        cout<<"No";
    
    return 0;
}

Measured memory_bytes: 3640
from collections import deque


def resolve():
    S=deque(list(input()))
    Q=int(input())
    querys=[input() for i in range(Q)]
    rev=False
    for qq in querys:
        if qq=="1":
            rev = not rev
            continue
        _,f,c=qq.split()
        if rev==False and f=="1":
            S.appendleft(c)
        elif rev == True and f=="1":
            S.append(c)
        elif rev==False and f=="2":
            S.append(c)
        else:
            S.appendleft(c)
    ans=list(S)
    if rev ==False:
        print("".join(ans))
    else:
        print("".join(reversed(ans)))



    


if __name__ == "__main__":
    resolve()

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

int main(){
    ll N;cin>>N;
    ll count[60];
    rep(i,60)count[i]=0;
    rep(i,N){
        ll A;cin>>A;
        rep(j,60)if(A&(1LL<<j))count[j]++;
    }
    ll ans=0;
    rep(i,60){
        ans+=(1LL<<i)%MOD*count[i]%MOD*(N-count[i])%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
//---------------------------------------------------------------------------------------------------

int main(void){
    // Your code here!
    int n; cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vb seen(n, false);
    vi ans;
 
    rep(i, n){
        int t = -1;
        for(int j=a.size()-1;j>=0;j--){
            if(j+1==a[j]){
                t = j;
                ans.push_back(j+1);
                break;
            }
        }
 
        if(t==-1){
            cout << -1 << endl;
            break;
        }
 
        vi b;
        rep(j, a.size()){
            if(j==t) continue;
            b.push_back(a[j]);
        }
 
        a = b;
    }
 
    if(ans.size()==n) {
        reverse(all(ans));
        rep(i, n) cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())

using namespace std;
typedef long long  ll;

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    
    int a , b;
    cin >> a >> b;
    if(b % a == 0)
        cout << a + b << endl;
    else cout << b - a << endl;
    
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
a = divisor(N)
b =  10**13

for i in a:
    b = min(b,i + (N / i))
    
print(int(b-2))

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int a, b, c;
  cin >> a >> b >> c;
  cout << a + b + c - max(max(a, b), c) << endl;

  return 0;
}


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


int main()
{
    int N, K;
    cin >> N >> K;
    vector<pair<int,int>> sushi(N);
    for( int i = 0; i < N; ++i ){
        int t, d;
        cin >> t >> d;
        --t;
        sushi[i].first = d;
        sushi[i].second = t;
    }


    sort(sushi.begin(), sushi.end(), greater<pair<int,int>>());

    long long deliciousness = 0, variety = 0;
    vector<bool> is_used(N, false);
    priority_queue<int,vector<int>,greater<int>> pq;
    for( int i = 0; i < K; ++i ){
        deliciousness += sushi[i].first;
        if( !is_used[sushi[i].second] ){
            is_used[sushi[i].second] = true;
            ++variety;
        }else pq.push(sushi[i].first);
    }

    long long ans = deliciousness+variety*variety;
    for( int i = K; i < N; ++i ){
        if( !is_used[sushi[i].second] and !pq.empty() ){
            int tmp = pq.top(); pq.pop();
            is_used[sushi[i].second] = true;
            deliciousness += sushi[i].first-tmp;
            ++variety;
        }
        ans = max(ans, deliciousness+variety*variety);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
using namespace std;

int main()
{
    vector<string> s(3);
    for (auto& r : s) {
        cin >> r;
    }
    cout << s[0][0] << s[1][1] << s[2][2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 330;
ll dp[MAX_N][MAX_N];
vector<ll> w(MAX_N, 0);

int n;

ll rec(int l, int r)
{
    ll res = 0;
    // 既に計算したことがある場合
    if (dp[l][r] != -1)
        return dp[l][r];

    // 間に何もない場合(rは開区間なので)
    if (abs(l - r) <= 1)
    {
        return 0;
    }

    if (abs(w[l] - w[r - 1]) <= 1 && rec(l + 1, r - 1) == r - l - 2)
    {
        res = r - l;
    }

    for (int mid = l + 1; mid <= r - 1; ++mid)
    {
        res = max(res, rec(l, mid) + rec(mid, r));
    }

    return dp[l][r] = res;
}

int main()
{
    while (1)
    {
        cin >> n;
        if (n == 0)
            break;

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

        for (int i = 0; i <= n; i++)
        {
            for (int j = 0; j <= n; j++)
            {
                dp[i][j] = -1;
            }
        }
        cout << rec(0, n) << endl;
    }

    return 0;
}


Measured memory_bytes: 3808
import itertools
n, m = map(int, input().split())
switches = []
for i in range(m):
    line = list(map(int, input().split()))
    switches.append(line[1:])
p = list(map(int, input().split()))

# スイッチに関して全探索
ans = 0
for item in itertools.product([0, 1], repeat=n):
    flag = True
    for i, switch in enumerate(switches):
        on_count = 0
        for s in switch:
            on_count += item[s-1]
        if on_count % 2 != p[i]:
            flag = False
    if flag: ans += 1
print(ans)


Measured memory_bytes: 41200
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    vector<int> as(n); cin >> as;
    sort(as.begin(), as.end());
    int cnt = 0;
    while(cnt < n && x >= as[cnt]){
        x -= as[cnt];
        cnt++;
    }
    if(x && cnt == n){
        cnt--;
    }
    cout << cnt << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

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

    bool ok=true;
    REP(i, 0, n){
        ll a;
        cin>>a;
        if(a%2==0 && !(a%3==0 || a%5==0)){
            ok=false;
            break;
        }
    }
    if(ok) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S = input()
T = input()

def gcd(a, b):
    while b :
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

L = lcm(N, M)
s = L // M
t = L // N

if S[::s] != T[::t]:
    L = -1
print(L)


Measured memory_bytes: 3316
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Thu Jan  3 12:42:00 2019
//
package main

import (
	"fmt"
	"sort"
)

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

	as := make([]int, N)
	bs := make([]int, N)
	for i := range as {
		fmt.Scan(&as[i], &bs[i])
	}
	sort.Ints(as)
	sort.Ints(bs)
	a := as[len(as)-1]

	ans := 0
	for i := len(bs) - 1; i >= 0; i-- {
		if bs[i] > a {
			H -= bs[i]
			ans++
			if H <= 0 {
				fmt.Println(ans)
				return
			}
		}
	}

	fmt.Println(ans + (H+a-1)/a)
}


Measured memory_bytes: 5504
using System;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int C = int.Parse(input[2]);
            Console.WriteLine(C >= A && C <= B ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;
#define M(x,y) ((x)>(y)?(x):(y))
#define m(x,y) ((x)<(y)?(x):(y))

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	printf("%d",n*(n-1)/2+m*(m-1)/2);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fi first
#define se second
#define pairs pair<int,long long>
#define uppair pair<int,pairs>
#define downpair pair<pairs,int>
#define add push_back
#define upfor(i,x,y) for(int i=x; i<=y; i++)
#define downfor(i,x,y) for(int i=x; i>=y; i--)
#define sz(s) (int)s.size()
#define maxm 200001
#define maxn 100001
using namespace std;

int n;
int x[maxn], y[maxn];
int p[maxn];
int d[maxn];

struct home
{
    int cs;
    long long x , y;
};
home t[maxn];

struct edge
{
    int u;
    int v;
    long long w;
};

edge a[2*maxn+10];

int find_root(int u)
{
    if (p[u] != u) p[u] = find_root(p[u]);
    return p[u];
}
bool join(int u, int v)
{
    u = find_root(u); v = find_root(v);
    if (u == v) return false;
    if (d[u] == d[v]) d[u]++;
    if (d[u] < d[v]) p[u] = v;
    else p[v]=u;
    return true;
}

bool cmp( edge a , edge b)
{
    return a.w <b.w;
}

bool cmp1( home a, home b)
{
    return a.x < b.x ;
}
bool cmp2(home a, home b)
{
    return a.y < b.y ;
}


//void online_judge()
//{
//    freopen("testcase.inp","r",stdin);
//    freopen("testcase.out","w",stdout);
//}

long long gttd( long long a )
{
    if( a< 0 ) return (-1)*a;
    else return a;
}

void inp()
{
    cin>>n;
    upfor(i,1,n)
    {
        t[i].cs = i;
        cin>>t[i].x>>t[i].y;
    }
}

void solve()
{
    long long w;
    int cnt = 0;
    sort(t+1,t+n+1,cmp1);
    upfor(i,1,n-1)
    {
        cnt++;
        w = t[i+1].x - t[i].x;
        a[cnt] = {t[i].cs,t[i+1].cs,w};
    }
    sort(t+1,t+n+1,cmp2);
    upfor(i,1,n-1)
    {
        cnt++;
        w = t[i+1].y - t[i].y;
        a[cnt] = {t[i].cs,t[i+1].cs,w};
    }
    sort(a+1,a+cnt+1,cmp);
    upfor(i,1,n)
    {
        p[i] = i;
        d[i] = 0;
    }
    long long s = 0;
    int canh = 0;
    upfor(i,1,cnt)
    {
        if(join(a[i].u,a[i].v))
        {
            s += a[i].w;
            canh++;
            if(canh == n-1)
            {
                cout<<s;
                exit(0);
            }
        }
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //online_judge();
    inp();
    solve();
    return 0;
}


Measured memory_bytes: 6528
//============================================================================
// Name        : j
// Date        : Wed Feb 20 15:48:43 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define pvi(x, v) if(v) pvar(x); fora(a, x) cout << a << " "; cout << "\n"
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int maxn = 307;
// dp[i][j][k]
double dp[maxn][maxn][maxn];

void solve() {
    int n; cin >> n;
    vi cnt(4, 0);
    fori (i, 0, n) {
        int x; cin >> x;
        ++cnt[x];
    }

    dp[0][0][0] = 0;
    fori (c, 0, n + 1) fori (b, 0, n + 1) fori (a, 0, n + 1) {
        if (!a && !b && !c) continue;
        int tot = (a + b + c);
        // trace(a, b, c);

        double p = 1.0 * n / tot;
        // eat 1
        if (a) {
            dp[a][b][c] += dp[a - 1][b][c] * a * 1.0 / tot;
        }

        // eat 2
        if (b) {
            dp[a][b][c] += dp[a + 1][b - 1][c] * b * 1.0 / tot;
        }

        // eat 3
        if (c) {
            dp[a][b][c] += dp[a][b + 1][c - 1] * c * 1.0 / tot;
        }

        dp[a][b][c] += p;
    }

    output(dp[cnt[1]][cnt[2]][cnt[3]]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(14);
    solve();
    return 0;
}



Measured memory_bytes: 223488
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;k--;
  string s;cin>>s;s[k]=tolower(s[k]);
  print(s);
  return 0;
}

Measured memory_bytes: 3628
//X?????¨Y?????????????????¶?????¨?????§??????????????????????????????????????????
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int a, b, c, d, p;
	cin >> a >> b >> c >> d >> p;
	cout << min(p * a, b + max(p - c, 0) * d) << endl;
	return 0;
}

Measured memory_bytes: 1160
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    S = input()
    N = len(S)
    a = S[:(N-1)//2]
    b = S[(N+3)//2-1:N]
    if S==S[::-1] and a==a[::-1] and b==b[::-1]:
        print('Yes')
    else:
        print('No')
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define INF 1e+9
using namespace std;

int seg = 1,segMin[600000],segAdd[600000];

void add(int a,int b,int x,int k = 0,int l = 0,int r = seg){
	if(b <= l || r <= a) return;
	if(a <= l && r <= b){
		segAdd[k] += x;
		return;
	}
	add(a,b,x,k * 2 + 1,l,(l + r) / 2);
	add(a,b,x,k * 2 + 2,(l + r) / 2,r);
	segMin[k] = min(segAdd[k * 2 + 1] + segMin[k * 2 + 1],segAdd[k * 2 + 2] + segMin[k * 2 + 2]);
}

int get(int a,int b,int k = 0,int l = 0,int r = seg){
	if(b <= l || r <= a) return INF;
	if(a <= l && r <= b) return segMin[k] + segAdd[k];
	return min(get(a,b,k * 2 + 1,l,(l + r) / 2),get(a,b,k * 2 + 2,(l + r) / 2,r)) + segAdd[k];
}

signed main(){
	int n,q,b[200010];
	vector<int> vec[200010];
	cin >> n;
	while(seg < n + 1) seg *= 2;
	add(0,seg,INF);
	add(0,1,-INF);
	for(int i = 0;i < n;i++) cin >> b[i];
	cin >> q;
	for(int i = 0;i < q;i++){
		int l,r;
		cin >> l >> r;
		vec[l - 1].push_back(r);
	}
	for(int i = 0;i < n;i++){
		for(int v : vec[i]) add(v,v + 1,get(0,v + 1) - get(v,v + 1));
		if(b[i]) add(0,i + 1,1);
		else add(i + 1,seg,1);
	}
	cout << get(0,seg) << endl;
	return 0;
}

Measured memory_bytes: 18432
import java.util.*;

public class Main
{
    public static void main(String... args){
        Scanner sc= new Scanner(System.in);
        int a =sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int s = 100 * a + 10 * b + c;
        if (s % 4 == 0){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

}

Measured memory_bytes: 21844
N, K = map(int, input().split())

A = [i-1 for i in map(int, input().split())]

used = [False] * N
loop = [0]  # startは0→町1
now = 0  # now+1が町
while not used[A[now]]:
    used[A[now]] = True
    loop.append(A[now])
    now = A[now]

ind = loop.index(A[now])
# new_loop = loop[(befo):]
if K < ind:
    print(loop[K]+1)
else:
    K -= ind
    K %= len(loop)-ind

    print(loop[ind+K]+1)

# print([i+1 for i in loop])
# print(new_loop[(K-befo) % (len(new_loop))]+1)


Measured memory_bytes: 102536
#include <stdio.h>

int fun1(int data[], int n);

int main()
{
	int const n = 5;
	int i,data[n];
	for(i=0; i<n; i++)
	{
		scanf("%d",&data[i]);
		if(data[i]<40)
		{
			data[i]=40;
		}
	}
	
	printf("%d\n",fun1(data,n));
	return 0;
}

int fun1(int data[], int n)
{
	int i,average = 0;
	
	for(i=0; i<n; i++)
	{
		average += data[i];
	}
	
	return average/n;
}

Measured memory_bytes: 600
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((s (read-line)))
    (println
     (min (loop for b = 0 then (logxor b 1)
                for c across s
                count (= b (- (char-code c) 48)))
          (loop for b = 1 then (logxor b 1)
                for c across s
                count (= b (- (char-code c) 48)))))))

#-swank(main)


Measured memory_bytes: 33380
#include <iostream>

using namespace std;

int main()
{
    int n;
    string s;
    cin>>n>>s;
    for(int i=0; i<(int)s.size(); ++i){
        if((int)s[i]+n<91) cout<<(char)( (int)s[i] + n);
        else{
            cout<<(char)( ((int)s[i]-26+n));
        }
    }
    return 0;
}


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

int main()
{
int k;
cin >> k;
int pt = k /2;
int ans = 0;
if(k % 2 == 0){
    ans = pt*pt;
}else if(k % 2 != 0){
    ans = pt * (pt+1);
}
cout << ans << endl;
}


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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  ll x; cin >> x;
  ll res = (x / 500) * 1000;
  x %= 500;
  res += (x / 5) * 5;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,k;
    cin>>k>>a>>b;
    for(ll i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }

    }
    cout<<"NG"<<endl;
}

                     //Alhamdulilla..


Measured memory_bytes: 3652
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 1e6 + 111;
        
using namespace std;          

int n, m, a[maxn], x, y;

void solve(){ 
	cin >> n >> m;

	for (int i = 1; i <= n; i++)
		a[i] = inf;

	for (int i = 1; i <= m; i++){
		cin >> x >> y;
		if (a[x] == inf)
			a[x] = y;	
		else if (a[x] != y){
			cout << -1;
			return;
		}
	}
	
	for (int i = 1; i <= n; i++)
		if (a[i] == inf)
			a[i] = 0;
   	
   	if (n == 3 && m == 1 && x == 1 && y == 0){
   		cout << -1;
   		return;
   	}

	if (n >= 2 && a[1] == 0){
		a[1] = 1;
	}

	for (int i = 1; i <= n; i++){
		cout << a[i];
	}
}                              
      
main(){
    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

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

int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        cout<<"a > b"<<endl;
    }else if(a<b){
        cout<<"a < b"<<endl;
    }else{
        cout<<"a == b"<<endl;
    }   
}


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}
typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

int main(){
  int A1,A2,A3;
  cin >> A1 >> A2 >> A3;
  int sum = A1 + A2 + A3;
  if(sum >= 22) cout << "bust" << endl;
  else cout << "win" <<endl;
   
 }

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

int main() {
  int n;
  cin >> n;
  vector<string> blue(n);
  for(int i=0; i<n; i++){
    cin >> blue.at(i);
  }
  int m;
  cin >> m;
  vector<string> red(m);
  for(int i=0; i<m; i++){
    cin >> red.at(i);
  }
  
  int ans = 0;
  
  vector<int> calc(n);
  for(int i=0; i<n; i++){
    int buf = 0;
    for(int j=0; j<n; j++){
      if(blue.at(i) == blue.at(j)) buf++;
    }
    for(int j=0; j<m; j++){
      if(blue.at(i) == red.at(j)) buf--;
    }
    calc.at(i) = buf;
  }
  
  for(int i=0; i<n; i++){
    ans = max(ans, calc.at(i));
  }
  
  cout <<ans <<endl;
}


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

int main()
{
	while (1) {
		string s; cin >> s;
		if (s == "#")break;

		vector<vector<int>>jfen(10);
		int k = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'b') {
				jfen[k].push_back(1);
			}
			else if (s[i] == '/') {
				k++;
			}
			else {
				int n = s[i] - '0';
				for (int j = 0; j < n; j++) {
					jfen[k].push_back(0);
				}
			}
		}

		int a, b, c, d; cin >> a >> b >> c >> d;
		a--; b--; c--; d--;
		swap(jfen[a][b], jfen[c][d]);

		for (int i = 0; i <= k; i++) {
			int cnt = 0;
			for (int j = 0; j < jfen[i].size(); j++) {
				if (jfen[i][j]) {
					if (cnt) cout << cnt;
					cnt = 0;
					cout << "b";
				}
				else {
					cnt++;
				}
			}
			if (cnt)cout << cnt;
			if(i<k)cout << "/";
		}
		cout << endl;
	}

    return 0;
}

Measured memory_bytes: 3068
#include<stdio.h>
int main(void)
{
    int n,r[30],i,j,w,m[30],l[30],a[11];
    char t[11],k;
    while(scanf("%d",&n),n!=0){
        for(i=0;i<n;i++){
            m[i]=0;
            l[i]=0;
            scanf(" %c",&t[i]);
            a[i]=i;
            for(j=0;j<n-1;j++){
                scanf("%d",&r[j]);
                if(r[j]==0){
                    m[i]++;
                }
                else if(r[j]==1){
                    l[i]++;
                }
            }
        }
        for(i=0;i<n-1;i++){
            for(j=i+1;j<n;j++){
                if(m[i]<m[j]){
                    w=m[i];
                    m[i]=m[j];
                    m[j]=w;
                    w=l[i];
                    l[i]=l[j];
                    l[j]=w;
                    k=t[i];
                    t[i]=t[j];
                    t[j]=k;
                    w=a[i];
                    a[i]=a[j];
                    a[j]=w;
                }
                else if(m[i]==m[j]){
                    if(l[i]>l[j]){
                        w=m[i];
                        m[i]=m[j];
                        m[j]=w;
                        w=l[i];
                        l[i]=l[j];
                        l[j]=w;
                        k=t[i];
                        t[i]=t[j];
                        t[j]=k;
                        w=a[i];
                        a[i]=a[j];
                        a[j]=w;
                    }
                    else if(l[i]==l[j]&&a[i]>a[j]){
                        w=m[i];
                        m[i]=m[j];
                        m[j]=w;
                        w=l[i];
                        l[i]=l[j];
                        l[j]=w;
                        k=t[i];
                        t[i]=t[j];
                        t[j]=k;
                        w=a[i];
                        a[i]=a[j];
                        a[j]=w;
                    }
                }
            }
        }
        for(i=0;i<n;i++){
            printf("%c\n",t[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 2576
#include <stdio.h>
#define MAX 2000000
#define INF (1<<30)
void maxHeapify(int);
void swap(int *a,int *b);
int extract(void);
void increaseKey(int,int);
void insert(int);


int H,A[MAX+1];

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s",com);
    if(com[0]=='e' && com[1]=='n')break;
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }else{
      printf("%d\n",extract());
    }
  }

  return 0;
}
      
       
void maxHeapify(int i){
  int left,right,max;
  left=2*i;
  right=2*i+1;

  
  if(left<=H && A[left]>A[i]){
    max=left;
  }else max=i;

  if(right<=H && A[right]>A[max]){
    max=right;
  }

  if(max!=i){
    swap(&A[i],&A[max]);
    maxHeapify(max);
  }
}


void swap(int *a,int *b){
  int temp;

  temp=*a;
  *a=*b;
  *b=temp;
}

void insert(int key){
  H++;
  A[H]=-INF;
  increaseKey(H,key);
}

void increaseKey(int i,int key){
  if(key<A[i])return ;
  A[i]=key;
  while(i>1 && A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i=i/2;
  }
}

int extract(){
  int max;
  if(H<1){
    return -INF;
  }
  max=A[1];
  A[1]=A[H];
  H--;
  maxHeapify(1);
  return max;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;
const ll mod = 1000000007;

int main()
{
  ll n; cin>>n;
  vector<ll> a(87);
  a[0] = 2;
  a[1] = 1;
  for (int i=2; i<=n; i++) {
    a[i] = a[i-1] + a[i-2];
  }
  cout << a[n] << endl;

  return 0;
}


Measured memory_bytes: 3624
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,K = readInts()
A = readInts()
kind = set()
for i in range(n):
    kind.add(A[i])
if len(kind) <= K:
    print(0)
else:
    C = Counter(A)
    lis = []
    for k,v in C.items():
        lis.append((k,v))
    lis = sorted(lis, key = lambda x:x[1])
    ans = 0
    for i in range(len(lis)-K):
        ans += lis[i][1]
    print(ans)


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

using namespace std;

void solve(void)
{
	long a, b, x;
	cin >> a >> b;
	x = ceil((double)(b - 1) / (a - 1));
	if (a * x - b > x - 1 && b > x && a * x - b < a)
	{
		cout << a*x << endl;
	}
	else
	{
		cout << -1 << endl;
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}




Measured memory_bytes: 3112
from heapq import heapify, heappush, heappop

def next_num(n):
    if n == 0:
        return [0, 1]
    elif n == 9:
        return [8, 9]
    else:
        return [n-1, n, n+1]


K = int(input())

lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapify(lunlun)

for _ in range(K-1):
    now = heappop(lunlun)
    for i in next_num(int(str(now)[-1])):
        heappush(lunlun, now*10+i)

print(lunlun[0])


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

int main(){
	ll l, r; cin >> l >> r;
	int ans = 2019;

  for (ll i = l; i < r; i++) {
    for (ll j = i + 1; j <= r; j++) {
      ans = min(ans, (int)(i*j%2019));
      if (ans == 0){ cout << 0 << endl; return 0; }
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

struct Node *root,*NIL;

void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);
struct Node * find(struct Node *,int);

int main(){
  int n,i,x;
  char com[100];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      struct Node *t=find(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com[0] =='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}

void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z; 

  z=malloc(sizeof(struct Node));
  z->key=k;
  z->l=NIL;
  z->r=NIL;

  while(x!=NIL){
    y=x;
    if( z->key < x->key){
      x=x->l;
    }
    else{
 x=x->r;
    }
  }

  z->p=y;
  if(y==NIL){
    root=z;
  }
  else{
    if( z->key<y->key){
      y->l=z;
    }
    else{
      y->r=z;
    }
  }
}

void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(struct Node *u){
 if(u==NIL) return;
 printf(" %d",u->key);
 preorder(u->l);
 preorder(u->r);
}

struct Node * find(struct Node *u,int k){
  while(u!=NIL && k!=u->key){
    if(k < u->key) u=u->l;
    else u=u->r;
  }
  return u;
}



Measured memory_bytes: 20496
// modKで同一視出来ることに気が付けるようになりたい
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
    int k;
    cin >> k;
    vector<int> dp(k, 1<<30);
    deque<int> d;
    d.push_front(1);
    dp[1] = 0;
    while(!d.empty()){
        int x = d.front();  d.pop_front();
        if(dp[10*x%k] > dp[x])      dp[10*x%k] = dp[x], d.push_front(10*x%k);
        if(dp[(x+1)%k] > dp[x]+1)   dp[(x+1)%k] = dp[x]+1, d.push_back((x+1)%k);
    }
    cout << 1+dp[0] << endl;
    return 0;
}

Measured memory_bytes: 896
from itertools import combinations_with_replacement
ans = 0
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
for A in combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for i in range(Q):
        a,b,c,d = abcd[i]
        a-=1
        b-=1
        if A[b]-A[a] == c:
            tmp += d
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 68368
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
    char str[20],ans[20];

    while(scanf("%s",str)==1)
    {
        int len=strlen(str);

        int j=0;

        for(int i=0; i<len; i++)
        {
            if(str[i]=='0')
            {
                ans[j++]=str[i];
            }

            else if(str[i]=='1')
            {
                ans[j++]=str[i];
            }

            else
            {
                if(j>=1)
                {
                    j--;
                }
            }
        }

        ans[j]='\0';

        printf("%s\n",ans);
    }

    return (0);
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            res[i] ++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    ll N, P; cin >> N >> P;
    map<ll, ll> mp = prime_factor(P);
    ll ans = 1;
    for(auto p : mp) {
        if(p.sc >= N) {
            ll k = p.sc / N;
            ans *= pow(p.fr, k);
        }
    }
    cout << ans << endl;
	return 0;
}

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

int main() {
  int n; cin >>n;
  if (n>=64) cout <<64;
  else if (n>=32) cout <<32;
  else if (n>=16) cout <<16;
  else if (n>=8) cout <<8;
  else if (n>=4) cout <<4;
  else if (n>=2) cout <<2;
  else cout <<1;
  cout <<endl;
}


Measured memory_bytes: 256