akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define int ll
using pii = pair<int, int>;

int fval[203020];
int org_plus, org, org_minus;
string str;
int cur_p;
ll modpow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int32_t main()
{
	usecppio
    for (int i = 1; i<=202000; i++)
    {
        int x = i, ct = 0;
        while (x)
        {
            int p = __builtin_popcountll(x);
            x %= p;
            ct++;
        }
        fval[i] = ct;
    }
    int n; cin >> n;
    cin >> str;
    for (auto it:str)
        if (it=='1')
            cur_p ++;
    for (int i = 0; i<n; i++)
    {
        if (str[i]=='1')
        {
            if (cur_p >= 1)
                org += modpow(2, n-i-1, cur_p);
            if (cur_p > 1)
                org_minus += modpow(2, n-i-1, cur_p-1);
            org_plus += modpow(2, n-i-1, cur_p+1);
        }
    }
    for (int i = 0; i<n; i++)
    {
        if (str[i] == '1')
        {
            if (cur_p == 1)
            {
                cout << 0 << '\n'; continue;
            }
            else if (cur_p > 1)
            {
                int nxt = org_minus + cur_p-1 - modpow(2, n-i-1, cur_p-1);
                nxt %= (cur_p-1);
                cout << fval[nxt]+1 << '\n'; continue;
            }
        }
        else if (str[i]=='0')
        {
            int nxt = org_plus + modpow(2, n-i-1, cur_p+1);
            nxt %= (cur_p + 1);
            cout << fval[nxt]+1 << '\n'; continue;
        }
    }
}

Measured memory_bytes: 5328
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
string A,B,C;






int main()
{

	cin >> A >> B >> C;


	char a = toupper(A[0]);
	char b = toupper(B[0]);
	char c = toupper(C[0]);

	cout << a << b << c << endl;




}


Measured memory_bytes: 256
a = []
b = []
while True:
    x,y = map(int,input().split())
    if x == 0 and y == 0:
        break
    else:
        a.append(x)
        b.append(y)
        
for i in range(0,len(a)):
    if a[i] >= b[i]:
        print(b[i],a[i])
    elif a[i] < b[i]:
        print(a[i],b[i])

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

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, p1, p2, x;
            var word = Console.ReadLine().Split(' ');
            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);

            p1 = n*a;
            p2 = b;

            if (p1 < p2)
                x = p1;
            else x = p2;
            Console.WriteLine(x);
            Console.ReadLine();
        }
    }
}


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

int main(void){
	int i,sum,x[5],ans[3];
	bool flg[3];

	while(1){
		memset(flg,0,sizeof(flg));
		for(i=0;i<5;i++){
			cin>>x[i];
			if(x[i] == 0) return 0;
			flg[x[i]-1] = true;
		}

		sum = flg[0] + flg[1] + flg[2];
		if(sum==1 || sum==3){
			for(i=0;i<5;i++) printf("3\n");
		}
		else{
			if(flg[0] && flg[1]){
				ans[0] = 1;
				ans[1] = 2;
			}
			else if(flg[0] && flg[2]){
				ans[0] = 2;
				ans[2] = 1;
			}
			else{
				ans[1] = 1;
				ans[2] = 2;
			}
			for(i=0;i<5;i++){
				printf("%d\n",ans[x[i]-1]);
			}
		}
	}
}

Measured memory_bytes: 0
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Main {

    public static int frog2(int[] arr, int k) {
        if(arr == null || arr.length == 0) {
            return 0;
        }
        int[] dp = new int[arr.length];

        for(int i = 1; i < arr.length; i++) {
            int min = Integer.MAX_VALUE;
            for(int j = 1; j <= Math.min(i, k); j++) {
                min = Math.min(min, dp[i - j] + Math.abs(arr[i] - arr[i - j]));
            }
            dp[i] = min;
        }
        return dp[arr.length - 1];
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        int[] arr = new int[n];
        int i = 0;
        while(sc.hasNextInt()) {
            arr[i] = sc.nextInt();
            i++;
        }
        
        System.out.println(frog2(arr, k));
  }
}


