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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plpll;

int N,M,K;
int par[100010];
int bef[100010];
vector<plpll> V;

void init()
{
    for(int i = 1; i <= N; i++)par[i] = i;
    return;
}

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

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

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

int main()
{
    cin >> N >> M >> K;
    init();
    for(int i = 0; i < 100010; i++)bef[i] = -1;
    for(int i = 1; i <= N; i++)
    {
        int c;
        cin >> c;
        if(c == 0)continue;
        if(bef[c] != -1)unite(i, bef[c]);
        bef[c] = i;
    }

    for(int i = 0; i < M; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        V.push_back(mk(c, mk(a,b)));
    }

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

    int cnt = 0;
    ll ans = 0;
    for(int i = 0; i < M; i++)
    {
        if(cnt == K - 1)continue;
        plpll now = V[i];
        int a = now.se.fi, b = now.se.se;
        if(!same(a, b))
        {
            unite(a, b);
            ans += now.fi;
            cnt++;
        }
    }

    if(cnt == K - 1)cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define NIL -1
typedef long long ll;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main() {
    string s;
    cin >> s;
    int count = 0;
    for(int i = 0; i < s.size()/2; ++i){
        if(s[i] != s[s.size()-1-i]) ++count;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n, m, d,ans;
	ans = 0;
	cin >> n >> m >> d;
	string a[111];
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int z = 0; z < m-d+1; z++) {
			for (int q = 0; q < d; q++) {
				if (a[i][z + q] != '.') {
					goto a;
				}
			}
			ans = ans + 1;
		a:;
		}
	}
	for (int i = 1; i <= n-d+1; i++) {
		for (int z = 0; z < m; z++) {
			for (int q = 0; q < d; q++) {
				if (a[i + q][z] != '.') {
					goto b;
				}
			}
				ans = ans + 1;
			b:;
			
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N;
  cin >> N;
  rep(i, 0, 9){
    if(N <= (i+1)*111){
      cout << (i+1)*111 << rt;
      return 0;
    }
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
S = input()
N = len(S)
S = list(S)

count = 0
count2 = 0
kekka = 0
for i in range(len(S)):
	if(S[i] == 'B'):
		count = count + 1
		count2 = count2 + i
for j in range(count):
	kekka = kekka + N - j-1

print(kekka-count2)

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t h, w;
    cin >> h >> w;

    vector<vector<bool>> s(h + 1, vector<bool>(w + 1));
    for (auto i : irange(0L, h)) {
        string ss;
        cin >> ss;
        for (auto j : irange(0L, w)) {
            s[i + 1][j + 1] = (ss[j] == '#');
        }
    }

    int64_t dxs[] = {0L, -1L};
    int64_t dys[] = {-1L, 0L};

    vector<vector<int64_t>> dp(
            h + 1, vector<int64_t>(w + 1, numeric_limits<int64_t>::max() / 2));
    dp[0][1] = 0;
    dp[1][0] = 0;
    for (auto i : irange(1L, h + 1)) {
        for (auto j : irange(1L, w + 1)) {
            for (auto k : {0, 1}) {
                auto dx = dxs[k];
                auto dy = dys[k];

                if (!s[i][j] || (s[i][j] == s[i + dy][j + dx])) {
                    dp[i][j] = min(dp[i][j], dp[i + dy][j + dx]);
                } else {
                    dp[i][j] = min(dp[i][j], dp[i + dy][j + dx] + 1);
                }
            }
        }
    }

    cout << dp[h][w] << endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1e5+4;
int n,m;
priority_queue<ll > q;
ll ans;
int main() {
	scanf("%d%d",&n,&m);
	for (register int i=1;i<=n;++i) {
		ll x;
		scanf("%lld",&x);
		q.push(x);
		ans+=x;
	}
	while (m--) {
		if (q.empty()) break;
		ll cur=q.top();
		ans-=(cur-(cur>>1));
		q.pop();
		q.push(cur>>1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1400
import math

N,D=map(int, input().split())
L=[]

for _ in range(N):
  L.append(list(map(int, input().split())))

An=0  
for i in range(N):
  for j in range(i+1,N):
    A=0
    for k in range(D):
      A=A+(L[i][k]-L[j][k])**2
    A=A**0.5
    if A-int(A)==0:
      An=An+1

print(An)

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

int main() {
  
  long long N,ans,N3;
  double N2;
  cin >> N >> N2;
  
  N2 *= 100;
  N2 += 0.01;
  
  N3 = int(N2);
  
  ans = N * N3;
  
  ans /= 100;
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define debug(x) cout<<#x<<"="<<x<<endl;
using namespace std;
const int N=1e5+10; 
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",(a+b+1)/2);
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;

int main(){
    int x;
    cin >> x;
    ll limit = 1000; // (x+1)^5 - x^5 > 10^9
    ll a, b;
    for(a = -limit; a <= limit; ++a){
        for(b = -limit; b <= limit; ++b){
            if (pow(a, 5) - pow(b, 5) == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4104
#include <iostream>
using namespace std;
#define ll long long
#define rep(i, start, end) for(ll i=(ll)start; i<(ll)end; i++)
#define INF 1000000007
#define print(a) cout << a << endl;
#define printarray(a, len) rep(i,0,len) cout << a[i] << " ";

int main(){
  ll n;
  cin >> n;
  ll w[110];
  ll leftdp[110] = {};
  ll total = 0;
  ll ans = INF;
  
  rep(i, 0, n){
    cin >> w[i];
    total += w[i];
    leftdp[i+1] += leftdp[i] + w[i];
  }
  rep(i, 1, n+1){
    ans = min(ans, llabs(total - 2*leftdp[i]));
  }
  
  cout << ans << endl;  
  
  return 0;
}


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

using namespace std;

typedef long long ll;
const ll mod = 998244353;
const int N = 3e5 + 100;
const int S = 7;

int n, m, id[N];
ll tot[10], fac[N], ans;
char str[N];

int main() {
  id['R'] = 1;
  id['G'] = 2;
  id['B'] = 4;
  fac[0] = ans = 1;
  scanf("%d", &n);
  m = 3 * n;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % mod;
  scanf("%s", str + 1);
  for (int i = 1; i <= m; i++) {
    bool chk = false;
    int cur = id[(int) str[i]];
    for (int j = S - cur; j; j = (j - 1) & (S - cur)) {
      if (!tot[j]) continue ;
      chk = true;
      (ans *= tot[j]) %= mod;
      tot[j]--;
      if (cur + j != S) tot[cur + j]++;
      break ;
    }
    if (!chk) tot[cur]++;
  }
  (ans *= fac[n]) %= mod;
  printf("%lld\n", ans);
  return 0;
}

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

 
int main(){
    
    int ans=0;
    string s,t;
    cin>>s>>t;
    rep(i,3){
        if(s.at(i)==t.at(i))ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
ll mod=1000000000+7;
int main(){
	int n,m;
	V fact(100005,1LL);
	for(ll i=1;i<100002LL;i++){
		fact[i]*=fact[i-1]*i;
		fact[i]%=mod;
	}
	ll ans=1LL;
	cin >>n>>m;
	if(abs(n-m)>1){
		ans=0LL;
	}else if(n==m){
		ans=fact[n]*fact[m]%mod*2;
		ans%=mod;
	}else
	{
		ans=fact[n]*fact[m];
		ans%=mod;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double[] p = new double[n+1];
    for(int i=1;i<=n;i++)p[i]=sc.nextDouble();
    double[][] dp = new double[n+1][n+1];
    dp[1][1]=p[1];
    dp[1][0]=1-p[1];
    for(int i=2;i<=n;i++){
      for(int j=0;j<=i;j++)
        if(j==0)dp[i][j]=dp[i-1][0]*(1-p[i]);
        else dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
    }
    double ans = 0;
    for(int i=(n+1)/2;i<=n;i++)ans+=dp[n][i];
    System.out.println(ans);
  }
}

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

int main(){
    int A,B; cin >> A >> B;
    rep(i,1251){
        if (floor(i*0.08)==A){
            if (floor(i*0.1)==B){
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << -1;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N=in();
	string S=in<string>();
	string WS[8];
	REP(i,8) WS[i].resize(N,'_');
	REP(i,4) WS[i][0]='S';
	if(S[0]=='o'){
		WS[0][1]='S';
		WS[0][N-1]='S';
		WS[1][1]='W';
		WS[1][N-1]='W';
		REP(i,2) WS[i+2].clear();
	}
	else{
		WS[2][1]='S';
		WS[2][N-1]='W';
		WS[3][1]='W';
		WS[3][N-1]='S';
		REP(i,2) WS[i].clear();
	}
	REP(i,4) WS[i+4][0]='W';
	if(S[0]=='x'){
		WS[4][1]='S';
		WS[4][N-1]='S';
		WS[5][1]='W';
		WS[5][N-1]='W';
		REP(i,2) WS[i+6].clear();
	}
	else{
		WS[6][1]='S';
		WS[6][N-1]='W';
		WS[7][1]='W';
		WS[7][N-1]='S';
		REP(i,2) WS[i+4].clear();
	}
	
	for(int i=1;i<N-2;i++){
		REP(j,8){
			if(WS[j].empty()) continue;
			if(S[i]=='o'){
				if(WS[j][i]=='S') WS[j][i+1]=WS[j][i-1];
				else if(WS[j][i]=='W') WS[j][i+1]=WS[j][i-1]=='W'?'S':'W';
			}
			else{
				if(WS[j][i]=='W') WS[j][i+1]=WS[j][i-1];
				else if(WS[j][i]=='S') WS[j][i+1]=WS[j][i-1]=='W'?'S':'W';
			}
		}
	}

	for(int i=N-2;i<N;i++){
		REP(j,8){
			if(WS[j].empty()) continue;
			if(S[i]=='o'){
				if(WS[j][i]=='S'){
					if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='W') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='S')){
						WS[j].clear();
					}
				}
				else if(WS[j][i]=='W'){
					if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='S') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='W')){
						WS[j].clear();
					}
				}
			}
			else{
				if(WS[j][i]=='S'){
					if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='S') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='W')){
						WS[j].clear();
					}
				}
				else if(WS[j][i]=='W'){
					if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='W') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='S')){
						WS[j].clear();
					}
				}
			}
		}
	}

	for(auto& x:WS){
		if(!x.empty()){
			out(x);
			return 0;
		}
	}

	out(-1);
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define FOR(i,l,r) for(int i=(l),i##R=(r);i<=i##R;i++)
#define DOR(i,r,l) for(int i=(r),i##L=(l);i>=i##L;i--)
#define loop(i,n) for(int i=0,i##R=(n);i<i##R;i++)
#define sf scanf
#define pf printf
#define mms(a,x) memset(a,x,sizeof a)
using namespace std;
typedef long long ll;
template<typename A,typename B>inline void chkmax(A &x,const B y){if(x<y)x=y;}
template<typename A,typename B>inline void chkmin(A &x,const B y){if(x>y)x=y;}
const int N=1e5+5,P=1e9+7;
int n,k;
struct Graph{
	int tot,to[N<<1],nxt[N<<1],head[N];
	void add(int x,int y){tot++;to[tot]=y;nxt[tot]=head[x];head[x]=tot;}
	void clear(){mms(head,-1);tot=0;}
	#define EOR(G,i,x) for(int i=G.head[x];i!=-1;i=G.nxt[i])
}G;
ll ans=1;
int son[N];
void dfs(int x,int f,int d){
	if(!f)ans=k;
	int num=min(d+1,2);
	EOR(G,i,x){
		int v=G.to[i];
		if(v==f)continue;
		dfs(v,x,d+1);
		if(num>=k)ans=0;
		else ans=ans*(k-num)%P;
		num++;
	}
}
int main(){
	G.clear();
	sf("%d%d",&n,&k);
	FOR(i,1,n-1){
		int x,y;
		sf("%d%d",&x,&y);
		G.add(x,y),G.add(y,x);
	}
	dfs(1,0,0);
	pf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6912
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		int[] x = new int[n];
		int[] y = new int[n];
		int[] dt = new int[n];
		int[] dx = new int[n];
		int[] dy = new int[n];
		t[0] = sc.nextInt();
		x[0] = sc.nextInt();
		y[0] = sc.nextInt();
		dt[0] = t[0];
		dx[0] = x[0];
		dy[0] = y[0];
		for(int i=1; i<n; i++){			
			t[i] = sc.nextInt();
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			dt[i] = t[i] - t[i-1];
			dx[i] = x[i] - x[i-1];
			dy[i] = y[i] - y[i-1];
		}
		boolean bl = true;
		for(int i=0; i<n; i++){
			if(dx[i]+dy[i]>dt[i] || (dx[i]+dy[i]+dt[i])%2!=0){
				bl = false;
				break;
			}
		}
		System.out.println(bl==true ? "Yes" : "No");
	}
}

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

const int mx = 1e5 + 5;

int n, m;
int v[mx], p[mx];
int rep[mx];

int f(int x){
    return x == rep[x] ? x : rep[x] = f(rep[x]);
}
void c(int x, int y){
    rep[f(y)] = f(x);
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) rep[i] = i;
    for(int i = 1, t; i <= n; i++){
        cin >> p[i];
        v[p[i]] = i;
    }
    for(int a, b; m--; ){
        cin >> a >> b;
        c(a,b);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(f(i) == f(p[i])) ++ans;
    }
    cout << ans << '\n';
}


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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
vi data[5005];
vi res;
bool used[5005];
vector<pii> a;
void f(int num){
    if(used[num]==true)return;
    used[num]=true;
    for(int v:data[num]){
       f(v);
    }
    res.pb(num);
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    rep(i,0,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        data[b].pb(a);
        //cout << b << " <- " << a << endl;
    }
    //a>b;
    memset(used,false,sizeof(used));
    rep(i,0,n)f(i);
    int ff=false;
    rep(i,0,n-1){
        bool u=false;
        int ue=res[i];
        int shi=res[i+1];
        for(int v=0;v<data[shi].size();v++){
            if(data[shi][v]==ue){
                u=true;
                break;
            }
        }
        if(u==false){
          //  cout<< endl << ue <<  " " <<i << " " << shi << endl;
            ff=true;
            break;
        }
    }
    rep(i,0,n){
        cout << res[i]+1 << endl;
    }
    cout << ff << endl;
    return 0;
}

Measured memory_bytes: 4420
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define all(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*
2d pointer array
int **dp;
in main function
int row,col;
dp=new int*[n];
rep(i,n)dp[i]=new int[m]
*/
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  int n,m;
  cin>>n>>m;
  priority_queue<int>q;
  rep(i,n)
  {
    int a;
    cin>>a;
    q.push(a);
  }
  while(q.empty()==false && m)
  {
    int temp=q.top();
    q.pop();
    temp=temp/2;
    m--;
    if(temp!=0)q.push(temp);
  }
  int ans=0;
  while(q.empty()==false)
  {
    int temp=q.top();
    q.pop();
    ans+=temp;
}
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1400
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')


n_queries = int(input())
queries = []
for _ in range(n_queries):
    l, r = map(int, input().split())
    queries.append([l, r])

MAX_INT = 10 ** 5


def eratos(number):
    is_prime = [1] * (number + 1)
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, number + 1):
        if not is_prime[i]:
            continue
        j = i + i
        while j < number + 1:
            is_prime[j] = 0
            j += i
    return is_prime


def like(number):
    is_like = [0] * (number + 1)
    for i in range(number + 1):
        if i % 2 == 0:
            continue
        if is_prime[i] and is_prime[(i + 1) // 2]:
            is_like[i] = 1
    return is_like


is_prime = eratos(MAX_INT)
is_like = like(MAX_INT)

cum_sum = [0] * (MAX_INT + 2)
for i in range(MAX_INT + 1):
    cum_sum[i+1] = cum_sum[i] + is_like[i]

for l, r in queries:
    res = cum_sum[r+1] - cum_sum[l]
    print(res)


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> s(n);

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

    vector<int> t(n);
    for(i = 0; i < n; i++) {
        t[s[i]-1]++;
    }

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

    int ans = 0;
    for(i = k; i < n; i++) {
        ans += t[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
bool chmin(long long &a, long long b) { if (a > b) {a = b; return true;} return false;}
const long long INF = 1LL<<60;

using Edge = pair<int, long long>;
int N, M,P;
vector<vector<Edge> > G;
                                 
int main() {
    cin >> N >> M>>P;
    G.clear(); G.resize(N);
    for (int i = 0; i < M; ++i) {
        int a, b; long long w;
        cin >> a >> b >> w; --a, --b;
        G[a].push_back(Edge(b, -(w-P)));
    }

    vector<long long> dist(N, INF);
    bool negative = false;
    dist[0] = 0;
    for (int iter = 0; iter <= N*2; ++iter) {
        for (int v = 0; v < N; ++v) {
            if (dist[v] >= INF/2) continue;
            for (auto e : G[v]) {
                if (chmin(dist[e.first], dist[v] + e.second)) {
                    if (e.first == N-1 && iter >= N-1) negative = true;
                    else if(iter>=N-1) dist[e.first]=-INF/2;
                }
            }
        }
    }
    if (!negative) cout << max(0ll,-dist[N-1]) << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 512
L = int(input())

r = 0

while 2**(r+1) <= L:
    r += 1

E = []
for i in range(1,r+1):
    E.append((i,i+1,0))
    E.append((i,i+1,2**(i-1)))

N = r+1

for i in range(N-1,0,-1):
    if L-(2**(i-1))>=2**r:
        E.append((i,N,L-2**(i-1)))
        L -= 2**(i-1)

print(N,len(E))
for e in E:
    print(e[0],e[1],e[2])

Measured memory_bytes: 80188
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int Q = sc.nextInt();
	String s = sc.next();
	int[] a = new int[N];
	char pre = s.charAt(0);
	for(int i = 1; i<N; i++) {
	    if(pre=='A' && s.charAt(i)=='C') a[i] = a[i-1] + 1;
	    else a[i] = a[i-1];
	    pre = s.charAt(i);
	}
	for(int i = 0; i<Q; i++) {
	    int start = sc.nextInt();
	    int end = sc.nextInt();
	    System.out.println(a[end-1]-a[start-1]);
	}
    }
}

Measured memory_bytes: 66000
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int x,y;
	while(1){
		cin>>x>>y;
		if(x==0 && y==0) break;
		if(y<x) swap(x,y);
		cout<<x<<" "<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
def bubble_sort(a)
  arr = a.dup
  n = arr.length
  for i in 0..n - 1
    j = n - 1
    while j > i
      if arr[j-1][1] > arr[j][1]
        arr[j-1],arr[j] = arr[j],arr[j-1]
      end
      j -= 1
    end
  end
  arr
end

def selection_sort(arr)
  a = arr.dup
  for i in 0..(a.length - 1)
    min = i
    for j in i ..(a.length - 1)
      if a[j][1] < a[min][1]
        min = j
      end
    end
    a[i], a[min] = a[min], a[i]
  end
  a
end

gets
x = gets.split.map { |v| [v[0], v[1].to_i] }
b = bubble_sort(x)
s = selection_sort(x)

puts b.map(&:join).join(' ')
puts 'Stable'
puts s.map(&:join).join(' ')
puts b == s ? 'Stable' : 'Not stable'

Measured memory_bytes: 6116
#include <iostream>
#include <string>

int main() {

	int n, a;

	std::cin >> n >> a;

	if (n - ((n / 1000) * 1000) <= a) {
		std::cout << "Yes"<< std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
/*int main(){
  string S;
  cin>>S;
  if(S[0]==S[1] && S[1]==S[2]) cout<<"NO\n"; 
  else cout<<"YES\n";
  return 0;
}*/
int main() {
    string S;
    cin >> S;
    if (S[0]==S[1] && S[1]==S[2]) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
f=[[] for i in range(n)]
for i in range(n):
    f[i]=list(map(int,input().split()))
p=[[] for i in range(n)]
for i in range(n):
    p[i]=list(map(int,input().split()))
ans=-10000000000
for i in range(1,1024):
    x=[]
    pro=0
    for j in range(10):
        x.append(i%2)
        i=i//2
    for j in range(n):
        c=0
        for k in range(10):
            if x[k]==f[j][k]==1:
                c+=1
        pro+=p[j][c]
    ans=max(ans,pro)
print(ans)


Measured memory_bytes: 74172
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int N;
	cin >> N;
	vi p(N);
	vi a;
	for(int i=0; i<N; i++){
		cin >> p[i];
		if(p[i]!=i+1){
			a.push_back(p[i]);
		}
	}

	string ans="NO";
	if(a.size()==0){
		ans="YES";
	}else if(a.size()==2 && p[a[0]-1]==a[1] && p[a[1]-1]==a[0]){
		ans="YES";
	}

	cout << ans << endl;

	return 0;
}

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

public class Main{
	public static void main(String[] args){
		for(int i = 1; i <= 9; i++){
			for(int j = 1; j <= 9; j++){
				System.out.println(i + "x" + j + "=" + (i*j));
			}
		}
	}
}

Measured memory_bytes: 24352
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;long long an=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        an+=gcd(gcd(j,i),k);
      }
    }
  }
  cout<<an<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
using namespace std;
int main() {
    int N;
    while (cin >> N && N != 0) {
        int gems[21][21]; // 宝石の位置を記録する配列
        memset(gems, 0, sizeof gems);

        int x, y;
        for (int i=0; i<N; ++i) {
            cin >> x >> y;
            gems[y][x] = 1;
        }

        int trace[21][21]; // 回収範囲を記録する配列
        memset(trace, 0, sizeof trace);

        int nx = 10; int ny = 10; // 初期位置

        int M; cin >> M;

        int dx[256], dy[256];
        dx['N'] = 0; dx['E'] = 1; dx['W'] = -1; dx['S'] = 0; 
        dy['N'] = 1; dy['E'] = 0; dy['W'] = 0;  dy['S'] = -1;

        for (int i=0; i<M; ++i) {
            trace[ny][nx] = 1;

            char d; cin >> d;
            int l; cin >> l;
            for (int j=0; j<l; ++j) {
                nx += dx[d];
                ny += dy[d];
                trace[ny][nx] = 1;
            }
        }

        string output = "Yes";
        for (int i=0; i<21; ++i) {
            for (int j=0; j<21; ++j) {
                if (gems[i][j] == 1 && trace[i][j] != 1) {
                    output = "No";
                }
            }
        }

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

Measured memory_bytes: 1208
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int N, W;
    
    scanf("%d", &N);
    scanf("%d", &W);
    
    vector<int> v(N);
    vector<int> w(N);
    
    for(int i = 0; i < N; i++)
    {
        scanf("%d", &v[i]);
        scanf("%d", &w[i]);
    }
    
    vector<vector<int> > dp(N + 1, vector<int>(W + 1, 0));
    
    for(int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= W; j++)
        {
            dp[i][j] = dp[i - 1][j];
            
            if(j - w[i - 1] >= 0)
            {
                dp[i][j] = max(dp[i][j], dp[i][j - w[i - 1]] + v[i - 1]);
            }
        }
    }
    
    printf("%d\n", dp[N][W]);
    
    return 0;
}

Measured memory_bytes: 6836
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] A = new int [N];
        
        for(int i =0; i<N; i++){
            A[i] = sc.nextInt();
        }
        
        int count =0; 
        
        for(int i=0; i<N; i++){
            while(A[i]%2 == 0){
                A[i] = A[i]/2;
                count++;
            }
        }
        
        System.out.println(count);
    }
}

Measured memory_bytes: 34392
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoderA
{
    static void Main()
    {
        int a;
        int b;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            a = int.Parse(words[0]);
            b = int.Parse(words[1]);
        }

        Console.WriteLine(Math.Max(0, a - 2 * b));
    }
}

Measured memory_bytes: 11092
#include <stdio.h>

int main(){
  int i, n, maxv, minv, R[1000000];

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

  for(i=1; i<n; i++){
    if(maxv < R[i]-minv) maxv = R[i]-minv;
    if(minv > R[i]) minv = R[i];
  }
  printf("%d\n",maxv);
  return 0;
  
}

Measured memory_bytes: 3216
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail;

void enqueue(P x){//追加                                                        
  Q[tail] = x;
  tail=(tail+1)%LEN;
}

P dequeue(){//取り出し                                                          
  P x = Q[head];
  head=(head+1)%LEN;

 return x;
}

int min(int a,int b){
   if(a<b) return a;
   else return b;
 }

int main(){
  int elaps = 0;//経過　                                                        
  int c;
  int i,n,q;
  P u;

  scanf("%d %d", &n, &q);

 for(i=1; i<=n; i++){
   scanf("%s", Q[i].name);//文字列だから＆なし                                  
    scanf("%d", &Q[i].t);
  }

 head=1; tail=n+1;

 while(head != tail){
   u=dequeue();
   c=min(q,u.t);
   u.t = u.t-c;
   elaps = elaps+c;
   if(u.t>0){
     enqueue(u);
   }
   else{
     printf("%s %d\n",u.name,elaps);
   }
 }

  return 0;
}



Measured memory_bytes: 11960
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,m,s=0;
  cin>>n>>m;
  long long a[n],i,p,r=0;
  for(i=0;i<n;i++){
    cin>>a[i];
    s=s+a[i];
  }if((s)%(4*m)==0)
p=((s)/(4*m));
else
p=((s)/(4*m))+1;
  for(i=0;i<n;i++){
    if(a[i]>=p)
      r++;
  }if(r>=m)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#!/usr/local/gnu/bin/bash
read n m
a=()
b=()
c=()
d=()
for i in `seq $n`
do
    read x y
    a[$i]=$x
    b[$i]=$y
done
for i in `seq $m`
do
    read x y
    c[$i]=$x
    d[$i]=$y
done
for i in `seq $n`
do
    min=1000000000
    minId=0
    for j in `seq $m`
    do
        ((c[j]>a[i])) && e=$((c[j]-a[i])) || e=$((a[i]-c[j]))
        ((d[j]>b[i])) && e=$((e+d[j]-b[i])) || e=$((e+b[i]-d[j]))
        ((e<min)) && min=$e && minId=$j
    done
    echo $minId
done


Measured memory_bytes: 640
package main

import "fmt"

var facts [100000000]uint64

func factorial(n uint64) (result uint64) {
	if facts[n] != 0 {
		result = facts[n] % 1000000007
		return result
	}

	if n > 0 {
		result = ((n % 1000000007) * (factorial(n-1) % 1000000007)) % 1000000007
		return result
	}

	return 1
}

func main() {
	var N, M, result uint64
	fmt.Scan(&N)
	fmt.Scan(&M)
	if N == M {
		result = ((factorial(N) % 1000000007) * (factorial(M) % 1000000007) * 2) % 1000000007
	} else if N-M == 1 || M-N == 1 {
		result = ((factorial(N) % 1000000007) * (factorial(M) % 1000000007)) % 1000000007
	} else {
		result = 0
	}
	fmt.Println(result)
}


Measured memory_bytes: 7040
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let xyh = get!(isize, isize, isize; n);

    for cx in 0..101 {
        for cy in 0..101 {
            let mut hl = 0;
            for i in 0..n {
                if xyh[i].2 != 0 {
                    hl = xyh[i].2 + (xyh[i].0-cx).abs() + (xyh[i].1-cy).abs();
                    break;
                }
            }
            if xyh.iter().all(|&(x,y,h)| h == max!(hl-(cx-x).abs()-(cy-y).abs(), 0)) {
                println!("{} {} {}", cx,cy,hl);
                return;
            }
        }
    }
}


Measured memory_bytes: 8572
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int a[101][101], b[101], c[101];
	int i, j;
	int n, m;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
	}
	for (j = 0; j < m; j++) scanf("%d", &b[j]);

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

	for (i = 0; i < n; i++) {
		printf("%d\n", c[i]);
	}
	return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
using ll = long long;


int main(void)
{
    ll x, y;
    cin >> x >> y;

    vector<ll> apples_cnt(3);
    for (size_t i = 0; i < 3; i++)
    {
        cin >> apples_cnt[i];
    }

    vector<vector<ll>> apples(3);
    for (size_t i = 0; i < 3; i++)
    {
        apples[i].resize(apples_cnt[i]);
        for (size_t j = 0; j < apples_cnt[i]; j++)
        {
            cin >> apples[i][j];
        }
        sort(apples[i].begin(), apples[i].end(), greater<ll>());
    }
    
    ll total_val = 0;
    for (size_t i = 0; i < x; i++)
    {
        total_val += apples[0][i];
    }
    for (size_t i = 0; i < y; i++)
    {
        total_val += apples[1][i];
    }

    x--; y--;
    
    int z = 0;
    while (z < apples_cnt[2])
    {
        if (x < 0 && y < 0)
        {
            break;
        }

        if (y < 0)
        {
            if (apples[2][z] > apples[0][x])
            {
                total_val += apples[2][z] - apples[0][x];
                x--; z++;
            }
            else
            {
                break;
            }
        }
        else if (x < 0)
        {
            if (apples[2][z] > apples[1][y])
            {
                total_val += apples[2][z] - apples[1][y];
                y--; z++;
            }
            else
            {
                break;
            }
        }
        else
        {
            ll red_apple_val = apples[0][x];
            ll green_apple_val = apples[1][y];
            ll white_apple_val = apples[2][z];

            if (white_apple_val <= red_apple_val && white_apple_val <= green_apple_val)
            {
                break;
            }
            
            if (red_apple_val < green_apple_val)
            {
                if (white_apple_val > red_apple_val)
                {
                    total_val += white_apple_val - red_apple_val;
                    x--; z++;
                }
                else
                {
                    break;
                }
            }
            else
            {
                if (white_apple_val > green_apple_val)
                {
                    total_val += white_apple_val - green_apple_val;
                    y--; z++;
                }
                else
                {
                    break;
                }
            }
        }
    }

    cout << total_val << endl;
}


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

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int ballCount = inpt[0];
        int kindMax = inpt[1];

        inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        Dictionary<int, int> cnt = new Dictionary<int, int>();
        inpt.ToList().ForEach(a=>{
            if(cnt.ContainsKey(a)) {
                cnt[a]++;
            } else {
                cnt.Add(a, 1);
            }
        });
        List<KeyValuePair<int, int>> list = cnt.OrderBy(a => a.Value).ToList();
        int ans = 0;
        for (int i = 0; i < list.Count - kindMax; i++) {
            ans += list[i].Value;
        }
        Console.WriteLine(ans);
    }

    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"




