akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

vector<int> a[nax], node[2];

int n , ct[3], c[3], col[nax];
int  ptr1 = -2, ptr2 = -1, ptr3  = 0;

void dfs (int nod,  int pa, int lv) {
    ct[lv % 2] ++;
    node[lv % 2].emplace_back(nod);
    for (int i : a[nod])
        if (i != pa)
            dfs(i, nod, lv + 1);
}


int main () {
    scanf("%d", &n);
    for (int i = 1 ; i < n ; ++ i) {
        int u, v;
        scanf("%d %d", &u, &v);
        a[u].emplace_back(v);
        a[v].emplace_back(u);
    }

    c[0] = n / 3 ;
    c[1] = n / 3 + (n % 3 > 0);
    c[2] = n / 3 + (n % 3 > 1);
    dfs(1, 0, 0);
    if (max(ct[0], ct[1]) >= c[1] + c[2]) {
        int toCol = ct[0] >= ct[1] ? 0 : 1;
        for (int i = 0 ;i < c[1] ; ++ i)
            col[node[toCol][i]] = (ptr1 += 3);

        for (int i = 0 ; i < c[2] ; ++ i)
            col[node[toCol][i + c[1]]] = (ptr2 += 3);
    }
    else if (max(ct[0], ct[1]) >= c[1] && min(ct[0], ct[1]) >= c[2]) {
        int maxCol = ct[0] >= ct[1] ? 0 : 1;
        int minCol = (maxCol ^ 1);
        for (int i = 0 ; i < c[1] ; ++ i)
            col[node[maxCol][i]] = (ptr1 += 3);

        for (int i = 0 ; i < c[2] ; ++ i)
            col[node[minCol][i]] = (ptr2 += 3);
    }

    for (int i = 1 ; i <= n ; ++ i)
        printf("%d ", col[i] ? col[i] : ptr3 += 3);


}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 23796
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,D; cin >> N >> D;
    ll V = 2*D+1;
    res = (N+V-1)/(V);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

int n;

int calc(vector<int> a){
    int ans = 0;
    for(int i=1;i<n-1;i++){
        if(a[i-1] < a[i] && a[i] < a[i+1]){
            ans++;
            if(i+1 == n-1) break;
            if(a[i+1] < a[i+2]){
                swap(a[i],a[i+1]);
            }
            else if(a[i] < a[i+2]){
                swap(a[i],a[i+1]);
            }
            else swap(a[i+1],a[i+2]);
        }
        if(a[i-1] > a[i] && a[i] > a[i+1]){
            ans++;
            if(i+1 == n-1) break;
            if(a[i+1] >a[i+2]) {
                swap(a[i],a[i+1]);
            }
            else if(a[i] > a[i+2]){
                swap(a[i],a[i+1]);
            }
            else swap(a[i+1],a[i+2]);
        }
    }
    return ans;
}

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

    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i] = a[i];
    }
    int ans = 0;
    ans = calc(a);
    swap(b[0],b[1]);
    ans = min(ans,1+calc(b));

    cout << ans << endl;
    
}


Measured memory_bytes: 4184
s = input()
check=1
flag=0
for i in s:
    #print(i)
    if check ==1:
        if i == "R" or i == "U" or i=="D":
            check=0
            continue
        else:
            flag=1
    else:
        if i == "L" or i == "U" or i=="D":
            check=1
            continue
        else:
            flag=1

if flag == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
using pll = pair<ll,ll>;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr int MOD = 1000000007;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int a = -1,b = -1;
    bool ok = false;
    for(int i=1;i<=2;i++){
        rep(j,n-i){
            if(s[j] == s[j+i]){
                a = j+1;b = j+i+1;
                ok = true;
                break;
            }
        }
        if(ok) break;
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m, k;
    cin >> m >> k;
	int two = (1<<m);
    if(k >= two){
        cout << -1 << endl;
        return 0;
    }
    if(m == 0){
        cout << "0 0" << endl;
		return 0;
    }
    if(m == 1){
        if(k == 0) cout << "0 0 1 1" << endl;
        else cout << -1 << endl;
		return 0;
    }
    vector<int> ans;
	ans.push_back(k);
	rep(i,two){
		if(i == k) continue;
		ans.push_back(i);
	}
	ans.push_back(k);
	for(int i = two-1; i >= 0; --i){
		if(i == k) continue;
		ans.push_back(i);
	}
	rep(i,ans.size()){
		cout << ans[i];
		if(i < ans.size()-1) cout << " ";
	}
	cout << endl;
    return 0;
}


Measured memory_bytes: 4232
a,b,c,d,e = input().split()

a = int (a)

b = int (b)

c = int (c)

d = int (d)

e = int (e)

if a == 0:
  print (1)
  
elif b == 0:
  print (2)
  
elif c == 0:
  print (3)
  
elif d == 0:
  print (4)
  
