akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stack>
#include<string>
#include<vector>
using namespace std;

int main(void){
    string state;
    cin >> state;
    stack<pair<int, int> > border;
    int count = 0, height = 0, maxheight = 0;
    double sum = 0;

    for(int i = 0; i < state.size(); ++i){
        if(state[i] == '\\'){
            if((border.size() % 2) == 0) border.push(make_pair(i, height));
            height--;
        }else if(state[i] == '/'){
            height++;
            if(maxheight < height){
                maxheight = height;
                continue;
            }
            if((border.size() % 2) == 1){
                border.push(make_pair(i, height));
            }else{
                while(1){
                    border.pop();
                    if(border.top().second >= height) {
                        // pair<int, int> t = border.top();
                        // border.pop();
                        // while(1){
                        //     if(t.second == height){
                        //         border.push(t);
                        //         break;
                        //     }else{
                        //         if(state[++t.first] == '\\') {
                        //             t.second--;
                        //         }else t.first++;
                        //     }
                        // }
                        border.push(make_pair(i, height));
                        break;
                    }
                    else border.pop();
                }
            }
        }
        // cout << i << ' ' << border.top().first << ' ' << border.top().second << endl;
    }
    if((border.size() % 2) == 1) border.pop();
    count = border.size() / 2;
    // while(!(border.empty())){
    //     cout << border.top().first << ' ' << border.top().second << endl;
    //     border.pop();
    // }
    // cout << endl;
    if(count == 0) {
        cout << 0 << endl << 0 << endl;
        return 0;
    }

    vector<double> S;
    int num = -1;
    while(!(border.empty())) {
        pair<int, int> border1, border2;
        border1 = border.top();
        border.pop();
        border2 = border.top();
        border.pop();
        int poolheight = border1.second;
        height = border2.second;
        S.push_back(0);
        num++;
        for(int i = border2.first; i <= border1.first; ++i){
            if(state[i] == '\\'){
                if(poolheight >= height) S[num] += (0.5 + (poolheight - height));  
                height--;
            }else if(state[i] == '_'){
                if(poolheight >= height) S[num] += (poolheight - height);
            }else if(state[i] == '/'){
                height++;
                S[num] += (0.5 + (poolheight - height));
            }
        }
            sum += S[num];
    }
    cout << (int)sum << endl << count << ' ';
    for(int i = num; i > 0; --i){
        cout << (int)S[i] << ' ';
    }
    cout << (int)S[0] << endl;
    return 0;
}


Measured memory_bytes: 3224
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
q = [[x+y, x-y] for x, y in p]
print(max(max(q)[0] - min(q)[0], max(q, key=lambda x: x[1])[1] - min(q, key=lambda x: x[1])[1]))

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, B[210], A[210];

int main(){
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  std::cin >> N;

  for(int i=0;i<N-1;++i){
      std::cin >> B[i];
  }

  A[0] = B[0];
  A[N-1] = B[N-2];

  for(int i=0;i+1<N-1;++i){
      A[i+1] = std::min(B[i], B[i+1]);
  }

  int res = std::accumulate(A, A + N, 0);
  std::cout << res << std::endl;
}


Measured memory_bytes: 256
def is_prime(x):
    if x == 2:
        return True
    for i in range(2, int(x**0.5) + 1):
        if x % i == 0:
            return False
    return True


if __name__ == '__main__':
    n = int(raw_input())
    cnt = 0
    for i in range(n):
        x = int(raw_input())
        if is_prime(x):
            cnt += 1
    print cnt