Measured memory_bytes: 57164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define PII pair<int,int>
#define s second
#define f first
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x)%MOD;
        }
        p = p >> 1;
        x = (x*x)%MOD;
    }
    return res;
}
vector<int> arr;
int n, K;
int dp[100005];
int solve(int k){
    if(k == 0){
        return 1;
    }
    if(dp[k] != -1){
        return dp[k];
    }
    int i = 0;
    int ans = 0;
    for(i = 0; i < n && arr[i] <= k; i++){
        int temp = solve(k-arr[i]);
        if(temp){
            ans = 1;
        }
    }
    return dp[k] =!ans;
}
int main() {
    IO;
    cin >> n >> K;
    memset(dp, -1, sizeof dp);
    arr.resize(n);
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    int ans = solve(K);
    cout << ((!ans) ? "First" : "Second");

    return 0;
}


Measured memory_bytes: 5376
def solve():
    n=int(input())
    A=list(map(int,input().split()))
    l=[]
    r=[]
    d={}
    x=[]
    for i in range(n):
        l.append(i+A[i])
        r.append(i-A[i])
        if(i+A[i] not in d):
            d[i+A[i]]=[0,0]
            x.append(i+A[i])
        if(i-A[i] not in d):
            d[i-A[i]]=[0,0]
            x.append(i-A[i])
        d[i+A[i]][0]+=1
        d[i-A[i]][1]+=1
    ans=0
    for i in x:
        ans+=d[i][0]*d[i][1]
    print(ans)
solve()

Measured memory_bytes: 119408
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    int n;
    cin >> n;

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

    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	std::vector<char> v;
	for (int i = 0; i < 3; ++i)
	{
		char x; cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	if(v[0]=='a' && v[1]=='b' && v[2]=='c')cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
typedef pair<int,int> pii;

#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

int dp[800][800];

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    char mat[h][w];
    int si, sj;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
            if(mat[i][j] == 'S')    si = i, sj = j;
        }
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[si][sj] = 0;
    queue<pii> q;
    q.push({si,sj});
    int ans = 1<<30;
    while(!q.empty()){
        pii p = q.front();  q.pop();
        int i = p.first, j = p.second;
        ans = min(ans, (min({i, h-1-i, j, w-1-j})+k-1)/k);
        if(dp[i][j] == k)   continue;
        for(int k = 0; k < 4; k++){
            int ni = i + di[k], nj = j + dj[k];
            if(!inRange(ni,0,h) || !inRange(nj,0,w) || mat[ni][nj] == '#' || dp[ni][nj] <= dp[i][j]+1)   continue;
            dp[ni][nj] = dp[i][j]+1;
            q.push({ni,nj});
        }
    }
    cout << ans+1 << endl;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
int main(){
  char str[10];
  int i,N,sum=0,num;
  
  scanf("%s",str);
  
  for(i=0;i<strlen(str);i++){
    //printf("%d\n",str[i]-'0');
    sum += (str[i]-'0');
  }
  num = atoi(str);
  if( num%sum == 0 )printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

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

int main()
{
  int n;
  cin>>n;

  cout<<n*n<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}


int main()
{
	long long n, dic_p = 0, dic_q = 0;
	string s;

	cin >> n;

	vector<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];


	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (p[j] > p[i])
				p[j]--;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (q[j] > q[i])
				q[j]--;
		}
	}

	for (int i = 0; i < n - 1; i++)
		dic_p += (p[i] - 1) * fact(n - i - 1);

	for (int i = 0; i < n - 1; i++)
		dic_q += (q[i] - 1) * fact(n - i - 1);

	cout << abs(dic_p - dic_q) << endl;

	return 0;
}

Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	int sum=0;
	int x=n;
	while(x>0){
		int rem=x%10;
		sum+=rem;
		x/=10;
	}
	if(n%sum==0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}


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

int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}