elif e == 0:
  print (5)
  


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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  vector<ll> sum_a(n + 1, 0), sum_b(m + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum_a[i + 1] += sum_a[i] + a[i];
    // cout << sum_a[i + 1] << '\n';
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    sum_b[i + 1] += sum_b[i] + b[i];
    // cout << sum_b[i + 1] << '\n';
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (sum_a[i] > k) break;
    int cnt = 0;
    for (int j = m; j >= 0; j--) {
      // cout << i << ' ' << j << '\n';
      // cout << sum_a[i] + sum_b[j] << '\n';
      if (sum_a[i] + sum_b[j] > k) continue;
      m = j;
      cnt = i + j;
      break;
    }
    ans = max(ans, cnt);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 9536
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef unsigned long long ull;
typedef pair<int,ull> P;
typedef pair<int,int>Pii;
#define F first
#define S second
 
 
int dep=0;;
int X[]={0,3,2,1,0,3,2,1,0,3,2,1,0,3,2,1};
int Y[]={0,3,3,3,3,2,2,2,2,1,1,1,1,0,0,0};
int dy[]={1,0,-1,0};
int dx[]={0,-1,0,1};
ull mask[4][4],bit[4][4];

const int MAX = 5000;
ull G=1311768467463790320 , x , s , M=-1;

Pii pos(ull A){
    r(y,4)r(x,4){
        if(!((A>>bit[y][x])&15)){
            return Pii(y,x);
        }
    }

}

int cost(ull A){
	int sum=0;
	r(y,4){
        r(x,4){
            int k=((A>>bit[y][x])&15);
            if(!k)continue;
    		sum += abs(X[k]-x) + abs(Y[k]-y);
        }
	}
	return sum;
}

signed main(){

    ull init = 0;
    unordered_set<ull>st;

    for(int i=3;i>=0;i--){
        for(int j=3;j>=0;j--){
            ull x;
            cin>>x;
            init|=(x<<((i*4+j)*4));
            mask[i][j] = (ull)15<<((i*4+j)*4);
            bit[i][j] = (i*4+j)*4;
        }
    }


    priority_queue<P> Q[2];
    Q[0].push(P(cost(init),init));
    st.insert(init);
 
    while( !Q[dep%2].empty() ){
        while( !Q[dep%2].empty() ){
            P A=Q[dep%2].top(); Q[dep%2].pop();

            if(A.S==G){
                cout<<dep<<endl;
                return 0;
            }

            Pii p=pos(A.S);
            int x=p.S, y=p.F;
            ull a = (A.S>>bit[y][x])&15;

            r(i,4){
            	int ny=p.F+dy[i];
            	int nx=p.S+dx[i];
            	if( ny<0 || nx<0 || 4<=ny || 4<=nx ) continue;

                ull b = ( A.S>>bit[ny][nx] )&15;
                ull c = ( A.S & ( M - mask[y][x] - mask[ny][nx] ) );
                ull nex = (c | ( b<<bit[y][x] ) | ( a<<bit[ny][nx] ) );

                if(st.count(nex)) continue;
                st.insert(nex);
                Q[(dep+1)%2].push(P(cost(nex),nex));
                if(Q[(dep+1)%2].size()>=MAX) Q[(dep+1)%2].pop();

            }
        }
        if(dep>=49)break;
        dep++;
    }
    
}



Measured memory_bytes: 17648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll MAX=2001;
ll MOD=1000000007;
vector<ll> F(MAX,1);
 
void fact(){
    for(ll i=1;i<MAX;i++){
    F[i]=F[i-1]*i%MOD;
    }
return;
}


// mod. m での a の逆元 a^{-1} を計算する
//ただしmとaが互いにその時のみ
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long comb(long long a, long long b){
    return (((F[a]*modinv(F[b],MOD))%MOD)*modinv(F[a-b],MOD))%MOD;
}



int main(){
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    fact();
    for(ll i=1;i<=K;i++){
        if(N-K<i-1)cout<<0<<endl;
        else{
            cout<<(comb(K-1,i-1)*comb(N-K+1,i))%MOD<<endl;
        }
    ;}

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    if(n%2==0) cout << n/2 << endl;
    else cout << (n+1)/2 << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long x = sc.nextLong();
		long[] a = new long[N];
		for(int i = 0 ; i < N; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		int ans = 0;
		int sum = 0;
		long tmp = x;
		for(int i = 0 ; i < N; i++) {
			if(tmp >= a[i]) {
				tmp = tmp - a[i];
				ans++;
				sum += a[i];
			} else {
				break;
			}
		}
		if(ans == N && x > sum) {
			ans--;
		}
		System.out.println(ans);
	}
}

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

namespace ConsoleApp28 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int n = st[0];
            int m = st[1];

            Console.WriteLine((n - 1) * (m - 1));
           
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    int a;
    int last = 0;
    int ans = 0;
    int kol = 1;
    char s;
    for(int i = 0; i<n; ++i){
        cin >> s;
        if(s=='R')a=1;
        else a=0;
        if(i==0){
            last = a;
        }else{
            if(a!=last)kol++;
            else ans++;
            last = a;
        }
    }
    if(n>1 && k<n-1){
        if(kol>=2){
            if(k>=kol/2)cout<<n-1;
            else{
                ans+= 2*k;
                cout << ans ;
            }
        }else{
            cout << n-1;
        }
    }else{
        if(n == 1)cout << 0;
        else cout << n-1;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	A
# CreatedDate:  2020-07-25 20:59:58 +0900
# LastModified: 2020-07-25 21:02:51 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    x = int(input())
    if 400 <= x and x < 600:
        print(8)
    elif 600 <= x and x < 800:
        print(7)
    elif 800 <= x and x < 1000:
        print(6)
    elif 1000 <= x and x < 1200:
        print(5)
    elif 1200 <= x and x < 1400:
        print(4)
    elif 1400 <= x and x < 1600:
        print(3)
    elif 1600 <= x and x < 1800:
        print(2)
    else:
        print(1)



if __name__ == "__main__":
    main()


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

int main(){
	int a,b,k;
	cin >> a >> b >> k;
	vector<int> ans;
	REP(i, min(a,b)){
		if(a % i == 0 && b % i == 0) ans.push_back(i);
	}
	sort(ans.rbegin(),ans.rend());
	cout << ans[k-1] << endl;
    return 0;
}



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

int main() {
  int N; cin >> N;
  int H[N];
  for(int i = 0; i < N; i++) cin >> H[i];
  int counter = 0;
  int maxH = H[0];
  for(int i = 1; i < N; i++) {
    if(maxH <= H[i]) {
      counter++;
      maxH = H[i];
    }
  }
  cout << counter + 1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int MAX = 500000;
const int maxnum = 1000000010;

// 两个局部数组
int L[MAX / 2 + 2], R[MAX / 2 + 2];
int A[MAX], n;
int cnt = 0;

// 排序和合并
void merge(int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];

    // 两个局部数组最后添加一个比较大的数
    L[n1] = R[n2] = maxnum;
    int i = 0, j = 0;
    // 合并
    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j])
            A[k] = L[i++];
        else
            A[k] = R[j++];
    }
}
// 分割
void mergeSort(int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
}
int main() {

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);

    mergeSort(0, n);
    for (int i = 0; i < n; i++)
        printf("%d%c", A[i], i == n - 1 ? '\n' : ' ');
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 6976
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        int[] cards = new int[n];
        for (int i = 0; i < n; i++) {
            cards[i] = sc.nextInt();
        }
        Arrays.sort(cards);
        
        int[][] ab = new int[m][2];
        for (int i = 0; i < m; i++) {
            int k = sc.nextInt();
            int v = sc.nextInt();
            ab[i][0] = v;
            ab[i][1] = k;
        }        
        Arrays.sort(ab, (x, y) -> Integer.compare(x[0], y[0]));
        
        int idx = 0;
        for (int i = m - 1; i >= 0; i--) {
            boolean end = false;
            int k = ab[i][1];
            int v = ab[i][0];
            
            while (k-- > 0) {
                if (cards[idx] >= v) {
                    end = true;
                    break;
                }
                cards[idx] = v;
                idx++;
                if (idx == n) {
                    end = true;
                    break;
                }
            }
            if (end) break;
        }
        
        long answer = 0;
        for (int val : cards) {
            answer += val;
        }
        
        System.out.println(answer);
    }
}