Measured memory_bytes: 5420
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(void){
 int n,len,count=0,max1,max2;
 char S[150];
 scanf("%s",S);
 len = strlen(S);
 max1=len/2.0;
 max2=(int)(len/2.0);
 if(len%2==0){
  for(n=0;n<max1;n++){if(S[n]!=S[len-1-n]){count++;}}
 }else if(len%2==1){
  for(n=0;n<max2;n++){if(S[n]!=S[len-1-n]){count++;}}
 }
 printf("%d\n",count);
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                     \
  ifstream in("abc179/abc179_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  ll ans = 0;
  repi(i, 1, N) {
    int temp = N / i;
    if (N % i == 0) temp--;
    ans += temp;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3644
N = int(input())
cards = list(map(int,input().split(" ")))
ruiseki = [cards[0]]
su  = sum(cards)
for i,card in enumerate(cards[1:-1]): #[1:-1]→片方が全部取るケースを除外
    ruiseki.append(ruiseki[i]+card)

ans = 10e15
for temp  in ruiseki:
    x = temp
    y = su - temp
    cand = abs(x-y)
    if cand < ans:
        ans = cand

print(ans)

Measured memory_bytes: 87388
#include <stdio.h>
#include <limits.h>
#define MAX 100

int n;
int p[MAX];
int m[MAX][MAX];

int min(int x, int y){

  if( x < y )
    return x;
  
  return y;

}

void matrixChainOrder(){

  int i,j,k,l;
  int q;

  for( i = 0 ; i < n ; i++ ){
    m[i][i] = 0;
  }

  for( l = 2 ; l <= n ; l++ ){
    for( i = 1 ; i <= n-l+1 ; i++ ){
      j = i+l-1;
      m[i][j] = INT_MAX;
      for( k = i ; k <= j-1 ; k++ ){
        q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        m[i][j] = min(m[i][j],q);
      }
      
    }

  }

}

int main(int argc, char const *argv[]) {

  int i;

  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ){
    scanf("%d %d",&p[i],&p[i+1]);
  }

  matrixChainOrder();
  
  printf("%d\n",m[1][n]);

  return 0;
}

Measured memory_bytes: 636
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

using pii =  pair<int, int>;
using ll = long long;

#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int n, m;

int main(){
  cin.tie(0);
  
  cin>>n>>m;
  cout<<((n-1)*(m-1))<<endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] input = Console.ReadLine().ToCharArray();
            char[] output = new char[input.Length];

            for (int i = 0; i < input.Length; i++)
            {
                char c = input[i];
                if (c >= 'a' && c <= 'z')
                {
                    output[i] = (char)(c - 'a' + 'A');
                }
                else if (c >= 'A' && c <= 'Z')
                {
                    output[i] = (char)(c - 'A' + 'a');
                }
                else
                {
                    output[i] = input[i];
                }
            }

            Console.WriteLine(output);

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 8760
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){

  ll N;
  cin >> N;

  ll root = sqrt(N);
  //cout << root <<endl;

  ll ans = 0;

  for(ll b=1;b<=root;b++){
    if(N%b==0){
      ll a = N/b;
      if(a-1>b) ans += a-1;
    }
  }
  cout << ans <<endl;
  
  return 0;
}













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

int main() {
  string s;
  cin >>s;
  int cnt1=0, cnt0=0;
  rep(i,s.size()){
    if(s[i]=='0') cnt0++;
    if(s[i]=='1') cnt1++;
  }
  int ans = 2*min(cnt0, cnt1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
class Dice:
    def __init__(self, eyes):
        self._eyes = ['dummy'] + eyes

    @property
    def eye(self):
        return self._eyes[1]

    def roll(self, direction):
        if direction == 'N':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[2]
            new[2] = old[6]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[1]
            new[6] = old[5]
            self._eyes = new
        elif direction == 'S':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[5]
            new[2] = old[1]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[6]
            new[6] = old[2]
            self._eyes = new
        elif direction == 'W':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[3]
            new[2] = old[2]
            new[3] = old[6]
            new[4] = old[1]
            new[5] = old[5]
            new[6] = old[4]
            self._eyes = new
        elif direction == 'E':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[4]
            new[2] = old[2]
            new[3] = old[1]
            new[4] = old[6]
            new[5] = old[5]
            new[6] = old[3]
            self._eyes = new
        else:
            raise ValueError('NEWS箱推し')


eyes = input().split()
dice = Dice(eyes)

direction_text = input()
for d in direction_text:
    dice.roll(d)

print(dice.eye)



Measured memory_bytes: 5576
import sys
from collections import deque

readline = sys.stdin.readline
H, W = map(int, readline().split())
S = [['#'] * (W+2)] + [['#'] + list(readline().rstrip()) + ['#'] for _ in range(H)] + [['#'] * (W+2)] 
black = sum(row.count('#') for row in S) - 2*(W+2) - 2*H

# bfs
q = deque([(1, 1)])
S[1][1] = 1
direction = ((0, 1), (1, 0), (0, -1), (-1, 0))
while q:
    x, y = q.popleft()
    d = S[x][y]
    for dx, dy in direction:
        # print(x+dx, y+dy, S[x+dx][y+dy])
        if S[x+dx][y+dy] == '.':
            S[x+dx][y+dy] = d + 1
            q.append((x+dx, y+dy))
ans = -1
if S[H][W] != '.':
    ans = H*W - S[H][W] - black
print(ans)


Measured memory_bytes: 3316
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int[] a = new int[N];
        int sum = 0;

        for(int i=0; i<N; i++){
            a[i] = sc.nextInt();
            sum += a[i];
        }

        int h = 0;
        if(sum%N==0){
            h = sum / N;
        }
        else{
            if(sum%N<=(double)N/2){
                h = sum / N;
            }
            else{
                h = sum / N + 1;
            }
        }
        int ans = 0;
        for(int i=0; i<N; i++){
            ans += (a[i] - h) * (a[i] - h);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N;
	cin >> N;
	cout << N*N*N << endl;
	return 0;
}


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

using namespace std;

bool flag=0;

int main()
{
    int N;

    int num[110][5];

    cin >> N;

    for(int i=0;i<N;i++)
     for(int j=0;j<2;j++)
    {
        cin>>num[i][j];
    }
    for(int i=0;i<N-2;i++)
    {
        if(num[i][0]==num[i][1] && num[i+1][0]==num[i+1][1] && num[i+2][0]==num[i+2][1]) flag=1;
    }
  if(flag==1) cout<<"Yes";
  else cout<<"No";
    return 0;
}




Measured memory_bytes: 3528
#include<stdio.h>
int main(){
    int i=0,n,cnt=0;
    scanf("%d",&n);
    char c[n];
    scanf("%s",c);
    int t=0;int j=65;
    i=0;
    while (i+2<n)
    { 
        if(c[i]=='A' and c[i+1]=='B' and c[i+2]=='C'){
            cnt++;
        }
        i++;
    }
    printf("%d",cnt);
    return 0;   
}

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

int main() {
    int n,q,t;
    string name;
    queue<pair<string,int> > Q;
    cin>>n>>q;

    for(int i=0;i<n;i++) {
        cin>>name>>t;
        Q.push(make_pair(name,t));
    }

    pair<string,int> u;
    int elaps=0,a;

    while(!Q.empty()) {
        u=Q.front();Q.pop();
        a=min(u.    second,q);
        u.second-=a;
        elaps+=a;
        if(u.second>0) Q.push(u);
        else {
            cout<<u.first<<" "<<elaps<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    int N;
    cin>>N;
    int count=0;
    for(int i=1;i<=N;i++){
        int keta=0;
        int ic=i;
        while(ic>0){
            keta++;
            ic/=10;
        }
        if(keta%2==1)count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int a,b,now=0;
	cin>>a>>b;
	int t=1;
	while(a--)t*=100;
	int yo=t;
	while(1)
	{
		if((yo/t)%100!=0)++now;
		if(now==b){
			printf("%d",yo);
			return 0;
		}
		
		yo+=t;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.S;
		int n=s.Length;
		long[,] dp=new long[n+1,2];
		dp[0,0]=1;
		for(int i=0;i<n;i++){
			if(s[i]=='0'){
				dp[i+1,0]=dp[i,0];
				dp[i+1,1]=(dp[i,1]*3)%mod;
			}
			else{
				dp[i+1,0]=(dp[i,0]*2)%mod;
				dp[i+1,1]=(dp[i,1]*3+dp[i,0])%mod;
			}
		}
		Console.WriteLine("{0}",(dp[n,0]+dp[n,1])%mod);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2(int b){return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}
	public int[] Ia3(int a,int b){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(int a,int b,int c,int d){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()+(c!=0?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2(int b){return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}
	public long[] La3(int a,int b){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(int a,int b,int c,int d){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()+(c!=0?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

int main() {
    char buffer[100];
    char duffer[100];
    char guffer[100];
    int number1;
    int number2;
    int number3;
    int a,b,c=0;
    scanf("%s%s%s",buffer,duffer,guffer);
    number1 = atoi(buffer);
    number2 = atoi(duffer);
    number3 = atoi(guffer);
if(1<=number1 && 1<=number2 && 1<=number3){
if(number1 <= number2){
    if(number2 <= number3){
    a=number1+number2;
}else{
    a=number1+number3;
}
    printf("%d",a);
}else{
    if(number1 <= number3){
        b=number1+number2;
    }else{
        b=number2+number3;
    }
    printf("%d",b);
}
}else{
    printf("error");
}
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define int long long
#define ll long long
using namespace std;
signed main() {
	int n,cnt=0,sum=0;
	cin >> n;
	for (int i = 10; i <= n*10; i *= 10) {
		if(i==10)cnt += n % i;
      else sum+=(n%i-n%(i/10))/(i/10);
	}
  	if (n%(cnt+sum) == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
a = input().split()
num = 3

if a[0] == a[1]:
    num = num - 1
    if a[0] == a[2]:
        num = num - 1
elif a[0] == a[2]:
    num = num - 1
elif a[1] == a[2]:
    num = num - 1
    
print(num)

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

using namespace std;

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

  int n, m, c;
  cin >> n >> m >> c;

  vector<int> b(m);
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }

  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }

  int cnt = 0;

  for (int i = 0; i < n; ++i) {
    int sum = 0;
    for (int j = 0; j < m; ++j) {
      sum += a[i][j] * b[j];
    }
    sum += c;
    if (sum > 0) {
      ++cnt;
    }
  }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datA, datB, datC, datK) = readLine.split(" ").map(_.toLong)

    val ans =
    if(datK <= datA) datK
    else if(datK <= datA + datB) datA
    else datA - (datK - (datA + datB))

    println(ans)
  }
}


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

class Program
{
    static void Main(string[] args)
    {
        long[] arr = Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
        long turn = arr[0] / (arr[1] + arr[2]);
        long turnMod = arr[0] % (arr[1] + arr[2]);
        Console.WriteLine(turn * arr[1] + Math.Min(turnMod,arr[1]));



    }

  




}





Measured memory_bytes: 13396
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

// ABC138-E

int main() {
    string s, t;
    cin >> s >> t;
    int N = s.size();
    s = s + s;
    vector<vector<int>> next(s.size() + 1, vector<int>(26, -1));
    for(int i = s.size() - 1; i >= 0; i--) {
        int c = s[i] - 'a';
        for(int j = 0; j < 26; j++) {
            if(next[i + 1][j] != -1) {
                next[i][j] = next[i + 1][j] + 1;
            }
        }
        next[i][c] = 1;
    }
    int now = 0;
    ll res = 0;
    for(int i = 0; i < t.size(); i++) {
        if(next[now][t[i] - 'a'] == -1) {
            cout << -1 << endl;
            return 0;
        }
        res += next[now][t[i] - 'a'];
        now = now + next[now][t[i] - 'a'];
        now %= N;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 27136
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    string s;
    cin>>s;
    unordered_map<char, int> m;
    for (int i=0;i<s.length();i++)
    {
        m[s[i]]++;
    }
    for (auto x:m)
    {
        if (x.second%2!=0)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;

    return 0;
}


Measured memory_bytes: 256
use std::collections::VecDeque;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!(
    n:usize,
    x:usize,
    y:usize,
);
    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
    graph[0] = vec![1];
    graph[n - 1] = vec![n - 2];
    for i in 1..n - 1 {
        graph[i].push(i - 1);
        graph[i].push(i + 1);
    }
    graph[x - 1].push(y - 1);
    graph[y - 1].push(x - 1);

    let mut ans:Vec<usize> = Vec::with_capacity(n);
    for _i in 0..n {
        ans.push(0);
    }

    for i in 0..n {
        let mut que = VecDeque::new();
        let mut dist = Vec::with_capacity(n);
        for _i in 0..n {
            dist.push(0);
        }
        que.push_back(i);
        while !que.is_empty() {
            let v = que.pop_front().unwrap();
            for nv in graph[v].clone() {
                if dist[nv] != 0 {
                    continue;
                }
                dist[nv] = dist[v] + 1;
                que.push_back(nv);
            }
        }
        dist[i] = 0;
        for i in dist.clone(){
            ans[i] += 1;
        }
    }
    ans.remove(0);
    for i in ans {
        println!("{}", i / 2);
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
//#include <boost/graph/adjacency_list.hpp>
using namespace std;

#define ll long long
#define IN(type, name) type name; cin >> name
#define IN_V(type, name, size) vector<type> name(size); for(auto& x: name) cin >> x
#define IN_VPair(type1, type2, name, size) vector<pair<type1, type2>> name(size); for(auto& x: name) cin >> x.first >> x.second
#define IN_VW(type, name, size) vector<type> name(size); for(auto& x: name) 

struct compare {
	bool operator()(pair<ll, ll> l, pair<ll, ll> r) const { 
		return l.second > r.second;
	}
};

int main()
{
	cout << fixed << setprecision(6);
	IN(ll, n);
	IN(ll, m);
	//vector<pair<ll, ll>> abls; for (auto& x : abls) { cin >> x.second >> x.first; }
	IN_VPair(ll, ll, abls, n);

	sort(abls.begin(), abls.end(), [](pair<ll, ll> l, pair<ll, ll> r) {
		return l.first > r.first;
	});
	
	multiset<pair<ll, ll>, compare> cands;
	ll total = 0;
	for (ll i = 1; i <= m; ++i) {
		while (!abls.empty()) {
			if (abls.back().first == i) {
				cands.insert(abls.back());
				abls.pop_back();
			}
			else break;
		}
		if (cands.size() > 0) {
			total += (*cands.begin()).second;
			cands.erase(cands.begin());
		}
	}

	cout << total << endl;
	
	return 0;
}

Measured memory_bytes: 7936
from collections import defaultdict

N,K =map(int,input().split())
xn=list(map(int,input().split()))

result=10**9

#プラスになる場所の特定
if xn[-1]<=0:
    result=-xn[-K]
elif xn[0]>=0:
    result=xn[K-1]
else:
    #プラスになる場所の特定
    for i in range(N):
        if xn[i]>=0:
            posi=i
            break
    
    for j in range(K-min(posi,K),min(K,N-posi)+1):
        if j==0:
            hantei=-xn[posi-K]

        elif j==K:
            hantei=xn[posi+K-1]
        else:
            hantei=min(xn[posi+j-1]*2-xn[posi-(K-j)],(xn[posi+j-1]-2*xn[posi-(K-j)]))
        result=min(hantei,result)

print(result)


Measured memory_bytes: 14636
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);

    for(LL i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<LL>());
    LL ans=0;
    for(LL i=0; i<n; i++){
        if(i%2==0){
            ans+=a[i];
        }else{
            ans-=a[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
using namespace std;

ll mpow(ll a,ll b){
    if(b == 0) return 1;
    if(b == 1) return a%mod;
    if(b%2 == 0) return mpow((a*a)%mod,b/2)%mod;
    else return (a%mod)*mpow((a*a)%mod,(b-1)/2)%mod;
}


ll comb(ll a,ll b){
    if(a<b) return 0;
    if(a == b) return 1;
    ll ue = 1,sita = 1;
    rep(i,b){
        sita *= (i+1);
        ue *= a--;
    }
    return ue/sita;
}

//necessary mpow
#define N 200000
ll fact[N+1],ifact[N+1];
void init_comb(){
    fact[0] = 1;
    ifact[0] = 1;
    rep1(i,N+1){
        fact[i] = (fact[i-1]*i)%mod;
    }
    ifact[N] = mpow(fact[N],mod-2);
    for(ll i=N;i>0;--i) ifact[i-1] = (ifact[i]*i)%mod;
}
ll mcomb(ll a,ll b){
    if(a<b) return 0;
    if(a==b) return 1;
    return (((fact[a]*ifact[b])%mod)*ifact[a-b])%mod;
}

int main(void){
    // Your code here!
    ll n,k;
    cin>>n>>k;
    k = min(k,n-1);
    ll ans = 0;
    init_comb();
    rep(i,k+1){
        ans = (ans+(mcomb(n,i)*mcomb(n-1,i))%mod)%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);


	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i];

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	ll x = 0, y = 0;
	if(n % 2 == 0){
		x = a[n / 2] + a[n / 2 - 1];
		y = b[n / 2] + b[n / 2 - 1];
	}
	else{
		x = a[n / 2];
		y = b[n / 2];
	}

	cout << y - x + 1 << endl;

	return 0;
}

Measured memory_bytes: 6404
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if b - a <= k:
    if c - a <= k:
        if d - a <= k:
            if e - a <= k:
                if c - b <= k:
                    if d - b <= k:
                        if e - b <= k:
                            if d - c <= k:
                                if e - c <= k:
                                    if e - d <= k:
                                        print("Yay!")
                                    else:
                                        print(":(")
                                else:
                                    print(":(")
                            else:
                                print(":(")
                        else:
                            print(":(")
                    else:
                        print(":(")
                else:
                    print(":(")
            else:
                print(":(")
        else:
            print(":(")
    else:
        print(":(")
else:
    print(":(")


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

using namespace std;

using int64 = long long;

int main() {
  int N, M;
  cin >> N >> M;
  vector< tuple< int64, int64, int64 > > s;
  for(int i = 0; i < N; i++) {
    int64 x, y, z;
    cin >> x >> y >> z;
    s.emplace_back(x, y, z);
  }
  int64 ret = 0;
  for(int i = 0; i < (1 << 3); i++) {
    sort(begin(s), end(s), [&](tuple< int64, int64, int64 > a, tuple< int64, int64, int64 > b) {
      int64 aa, bb, cc;
      int64 dd, ee, ff;
      tie(aa, bb, cc) = a;
      tie(dd, ee, ff) = b;
      if((i >> 0) & 1) {
        aa *= -1;
        dd *= -1;
      }
      if((i >> 1) & 1) {
        bb *= -1;
        ee *= -1;
      }
      if((i >> 2) & 1) {
        cc *= -1;
        ff *= -1;
      }
      return aa + bb + cc > dd + ee + ff;
    });

    int64 dd = 0, ee = 0, ff = 0;
    for(int j = 0; j < M; j++) {
      int64 aa, bb, cc;
      tie(aa, bb, cc) = s[j];
      if((i >> 0) & 1) {
        aa *= -1;
      }
      if((i >> 1) & 1) {
        bb *= -1;
      }
      if((i >> 2) & 1) {
        cc *= -1;
      }
      dd += aa;
      ee += bb;
      ff += cc;
    }
    ret = max(ret, llabs(dd) + llabs(ee) + llabs(ff));
  }
  cout << ret << endl;

}


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

int main(void) {
  int a, b, c; 
  cin >> a >> b >> c;
  set<int> check;
  check.insert(a);
  check.insert(b);
  check.insert(c);
  if ((int) check.size() == 2) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static final long MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PriorityQueue<Unit> queue = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
		    queue.add(new Unit(sc.nextInt(), true));
		}
		for (int i = 0; i < n; i++) {
		    queue.add(new Unit(sc.nextInt(), false));
		}
		long ans = 1;
		boolean currentType = false;
		ArrayDeque<Unit> stack = new ArrayDeque<>();
		while (queue.size() > 0) {
		    Unit u = queue.poll();
		    if (stack.size() == 0 || currentType == u.type) {
		        stack.push(u);
		        currentType = u.type;
		    } else {
		        ans *= stack.size();
		        ans %= MOD;
		        stack.pop();
		    }
		}
		System.out.println(ans);
	}
	
	static class Unit implements Comparable<Unit> {
	    int place;
	    boolean type;
	    
	    public Unit (int place, boolean type) {
	        this.place = place;
	        this.type = type;
	    }
	    
	    public int compareTo(Unit another) {
	        return place - another.place;
	    }
	}
	    
}
	


Measured memory_bytes: 77600
def calc(intA,intB,intC,intD):  
    W=intA*intC
    X=intB*intC
    Y=intA*intD
    Z=intB*intD
    ret=max(W,X,Y,Z)
    return ret

a,b,c,d = map(int,(input()).split())

print(calc(a,b,c,d))

Measured memory_bytes: 61784
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int par[213456];//親
int depth[213456];//木の深さ
//n要素で初期化
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		depth[i] = 0;
	}
}
//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (depth[x] < depth[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (depth[x] == depth[y])depth[x]++;
	}
}
//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}
struct edge { int u, v, cost; };
bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}
edge es[313456];
int kruskal(int V, int E) { //頂点数と辺数
	sort(es, es + E, comp); //edge.costが小さい順にソート
	init(V); //Union-Findの初期化
	int res = 0;
	for (int i = 0; i < E; i++) {
		edge e = es[i];
		if (!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}
int bb[1234][1234], cc[123][123][123];
int res[123456], uio[1234][1234];
signed main() {
	int n, m, a, b, x = 0, y = 0, ans = 0; cin >> n;
	init(n + 1);
	vector<vector<int>>aa(n, vector<int>(3));
	vector<vector<int>>ab(n, vector<int>(3));
	for (int h = 0; h < n; h++) {
		cin >> aa[h][0] >> aa[h][1]; aa[h][2] = h;
		ab[h][1] = aa[h][0]; ab[h][0] = aa[h][1]; ab[h][2] = h;
	}
	sort(aa.begin(), aa.end()); sort(ab.begin(), ab.end());
	for (int h = 1; h < n; h++) {
		es[x] = { aa[h - 1][2], aa[h][2], min(abs(aa[h - 1][0] - aa[h][0]),abs(aa[h - 1][1] - aa[h][1])) }; x++;
	}
	for (int h = 1; h < n; h++) {
		es[x] = { ab[h - 1][2], ab[h][2], min(abs(ab[h - 1][0] - ab[h][0]),abs(ab[h - 1][1] - ab[h][1])) }; x++;
	}
	cout << kruskal(n, x) << endl;
	return 0;
}

Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
 
template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}
 
ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}
 
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M) % M;
}

int main() {
    int K;
    cin >> K;
    string S;
    cin >> S;
    if(S.size() <= K) {
        cout << S << endl;
    }
    else {
        string ret = S.substr(0,K);
        cout << ret << "..." << endl;
    }
}

Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        int c = 0;
        for (int i = 0; i < n; i++) {
            int x = in.nextInt();
            while (x % 2 == 0) {
                c++;
                x /= 2;
            }
        }

        out.println(c);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 24644
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scan = new Scanner(System.in);
        long A = scan.nextLong();
        long B = scan.nextLong();
        long C = scan.nextLong();
        long K = scan.nextLong();

        if(K <= A){
            System.out.println(K);
        } else if(K <= A+B){
            System.out.println(A);
        } else {
            System.out.println(A-(K-A-B));
        }
    }

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


Measured memory_bytes: 35784
#include <iostream>
using namespace std;
int abs(int s){
	if(s<0) s=-s;
	return s;
}
int main(){
	int x1, x2,x3,x4,y1,y2,y3,y4;
	cin >> x1 >> y1 >> x2 >> y2;
	x3 = x2 -y2+y1;
	y3 = -x1 +x2 +y2;
	x4 = x3 -y3 +y2;
	y4 = -x2 +x3 +y3;
	cout << x3<<" "<< y3<<" "<< x4<<" "<< y4;
}





Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))
MOD = 998244353
if d[0] != 0:
    print(0)
    exit()
    
a = [0] * n
for i in range(n):
    a[d[i]] += 1

ans = 1
for i in range(n):
    if i == 0:
        if a[i] != 1:
            ans *= 0
    else:
                for _ in range(a[i]):
                    ans *= a[i-1]
                    ans %= MOD
print(ans % MOD)


Measured memory_bytes: 53556
#
# File    : B2.rb
# Author  : Kazune Takahashi
# Created : 2018-12-2 21:33:52
# Powered by Visual Studio Code
#

s = gets.chomp
ans = []
for i in 0...s.size - 2
  ans << (753 - s[i...i + 3].to_i).abs
end
puts ans.min



Measured memory_bytes: 1788
package main
import (
  "fmt"
)

func f(n int) int{
  if n % 2 == 0{
    return n/2
  }else{
    return 3*n+1
  }
}

func a(i int, s int) int{
  if i == 1{
    return s
  }else{
    return f(a(i-1, s))
  }
}

func main(){
  var s int
  fmt.Scan(&s)
  for i := 1; i<=1000000; i++{
    for j:=1; j<i; j++{
      if a(i,s) == a(j,s){
        fmt.Print(i)
        return
      }
    }
  }
}



Measured memory_bytes: 512
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; ++i) {
            p[i] = sc.nextInt();
        }

        System.out.println(solve(p));

        sc.close();
    }

    static int solve(int[] p) {
        return (int) IntStream.range(1, p.length - 1).filter(i -> p[i - 1] < p[i] == p[i] < p[i + 1]).count();
    }
}

Measured memory_bytes: 36020
n = int(input())
d = [[0] for i in range(n)]
for i in range(n):
    d1, d2 = map(int, input().split())
    d[i].append(d1)
    d[i].append(d2)

seq = 0
ans = 0
for pair in d:
    if pair[1] == pair[2]:
        seq += 1
    else:
        seq = 0
    ans = max(ans, seq)
if ans >= 3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9188
// Template Headers {{{
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<long long>; using vvll = vector<vll>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}
// Preprocessing & "Global" variables {{{
struct Solver {
	Solver() {}
	int solve();
};
// }}}

