akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, k;
int a[200000];
int dp[200000];
signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dp[i] = Inf;
	}
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = i - 1; j >= 0 && i - j <= k; j--) {
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}
	}
	cout << dp[n - 1] << endl;
}

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

int main(void){
    long long n,a,b;
    cin >> n >> a >> b;
    long long d = (n/(a+b)) * a; //青の個数
    long long e = n%(a+b);
    if(e >= a){
        cout << d+a << endl;
    }else{
        cout << d+e << endl;
    }

}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::Read;

const MOD: i64 = 1_000_000_007;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n = iter.next().unwrap().parse().unwrap();
    let m = iter.next().unwrap().parse().unwrap();
    let A: Vec<usize> = (0..n)
        .map(|_| iter.next().unwrap().parse::<usize>().unwrap() - 1)
        .collect();
    let mut S = vec![0i64; 2 * m + 2];
    let mut sum = 0i64;
    for i in 0..n - 1 {
        if A[i] < A[i + 1] {
            S[A[i] + 2] += 1;
            S[A[i + 1] + 1] -= 1;
            sum += (A[i + 1] - A[i]) as i64;
        } else {
            S[A[i] + 2] += 1;
            S[m + A[i + 1] + 1] -= 1;
            sum += (A[i + 1] + m - A[i]) as i64;
        }
    }
    //    dbg!(&S);
    for i in 0..2 * m {
        S[i + 1] += S[i]
    }
    //    dbg!(&S);
    for i in 0..n - 1 {
        if A[i] < A[i + 1] {
            S[A[i + 1] + 1] -= (A[i + 1] - A[i] - 1) as i64;
        } else {
            S[m + A[i + 1] + 1] -= (m + A[i + 1] - A[i] - 1) as i64;
        }
    }
    for i in 0..2 * m {
        S[i + 1] += S[i]
    }
    //    dbg!(&S);

    for i in 0..m {
        S[i] += S[i + m]
    }

    println!("{}", sum - S.iter().max().unwrap());
}