Measured memory_bytes: 94680
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

const INF: i64 = 1 << 60;

struct Ans {
    S: Vec<char>,
    ans: usize,
}

impl Ans {
    fn dfs(&mut self, i: usize, num: usize, res: usize) {
        let d = self.S[i] as usize - '0' as usize;
        if i == self.S.len() - 1 {
            self.ans += res + num * 10 + d;
            return;
        }
        self.dfs(i+1, num * 10 + d, res);
        self.dfs(i+1, 0, res + num * 10 + d);
    }
    fn solve(&mut self) {
        self.dfs(0, 0, 0);
    }
}

fn main() {
    input!{
        S: chars,
    }
    let mut ans = Ans { S: S, ans: 0 };
    ans.solve();
    println!("{}", ans.ans);
}

Measured memory_bytes: 4352
n = int(input())
b = list(map(int, input().split()))

ans = []
while len(b) > 0:
    flag = False
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            ans.append(b[i])
            b.pop(i)
            flag = True
            break
    if not flag:
        print(-1)
        exit()

for i in range(len(ans)):
    print(ans[-i-1])

Measured memory_bytes: 3064
import itertools
n,m = map(int, input().split())

switch = [[] for i in range(n)]
for i in range(m):
    line = list(map(int, input().split()))
    del line[0]
    for l in line:
        switch[l - 1].append(i)
p = list(map(int, input().split()))