int main(void){
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    qsort (a,3,sizeof(int),sort); 
    printf("%d\n",10*a[2]+a[1]+a[0]);
	return 0 ;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct node_ {
	int v,c,next;
} node[3000001];
int head[1000001],e;
void addnode(int u,int v,int c) {
	e++;
	node[e].c=c;
	node[e].v=v;
	node[e].next=head[u];
	head[u]=e;
}
int n,m;
bool b[1000001],flag;
int d[1000001];
int L,R,D;
bool dfs(int x) {
	b[x]=1;
	for(int i=head[x]; i!=0; i=node[i].next) {
		int y=node[i].v,c=node[i].c;
		if(d[y]>d[x]+c) {
			if(b[y]) return 1;
			d[y]=d[x]+c;
			if(dfs(y))return 1;
		}
	}
	b[x]=0;
	return 0;
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=0; i<m; i++) {
		scanf("%d%d%d",&L,&R,&D);
		addnode(R,L,D);
		addnode(L,R,-D);
	}
	for(int i=1; i<=n; i++) {
		addnode(0,i,0);
	}
	memset(b,0,sizeof(b));
	memset(d,1000000,sizeof(d));
	d[0]=0;
	if(dfs(0)) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  string ans;
  cin >> n;
  while(n>=1){
    n--;
    ans += 'a'+n%26;
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<math.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
		if (a < 10 && b < 10)
		{
			printf("%d", a * b);
		}
		else
			printf("%d", -1);
	return 0;
}

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

#define MAX 21
 
double dis(double x1, double y1, double x2, double y2)
{
    double d;
    d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    return d;
}
 
int main()
{
    double x[MAX], y[MAX];
    int t = 0;
    double S = 0.0, z, a, b, c;
 
    while (1) {
	if(scanf("%lf,%lf",&x[t] ,&y[t]) == EOF) break;
	t++;
    }
 
    for (int i = 2; i < t; i++) {
	a = dis(x[0], y[0], x[i-1], y[i-1]);
	b = dis(x[0], y[0], x[i], y[i]);
	c = dis(x[i-1], y[i-1], x[i], y[i]);
	z = (a + b + c) / 2;
 
	S += sqrt(z * (z - a) * (z - b) * (z - c));
    }
    printf("%.6f\n", S);
    return 0;
}

Measured memory_bytes: 3124
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   cin >> N;
   int A[N];
   long long cnt[100001];
   for(int i=0;i<100001;i++)cnt[i]=0;
   long long ans = 0;
   for (int i = 0; i < N; i++)
   {
      cin >> A[i];
      cnt[A[i]]++;
      ans += A[i];
   }
   int Q;
   cin >> Q;
   for (int i = 0; i < Q; i++)
   {
      int B,C;
      cin >> B >> C;
      ans -= B * cnt[B];
      ans += C * cnt[B];
      cnt[C]+=cnt[B];
      cnt[B]=0;
      cout << ans << endl;
   }
   
   return 0;
}


Measured memory_bytes: 4764
N = int(input())
a = list(map(int, input().split()))

def minVal(minInt, val):
    if minInt < val:
        return minInt
    else:
        return val

dp = [100000000000000] * N
(dp[0], dp[1]) = [0, abs(a[1]-a[0])]

for i in range(2,N):
    dp[i] = minVal(dp[i], dp[i - 1] + abs(a[i - 1] - a[i]))
    dp[i] = minVal(dp[i], dp[i - 2] + abs(a[i - 2] - a[i]))
else:
    print(dp[N - 1])

Measured memory_bytes: 13924
n = int(input())
ans = 0
N = n