Measured memory_bytes: 8444
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  string S; cin >> S;

  int ret = 1000;
  for(auto i=0u; i<S.size()-2; ++i) {
    auto s = S.substr(i, 3);
    ret = min(ret, abs(753-stoi(s)));
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 500000
#define INFTY 1000000000

int count = 0;

void merge(int *A,int left,int mid,int right){
  int i,j,k,n1,n2,L[MAX],R[MAX];

  n1 = mid - left;
  n2 = right - mid;

  for (i = 0; i < n1; i++)
    L[i] = A[left + i];
  for (i = 0 ; i < n2; i++)
    R[i] = A[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for( k = left; k < right; k++){
    count++;
    if (L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{ 
      A[k] = R[j];
      j = j + 1;
    }
  }
  
}

void mergeSort(int *A,int left,int right){
  int mid;

  if ((left + 1) < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}


int main(){
  int i,l,A[MAX];

  scanf("%d",&l);
  for(i = 0; i < l; i++)
    scanf("%d",&A[i]);
  mergeSort(A,0,l);
  
  for(i = 0; i < l-1; i++)
    printf("%d ",A[i]);
  printf("%d\n%d\n",A[l-1],count);
  
  return 0;
}



Measured memory_bytes: 5624
function Main(input) {
    input = input.split(" ");
  	const total = parseInt(input[0]);
  	const foot = parseInt(input[1]);
  	let bool = false;
  	for(let i=0; i<=total; i++){
    	if(4*i+2*(total-i) == foot){
        	console.log("Yes");
          	bool=true;
          	break;
        }
    }
  if(!bool){
  	console.log("No");
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29632
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 1e6+2;
const ll mod = 1e9+7;



int main(){ 
	speedhack()
	int n; cin >> n;
	int prev = 0;
	bool ok = true;
	for(int i = 1; i <= n; i++){
		int x; cin >> x;
		if(x > prev){
			x--;
			prev = x;
		}else if(prev > x){
			ok = false;
		}else{
			prev = x;
		}
	}
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int n, l;
string s[110];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> n >> l;
    FOR(i,1,n) cin >> s[i];
    sort(s+1, s+n+1);
    FOR(i,1,n) cout << s[i];
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int len = s.size();
    int ans = 0;
    int l = 0;
    for(int i = 0; i < len; i++)
    {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            l++;
            ans = max(ans, l);
        }
        else
        {
            l = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
	int a[3];
	int tmp;
	
	for(int t=0;t<3;t++)
		cin>>a[t];

	for(int i=0;i<3;i++){
		for (int j=i+1; j<3; ++j) {
			if (a[i] > a[j]) {
		        tmp =  a[i];
		        a[i] = a[j];
		        a[j] = tmp;
	        }
		}
	}
	cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
	return 0;
}


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

int main(){
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  vector<long long> tab(n);
  for(int i = 0; i < n; i++) cin >> tab[i];
  vector<long long> dp(n);

  dp[0] = 0;
  dp[1] = abs(tab[1] - tab[0]);
  for(int i = 2; i < n; i++){
    dp[i] = min(dp[i-1] + abs(tab[i] - tab[i-1]),dp[i-2] + abs(tab[i] - tab[i-2]));
  }
  cout << dp[n-1];
}


Measured memory_bytes: 1792
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    S = input()
    T = input()
    mc = 100000
    for i in range(len(S) - len(T) + 1):
        c = 0
        si = S[i:i + len(T)]
        for k in range(len(T)):
            if si[k] != T[k]:
                c += 1
        mc = min(mc, c)
    print(mc)

if __name__ == '__main__':
    main()


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    string s;
    cin >> s;
    int cnt = 0;

    if (s[0] == 'o')
        cnt++;
    if (s[1] == 'o')
        cnt++;
    if (s[2] == 'o')
        cnt++;

    cout << 700 + cnt * 100 << endl;
}


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


int main(){
    int n, t;
    cin >> n >> t;
    int ans = 100000;
    int is_min = 100000;
    REP(i, n){
        int c, time;
        cin >> c >> time;
        if (time <= t){
            ans = min(ans, c);
        }
    }
    if (ans == 100000) cout << "TLE\n";
    else cout << ans << "\n";
}


Measured memory_bytes: 256
H,W,A,B = map(int,input().split())
MOD = 10**9+7

fact = [1]*200001
t = 1
for i in range(1,200001):
    t = (t*i)%MOD
    fact[i] = t

def ncr(n,r):
    return (fact[n] * pow(fact[r],MOD-2,MOD) % MOD) * pow(fact[n-r],MOD-2,MOD) % MOD

Ans = 0
for i in range(H-A):
    Ans += ncr(i+B-1,i)*ncr(W-B+H-i-2,W-B-1)

print(Ans%MOD)

Measured memory_bytes: 10868
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

aarr=sorted(limii())
barr=sorted(limii())
carr=sorted(limii())

ans=0

for i in range(n):
    temp1=bisect_left(aarr,barr[i])
    temp2=n-bisect_right(carr,barr[i])
    #print(temp1,temp2)
    if temp1>0 and temp2>0:
        ans+=temp1*temp2
print(ans)



Measured memory_bytes: 120228
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        System.out.println(N * (N - 1) / 2 + M * (M - 1) / 2);
    }
}

Measured memory_bytes: 22356
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	long n,k;
	cin >> n >> k;
	long mod_0 = 0, mod_half = 0;
	for (long i=1;i<=n;++i) {
		if (i%k==0) ++mod_0;
		if (k%2==0 && i%k==k/2) ++mod_half;
	}
	cout << mod_0*mod_0*mod_0 + mod_half*mod_half*mod_half << "\n";
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

// [lb, ub) の範囲で val を超える要素が初めて出てくるインデックスを返す
// なければ -1 を返す
// -1 を返すとこ以外 std::upper_bound と同じ
// 同じ数が複数ある場合は一番小さいインデックスを返す
static inline ll bin_search3(const vector<ll>& v, ll lb, ll ub, ll val) {
    lb--; ub--;
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if(v[mid] > val) { ub = mid; }
        else { lb = mid; }
    }
    // この時点で lb + 1 = ub
    return (v[ub] > val) ? ub : -1;
}

// [lb, ub) の範囲で val 未満の要素で最大のもののインデックスを返す
// なければ -1 を返す
// 同じ数が複数ある場合は一番大きいインデックスを返す
static inline ll bin_search5(const vector<ll>& v, ll lb, ll ub, ll val) {
    lb--; ub--;
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if(v[mid] >= val) { ub = mid; }
        else { lb = mid; }
    }
    // この時点で lb + 1 = ub
    if(v[ub] < val) { return ub; }
    if(lb < 0 || v[lb] >= val) { return -1; }
    return lb;
}

int N;
vector<int> L;

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

    cin >> N;
    L.resize(N);
    REP(i, N) { cin >> L[i]; }
    SORT(L);

    ll ans = 0;
    REP(i, N) {
        for(int j = i + 1; j < N; ++j) {
            // 下を見つける
            int max_l = max(L[i], L[j]);
            int min_l = min(L[i], L[j]);
            int l_ind = bin_search3(L, 0, L.size(), max_l - min_l);
            int r_ind = bin_search5(L, 0, L.size(), max_l + min_l);
            if(l_ind >= 0 && r_ind >= 0 && l_ind <= r_ind) { ans += r_ind - l_ind + 1; }
            if(l_ind <= i && i <= r_ind) { ans--; }
            if(l_ind <= j && j <= r_ind) { ans--; }
        }
    }

    printf("%lld\n", ans / 3);

    return 0;
}


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

int main()
{
    long long a, b, c, k;
    cin >> a >> b >> c >> k;

    if( a >= k ){
        cout << k << endl;
    }
    else if( k > a && (a+b) >= k ){
        cout << a << endl;
    }
    else if( k > (a+b) && (a+b+c) >= k ){
        cout << a-(k-a-b) << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstring>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

ll INF = 1LL << 60;

vector<int> S;

bool isOK(int index, int key) {
	if (S[index] >= key) return true;
	else return false;
}

int binary_search(int key) {
	int ng = -1;
	int ok = (int)S.size();

	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (isOK(mid, key)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main() {
	int n, q;
	cin >> n;
	S.resize(n);
	for (int i = 0; i < n; i++) cin >> S[i];
	cin >> q;
	int count = 0;
	for (int i = 0; i < q; i++) {
		int T;
		cin >> T;
		int a = binary_search(T);
		if (a == S.size()) continue;
		if (S[a] != T) continue;
		count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define NIL -(long long)(1e9)
#define ll long long
// long long n,w;
typedef struct Node node;
struct Node
{	int myV;
	vector<int> Ways;
	//vector<pair<int,int>> NoWays;
	bool visit=0;
	int dist=0;
	int myins=1;
};
void self_max (int&a ,int b){
 a= max(a,b);
return;
}
std::vector<node*> graph;
int dfs(int a){
	graph[a]->visit=1;
	for(int b : graph[a]->Ways){
		self_max(graph[b]->dist, graph[a]->dist + 1);
		graph[b]->myins--;
		if(graph[b]->myins ==0  ){		//&&!graph[b]->visit
			dfs(b);
		}
	}

return 0;
}

int n,m;

int main () {
//memset(dp,-1,sizeof(dp));
 
cin>>n>>m;
node bos;
graph.pb(&bos);
for (int i = 1; i <= n; ++i)
{	node* temp= new node;
	temp->myV=i;
	graph.pb(temp);
	graph[0]->Ways.pb(i);

}
for (int i = 0; i < m; ++i)
{	int d1,d2;
	cin>>d1>>d2;
	graph.at(d1)->Ways.pb(d2);
	//graph.at(d2)->NoWays.pb({d1,0});
	graph[d2]->myins++;
}
dfs(0);
/*
for (int i = 0; i <= n; ++i)
{if(graph[i]->visit==0 && graph[i]->myins==0 ){
	dfs(i);}
}*/
int ans=0;
for (int i = 0; i <= n; ++i)
	{
		self_max(ans,graph[i]->dist);
	}	

cout<<ans-1;
}









Measured memory_bytes: 11764
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int h=sc.nextInt();
		int w=sc.nextInt();
		int k=sc.nextInt();
		char[][] map=new char[h][w];
		boolean[] sp=new boolean[h];
		for(int i=0; i<h; i++){
			String s=sc.next();
			for(int j=0; j<w; j++){
				map[i][j]=s.charAt(j);
				if(map[i][j]=='#'){
					sp[i]=true;
				}
			}
		}
		int[][] ans=new int[h][w];
		int num=1;
		int count=0;
		int kk=0;
		for(int i=0; i<h; i++){
			if(!sp[i]){
				continue;
			}else{
				kk=i;
			}
			for(int j=0; j<w; j++){
				if(map[i][j]=='#'){
					count++;
					if(count>1){
						num++;
					}
				}
				ans[i][j]=num;
			}
			count=0;
			num++;
		}
		int up=kk+1;
		while(up<h){
			if(!sp[up]){
				for(int i=0; i<w; i++){
					ans[up][i]=ans[up-1][i];
				}
			}
			up++;
		}
		int down=kk-1;
		while(down>-1){
			if(!sp[down]){
				for(int i=0; i<w; i++){
					ans[down][i]=ans[down+1][i];
				}
			}
			down--;
		}
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				System.out.print(ans[i][j]+" ");
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 46280
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <sstream>
using namespace std;

map<int,int> m;
map<int,int> v;

int main() {
  string line;
  int p = 0;
  while(getline(cin, line)) {
    if(line.size() == 0) {
      p = 1;
      continue;
    }
    replace(line.begin(), line.end(), ',', ' ');
    stringstream ss;
    ss << line;
    int a;
    ss >> a;
    ++m[a];
    v[a] |= (1<<p);
  }
  for(map<int,int>::iterator it = m.begin(); it != m.end(); ++it) {
    if(v[it->first] == (1<<2)-1)
      cout << it->first << " " << it->second << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A =[list(map(int,input().split())) for i in range(N)]

ans = 0

for i in range(N):
    temp=0
    for j in range(M):
        temp += A[i][j]*B[j]
    if temp+C>0:
        ans +=1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
    int X,Y;
    int big,small;
    scanf("%d %d",&X,&Y);
    if(Y>=X){
        if(Y%X==0&&Y-X<X){
            printf("-1");
            return 0;
        }else{
            printf("%d",X);
        }
    }else{
        if(X%Y==0){
            printf("-1");
            return 0;
        }else{
            printf("%d",X);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define i64 long long
#define N (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;
bool cmp(pii p1, pii p2){
	if(p1.L == p2.L) return p1.R < p2.R;
	return p1.L < p2.L;
}
int main() {
	// your code goes here
	int n;
	cin>>n;
	vector<pii> range(n);
	for(int i=0;i<n;i++) cin>>range[i].L>>range[i].R;
	sort(all(range), cmp);
	int cnt = range[0].R-range[0].L+1;
	for(int i=1;i<n;i++){
		if(range[i].L > range[i-1].R){ //no overlap
			cnt+=(range[i].R-range[i].L+1);
		}
		else if(range[i].L >=range[i-1].L and range[i].R <= range[i-1].R){
			continue; // complete overlap, so already included
		}
		else{
			cnt+=(range[i].R-range[i-1].R);
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;


#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define                   pi acos(-1)


int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    int i;
    for(i=0; i<s.size(); i++){
        if(i%2==0 && s[i]!='h')
            break;
        else if(i%2 && s[i]!='i')
            break;
    }
    if(s.size()==1 || s.size()%2!=0)
        cout<<"No"<<endl;
    else if(i==s.size())
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    End;
}
/* pray for me
Do before die
*/





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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;
bool ng[20][20];
int dp[20][20];
signed main(){
    while(cin>>W>>H,W||H){
        memset(ng,0,sizeof(ng));
        int N;cin>>N;
        rep(i,N){
            int x,y;
            cin>>x>>y;
            x--;y--;
            ng[y][x]=true;
        }
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        rep(i,H)rep(j,W){
            if(ng[i][j])dp[i][j]=0;
            dp[i+1][j]+=dp[i][j];
            dp[i][j+1]+=dp[i][j];
        }
        cout<<dp[H-1][W-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <vector>
#include <iostream>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	vector<vector<int> > a(H, vector<int>(W));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> a[i][j];
		}
	}
	vector<pair<int, int> > ord;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			ord.push_back(make_pair(i, i % 2 == 0 ? j : W - j - 1));
		}
	}
	vector<vector<int> > ans;
	int pre = -1;
	for (int i = 0; i < H * W; ++i) {
		if (a[ord[i].first][ord[i].second] % 2 == 1) {
			if (pre == -1) {
				pre = i;
			}
			else {
				for (int j = pre; j < i; ++j) {
					ans.push_back({ ord[j].first + 1, ord[j].second + 1, ord[j + 1].first + 1, ord[j + 1].second + 1 });
				}
				pre = -1;
			}
		}
	}
	cout << ans.size() << endl;
	for (vector<int> i : ans) {
		cout << i[0] << ' ' << i[1] << ' ' << i[2] << ' ' << i[3] << endl;
	}
	return 0;
}

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

typedef long long ll;
 

int main()
{
	//Write code here
	
	string s, t;
	cin >> s >> t;
	int res = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		/* code */
		if (s[i] != t[i]){
			res++;
		}
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 3464
#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 N;
	cin >> N;

	vector<ll> T(N), A(N);
	rep(i, N) {
		cin >> T[i] >> A[i];
	}
	ll tmp;
	for (int i = 1; i < N; i++)
	{
		tmp = max((T[i - 1] + T[i] - 1) / T[i], (A[i - 1] + A[i] - 1) / A[i]);
		T[i] *= tmp;
		A[i] *= tmp;
	}
	ll ans = T[N - 1] + A[N - 1];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
use std::io;
use std::str;

/// Reads white-space separated tokens one at a time.
pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buffer: vec![],
        }
    }

    /// Use "turbofish" syntax token::<T>() to select data type of next token.
    ///
    /// # Panics
    ///
    /// Panics if there's an I/O error or if the token cannot be parsed as T.
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let s: String = scan.token();
    let t: String = scan.token();
    let mut ans = 0;
    for it in s.chars().zip(t.chars()) {
        let (cs, ct) = it;
        if cs != ct {
            ans += 1;
        }
    }
    writeln!(out, "{}", ans).ok();
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}

Measured memory_bytes: 2744
#include <bits/stdc++.h>
#include <iomanip>
#define fi(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define imax INT_MAX
#define imin INT_MIN
#define lmin LONG_LONG_MIN
#define lmax LONG_LONG_MAX
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define st first
#define nd second
 
using namespace std;
typedef long long ll;
 
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;
 
int l[3000],r[3000];
int Max[3000];
 
int main(){
	string a,b;cin>>a>>b;
	if(a==b){
		puts("0");return 0;
	}
	int n=a.size();
	bool ok=false;
	rep(i,n){
		if(b[i]=='1')ok=true;
	}
	if(!ok){
		puts("-1");return 0;
	}
	rep(i,n){
		if(b[i]=='1'){
			l[i]=r[i]=0;
			continue;
		}
		int c=0;
		for(int j=(i+n-1)%n;j!=i;j=(j+n-1)%n){
			c++;
			if(b[j]=='1'){
				l[i]=c;
				break;
			}
		}
		c=0;
		for(int j=(i+1)%n;j!=i;j=(j+1)%n){
			c++;
			if(b[j]=='1'){
				r[i]=c;
				break;
			}
		}
	}
	int ans=INT_MAX;
	rep(i,n){
		vector<P>v;
		int d=0;
		rep(j,n){
			int x=(j+i)%n;
			if(a[x]!=b[j]){
				d++;
				v.push_back(P(l[x],r[x]));
			}
		}
		sort(v.begin(),v.end());
		Max[v.size()]=0;
		for(int j=v.size()-1;j>=0;j--){
			Max[j]=max(Max[j+1],v[j].second);
		}
		int pos=(n-i)%n;
		rep(j,v.size()+1){
			int L=(j?v[j-1].first:0);
			int R=Max[j];
			int pl=(n-L)%n,pr=R%n;
			int cnt=2*L+R+min((pr+n-pos)%n,(pos+n-pr)%n);
			cnt=min(cnt,2*R+L+min((pl+n-pos)%n,(pos+n-pl)%n));
			ans=min(ans,cnt+d);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=2e5+5,OO=1e18;
int a[N];
int v[6][N];
int dp[6][N];
int32_t main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        v[1][i]=a[i];
        v[2][i]=a[i]&1;
        v[3][i]=(a[i]&1)^1;
        v[4][i]=a[i]&1;
        v[5][i]=a[i];
        if(!a[i])v[2][i]=v[4][i]=2;
    }
    forn(i,6)forn(j,n+1)dp[i][j]=OO;
    dp[0][0]=0;
    for(int i=1;i<=5;++i){
        for(int j=1;j<=n;++j){
            forn(k,i+1)upn(dp[i][j],dp[k][j-1]);
            dp[i][j]+=v[i][j];
        }
    }
    int ans=OO;
    forn(i,6)upn(ans,dp[i][n]);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 22408
import sys
res = dict()
dll = [None] * 2000000
left = 0
right = 0
n = int(input())
for inpt in sys.stdin.read().splitlines():
    i = inpt.split()
    if i[0] == "insert":
        x = int(i[1])
        dll[left] = x
        if(x in res):
            res[x].add(left)
        else:
            res[x] = set([left])
        left += 1
    if i[0] == "delete":
        x = int(i[1])
        if(x in res):
            ind = max(res[x])
            dll[ind] = None
            res[x].remove(ind)
            if(len(res[x]) == 0):
                del res[x]
            if(ind == (left - 1)):
                left = ind
            if(ind == right):
                right += 1
    if i[0] == "deleteFirst":
        left -= 1
        x = dll[left]
        res[x].remove(left)
        if(len(res[x]) == 0):
            del res[x]
        dll[left] = None
    if i[0] == "deleteLast":
        right += 1
    # print(dll[right:left])
ret = []
for x in dll[right:left]:
    if(x is not None):
        ret.append(str(x))
ret.reverse()
print(" ".join(ret))

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

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

    long long n, x;
    cin >> n >> x;

    cout << 3 * (n - __gcd(n - x, x)) << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdint>
using namespace std;

#define N 300000

char s[N];
int lsum[N] = {0};

int main() {
	int n;
	int ans = INT32_MAX;

	cin >> n;
	cin >> s;

	int cnt = 0;
	for( int i = 0; i < n - 1; i++ ) {
		if( s[i] == 'W' ) {
			cnt++;
		}
		lsum[i+1] = cnt;
	}

	cnt = 0;
	for( int i = n - 1; i >= 0; i-- ) {
		int n = lsum[i] + cnt;
		if( n < ans ) {
			ans = n;
		}
		if( s[i] == 'E' ) {
			cnt++;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  double l;
  cin >> l;
  cout << fixed<<setprecision(12)<<pow(l / 3, 3) << endl;
}


Measured memory_bytes: 384
function LinkedNode(element) {
    this.element = element;
    this.previous = null;
    this.next = null;
}

function LinkedList() {
    this.dummy = new LinkedNode(null);
    this.dummy.previous = this.dummy;
    this.dummy.next = this.dummy;
}

LinkedList.prototype.getFirst = function() {
    return this.dummy.next.element;
};

LinkedList.prototype.getLast = function() {
    return this.dummy.previous.element;
};

LinkedList.prototype.addFirst = function(element) {
    var firstNode = this.dummy.next;
    var node = new LinkedNode(element);
    node.previous = this.dummy;
    node.next = firstNode;
    this.dummy.next = node;
    firstNode.previous = node;
};

LinkedList.prototype.remove = function(element) {
    var node = this.dummy;
    while (node = node.next) {
        if (node == this.dummy) {
            return;
        }
        if (node.element === element) {
            break;
        }
    }
    var previousNode = node.previous;
    var nextNode = node.next;
    previousNode.next = nextNode;
    nextNode.previous = previousNode;
};

LinkedList.prototype.removeFirst = function() {
    var firstNode = this.dummy.next;
    var secondNode = firstNode.next;
    this.dummy.next = secondNode;
    secondNode.previous = this.dummy;
};

LinkedList.prototype.removeLast = function() {
    var lastNode = this.dummy.previous;
    var secondLastNode = lastNode.previous;
    this.dummy.previous = secondLastNode;
    secondLastNode.next = this.dummy;
};

LinkedList.prototype.toArray = function() {
    var array = [];
    var node = this.dummy;
    while (node = node.next) {
        if (node == this.dummy) {
            return array;
        }
        array.push(node.element);
    }
};

(function(input) {
    var p = input.split('\n');
    var n = Number(p.shift());
    var commands = p.slice(0, n);
    var linkedList = new LinkedList();

    commands.forEach(function(e) {
        linkedList = execCommand(linkedList, e);
    });

    console.log(linkedList.toArray().join(' '));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function execCommand(linkedList, c) {
    var a = c.split(' ');
    var command = a.shift();
    var arg = Number(a.shift());
    switch (command) {
        case 'insert':
            linkedList.addFirst(arg);
            break;
        case 'delete':
            linkedList.remove(arg);
            break;
        case 'deleteFirst':
            linkedList.removeFirst();
            break;
        case 'deleteLast':
            linkedList.removeLast();
            break;
    }
    return linkedList;
}

Measured memory_bytes: 227672
# -*- coding: utf-8 -*-
N = int(input())
S = []
for i in range(N):
  S.append(input())

dic = {}

for i in range(N):
  if(S[i] in dic):
    dic[S[i]] += 1
  else:
    dic[S[i]] = 1

dic_sorted = sorted(dic.items(), key=lambda x:x[1], reverse=True)
NN = len(dic_sorted)

st = [dic_sorted[0][0]]
num = dic_sorted[0][1]

for i in range(1, NN):
  if(dic_sorted[i][1] == num):
    st.append(dic_sorted[i][0])
  else:
    break

st.sort()
for item in st:
  print(item)


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


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  sort(a.begin(),a.end(),greater<int>());
  int alice,bob;
  alice=0;
  bob=0;
  for(int i=0;i<n;++i){
    if(i%2==0){
      alice+=a[i];
    }else{
      bob+=a[i];
    }
  }
  cout << alice-bob << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
x_str = input().split()
xs = [int(c) for c in x_str]

xs_len = len(xs)
center = (xs_len - 1)//2

c_xs = xs[:]
c_xs.sort()

for x in xs:
    print(c_xs[center+1] if x <= c_xs[center] else c_xs[center])


Measured memory_bytes: 29504
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <bits/stdc++.h>
#include <complex>
#include <numeric>
#include <climits>
#include <stack>
#include <locale.h>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <ctime>
#include <deque>
#include <queue>
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define rept(i,n)for(int i=0;i<(int)(n);i++)
#define fi first
#define se second
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	vector<int> X(n+1);
	vector<int> S(n+1);
	for(int i=0;i<n;i++)X[i+1]=X[i]^a[i],S[i+1]=S[i]+a[i];
	ll ans=0;
	for(int l=0;l<n;l++)
	{
		int lb=l+1,ub=n+1;
		while(ub-lb>1)
		{
			int mid=(lb+ub)/2;
			if((X[mid]^X[l])==(S[mid]-S[l]))lb=mid;
			else ub=mid;
		}
		ans+=lb-l;
//		cout<<ub<<" "<<lb<<" "<<ans<<endl;
	}
	cout<<ans;
    return 0;
}


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

using namespace std;

#define mod1 1000000007
#define mod2 998244353
#define int long long int
#define pii pair<int,int>
#define vpii vector<pii>
#define vi vector<int>
#define fi first
#define se second
#define psb push_back
#define ppb pop_back
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define all(x) x.begin(),x.end()
// #define endl "\n"

const int xn=1;
const int maxn=xn*1e3+5;
int ar[maxn];
vpii ans;

void solve()
{
	int n;
	cin>>n;
	int c1=0,c2=0,c3=0,c4=0;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		if(s=="AC")
			c1++;
		else if(s=="WA")
			c2++;
		else if(s=="TLE")
			c3++;
		else 
			c4++;
	}
	cout<<"AC x "<<c1<<endl;
	cout<<"WA x "<<c2<<endl;
	cout<<"TLE x "<<c3<<endl;
	cout<<"RE x "<<c4<<endl;
}	

int32_t main()
{
	fio;
	int t;
	// cin>>t;
	t=1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3652
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
			Scanner sc = new Scanner(System.in);
			String str = sc.next();
			if( Character.isUpperCase( str.charAt( 0 ) ) ) {
				System.out.println("A");
			}else {
				System.out.println("a");
			}
	}

}

Measured memory_bytes: 27008
s = 5.times.map {gets.split.map(&:to_i)[0]}
r =  s.map{|n| n%10 }.map{|n| n == 0 ? n = 10 : n}
rm = s.delete_at(r.index(r.min))
p s.map{|n| ((n.to_f*0.1).ceil)*10}.inject(:+) + rm

Measured memory_bytes: 1788
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e5+5;
int n,fa[N],dep[N],mrk[N],len,t[N];
vector<int>E[N];
void dfs(int u,int f){
	fa[u]=f;dep[u]=dep[f]+1;
	for(int v:E[u])if(v!=f)dfs(v,u);
}
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<n;++i){
		scanf("%d%d",&x,&y);
		E[x].push_back(y);E[y].push_back(x);
	}
	dfs(1,0);int P=0;
	for(int i=1;i<=n;++i)P=dep[i]>dep[P]?i:P;
	dfs(P,0);int Q=0;
	for(int i=1;i<=n;++i)Q=dep[i]>dep[Q]?i:Q;
	for(int i=Q;i;i=fa[i])mrk[i]=++len;
	for(int i=1;i<=n;++i)
		if(!mrk[i]){
			if(!mrk[fa[i]])return puts("-1"),0;
			++t[mrk[fa[i]]];
		}
	for(int i=1;i<=len;++i)
		if(t[i]!=t[len-i+1]){
			if(t[i]>t[len-i+1])
				reverse(t+1,t+len+1);
			break;
		}
	for(int i=1,j=0;i<=len;++i){
		for(int k=j+2;k<=j+t[i]+1;++k)printf("%d ",k);
		printf("%d ",j+1);j+=t[i]+1;
	}
	puts("");return 0;
}


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

int main() {
    int a;
    cin >> a;
    cout << a+a*a+a*a*a <<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int cnt[200010];

int main(){
    int n,k;
    cin>>n>>k;
    rep(i,n){
        int a;
        cin>>a;
        cnt[a]++;
    }

    int s=0;
    vector<int> v;
    rep(i,200010){
        if(cnt[i]){
            s++;
            v.push_back(cnt[i]);
        }
    }

    if(s<=k) cout<<0<<endl;
    else{
        k=s-k;
        sort(all(v));
        int ans=0;
        rep(i,k) ans+=v[i];
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 4896
#include<iostream>
#include<queue>
#include<vector>
#include<map>
using namespace std;

int main() {
    int N;
    cin>>N;
    int P[N], Q[N];
    for(int i=0;i<N;++i){
        cin>>P[i];
    }
    for(int i=0;i<N;++i){
        cin>>Q[i];
    }

    queue<vector<int> >que;
    vector<int> state;
    for(int i=0;i<N;++i){
        state.push_back(i+1);
        que.push(state);
        state.clear();
    }
    int a, b;
    int ans = 0;
    while(!que.empty()){
        state = que.front();
        /**
        for(int i=0;i<state.size();++i){
            cout<<state[i]<<" ";
        }
        cout<<endl;
        cout<<ans<<endl;
        **/
        que.pop();
        if(state.size()==N){
            /**
            bool tmpbool = true;
            map<int, int> tmpmap;
            for(int i=0;i<N;++i){
                if(tmpmap[state[i]]!=0){
                    tmpbool = false;
                }
                tmpmap[state[i]]++;
            }
            **/
            bool tmpbool = true;
            if (tmpbool){
                ans++;
                bool tmpP = true, tmpQ = true;
                for(int i=0;i<N;++i){
                    if(P[i] != state[i]) tmpP = false;
                    if(Q[i] != state[i]) tmpQ = false;
                }
                if(tmpP){
                    a = ans;
                }
                if(tmpQ){
                    b = ans;
                }
            }
        }
        else {
            for(int i=0;i<N;++i){
                bool tmpbool1 = true;
                for(int j=0;j<state.size();++j){
                    if(state[j]==i+1)tmpbool1 = false;
                }
                if(tmpbool1){
                    state.push_back(i+1);
                    que.push(state);
                    state.pop_back();
                }
            }
        }
    }
    if(a<b)cout<<b-a<<endl;
    else cout<<a-b<<endl;
}


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

main() {
    int N; cin >> N; int ans=0;
    map<int,int> m;
    rep(i,N){
        int a; cin >> a;
        m[a]++;
    }
    for(auto p:m){
        if(p.first>p.second){
            ans+=p.second;
        }
        else ans+=p.second-p.first;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    int cnt=0;
    for(int i=0; i<3; i++) {
        if(s[i]==t[i]) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

char s[5];
int n;

bool compare(const char &a, const char &b)
{
	return a < b;
}


int main()
{
	scanf("%s", &s);
	
	n = strlen(s);
	sort(s, s + n, compare);
	
	if ((s[0] == s[1]) && (s[2] == s[3]) && (s[1] != s[2]))
		printf("Yes\n");
	else
		printf("No\n");
	
	return 0;
}



Measured memory_bytes: 128
import java.util.*;

public class Main{

static ArrayList<Integer[]> fr=new ArrayList<Integer[]>();
static ArrayList<Integer[]> to=new ArrayList<Integer[]>();

    private static final Scanner scan = new Scanner(System.in);
    static int count = 0;
    public static void main(String[] args){

        for(;;){
            int n = scan.nextInt();
            int s = scan.nextInt();
            if(n == 0 && s == 0)break;
            count = 0;

    Integer[] ne=new Integer[3];
    ne[0]=0;
    ne[1]=n;
    ne[2]=s;    
    fr.add(ne);    
    for(;;){
        if(fr.size()==0)break;
        for(Integer[] sd:fr){
             if(sd[0] > sd[2] || sd[1] == 0 || sd[0] > 9){continue;}
                    if(sd[1] == 1 && sd[0] == sd[2])count++;            
            Integer[] ne1=new Integer[3];
            Integer[] ne2=new Integer[3];

            ne1[0]=sd[0]+1;
            ne1[1]=sd[1]-1;
            ne1[2]=sd[2]-sd[0];
            ne2[0]=sd[0]+1;
            ne2[1]=sd[1];
            ne2[2]=sd[2];


            to.add(ne1);
            to.add(ne2);



        }
    fr.clear();
    for(Integer[] q:to){
        fr.add(q);
        }
    to.clear();

    }


            System.out.printf("%d\n", count);
        }
    }


}

Measured memory_bytes: 27256
#include<bits/stdc++.h>
#define maxn 100100
using namespace std;
typedef long long ll;
ll sta[maxn],g[maxn],c[maxn],x;
int n,tp,q;
int main(){
	scanf("%d%d",&n,&q);
	sta[++tp]=n;
	for(int i=1;i<=q;++i){
		scanf("%lld",&x);
		while(tp&&sta[tp]>=x)tp--;
		sta[++tp]=x;
	}
	c[tp]=1;
	for(int i=tp;i>=2;--i){
		c[i-1]+=sta[i]/sta[i-1]*c[i];
//		printf("[%lld,%lld]",sta[i],sta[i-1]); 
		ll A=sta[i]%sta[i-1];
		while(A>=sta[1]){
//			puts("[ok]");
			int l=1,r=i,ans=0;
			while(l<=r){
				int mid=l+r>>1;
				if(sta[mid]<=A)ans=mid,l=mid+1;
				else r=mid-1;
			}
			if(!ans)exit(-1);
			c[ans]+=A/sta[ans]*c[i],A%=sta[ans];
		}
		g[A]+=c[i];
	}
	g[sta[1]]+=c[1];
	for(int i=n;i>=1;--i)g[i]+=g[i+1];
	for(int i=1;i<=n;++i)printf("%lld\n",g[i]);
} 

Measured memory_bytes: 4096
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
//fflush(stdin);
class abc
{
    public:
    ll w,v;
};
bool fun (abc x, abc y)
{
    return x.w<y.w;
}
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,W;
    cin>>n>>W;
    abc arr [n];
    rep (i,0,n)
    {
        cin>>arr[i].w;
        cin>>arr[i].v;
    }
    ll dp[n][W+1];
    rep (i,0,n)
    {
        rep (j,0,W+1)
        {
            dp[i][j]=0;
        }
    }
    rep (i,0,W+1)
    {
        if (arr[0].w<=i)
        dp[0][i]=arr[0].v;
    }
    rep (i,1,n)
    {
        rep (j,0,W+1)
        {
            if (j-arr[i].w>=0)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-arr[i].w]+arr[i].v);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    // rep (i,0,n)
    // {
    //     rep (j,0,W+1)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[n-1][W]<<endl;



}


Measured memory_bytes: 78336
/* ex6_2.c i18n
    dada__      */
#include<stdio.h>
#include<string.h>
#define SIZE 100

int main(void){
    int length;
    char word[SIZE];

    scanf("%s", word); //単語の入力
    length=strlen(word); //単語の長さの取得

    printf("%c%d%c\n", word[0], length-2, word[length-1]); //出力
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	static int A,B,C;
	static String S;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long ans=0;
		int zero=0;
		int one=0;
	S=sc.nextLine();
	String s[]=S.split("");
	for(int i=0;i<S.length();i++) {
		if(s[i].equals("0")) {
			zero++;
		}else {
			one++;
		}
	}
ans=Math.min(zero, one);
ans*=2;
		System.out.println(ans);
	}
}


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

int main(){
  int N, M;
  while(cin >> N >> M,N){
    vector<int> V(M);
    for(int i = 0; i < N; ++i){
      int d, v;
      cin >> d >> v;
      --d;
      V[d] = max(V[d],v);
    }
    int ans = 0;
    for(auto v: V) ans += v;
    cout << ans << endl;
  }
}



Measured memory_bytes: 3100