def make_select(m):
    select = []
    i = 0
    def make_bool(m, i):

        if i > m:
            return 0

        for a in itertools.combinations(range(m), i):
            bool = [False] * m
            for b in a:
                bool[b] = True
            select.append(bool)
        
        i += 1
    
        make_bool(m, i)
    
    make_bool(m, i)
    return select
    
select = make_select(n)

ans = 0
for c in select:
    light = [0] * m
    for i in range(n):
        if c[i]:
            for s in switch[i]:
                light[s] ^= 1
    
    if light == p:
        ans += 1

print(ans)


Measured memory_bytes: 42096
S=input()

ans = []
for i in range(len(S)):
    for j in range(len(S[i:])):
        if all([S[i:i+j+1][k] in ['A','C','G','T'] for k in range(len(S[i:i+j+1]))]):
            ans.append(S[i:i+j+1])
if len(ans) != 0:
    print(max(list(map(len,ans))))
else:
    print(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,-1,sizeof(i));
#define pb push_back
const ll mod=998244353;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	while(cin >> n){
		map<pair<int,int> ,int>mp;
		vector<pair<int,int> >v;
		f(n){
			int a,b;
			cin >> a >> b;
			v.pb({a,b});
		}
		sort(v.begin(),v.end());
		int mx = 0;
		f(n){
			fr(j,i+1,n){
				int x=v[j].first-v[i].first;
				int y=v[j].second-v[i].second;
				mp[{x,y}]++;
				mx=max(mx,mp[{x,y}]);
			}
		}
		cout<<n-mx<<endl;
	}
}

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

using namespace std;
typedef unsigned long long ull;

int N, M, Q;
int A[20];
int a[50];
int b[50];
int c[50];
int d[50];

typedef unsigned long long ull;
ull dfs(int i, int m){
    if(i == N){
        ull result = 0; 
        for(int p = 0; p < Q; p++){
            if(A[b[p]-1] - A[a[p]-1] == c[p]){
                result += d[p];
            }
        }
        return result;
    }
    ull result = 0;
    for(int l = m; l <= M; l++){
        A[i] = l;
        result = max(result, dfs(i+1, l));
    }
    return result;
}

int main() {
    cin >> N >> M >> Q;
    for(int i = 0;i < Q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    cout << dfs(0, 1) << endl;
    return 0;
}


Measured memory_bytes: 3636
a=[]
for _ in range(3):
    a.append(list(map(int,input().split())))
b=int(input())
c=[]
for _ in range(b):
    c.append(int(input()))

if (a[0][0] in c and a[0][1] in c and a[0][2] in c) or (a[1][0] in c and a[1][1] in c and a[1][2] in c) or (a[2][0] in c and a[2][1] in c and a[2][2] in c) or (a[0][0] in c and a[1][0] in c and a[2][0] in c) or (a[0][1] in c and a[1][1] in c and a[2][1] in c) or (a[0][2] in c and a[1][2] in c and a[2][2] in c) or (a[0][0] in c and a[1][1] in c and a[2][2] in c) or (a[0][2] in c and a[1][1] in c and a[2][0] in c):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9276
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

string upper(string s)
{
    for (int i = 0; i < s.size(); i++)
        s[i] = toupper(s[i]);
    return s;
}

int main()
{
    string T, W;
    int cnt = 0;

    cin >> W;
    W = upper(W);
    while (1) {
        cin >> T;

        if (T == "END_OF_TEXT")
            break;
        T = upper(T);
        if (W == T)
            cnt++;
    }
    cout << cnt << endl;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

int main ()
{
    int N , i ;
    cin >> N >> i ;

    cout << N - i + 1 ;

    return 0 ;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

template <class... Args>
struct tuple_input_impl;
template <std::size_t i, std::size_t... tail>
struct tuple_input_impl<std::index_sequence<i, tail...>>
{
    template <class... Args>
    static void f(std::tuple<Args...>& x)
    {
        std::cin >> std::get<i>(x);
        tuple_input_impl<std::index_sequence<tail...>>::f(x);
    }
};
template <>
struct tuple_input_impl<std::index_sequence<>>
{
    static void f(...) {}
};

template <class... Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& x)
{
    tuple_input_impl<std::index_sequence_for<Args...>>::f(x);
    return in;
}

template <class T>
T read()
{
    T res;
    std::cin >> res;
    return res;
}
template <class T>
std::vector<T> read(std::size_t n)
{
    std::vector<T> res(n);
    for (std::size_t i = 0; i < n; ++i) std::cin >> res[i];
    return res;
}

template <class T, class... Args>
void out_impl(T&& v, Args&&... args)
{
    std::cout << std::forward<T>(v) << ' ';
    impl(std::forward<Args>(args)...);
}
template <class T>
void out_impl(T&& v) { std::cout << std::forward<T>(v); }
template <class... Args>
void out(Args&&... args)
{
    out_impl(std::forward<Args>(args)...);
    std::cout << '\n';
}
template <class... Args>
void out_noreturn(Args&&... args) { out_impl(std::forward<Args>(args)...); }

template <class T>
void print(const T& container)
{
    bool first = true;
    for (auto&& x : container) {
        if (!first) std::cout << ' ';
        std::cout << x;
        first = false;
    }
    std::cout << '\n';
}

void prog()
{
    std::uint64_t n, m;
    std::cin >> n >> m;
    auto d = read<std::tuple<std::uint64_t, std::uint64_t>>(n);
    std::sort(std::begin(d), std::end(d));
    std::uint64_t res = 0;
    for (auto i : boost::irange(0ul, n)) {
        auto b = std::min(m, std::get<1>(d[i]));
        res += b * std::get<0>(d[i]);
        m -= b;
        if (m == 0) break;
    }
    out(res);
}

int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    prog();
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
using namespace std; int n;
double SIN(double p) { return sin(p*acos(-1) / 180); }
int main() {
	while (cin >> n, n) {
		if (n % 3 == 0)n /= 3;
		double D = sqrt(3)*(SIN(60.0 + 60.0 / n) / (SIN(60.0 + 60.0 / n) + SIN(60.0 / n))) - sqrt(0.75);
		printf("%.99lf\n", sqrt(0.25 + D*D)*SIN(60.0 / n)*n);
	}
	return 0;
}

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



int main() {
  //
  int N;
  cin >> N;
  map<long long, int> len_frq_map;

  //
  priority_queue<long long> keys;
  long long a;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    if(len_frq_map.find(a) == len_frq_map.end()) {
      len_frq_map[a] = 1;
      keys.push(a);
    }else {
      len_frq_map[a] += 1;
    }
  }

  //
  long long a1 = 0, a2 = 0;
  while(!keys.empty()){
    long long len = keys.top(); keys.pop();
    int frq = len_frq_map[len];
//    cout << len << " " << frq << endl;

    if(frq > 3){
      if(a1 == 0){
        cout << len * len << endl;
        return 0;
      }else{
        cout << len * a1 << endl;
        return 0;
      }
    }else if(frq > 1){
      if(a1 == 0) {
        a1 = len;
        continue;
      }else{
        a2 = len;
        cout << a1 * a2 << endl;
        return 0;
      }
    }
  }

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



Measured memory_bytes: 7284
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

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

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//













int H, W;
vector<string> a;

int dp[1100][1100] = {0};

void add(int &a, int b){
        a += b;
        if(a >= mod) a -= mod;
}

int main(){
        cin >> H >> W;
        a.resize(H);
        for(int i = 0; i < H; i++) cin >> a[i];

        dp[0][0] = 1;

        for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                        if(i+1 < H && a[i+1][j] == '.') add(dp[i+1][j], dp[i][j]);
                        if(j+1 < W && a[i][j+1] == '.') add(dp[i][j+1], dp[i][j]);
                }
        }

        cout << dp[H-1][W-1] << endl;
        return 0;
}








































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

