akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl;
}

const int Maxn = 1e5 + 100;

int N, Mod;

int e, Begin[Maxn], To[Maxn << 1], Next[Maxn << 1];
int fa[Maxn], f[Maxn], g[Maxn];

inline void add_edge (int x, int y) { To[++e] = y; Next[e] = Begin[x]; Begin[x] = e; }

vector <int> Id[Maxn], Pre[Maxn], Suf[Maxn];

inline void dfs_pre (int x)
{
	f[x] = 1;
	for (int i = Begin[x]; i; i = Next[i])
	{
		int y = To[i]; 
		if (y == fa[x]) continue;
		fa[y] = x, Id[x].pb(y);
		dfs_pre (y);
		f[x] = (LL)f[x] * (f[y] + 1) % Mod;
	}
}

inline void dfs (int x)
{
	if (!Id[x].empty()) Pre[x].pb(f[Id[x][0]] + 1);
	for (int i = 1; i < Id[x].size(); ++i)
		Pre[x].pb((LL)(f[Id[x][i]] + 1) * Pre[x].back() % Mod);

	if (!Id[x].empty()) Suf[x].pb(f[Id[x][(int)Id[x].size() - 1]] + 1);
	for (int i = (int)Id[x].size() - 2; i >= 0; --i)
		Suf[x].pb((LL)(f[Id[x][i]] + 1) * Suf[x].back() % Mod);
	reverse (Suf[x].begin(), Suf[x].end());

	for (int i = 0; i < Id[x].size(); ++i)
	{
		int y = Id[x][i], pre = 1, suf = 1;
		if (i) pre = Pre[x][i - 1];
		if (i != (int)Id[x].size() - 1) suf = Suf[x][i + 1];
		g[y] = ((LL)pre * suf % Mod * g[x] % Mod) + 1;
		dfs (y);
	}
}

inline void Solve ()
{
	dfs_pre(1);
	g[1] = 1;
	dfs(1);

	for (int i = 1; i <= N; ++i) printf("%lld\n", (LL)f[i] * g[i] % Mod);
}

inline void Input ()
{
	N = read<int>(), Mod = read<int>();
	for (int i = 1; i < N; ++i)
	{
		int x = read<int>(), y = read<int>();
		add_edge (x, y);
		add_edge (y, x);
	}
}