for i in range(2,int(n**0.5//1 + 2)):
  if n % i == 0:
    c = 0
    while n%i == 0:
      n//=i
      c += 1
    j = 1
    while c-j >= 0:
      ans += 1
      c -= j
      j += 1
    
if n > 1:
  ans = ans + 1
print(ans)

Measured memory_bytes: 9460
#include<stdio.h>
int main()
{
    int n,k,x,y,i,cost;
    scanf("%d %d %d %d",&n,&k,&x,&y);
    if(n<k)
    {
        cost=(n*x);
    }
    else
    {
         cost=(k*x)+(y*(n-k));
    }
    printf("%d",cost);

    return 0;
}


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

using namespace std;

typedef complex<double> comp ;

const int MAX = 3e5 + 5 ;

const double PI = acos(-1) ;

valarray<comp>fft(valarray<comp> &x , int sign = -1)
{
    int N = x.size() ;
    ///Case
    if(N == 1)
        return x ;
    valarray<comp> X(N) , even = x[slice(0 , N/2 , 2)] , odd = x[slice(1 , N/2 , 2)] ;
    even = fft(even , sign) ;
    odd = fft(odd , sign) ;
    comp Yk = 1 , Y1 = exp(comp(sign * 2 * PI , 0) * comp(0 , 1) / comp(N , 0)) ;
    for(int k = 0 ; k < N/2 ; ++k)
    {
        X[k] = even[k] + Yk * odd[k] ;
        X[k+N/2] = even[k] - Yk * odd[k] ;
        Yk *= Y1 ;
    }
    return X ;
}

valarray<comp>ifft(valarray<comp> &x , int sign = -1)
{
    return (fft(x , 1) / comp(x.size() , 0)) ;
}

vector<long long>mul(const vector<int> &a , const vector<int> &b)
{
    int deg = a.size() + b.size() - 2 ;
    int sz = 1 << ((int)(round(ceil(log2(deg+1))))) ;
    valarray<comp>A(sz) , B(sz) ;
    for(int i = 0 ; i < a.size() ; ++i)
        A[i] = a[i] ;
    for(int i = 0 ; i < b.size() ; ++i)
        B[i] = b[i] ;
    A = fft(A) ;
    B = fft(B) ;
    valarray<comp>C = A * B ;
    C = ifft(C) ;
    vector<long long>result ;
    for(int i = 0 ; i <= deg ; ++i)
    {
        result.push_back(round(C[i].real())) ;
    }
    return result ;
}
char str[MAX];
int main()
{
   // freopen("in.txt","rt",stdin);
    long long ans = 0;
    int n;
    long long m;
    scanf("%d %lld",&n,&m);
    vector<int> A(100005,0);
    int x;
    for(int i=0;i<n;++i){
        scanf("%d",&x);
        A[x]++;
    }
    auto vec = mul(A,A);
    long long i = vec.size()-1;
    while(i>=0){
        if(vec[i]<m){
            ans+=i*vec[i];
            m-=vec[i];
        }
        else{
            ans+=i*m;
            break;
        }
        --i;
    }
    printf("%lld",ans);
    return 0 ;
}


Measured memory_bytes: 29760
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, k;
    cin >> n >> k;
    map<int, int> pre;
    set<P> cnt;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        if(pre.find(a) == pre.end()){
            pre[a] = 1;
            cnt.insert(P(1, a));
        }
        else{
            cnt.erase(P(pre[a]++, a));
            cnt.insert(P(pre[a], a));
        }
    }
    priority_queue<int, vector<int>, greater<int>> que;
    for(auto it : cnt){
        int hoge = it.first;
        que.push(hoge);
    }
    int res = 0;
    while(que.size() > k){
        res += que.top();
        que.pop();
    }
    cout << res << endl;
}

Measured memory_bytes: 20216
S = input()
K = int(input())

substring_set = set()
for i in range(len(S)):
    substring = []
    for j in range(min([K, len(S)-i])):
        substring.append(S[i+j])
        substring_set.add(''.join(substring))

print(sorted(list(substring_set))[K-1])


Measured memory_bytes: 4592
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  ll N;string S;cin>>N>>S;
  ll r=0,g=0,b=0;
  rep(i,N){
    if(S[i]=='R')r++;
    else if(S[i]=='G')g++;
    else b++;
  }
  ll cnt =r*g*b;
  for(ll i=0;i<N;i++){
    for(ll k=1;i+2*k<N;k++){
      if(S[i]!=S[i+k] &&S[i]!=S[i+2*k] &&S[i+k]!=S[i+2*k])cnt--;
    }
  }
  cout<<cnt<<endl;
}   





Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