int main(){
	std::vector<int> number;
	int inputNum,tmp;

	std::cin >> inputNum;

	//input
	for(int i = 0; i < inputNum; ++i){
		std::cin >> tmp;
		number.push_back(tmp);
	}

	std::vector<std::vector<long int>> vec(inputNum + 1, std::vector<long int>(21, 0));

	vec[0][number[0]] = 1;

	for(int i = 0; i < inputNum; ++i){
		for(int j = 0; j < 21; j++){
			if(vec[i][j] != 0){

				//addition
				if(j + number[i + 1] <= 20) vec[i+1][j + number[i + 1]] += vec[i][j];

				//subtraction
				if(j - number[i + 1] >= 0) vec[i+1][j - number[i + 1]] += vec[i][j];
			}
		}
	}
	//output
	std::cout << vec[inputNum - 2][number[inputNum - 1]] << std::endl;

	return 0;
}

Measured memory_bytes: 1240
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] DR = { 1, 0, -1, 0 };
	static int[] DC = { 0, 1, 0, -1 };
	static int W, H;
	static int[][] f;
	static int gr, gc;

	public static void main(String[] args) {
		W = sc.nextInt();
		H = sc.nextInt();
		f = new int[H][W];
		for (int i = 0; i < H; ++i) {
			char[] line = sc.next().toCharArray();
			for (int j = 0; j < W; ++j) {
				char c = line[j];
				if (c == '#') {
					f[i][j] = 9999;
				} else if (c == 't') {
					gr = i;
					gc = j;
				}
			}
		}
		int N = sc.nextInt();
		for (int i = 0; i < N; ++i) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			f[y][x] = i + 1;
		}
		if (!solve(N)) {
			System.out.println(-1);
			return;
		}
		int hi = N;
		int lo = -1;
		while (hi - lo > 1) {
			int mid = (hi + lo) / 2;
			if (solve(mid)) {
				hi = mid;
			} else {
				lo = mid;
			}
		}
		System.out.println(hi);
	}

	static boolean solve(int t) {
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.add(0);
		boolean[][] visited = new boolean[H][W];
		while (!q.isEmpty()) {
			int pos = q.poll();
			int r = pos >> 10;
			int c = pos & 0x3FF;
			for (int i = 0; i < 4; ++i) {
				int nr = r + DR[i];
				int nc = c + DC[i];
				if (nr < 0 || H <= nr || nc < 0 || W <= nc || visited[nr][nc] || f[nr][nc] > t) continue;
				if (nr == gr && nc == gc) return true;
				q.add((nr << 10) + nc);
				visited[nr][nc] = true;
			}
		}
		return false;
	}

}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