int main()
{
#ifdef hk_cnyali
	freopen("V.in", "r", stdin);
	freopen("V.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

int main() {
	int N, K; cin >> N >> K;
	long double ans = 0;
	rep(i, N) {
		if (i + 1 < K) {
			int x = ceil(log2(K / ((double)i + 1)));
			ans += (long double)pow(0.5, x);
			/*cout << x << ":" << endl;
			cout << ans << endl;*/
		}
		else ans += 1;
	}
	cout << fixed << setprecision(15) << ans/N << endl;
}

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

int main(){
    int N, K;
    cin>>N>>K;
    
    vector<int> V(N);
    for(int i=0;i<N;i++) cin>>V[i];
    
    int ans = 1;
    N -= K;
    K--;
    ans += (N + (K-1))/K;
    cout<<ans<<endl;
}

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

/////////////////////////////////////////////////////////////////////////
// UNION FIND
/////////////////////////////////////////////////////////////////////////
class UnionFind {
private:
  int siz;
  vector<int> a;

public:
  UnionFind(int x) : siz(x), a(x, -1) {}

  int root(int x) {
    return a[x] < 0 ? x : a[x] = root(a[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    siz--;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] =x;
    return true;
  }

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

  int size(int x) {
    return -a[root(x)];
  }
  
  int connected_component() {
  	return siz;
  }
};
/////////////////////////////////////////////////////////////////////////
// END UNION FIND
/////////////////////////////////////////////////////////////////////////


signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //d
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) ans = max(ans, uf.size(i));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3988
#include<cstdio>
#include<cstring>
char s[1005], t[1005];

int main(){
    scanf("%s%s",s+1,t+1);
    int n = strlen(s+1), m = strlen(t+1);
    int ans = m;
    for(int i = 1; i <= n; i++){
        if(i+m-1>n) break;
        else{
            int cnt = 0;
            for(int j = 1; j <= m; j++){
                if(s[i+j-1]!=t[j]) cnt++;
            }
            if(ans>cnt) ans = cnt;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1732
#include<stdio.h>
int main(){
  int k,s,i,j,ans=0;
  scanf("%d%d",&k,&s);
  for(i=0;i<=k;i++){
    for(j=0;j<=k;j++){
      if(s-i-j<=k&&s-i-j>=0) ans++;
    }
  }
  printf("%d",ans);
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

int INF = 1e9;
long long int MOD = 1e9 + 7;

int x[110000], y[110000];

int dist(int p1, int p2){
	return abs(x[p1] - x[p2]) + abs(y[p1] - y[p2]);
}

int main(){
	int N;
	cin >> N;
	int n1 = INF, n2 = -INF, n3 = INF, n4 = -INF;
	int p1, p2, p3, p4;
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i];
		int m1 = x[i] + y[i], m2 = x[i] - y[i];
		if(m1 < n1){
			n1 = m1;
			p1 = i;
		}
		if(m1 > n2){
			n2 = m1;
			p2 = i;
		}
		if(m2 < n3){
			n3 = m2;
			p3 = i;
		}
		if(m2 > n4){
			n4 = m2;
			p4 = i;
		}
	}
	int ans = INF;
	int S = dist(p3, p4);
	for(int i = 0; i < N; i++){
		S = max(S, min(dist(i, p1), dist(i, p2)));
	}
	ans = min(S, ans);
	S = dist(p1, p2);
	for(int i = 0; i < N; i++){
		S = max(S, min(dist(i, p3), dist(i, p4)));
	}
	ans = min(S, ans);
	S = max(dist(p1, p3), dist(p2, p4));
	for(int i = 0; i < N; i++){
		S = max(S, min(max(dist(i, p1), dist(i, p3)), max(dist(i, p2), dist(i, p4))));
	}
	ans = min(S, ans);
	S = max(dist(p1, p4), dist(p2, p3));
	for(int i = 0; i < N; i++){
		S = max(S, min(max(dist(i, p1), dist(i, p4)), max(dist(i, p2), dist(i, p3))));
	}
	ans = min(S, ans);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3796
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cctype>
using namespace std;
 
class dice {
public:
    int face[7];
    int get;
 
    dice(int x[]) {
        for (int i = 1; i <= 6; i++)
            face[i] = x[i];
    }
 
    void round(char x) {
            switch (x) {
            case 'E':
                get = face[1];
                face[1] = face[4];
                face[4] = face[6];
                face[6] = face[3];
                face[3] = get;
                break;
            case 'W':
                get = face[1];
                face[1] = face[3];
                face[3] = face[6];
                face[6] = face[4];
                face[4] = get;
                break;
            case 'N':
                get = face[1];
                face[1] = face[2];
                face[2] = face[6];
                face[6] = face[5];
                face[5] = get;
                break;
            case 'S':
                get = face[1];
                face[1] = face[5];
                face[5] = face[6];
                face[6] = face[2];
                face[2] = get;
                break;
            }
    }
};
 
int main() {
    int facef[7], i, ident=0;
    string operate="EEENEEENEEESEEESEEENEEEN";
 
    for (int i = 1; i <= 6; i++) {
        cin >> facef[i];
    }
 
    dice dice1(facef);
 
    for (int i = 1; i <= 6; i++) {
        cin >> facef[i];
    }

    dice dice2(facef);
 
    if(dice1.face[1]==dice2.face[1] && dice1.face[2]==dice2.face[2] && dice1.face[3]==dice2.face[3] && dice1.face[4]==dice2.face[4] && dice1.face[5]==dice2.face[5] && dice1.face[6]==dice2.face[6]  ){
        ident=1;
    }

    for(i=0;i<operate.size();i++){
        dice2.round(operate[i]);
        if(dice1.face[1]==dice2.face[1] && dice1.face[2]==dice2.face[2] && dice1.face[3]==dice2.face[3] && dice1.face[4]==dice2.face[4] && dice1.face[5]==dice2.face[5] && dice1.face[6]==dice2.face[6]  ){
            ident=1;
            break;
        }
    } 
    if(ident==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,i,j;
	cin>>n;
	ll sum=1;
	sum=(n*(n-1))/2;
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include<string>
#include<cstdio>
#include<iostream>

using namespace std;
 
int main(){
	int a[15][15]={0};
	int x,y,s;

	while(scanf("%d,%d,%d", &x, &y, &s) != EOF){
		a[x+2][y+2]++; a[x+1][y+2]++; a[x+3][y+2]++; a[x+2][y+1]++; a[x+2][y+3]++;
		if(1<s){ a[x+1][y+1]++; a[x+3][y+3]++; a[x+1][y+3]++; a[x+3][y+1]++; }
		if(2<s){ a[x][y+2]++; a[x+4][y+2]++; a[x+2][y]++; a[x+2][y+4]++; }
	}

	int br=0, max=0;
	for(int i=2; i<12; i++){
		for(int j=2; j<12; j++){
			if(0==a[i][j]) br++;
			if(max<a[i][j]) max=a[i][j];
		}
	}

		cout<<br<<endl;
		cout<<max<<endl;

    return 0;
}

Measured memory_bytes: 1208
#include<iostream>
using namespace std;
int main(){
    long long b,n,s=0;
    cin>>n;
    if (n%2==1){
        cout<<0;
    }else{
        b=n/2;
        while(b>=5){
            s=s+b/5;
            b=b/5;
        }
        cout<<s;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int a[20];
    a[1] = 1;
    a[2] = 3;
    a[3] = 1;
    a[4] = 2;
    a[5] = 1;
    a[6] = 2;
    a[7] = 1;
    a[8] = 1;
    a[9] = 2;
    a[10] = 1;
    a[11] = 2;
    a[12] = 1;
    int x, y;
    cin >> x >> y;
    if (a[x] == a[y]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

#define ft first
#define sd second
#define sz(x) ((int)x.size())

using namespace std;

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







string s;


int main() {
	cin >> s;
	for (int i = 0; i < sz(s) - 1; i++)
		if (s[i] == s[i + 1])
			return cout << i + 1 << ' ' << i + 2, 0;
	for (int i = 0; i < sz(s) - 2; i++)
		if (s[i] == s[i + 2])
			return cout << i + 1 << ' ' << i + 3, 0;
	cout << -1 << ' ' << -1;
	return 0;
}

Measured memory_bytes: 512
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      k: usize,
      aa: [usize; n],
    }
    let mut dp = vec![vec![None; 2]; 42];
    dp[41][0] = Some(0);

    for d in (0..41).rev() {
        let bit = 1 << d;
        let mut n1 = 0;
        for i in 0..n {
            if aa[i] & bit > 0 {
                n1 += 1;
            }
        }
        let n0 = n - n1;

        if k & bit > 0 {
            dp[d][0] = dp[d+1][0].map(|v| v + n0 * bit); // 1->1
            dp[d][1] = dp[d+1][0].map(|v| v + n1 * bit); // 1->0
        } else {
            dp[d][0] = dp[d+1][0].map(|v| v + n1 * bit);
        }
        dp[d][1] = max(dp[d][1], dp[d+1][1].map(|v| v + bit * max(n0, n1)));
    }
    let ans = max(dp[0][0], dp[0][1]);
    println!("{}", ans.unwrap());
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		char[] s = sc.next().toCharArray();
		long k = sc.nextLong();
		char a = '1';
		if(k > s.length) {
			k = s.length;
		}
		for(int i = 0; i < k; i++) {
			if(s[i] != '1') {
				a = s[i];
				break;
			}
		}
		System.out.println(a);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


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

int main()
{
	int a, b, c, dist;
  	scanf("%d%d%d%d", &a, &b, &c, &dist);
  	if (abs(c - a) <= dist){
    	printf("Yes");
    } else if (abs(c - b) <= dist && abs(b - a) <= dist){
    	printf("Yes");
    } else {
    	printf("No");
    }
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> 
#include <vector>
#include <map>
#define N 100010
using namespace std;
vector<int>Q[N];
map<int,int>d;
bool vis[N];
int n,a[N],b[N],x[N],y[N],cnt,ans;
void dfs(int x){
    vis[x]=1;
    for (int i=0;i<Q[x].size();i++) if (!vis[Q[x][i]]) dfs(Q[x][i]);
}
int main(){
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]),a[n+1]^=a[i];
        if(!d[a[i]]) d[a[i]]=++cnt;
    }

    if(!d[a[n+1]]) d[a[n+1]]=++cnt;

    for(int i=1;i<=n;i++){
        scanf("%d",&b[i]),b[n+1]^=b[i];
        if(!d[b[i]]) d[b[i]]=++cnt;
    }

    if(!d[b[n+1]]) d[b[n+1]]=++cnt;

    memcpy(x,a,sizeof x),memcpy(y,b,sizeof y);

    sort(x+1,x+n+2),sort(y+1,y+n+2);

    for(int i=1;i<=n;i++) if(x[i]!=y[i]) {printf("-1");return 0;}

    for(int i=1;i<=n+1;i++) a[i]=d[a[i]],b[i]=d[b[i]];

    for(int i=1;i<=n;i++) if(a[i]!=b[i]) ans++,Q[a[i]].push_back(b[i]);

    if(a[n+1]!=b[n+1]) Q[a[n+1]].push_back(b[n+1]);

    for(int i=1;i<cnt;i++) if(Q[i].size()&&!vis[i]) dfs(i),ans++;

    if(!vis[cnt]) ans++;

    printf("%d",ans-1);

	return 0;
}


Measured memory_bytes: 15232
#include <bits/stdc++.h>
typedef long long ll;
int main(int argc, char const *argv[]) {
    std::string S;
    std::cin >> S;
    for (size_t i = 0; i < S.size(); i++) {
        if (S[i] == '9') {
            std::cout << '1';
        } else if (S[i] == '1') {
            std::cout << '9';
        } else {
            std::cout << S[i];
        }
    }
    std::cout << '\n';
    return 0;
}


Measured memory_bytes: 256
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a, _ in ab)
dp = [10 ** 18 for _ in range(h + max_a)]
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))


Measured memory_bytes: 3832
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=stdIn.nextInt();
		int a[]=new int[n];
		int cnt=0,mode=0;
		for(int i=0;i<n;i++)
			a[i]=stdIn.nextInt();
		for(int i=1;i<n;i++){
			if(mode==0){
				if(a[i-1]<a[i])
					mode=1;
				else if(a[i-1]>a[i])
					mode=2;
			}
			else if(mode==1&&a[i-1]>a[i]){
				cnt++;
				mode=0;
			}
			else if(mode==2&&a[i-1]<a[i]){
				cnt++;
				mode=0;
			}
		}
		System.out.println(cnt+1);
	}
}

Measured memory_bytes: 51628
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n;
int a[200100];
vector<int> t;

int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i];
	string s;
	for(int i=n-1;i!=-2&&i!=-1;i-=2){
		t.push_back(a[i]);
	}
	
	int m=(n%2==0)?0:1;
	for(int i=m;i<n;i+=2){
		t.push_back(a[i]);
	}
	for(int i=0;i<t.size();i++){
		cout<<t[i]<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3828
a[11],j;main(N,i){for(;scanf("%d",&N),j=N;memset(a,0,sizeof(a))){
	for(getchar(),i=0;(j=getchar())!='\n';i++)if(j=='M')a[i%N]++;else if(j-'L')a[N]+=a[i%N]+1,a[i%N]=0;else a[i%N]+=a[N]+1,a[N]=0;
	for(i=0;i<N-1;i++)for(j=0;j<N-i-1;j++)if(a[j]>a[j+1])a[j+1]^=a[j],a[j]^=a[j+1],a[j+1]^=a[j];
	for(i=0;i<=N;i++)printf(i<N?"%d ":"%d\n",a[i]);
}}

Measured memory_bytes: 604
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 200010;
const int MOD = 998244353;
const int INF = 1000000010;

int main()
{
	
	int n, x;
	cin >> n >> x;
	int ans = 0;
	for (int i = 1; i <= n; ++ i)
	{
		int y;
		cin >> y;
		ans = __gcd(ans, abs(x-y));
	}
	cout << ans << endl;
	
	return 0;
}


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

int main(void)
{
    int n,i,j;
    scanf("%d",&n);
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            if(4*i+7*j==n){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 128
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;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static List<Tuple<int,int>>[] li;
	static bool[] b,bg;
	static long[] h;
	static bool gg=false;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int n=s[0],m=s[1];
		li=new List<Tuple<int,int>>[n+1];
		b=new bool[n+1];
		bg=new bool[n+1];
		h=new long[n+1];
		var e=new int[m][];
		for(int i=1;i<=n;i++){li[i]=new List<Tuple<int,int>>();}
		for(int i=0;i<m;i++){
			e[i]=sc.Ia;
			e[i][2]=s[2]-e[i][2];
			li[e[i][1]].Add(Tuple.Create(e[i][0],e[i][2]));
		}
		for(int i=1;i<=n;i++){h[i]=long.MaxValue;}
		h[1]=0;
		bool bo=true;
		for(int i=0;bo&&i<=n;i++){
			bo=false;
			for(int j=0;j<m;j++){
				if(h[e[j][0]]!=long.MaxValue&&h[e[j][1]]>h[e[j][0]]+e[j][2]){
					h[e[j][1]]=h[e[j][0]]+e[j][2];
					bo=true;
					if(i==n){b[e[j][1]]=true;}
				}
			}
		}
		Fu(n);
		Console.WriteLine("{0}",gg?-1:(Max(-h[n],0)));
	}
	static void Fu(int a){
		bg[a]=true;
		if(b[a]){gg=true;}
		for(int i=0;i<li[a].Count&&!gg;i++){
			if(!bg[li[a][i].Item1]){Fu(li[a][i].Item1);}
		}
	}
}

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{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+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: 15828
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	string s; cin >> s;
	string ans = "";
	rep(i, 0, s.size()) {
		if (ans.size() & 1) {
			if (s[i] == 'Z')ans += 'Z';
		}
		else {
			if (s[i] == 'A')ans += 'A';
		}
	}
	if (ans.size() >= 2)
		cout << ans.substr(0, ans.size() / 2 * 2) << endl;
	else
		cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <cmath>
#include <cstdio>
#include <map>
#define EPS 1e-10
//#define double long double
using namespace std;

double add(double a,double b){
	if(abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
	return a + b;
}

struct vect{
	double x,y;
	vect(){}
	vect(double x,double y) : x(x),y(y){}
	vect operator + (vect v){
		return vect(add(x,v.x),add(y,v.y));
	}
	vect operator - (vect v){
		return vect(add(x,-v.x),add(y,-v.y));
	}
	vect operator * (double d){
		return vect(x * d,y * d);
	}
	double dot(vect v){
		return add(x * v.x,y * v.y);
	}
	double det(vect v){
		return add(x * v.y,-y * v.x);
	}
	bool operator<(const vect& v2) const{
		if(x != v2.x) return x < v2.x;
		return y < v2.y;
	}
};

bool on_seg(vect p1,vect p2,vect q){
	return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}

vect inter(vect p1,vect p2,vect q1,vect q2){
	return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1));
}

double rnd(double x){
	x *= 1000000000.0;
	x = round(x);
	x *= 0.000000001;
	return x;
}

int main(){
	int n;
	while(cin >> n,n){
		int ans = n + 1;
		vect p[100],q[100];
		for(int i = 0;i < n;i++) cin >> p[i].x >> p[i].y >> q[i].x >> q[i].y;
		for(int i = 0;i < n;i++){
			map<vect,bool> mp;
			for(int j = 0;j < i;j++){
				if((p[i] - q[i]).det(p[j] - q[j]) != 0){
					vect r = inter(p[i],q[i],p[j],q[j]);
					r.x = rnd(r.x);
					r.y = rnd(r.y);
					if(r.x > -100.0 && r.x < 100.0 && r.y > -100.0 && r.y < 100.0) mp[r] = true;
				}
			}
			ans += mp.size();
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3240
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{

    class ProgramD
    {
        static void Main(string[] args)
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            long k = long.Parse(s[1]);

            string[] s2 = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            int[] b = new int[n];
            int[] to = new int[n];

            for (int i = 0; i < n; i++)
                a[i] = int.Parse(s2[i]);


            to[0] = 1;
            

            int townfrom = 1;
            int townto = 0;
            int count = 0;

            while(true)
            {
                b[0] = -1;
                townto = a[townfrom - 1];
                count++;
                if (b[townto - 1] == -1)
                    break;
                b[townto - 1] = -1;
                to[count] = townto;
                townfrom = townto;
            }

            int r = 0;
            for(int i = 0; i < n;i++)
            {
                if (to[i] == townto)
                    r = i;
            }

            if(r == 0)
                Console.WriteLine(to[k % count]);
            else
            {
                if(k <= r)
                    Console.WriteLine(to[k]);
                else
                    Console.WriteLine(to[r + (k - r) % (count - r)]);

            }
                
        }
    }
}


Measured memory_bytes: 43640
#include <bits/stdc++.h>
#define ll long long
#define re register
#define IL inline
using namespace std;
const int maxn=1e3+10;
const int mod=1e9+7;
template<typename T> void read(T &x){
	T f=1;x=0;
	char s=getchar();
	while(s<'0' || s>'9'){if(s=='-') f=-1;s=getchar();}
	while(s>='0' && s<='9'){x=x*10+s-'0';s=getchar();}
	x*=f;
}
char c[maxn][maxn];
int f[maxn][maxn];
int n,m;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	read(n);read(m);
	for(re int i=1;i<=n;i++){
		for(re int j=1;j<=m;j++){
			cin>>c[i][j];
		}
	}
	for(re int i=1;i<=n;i++){
		if(c[i][1]=='#') break;
		f[i][1]=1;
	}
	for(re int j=1;j<=m;j++){
		if(c[1][j]=='#') break;
		f[1][j]=1;
	}
	for(re int i=2;i<=n;i++){
		for(re int j=2;j<=m;j++){
			if(c[i][j]=='.'){
				f[i][j]=(f[i-1][j]+f[i][j-1])%mod;
			}
		} 
	}
	cout<<f[n][m]<<endl;
	return 0;
}


Measured memory_bytes: 5248
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		
      	int avg = (a + b)/2;
      	if ((a+b) %2 == 0){
          System.out.println(avg);
        } else{
          System.out.println(avg+ 1);
        }
	}
}

Measured memory_bytes: 21076
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<set>
#define N 100000
#define IOS ios::sync_with_stdio(false)
#define INF 1e9
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
int abs(int x)
{return x>0?x:-x;}
int sqr(int x)
{return x*x;}
//coding......
int  a[250][250];
int  b[250][250];
int h,w;
int sum=0;
int d[250][250];
int k;
void solve()
{
    for (int k=0;k<10;k++)
       for (int i=0;i<10;i++)
          for (int j=0;j<10;j++)
          d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}

int main()
{
    IOS;
    cin>>h>>w;
    for (int i=0;i<=9;i++)
        for (int j=0;j<=9;j++)
        cin>>d[i][j];
    for (int i=1;i<=h;i++)
        for (int j=1;j<=w;j++)
        cin>>b[i][j];
        int i,j;
        solve();
    for (i=1;i<=h;i++)
        for (j=1;j<=w;j++)
            if (b[i][j]!=-1)
                sum+=d[b[i][j]][1];
   cout << sum << endl;
    return 0;
}



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

int main() {
	int N, answer = 0;
	cin >> N;

	vector<string> S(N);
	for (int i = 0; i < N; i++) cin >> S.at(i);

	sort(S.begin(), S.end());

	for (int i = 0; i < S.size() - 1; i++) {
		if (S.at(i) != S.at(i + 1)) {
			answer++;
		}
	}

	cout << answer + 1 << endl;
}


Measured memory_bytes: 9548
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;

int c2(int n) {
	return n*(n - 1) / 2;
}



int main()
{
	int n, m;
	cin >> n >> m;
	cout << c2(n) + c2(m);
	
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    lint x; cin >> x;
    lint ans = (x / 11) * 2; 
    if(x % 11 > 0){
        if(x % 11 <= 6) ans += 1;
        else ans += 2;
    }
    out(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
ll a;
bool isInt(long double s)
{
 return fabs(s-floor(s))<=eps;
}
long double dist(vector<long double>&v, vector<long double>&b)
{
  ll i;
  long double di=0;
  rep(i,0,a)
  {
    di+=(fabs(v[i]-b[i]))*(fabs(v[i]-b[i]));
  }
  return sqrtf(di);
}
void solve()
{
  ll n,m=0, k=0, i, j,l=2e9+7;
  string s, r, y;
  cin>>n>>a;
  vector<vector<long double>>v(n,vector<long double>(a));
  rep(i,0,n) rep(j,0,a) cin>>v[i][j];
  rep(i,0,n)
  {
    rep(j,i+1,n)
    {
      long double res=dist(v[i],v[j]);
      if(isInt(res)) k++;
    }
  }
  cout<<k;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
int main(void){ string S;cin >> S; int N = S.size(),m=N; for(int i = 1; i<N;++i) if(S[i-1]!=S[i]) m = min(m, max(i,N-i)); cout << m << endl; return 0; }


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s.at(0)==s.at(1))cout<<"Bad"<<endl;
    else if(s.at(1)==s.at(2))cout<<"Bad"<<endl;
    else if(s.at(2)==s.at(3))cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}

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

int main(){
	int a,b,dif,tall;
  	cin >> a >> b;
  	dif = b - a;
  
  	for(int i = 1;i <= dif;i++){
     	tall+= i;
    }
  
  	cout << tall - b << endl;
  
 	return 0; 
}

Measured memory_bytes: 256
import sys
import re
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def SI(): return input()


def main():
    S = SI()
    ans = 0
    S = S.replace("A", "0")
    S = S.replace("BC", "1")
    a = 0
    b = 0
    for s in S:
        if s == "0":
            a += 1
        elif s == "1":
            ans += a
            b = 1
        else:
            a = 0
    print(ans)


main()


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N,M;
vector<pll> abv[55];
vector<pll> uvv[22];
ll mk[55];
ll p2[55];
ll dp[55][1 << 21];
ll i, j, k, ans;

bool dfs(ll a,ll p,ll g,ll l){
    if(g==a){
        return true;
    }
    ll i = 0,j=0;
    fornum(i,0,abv[a].size()){
        ll b = abv[a][i].first;
        if(b==p){
            continue;
        }
        if (dfs(b, a, g, l))
        {
            mk[l] |= 1ll << abv[a][i].second;
            return true;
        }
    }
    return false;
}
int main(){
    scanf("%lld",&N);
    fornum(i,1,N){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        abv[a].push_back({b, i});
        abv[b].push_back({a, i});
    }
    scanf("%lld", &M);
    fornum(i,0,M){
        ll u, v;
        scanf("%lld%lld", &u, &v);
        dfs(u, 0, v, i);
    }

    p2[0] = 1;
    fornum(i,0,N){
        p2[i + 1] = p2[i] * 2ll;
    }

    ans = 0;
    fornum(i,0,1<<M){
        ll a = __builtin_popcountl(i);
        ll b = 0;
        fornum(j,0,M){
            if (i & (1 << j))
            {
                b |= mk[j];
            }
        }
        ll c = N - 1 - __builtin_popcountl(b);
        //printf("%lld:%lld\n", i, b);
        ans += (a & 1 ? -1 : 1) * p2[c];
    }
    printf("%lld", ans);
    return 0;
}

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

int n;
string s[200000];
vector<pair<int, string>> p;

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> s[i];

	sort(s, s + n);

	int j = 1;

	for (int i = 1; i < n; i++) {
		if (s[i] != s[i - 1]) {
			p.push_back(make_pair(n - j, s[i - 1]));
			j = 1;
		}
		else
			j++;
	}

	p.push_back(make_pair(n - j, s[n - 1]));

	sort(p.begin(), p.end());

	int k = p[0].first;

	int i = 0;
	while (i < p.size() && p[i].first == k) {
		cout << p[i].second << endl;
		i++;
	}

	return 0;
}

Measured memory_bytes: 18676
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

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

ll LCM(ll a, ll b){
  return a/GCD(a,b) * b;
}
 
int main(){
  int N,K; cin >> N >> K;
  vector<int> A(N);
  rep(i,N) cin >> A[i];

  vector<int> nums(N+100);
  rep(i,N){
    nums[A[i]]++;
  }
  int sum = 0;
  rep(i,N+100){
    if(nums[i] > 0) sum++;
  }
  sort(nums.begin(),nums.end());
  int ans = 0;
  rep(i,N+100){
    if(sum <= K) break;
    if(nums[i] > 0){
      ans += nums[i];
      sum -= 1;
    }
  }
  cout << ans << endl;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 078_arc_b / Link: https://abc067.contest.atcoder.jp/tasks/arc078_b?lang=en  ----- */
/* ------問題------

フェネックとすぬけくんがボードゲームで遊んでいます。
このボードゲームには 1 番から N 番までの番号がついた N 個のマスと、マスどうしをつなぐ N−1 本の道が存在しています。 ai 番のマスと bi 番のマスは i 番目の道を介して隣り合っています。どの 2 つのマスも隣接するマスをいくつか辿って必ず辿り着くことが可能です。すなわち、グラフ理論の言葉を用いると、マスと道から構成されるグラフは木です。
はじめに 1 番のマスは黒く、N 番のマスは白く塗られています。その他のマスはまだ色が塗られていません。 先手のフェネックと後手のすぬけくんは残りのマスに交互に色を塗ります。 自分の手番において、2 人はそれぞれ以下のような行動を行います。
フェネック：黒く 塗られたマスに隣接したマスであって、色が塗られていないマスを 1 つ選んで 黒く 塗る。
すぬけくん：白く 塗られたマスに隣接したマスであって、色が塗られていないマスを 1 つ選んで 白く 塗る。
手番のプレイヤーがマスに色を塗ることができなかったとき、敗者となります。フェネックとすぬけくんが最適に行動したとき勝者はどちらか判定してください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;
void dfs(int v, int p, int d, VVI& G, VI& dist) {
	dist[v] = d;
	FOR(i, 0, SZ(G[v])) {
		int nx = G[v][i];
		if (nx != p) {
			dfs(nx, v, d + 1, G, dist);
		}
	}
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N;
	VVI G(N);
	FOR(i, 0, N - 1) {
		int a, b;
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}
	VI distF(N, -1);
	VI distS(N, -1);
	dfs(0, -1, 0, G, distF);
	dfs(N-1, -1, 0, G, distS);
	int Fcnt = 0;
	FOR(i, 0, N) {
		if (distF[i] <= distS[i])Fcnt++;
	}

	if (Fcnt > N - Fcnt) {
		cout << "Fennec" << endl;
	}
	else cout << "Snuke" << endl;

	return 0;
}


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

#define ll long long
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define int long long
#define INF 1e9
#define pii pair<int, int>
#define pt(xx) cout << "\n" \
                    << xx << "\n"
#define debugv(x, n)               \
    cout << "\n"                   \
         << #x << ": ";            \
    rep(i, n) cout << x[i] << " "; \
    cout << endl
#define debug2d(x, m, n)            \
    cout << "\n"                    \
         << #x << " is: \n";        \
    for (int i = 0; i < m; ++i)     \
    {                               \
        for (int j = 0; j < n; ++j) \
        {                           \
            cout << x[i][j] << " "; \
        }                           \
        cout << endl;               \
    }
#define nl cout << endl

#define MOD 1000000007

int N, K, L;
int ans;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //==============================================

    cin >> N >> K;
    int cmb = (N - 1) * (N - 2) / 2;
    vector<pair<int, int>> path;
    int M;

    if (cmb < K)
    {
        cout << "-1" << endl;
    }
    else
    {
        // make_star.
        rep(i, N - 1)
        {
            path.push_back(make_pair(0, i + 1));
        }
       // debug(cmb);

        int repc = cmb - K;
        //debug(repc);

        int cut = 0;
        rep(i, N - 1)
        {
            rep(j, N - 1)
            {
                    if (i < j && cut<repc)
                    {
         //               debug(cut);
                        path.push_back(make_pair(i + 1, j + 1));
                        ++cut;
                    }
                }
            }
        M = path.size();
        cout << M << endl;
        for (auto x : path)
        {
            cout << x.first + 1 << " " << x.second + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    string s;cin>>s;
    ll a[n],b[n];
    a[0]=0;
    b[n-1]=0;
    for(ll i=1;i<n;i++){
        if(s[i-1]=='W'){
            a[i]=a[i-1]+1;
        }else{
            a[i]=a[i-1];
        }
    }
    for(ll i=n-2;i>=0;i--){
        if(s[i+1]=='E'){
            b[i]=b[i+1]+1;
        }else{
            b[i]=b[i+1];
        }
    }
    ll ans=inf;
    for(ll i=0;i<n;i++){
        ans=min(ans,a[i]+b[i]);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 5380
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n, k = f.read_int_list()

    c1 = n / k
    c2 = (n+k/2) / k if k % 2 == 0 else 0

    return c1**3 + c2**3


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 4764
h, w, k = map(int, input().split())
C = [input() for _ in range(h)]

count = 0
for i in range(2**h):
    for l in range(2**w):
        tmp = ""
        for j in range(h):
            for m in range(w):
                if ((i >> j) & 1) and ((l >> m) & 1):
                    tmp += C[j][m]
        if tmp.count("#") == k:
            count += 1

print(count)

Measured memory_bytes: 9052
s=input()
a=0
b=0
c=0
for i in range(1,4):
  if ord(s[0])==ord(s[i]):
    a=i
    b+=1
if b==1:
  if a==1:
    if ord(s[2])==ord(s[3]):
      print('Yes')
    else:
      print('No')
  elif a==2:
    if ord(s[1])==ord(s[3]):
      print('Yes')
    else:
      print('No')
  elif a==3:
    if ord(s[1])==ord(s[2]):
      print('Yes')
    else:
      print('No')
else:
    print('No')


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

using namespace std;
constexpr long long int mod = 1000000007;

int main() {
    int N;
    cin >> N;
    map<long long,long long>sumlist,distlist;
    vector<int>Height(N);
    for (long long i = 0; i < N; i++)
    {
        cin >> Height.at(i);
        sumlist[Height.at(i) + (i + 1)] = sumlist[Height.at(i) + (i + 1)] + 1;
        distlist[  -Height.at(i)+ (i + 1)] = distlist[-Height.at(i) + (i + 1)] + 1;
    }
    long long ans=0;

    for (auto t:distlist)
    {
        ans += t.second * sumlist[t.first];
    }
    cout << ans;
}

Measured memory_bytes: 38088
#include <stdio.h>
#include <string.h>
int main(void)
{
    int n;
    scanf("%d",&n);
    char s[n][4];
    int i,c[4];
    for(i=0;i<4;i++){
        c[i]=0;
    }
    for(i=0;i<n;i++){
        scanf("%s",s[i]);
        if (!strcmp(s[i],"AC"))
        {
            c[0]++;
        }
        else if (!strcmp(s[i], "WA"))
        {
            c[1]++;
        }
        else if (!strcmp(s[i], "TLE"))
        {
            c[2]++;
        }
        else if (!strcmp(s[i], "RE"))
        {
            c[3]++;
        }
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",c[0],c[1],c[2],c[3]);

    return 0;
}


Measured memory_bytes: 2540