int main() {
  ll n;
  cin >> n;
  vector<set<ll>> e(n);
  for(ll i=0;i<n-1;i++) {
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    e[a].insert(b);
    e[b].insert(a);
  }
  vector<ll> c(n);
  for(ll i=0;i<n;i++) {
    cin >> c[i];
  }
  sort(c.rbegin(),c.rend());
  ll count=0;
  ll root=-1;
  for(ll i=0;i<n;i++) {
    if(count<e[i].size()) {
      count =e[i].size();
      root=i;
    }
  }
  vector<ll> dis(n,-1);
  dis[root]=0;
  count=0;
  queue<ll> q;
  q.push(root);
  while(q.size()) {
    ll f=q.front();
    q.pop();
    for(ll t:e[f]) {
      if(dis[t]<0) {
        dis[t]=++count;
        q.push(t);
      }
    }
  }
  ll m=0;
  for(ll i=1;i<n;i++) {
    m+=c[i];
  }
  cout << m << endl;
  for(ll i=0;i<n;i++) {
    if(i!=0) {
      cout << " ";
    }
    cout << c[dis[i]];
  }
  cout << endl;
}

Measured memory_bytes: 1920
#include <math.h>
#include <stdio.h>

int main() {
	double x_1,y_1,x_2,y_2;
	scanf("%lf%lf%lf%lf",&x_1,&y_1,&x_2,&y_2);
	printf("%lf\n",sqrt(pow(x_1-x_2,2)+pow(y_1-y_2,2)));
	return 0;
}

Measured memory_bytes: 652
import math
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
print(sum(abs(xi-yi) for xi,yi in zip(x,y)))
print(math.sqrt(sum((xi-yi)**2 for xi,yi in zip(x,y))))
print((sum(abs(xi-yi)**3 for xi,yi in zip(x,y)))**(1/3))
print(max(abs(xi-yi) for xi,yi in zip(x,y)))


Measured memory_bytes: 5696
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;

#pragma endregion

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 




/*****************************************************************************/

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

	int h, w;
	cin >> h >> w;
	vvc a(h, vc(w));
	f(i, 0, h) {
		f(j, 0, w) {
			cin >> a[i][j];
		}
	}
	vvi dp(h + 1, vi(w + 1));
	dp[0][0] = 1;
	f(i, 0, h) {
		f(j, 0, w) {
			if (i + 1 < h&&a[i + 1][j] == '.') {
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= MOD;
			}
			if (j + 1 < w&&a[i][j + 1] == '.') {
				dp[i][j + 1] += dp[i][j];
				dp[i][j + 1] %= MOD;
			}
		}
	}
	cout << dp[h-1][w-1];
	return 0;
}

Measured memory_bytes: 9088
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
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 fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,H=MI()
    A=[]
    B=[]
    for i in range(N):
        a,b = MI()
        A.append(a)
        B.append(b)

    A_max=max(A)
    B.sort(reverse=False)
    ans = 0
    while H>0 and B and B[-1]>A_max:
        H-=B[-1]
        ans += 1
        B.pop()
    if H>0:
        ans += ceil(H,A_max)
    print(ans)