bool is_palindrome(const string& s, int a, int b)
{
    for (int i = 0; i < b - a + 1; ++i)
        if (s[a + i] != s[b - i])
            return false;

    return true;
}

int main()
{
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    int N = S.size();
    S = "*" + S;

    cout << (is_palindrome(S, 1, N) and is_palindrome(S, 1, (N - 1)/2) 
        and is_palindrome(S, (N + 3)/2, N) ? "Yes" : "No") << '\n';

    return 0;
}


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

using namespace std;

typedef long long int ll;

int main(){
    ll n, k;
    cin>>n>>k;
    ll h[n];
    for(int i=0;i< n;i++){
        cin>>h[i];
    }
    sort(h, h+n,greater<int>());
    ll rem=0;
    for(int i =k;i<n;i++){
        rem += h[i];
    }
    cout<<rem<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>

using namespace std;

static const int MAX = 1050000;
string T[MAX];

// ハッシュ Directory
// オープンアドレス法は、ハッシュが衝突したらハッシュを再計算。

int h(int key)
{
    return key % MAX;
}
int g(int key)
{
    return 1 + (key % (MAX - 1));
}

int hash(int key, int i)
{
    return (h(key) + i * g(key)) % MAX;
}

int getChar(char ch)
{
    if ( ch == 'A') return 1;
    else if ( ch == 'C') return 2;
    else if ( ch == 'G') return 3;
    else if ( ch == 'T') return 4;
    return 0;
}

long long getKey(const char str[])
{
    long long sum = 0, p = 1, i;
    for ( i = 0; i < strlen(str); i++ )
    {
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}
int getKey_(string value)
{
    int sum = 0;
    int p = 1;
    for (string::size_type i = 0; i < value.size(); i++)
    {
        sum += p * (getChar(value[i]));
        p *= 5;
    }
    return sum;
}

bool search(string value)
{
    //int key = getKey(value.c_str());
    int key = getKey_(value);

    for (int i = 0; ; i++)
    {
        int j = hash(key, i);
        if (T[j].compare(value) == 0) return true;
        else if (T[j].empty())
        {
            return false;
        }
    }
    return false;
}

int insert(string value)
{
    //int key = getKey(value.c_str());
    int key = getKey_(value);

    for (int i = 0; ; i++)
    {
        int j = hash(key, i);
        if (value.compare(T[j]) == 0)
        {
            // データが一致したら挿入しない。
            return 1;
        }
        else if (T[j].empty())
        {

            T[j] = value;
            return 0;
        }
    }
    return 0;
}

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string cmd, str;
        cin >> cmd >> str;
        if (cmd.find("insert") == string::npos)
        {
            string msg = search(str) ? "yes" : "no";
            cout << msg << endl;
        }
        else
        {
            insert(str);
        }
    }

    return 0;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(fabs(c-a) <= d)
    cout << "Yes" << endl;
  else if (fabs(b-a) <= d && fabs(c-b) <= d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define lli long long
typedef long double ldb;
#define deci(n) fixed << setprecision(n)
 
lli M=1e9+7;
lli MOD=1e9+7;
 
#define MAXN 2000006 
 
// Template function //
lli powermod(lli x, lli y)  
{  
    lli res = 1;  
    x = x % MOD;
    if (x == 0) return 0;  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % MOD;  
        y = y>>1;   
        x = (x*x) % MOD;  
    }  
    return res;  
}
lli modinv(lli x)
{
    return powermod(x,MOD-2);
}
// Template functions end //
 
// Custom funtions //
lli findset(lli p[], lli x){
	if(x!=p[x]){
		p[x]=findset(p,p[x]);
	}
	return p[x];
}
 
void unionset(lli p[],lli r[],lli a,lli b){
	lli x=findset(p,a);
	lli y=findset(p,b);
	if(x!=y){
		if(r[x]<r[y]) swap(x,y);
		p[y]=x;
		if(r[x]==r[y]){
			r[x]++;
		}
	}
}

void dfs(vector<lli> v[], lli s[], lli x)
{
    lli S=1;
    for(lli i=0;i<v[x].size();i++)
    {
        dfs(v,s,v[x][i]);
        S+=s[v[x][i]];
    }
    s[x]=S;
}

lli f[100005];



void preprocess()
{
    f[0]=1;
    for(lli i=1;i<100005;i++)
    {
        f[i] = (f[i-1]*i)%MOD;
        if(i%2==0)
        f[i]/=2;
    }
}

lli tree[MAXN];


void buildTree(vector<lli> a, lli n)
{
    for(lli i=0;i<n;i++)
        tree[n+i] = a[i];
    for(lli i=n-1;i>0;i--)
    {
        tree[i] = tree[i<<1] + tree[i<<1|1];
    }
}

void updateTree(lli n, lli p, lli value)
{
    tree[p+n] = value;
    p+=n;
    for(lli i=p; i>1;i >>= 1)
        tree[i>>1] = tree[i] + tree[i^1];
}

lli queryTree(lli n, lli l, lli r)
{
    lli res = 0;
    for(l+=n,r+=n;l<r;l>>=1, r>>=1)
    {
        if(l&1)
            res += tree[l++];
        if(r&1)
            res += tree[--r];
    }
    return res;
}

bool sortbysec(const pair<pair<lli,lli>,lli> &a, 
              const pair<pair<lli,lli>,lli> &b) 
{ 
    if(a.first.second == b.first.second)
    return a.first.first>b.first.first;
    return (a.first.second < b.first.second); 
} 

void dfs(int x, int vi[], vector<int> v[], int k)
{
    vi[x] = k;
    for(int i=0;i<v[x].size();i++) 
    {
        if(vi[v[x][i]]==0)
        {
            dfs(v[x][i],vi,v,k);
        }
    }
}

void solve()
{ 
    int n,m;
    cin>>n>>m;
    int x,y;
    vector<int> v[n];
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        x--; y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int vi[n] = {0};
    int k = 1;
    for(int i=0;i<n;i++)
    {
        if(vi[i]==0)
        {
            dfs(i,vi,v,k);
            k++;
        }
    }
    int ans = 0;
    int c[k] = {0};
    for(int i=0;i<n;i++)
    {
        c[vi[i]]++;
        // cout<<vi[i]<<' ';
        ans = max(ans,c[vi[i]]);
    }
    cout<<ans<<endl;

}
// Custom functions end //
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli q=1;
    //cin>>q;
    for(lli tc=1;tc<=q;tc++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 24704
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	int k,a,b;
	cin>>k>>a>>b;
	if(b/k*k<a)cout<<"NG"<<endl;
	else cout<<"OK"<<endl;
	return 0;
}

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

class Sai {
    vector<int> m_s;
public:
    Sai(vector<int> s) {
        m_s = vector<int>(6);
        rep(i, 6) {
            m_s.at(i) = s.at(i);
        }
    }
    void move(char ch) {
        switch(ch) {
        case 'E':
            swap(m_s.at(0), m_s.at(3));
            swap(m_s.at(2), m_s.at(3));
            swap(m_s.at(3), m_s.at(5));
            break;
        case 'N':
            swap(m_s.at(0), m_s.at(1));
            swap(m_s.at(4), m_s.at(1));
            swap(m_s.at(5), m_s.at(1));
            break;
        case 'S':
            swap(m_s.at(0), m_s.at(4));
            swap(m_s.at(1), m_s.at(4));
            swap(m_s.at(5), m_s.at(4));
            break;
        case 'W':
            swap(m_s.at(0), m_s.at(2));
            swap(m_s.at(3), m_s.at(2));
            swap(m_s.at(5), m_s.at(2));
            break;
        default:
            assert(false);
        }
    }
    int top(void) {
        return m_s.at(0);
    }
    int right(void) {
        return m_s.at(2);
    }
    void get_all(vector<int> &vec) {
        for (int i = 0; i < 6;i++ ) {
            vec.push_back(m_s.at(i));
        }
    }
    bool equal(vector<int> vec) {
        for (int i = 0; i < 6; i++) {
            if (m_s.at(i) != vec.at(i)) return false;
        }
        return true;
    }
    bool set_top_and_before(int top, int before) {
        for (int h=0; h < 4; h++) {
        for (int i=0; i < 4; i++) {
            move('S');
            //cout << "before:" << m_s.at(1) << endl;
            if (m_s.at(1) != before) continue;
            for (int j = 0; j < 4; j++) {
                move('E');
                //cout << "top:" << m_s.at(0) << endl;
                if (m_s.at(0) == top) return true;
            }
        }
        move('E');
        }
        return false;
    }
    bool equals(Sai sai2) {
        for (int i=1; i < 6;i++) {
            bool flg = sai2.set_top_and_before(m_s.at(i-1), m_s.at(i));
            if (flg == false) continue;

            vector<int> tmp;
            sai2.get_all(tmp);
            flg = equal(tmp);
            if (flg == true) {
                //puts("Yes");
                return true;
            }
        }
        return false;
    }
};

int main() {
    vector<int> n1(6);
    rep(i, 6) cin >> n1.at(i);
    Sai sai1(n1);

    vector<int> n2(6);
    rep(i, 6) cin >> n2.at(i);
    Sai sai2(n2);
    bool flg = sai1.equals(sai2);
    cout << (flg ? "Yes" : "No") << endl;
#if 0
    for (int i=1; i < 6;i++) {
        bool flg = sai2.set_top_and_before(n1.at(i-1), n1.at(i));
        if (flg == false) continue;

        vector<int> tmp;
        sai2.get_all(tmp);
        flg = sai1.equal(tmp);
        if (flg == true) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
#endif
}



Measured memory_bytes: 3164
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    string s;
    cin >> s;
    int ans = 1e9;
    forn(d, 26) {
        int res = 0;
        int px = -1;
        forn(i, s.size()) {
            if (s[i] == 'a' + d) {
                uax(res, i - px - 1);
                px = i;
            }
        }
        uax(res, (int)s.size() - px - 1);
        uin(ans, res);
    }
    cout << ans << '\n';

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


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

# N=O(10^5)なので、O(N)で解く
# ABC-155-C-Poll の類題

# 各数字の出現回数を数える
dic = {}
for i in range(N):
  a = A[i]
  if a not in dic: dic[a] = 1
  else: dic[a] += 1

# dicを昇順にソート
dic = sorted(dic.items(), key=lambda x:x[1])

# dicは [(5, 1), (3, 2), (2, 2), (4, 2), (1, 3)] のようになっている
# dicのvalueにおいて、前からlen(dic)-K個の和を取る
ans = 0
for i in range(max(len(dic)-K, 0)):
  ans += dic[i][1]
  
print(ans)

Measured memory_bytes: 42820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, cnt = 0;
    string x;
    cin >> n >> x;
    rep(i, n) if(x[i] == '1') cnt++;
    int plus = cnt + 1, minus = cnt - 1;

    int rui_plus[202020] = {0}, rui_minus[202020] = {0};

    int bp = 1, bm = 1, p = 0, m = 0;

    if (minus == 0) {
        rep(j, n){
            int i = n - j - 1;

            if (x[i] == '1') {
                p = (p + bp) % plus;
            }

            rui_plus[i] = bp;
            bp = (bp * 2) % plus;
        }
    } else {
        rep(j, n){
            int i = n - j - 1;

            if (x[i] == '1') {
                p = (p + bp) % plus;
                m = (m + bm) % minus;
            }

            rui_plus[i] = bp;
            rui_minus[i] = bm;
            bp = (bp * 2) % plus;
            bm = (bm * 2) % minus;
        }
    }

    rep(i, n) {
        int y;

        if (x[i] == '1') {
            if(minus == 0) {
                cout << 0 << endl;
                continue;
            } else {
                y = m - rui_minus[i];
                y = (y + minus) % minus;
            }
        } else {
            y = p + rui_plus[i];
            y = (y + plus) % plus;
        }

        int pop = 1;
        while(y) {
            y = y % __builtin_popcount(y);
            pop++;
        }
        cout << pop << endl;
    }
}

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

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const ll MOD = 1000000007;

const int N = 1000005;

void set_file_io(string in, string out)
{
    freopen((in+".in").c_str(), "r", stdin);
    freopen((out+".out").c_str(), "w", stdout);
}

int distance(string a, string b)
{
    int res = 0;
    for(int i=0; i<(int)a.size(); i++)
    {
        res += (a[i] != b[i]);
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //set_file_io("input", "output");
    string s, t;
    cin >> s >> t;
    int ans = 1001;
    for(int i=0; i<=(int)s.size()-(int)t.size(); i++)
    {
        ans = min(ans, distance(s.substr(i, (int)t.size()), t));
    }
    cout << ans;
    return 0;
}


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

int main()
{
	int N, A[100001];
	long long int ans = 0,t;

	cin >> N;

	A[0] = 0;
	A[N + 1] = 0;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];

		ans += abs(A[i] - A[i - 1]);
	}
	ans += abs(A[N]);

	for (int i = 1; i <= N; i++) {
		if (abs(A[i + 1] - A[i - 1]) != abs(A[i] - A[i - 1]) + abs(A[i] - A[i + 1])) {
			t = ans;
			t -= -abs(A[i + 1] - A[i - 1])+abs(A[i] - A[i - 1]) + abs(A[i] - A[i + 1]);
			cout << t << endl;
		}
		else cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
int n, a, b, c, d;
string s;
signed main() {
	cin >> n >> a >> b >> c >> d >> s;
	a--; b--; c--; d--;
	for (int i = min(a, b); i <= max(c, d) - 1; i++) {
		if (s[i] == '#' && s[i + 1] == '#') {
			cout << "No" << endl;
			return 0;
		}
	}
	if (c < d) {
		cout << "Yes" << endl;
	}
	else {
		bool can = false;
		for (int i = min(a, b); i <= min(c, d) - 1; i++) {
			if (i + 2 < n && s[i] == s[i + 1] && s[i + 1] == s[i + 2]) {
				if (i + 1 < b) continue;
				can = true;
				break;
			}
		}
		if (can) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 640