int Solver::solve() {
	int n, k; cin >> n >> k;
	vi wtf(n + 1);
	vi a(n); cin >> a;
	for (int x : a) wtf[x]++;
	sort(wtf.rbegin(), wtf.rend());
	int cnt = 0;
	for (int i = 0; i < k; i++) cnt += wtf[i];
	cout << n - cnt << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	Solver solver;
	#ifdef JUDGE_MULTI_CASE
		int t; cin >> t; for (int i = 1; i <= t; i++)
	#endif
	solver.solve();
	// cout << "Case #" << i << ": ", solver.solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 4732
def main():
    N, K = map(int, input().split())
    S = list(input())
    base = S[0]
    flag = False
    for i in range(0, N):
        if K == 0:
            break
        if S[i] != base and (not flag):
            flag = True
            S[i] = base
        elif S[i] != base and flag:
            S[i] = base
        elif S[i] == base and flag:
            flag = False
            K -= 1
        else:
            pass
    
    ans = 0
    for i in range(N-1):
        ans += S[i] == S[i+1]
    
    print(ans)
  
if __name__ == "__main__":
    main()


Measured memory_bytes: 10024
n = gets.to_i
as = gets.split(/ /).collect{|x| x.to_i}

min1 = 0
sum = 0
n.times{|i|
	sum += as[i]
	if i % 2 == 0
		if sum >= 0
			min1 += 1 + sum
			sum = -1
		end
	else
		if sum <= 0
			min1 += 1 - sum
			sum = 1
		end
	end
}

min2 = 0
sum = 0
n.times{|i|
	sum += as[i]
	if i % 2 == 1
		if sum >= 0
			min2 += 1 + sum
			sum = -1
		end
	else
		if sum <= 0
			min2 += 1 - sum
			sum = 1
		end
	end
}

puts [min1, min2].min


Measured memory_bytes: 9868
#include <iostream>

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

bool is_productday(int m, int d) {
    if (d < 10) return false;
    int d1 = d % 10, d10 = d / 10;
    if (d1 < 2 || d10 < 2) return false;
    return d1 * d10 == m;
}

int main() {
    int m, d;
    int ans = 0;
    std::cin >> m >> d;
    rep(i, 1, m+1) {
        rep(j, 1, d+1) {
            if (is_productday(i, j)) ++ans;
        }
    }

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

    return 0;
}



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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin >>n;

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout<<ans<<endl;
    if(n/10 == 9 || n%10==9)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256