if __name__ == '__main__':
    main()
    # S=ST()
    # ans = 0
    # for i in range(len(S)):
    #     for it in combinations([i for i in range(len(S))], i):
    #         before = 0
    #         for j in it:
    #             print(int(S[before:j+1]), before,j)
    #             ans += int(S[before:j+1])
    #             before = j+1
    #         try:
    #             ans += int(S[before:])
    #         except:
    #             pass
    #         print(ans)
    # print(ans)

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int i, j, n, m, k, l;
    cin>>n>>m;
    char a[n][n], b[m][m];
    for(i=0; i<n; i++){
        cin>>a[i];
    }
    for(i=0; i<m; i++){
        cin>>b[i];
    }
    int flag = 0;
    for(i=0; i<n-m+1; i++){
        for(j=0; j<n-m+1; j++){
            flag = 1;
            for(k=0; k<m; k++){
                for(l=0; l<m; l++){
                    if(a[i+k][j+l]!=b[k][l]){
                        flag = 0;
                        break;
                    }
                }
            }
            if(flag == 1){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,K = inpl()

ans = 0
for n in range(1,N+1):
    tmp = 1/N
    now = n
    while now < K:
        now *= 2
        tmp /= 2
    ans += tmp

print(ans)


Measured memory_bytes: 4464
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n;
int a[101];
ll dp[101][1000];
int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
	}
	for(int i=0;i<101;i++)
	{
		for(int j=0;j<1000;j++)
		{
			dp[i][j]=0ll;
		}
	}
	dp[0][a[0]]=1ll;
	for(int i=0;i<n-2;i++)
	{
		for(int j=0;j<=20;j++)
		{
			if(j-a[i+1]>=0)dp[i+1][j]+=dp[i][j-a[i+1]];
			if(j+a[i+1]<=20)dp[i+1][j]+=dp[i][j+a[i+1]];
		}
	}
	cout << dp[n-2][a[n-1]] << endl;
	return 0;
}

Measured memory_bytes: 1944
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n){ 
    cin >> a[i];
    a[i]++;
  }
  vector<int> cnt(n, 0);
  mint ans = 1;
  cnt[0] = 3;
  REP(i,n){
    if(cnt[a[i]-1]>0){
      ans *= cnt[a[i]-1];
      cnt[a[i]-1]--;
      cnt[a[i]]++;
    }else{
      cout << 0 << endl;
      return 0;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for(int i = 0; i < n; i++)
const int inf9 = 1e9; const lint inf18 = 1e18;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ double y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); } double euclidean(double first, double second){ return sqrt(first * first + second * second); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint P(int n, int r){ if(r < 0 || n < r) return 0; return (fact[n] * inv[n - r] % mod); } lint C(int p, int q){ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }
inline int at(lint i, int j){ return (i >> j) & 1; }

int main(){
    string S;
    cin >> S;
    cout << string(S.size(), 'x') << endl;
}


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

int n,a[21][21],dp[22][2097152]={};
int poo;
int mod(int a){
	return a%1000000007;
}
int sbits(int a){
	int cnt=0;
	for(int i=0;i<n;i++)
		if(a&(1<<i))
			cnt++;
	return cnt;
}

void match(int b){
	for(int i=0;i<poo;i++)
	{
		if(sbits(i)!=b)
			continue;
		for(int j=0;j<n;j++)
		{
			if(a[b-1][j])
				if(i&1<<j)
					{dp[b][i]=mod(dp[b][i]+=dp[b-1][i-(1<<j)]);
			}
		}
	}
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	poo=pow(2,n);
	for(int i=0;i<poo;i++)
		dp[0][i]=1;	
	for(int i=1;i<=n;i++){
		match(i);
	}
	cout<<dp[n][int((poo-1))]<<endl;
}
	

Measured memory_bytes: 170240
#include<stdio.h>
#include<stdlib.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2;
void DFS(void);
void visit(int);
int n,**M,*color,*d,*f,time=0;
int main(){
  int i,j,u,k,v;
  scanf("%d",&n);
  M = (int**)malloc(sizeof(int*) * n);     // dynamic allocation start
  for(i=0; i<n+1; i++){                    // *
    M[i] = (int*)malloc(sizeof(int) * n);  // *
  }                                        // *
  color = (int*)malloc(sizeof(int) * n);   // *
  d = (int*)malloc(sizeof(int) * n);       // *
  f = (int*)malloc(sizeof(int) * n);       // dynamic allocation end
  for(i=0; i<n; i++){    // initialization start
    color[i] = WHITE;    // *
    d[i] = f[i] = 0;     // *
    for(j=0; j<n; j++){  // *
      M[i][j] = 0;       // *
    }                    // *
  }                      // initialization end
  for(i=0; i<n; i++){     // input data start
    scanf("%d%d",&u,&k);  // *
    for(j=0; j<k; j++){   // *
      scanf("%d",&v);     // *
      M[u-1][v-1] = 1;    // *
    }                     // *
  }                       // input data end
  DFS();  // Depth First Search
  return 0;
}
void DFS(void){
  int u;
  for(u=0; u<n; u++){
    if(color[u] == WHITE){
      visit(u);
    }
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
void visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++time;
  for(v=0; v<n; v++){
    if(M[u][v] != 0 && color[v] == WHITE){
      visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++time;      // visit completed
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;

const int MX = 1000;
mint f[MX],g[MX],inv[MX];
void precalc(){
	f[0]=1;
	rep1(i,MX-1) f[i] = f[i-1] * i;

	const int mod = 1e9+7;
	inv[1]=1;
	for(int i=2;i<=MX-1;i++) inv[i] = -inv[mod%i] * (mod/i);

	g[0]=1;
	rep1(i,MX-1) g[i] = g[i-1] *inv[i];
}


mint dp[2][301][601];

int main(){
	precalc();
	int N;
	cin>>N;
	dp[0][0][0] = 1;
	rep(i,N){
		int d;
		cin>>d;
		int ni = 1-i%2;
		rep(k,301) rep(s,601) dp[ni][k][s] = 0;
		rep(k,301) rep(s,601) if(dp[i%2][k][s]){
			mint val = dp[i%2][k][s];
			if(d>=2){	//sel
				int nk = k+1;
				int ns = s+(d-2);
				dp[ni][nk][ns] += val*g[d-2];
			}
			{
				dp[ni][k][s] += val*g[d-1];
			}
		}
	}
	mint ans;
	for(int k=3;k<=N;k++) rep(s,601) if(dp[N%2][k][s]){
		if(k==N){
			mint tmp = dp[N%2][k][s] * f[k-1] / 2;
			ans += tmp;
			continue;
		}
		mint tmp = dp[N%2][k][s] * f[N+1-k-2] * s * f[k-1] / 2;
		ans += tmp;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1664
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

int main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  sort(L.begin(), L.end());

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      for (int k = j+1; k < N; k++) {
        if (L.at(i) + L.at(j) > L.at(k)) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int N,M; cin >> N >> M;
    vector<bool> out(N);
    vector<int> H(N);
    REP(i,N){
        cin >> H[i];
    }

    REP(i,M){
        int A,B; cin >> A >> B;
        A--; B--;
        if (H[A] <= H[B]) out[A] = true;
        if (H[A] >= H[B]) out[B] = true;
    }

    int ans = 0;
    REP(i,N){
        if (out[i]) continue;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3784
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String str = br.readLine();
        String[] strs = str.split(" ");
        //--- list??????¨??? ---
        for(int i = strs.length-1; i >= 0; i--){
            if(i != 0){
                System.out.print(strs[i] + " ");
            }else{
                System.out.print(strs[i]);
            }//if
        }//for
        System.out.println();
    }
}

Measured memory_bytes: 24352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N>>K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  int answer = 0;
 
  for (int i = 0; i < N; i++) {
 
    if (h.at(i) >= K) {
      answer++;
    }
 
  }
 
  cout << answer << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
    //ll t;
    //cin>>t;
    //while(t--)
    //{
       
    //}
    ll n,m;
    cin>>n>>m;
    ll a[n],sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n);
    ll x=m;
    for(ll i=n-1;i>=0;i--)
    {
        if(a[i]>=(1/(4.0*m)*sum)&&x>0)
        {
            x--;
        }
    }
    if(x==0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
# ARC082D - Derangement
def main():
    N = int(input())
    P = tuple(map(int, input().split()))
    A = [1 if i == j else 0 for i, j in enumerate(P, 1)]
    ans, cur = 0, 0
    for i in A:
        if i:
            cur += 1
        else:
            ans += (cur + 1) // 2
            cur = 0
    ans += (cur + 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

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

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int x;

int main(){
    cin >> x;
    if(x) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n;
    cin >> n;
    int ans = (n-1)/2+1;
    
    
    
    cout << ans << endl;
    return 0;
}


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

int func(int x)
{
    if(x%2==0)
    {
        return x/2;
    }
    else
    {
        return 3*x+1;
    }
}
int main()
{
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    set <char> alph;
    for(int i=0;i<s.size();i++)
    {
        alph.insert(s[i]);
    }
    vector <pair<bool,char>> check(26);
    char alphabet[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    for(int i=0;i<26;i++)
    {
        check[i].first=false;
        check[i].second=alphabet[i];
    }
    for(auto itr = alph.begin(); itr != alph.end(); ++itr)
    {
        for(int j=0;j<26;j++)
        {
            if(*itr==alphabet[j])
            {
                check[j].first=true;
            }
        }
    }
    for(int i=0;i<26;i++)
    {
        if(!check[i].first)
        {
            cout<<check[i].second<<endl;;
            return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}

Measured memory_bytes: 512