5 2
1 1 2 2 5




";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 42704
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a % b)
    return [y, x - a//b * y, g]


def mod_inverse(a, m):
    x, _, _ = extgcd(a, m)
    return (m + x % m) % m


def mod_comb(n, k, mod):
    mul, div = 1, 1
    for i in range(k):
        mul *= (n-i)
        div *= (i+1)
        mul %= mod
        div %= mod
    return mul * mod_inverse(div, mod) % mod


def main():
    
    x, y = map(int, readline().split())
    if (x+y)%3!=0:
        print(0)
        return
    n = (x+y)//3
    a, b = (2*y-x)//3, (2*x-y)//3
    if a<0 or b<0:
        print(0)
        return
    print(mod_comb(n, min(a, b), (10**9+7)))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

typedef long long i64;

int main(void) {
    i64 A, B, C;
    cin >> A >> B >> C;

    if (!(A&1) || !(B&1) || !(C&1)) {
        cout << "0\n";
    } else {
        cout << min(min(A*B, B*C), C*A) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

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

int main(void){
    string s;
    cin>>s;
    int n=s.length();
    vector<int> ans(n,0);
    int count=0;
    int first_L_pos=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){count++;continue;}

        if(s[i]=='L'&&s[i-1]=='R'){
            first_L_pos=i;
            ans[first_L_pos-1]+=(count/2)+(count%2);
            ans[first_L_pos]+=(count/2)+1;
            count=0;
        }else{
            int p=first_L_pos-(i-first_L_pos)%2;
            ans[p]++;
        }
    }
    rep(i,n-1){cout<<ans[i]<<" ";}
    cout<<ans[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String firstLine[] = scanner.nextLine().split(" ", 2);

        int n = Integer.parseInt(firstLine[0]);
        long m = Long.parseLong(firstLine[1]);

        long max;
        if (m % n == 0) {
            max = m / n;
        } else {
            max = new Main().maxNum(n, m);
        }
        System.out.println(max);
    }

    public long maxNum(int n, long m) {
        long max = 1;
        for (long base = 2; base <= m; base++) {
            long sum = n * base;
            if (sum <= m && (m - sum) % base == 0) {
                max = base;
            }
        }
        return max;
    }
}


Measured memory_bytes: 23252
using System;
using System.Linq;

namespace _2780
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = -1;
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    int now = x[i] * x[j];
                    string s = now.ToString();
                    bool flag = true;
                    for (int k = 1; k < s.Length; k++)
                    {
                        if (s[k - 1] + 1 != s[k]) flag = false;
                    }
                    if (flag) ret = Math.Max(ret,now);
                }
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 9968
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

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

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

int main()
{
    int N = inputValue();
    int x[8];
    int y[8];
    double d[8][8];
    REP(i, N){
        x[i] = inputValue();
        y[i] = inputValue();
    }
    int exc = 1;
    REP(i,N){
        exc *= (i+1);
    }
    double sum = 0;
    REP(i, N){
        FOR(j, i+1, N){
            sum += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) * 2;
        }
    }
    sum /= N;

    cout << setprecision(12) << sum << endl;
}


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

int main(){
  ll a,b; cin >> a >> b;
  if(a+b == 3)cout << 3 << endl;
  else if(a+b == 4)cout << 2 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var N,K int
	var S string
	fmt.Scan(&N, &K, &S)
	
	ans := S[:K-1] + strings.ToLower(S[K-1:K]) + S[K:]
	
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <random>
#include <stack>
#include <ctime>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    long x, y;
    cin >> x >> y;
    if (x % y == 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int n, m, x;
int c[12];
int a[12][12];
int ans = INF;

void dfs(string s) {
    if ((int)s.size() == n) {
        int cost = 0;
        int p[m] = {};
        rep(i, 0, s.size()) {
            if (s[i] == '1') {
                cost += c[i];
                rep(j, 0, m) {
                    p[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        rep(i, 0, m) {
            if (p[i] < x) {
                ok = false;
            }
        }
        if (ok) ans = min(ans, cost);
        return;
    }
    dfs(s + '0');
    dfs(s + '1');
}

int main() {
    cin >> n >> m >> x;
    rep(i, 0, n) {
        cin >> c[i];
        rep(j, 0, m) cin >> a[i][j];
    }
    dfs("");
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592