akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
  int key;
  struct Node *next,*prev;
};

struct Node *nil;

struct Node* listSearch(int key){
  struct Node *cur = nil->next;
  while(cur!=nil&&cur->key!=key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = (struct Node *)malloc(sizeof(struct Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  struct Node *cur = nil->next;
  int isf = 0;
  while(1){
    if(cur == nil) break;
    if(isf++ > 0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(struct Node *t){
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deletekey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  struct Node *x = (struct Node *)malloc(sizeof(struct Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key,n,i;
  int size = 0;
  char com[20];
  int np = 0,nd = 0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0] == 'i'){insert(key);np++;size++;}
    else if(com[0] == 'd'){
      if(strlen(&com[0]) > 6){
        if(com[6] == 'F') deleteFirst();
        else if(com[6] == 'L') deleteLast();
      }else{
        deletekey(key);
       nd++;
      }
      size--;
    }
  }
  printList();

  return 0;
}



Measured memory_bytes: 32984
import java.util.Scanner;
import java.util.ArrayDeque;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] a = new char[h][w];
		int[][] b = new int[h][w];
		long black=0;
		ArrayDeque<int[]> queueh = new ArrayDeque<>();
		for(int i = 0; i<h; i++){
			String c = sc.next();
			for(int j = 0; j<w; j++){
				a[i][j]=c.charAt(j);
				if(a[i][j]=='#'){
					black++;
				}
			}
		}
		int[] start = {0,0};
		b[0][0]=1;
		queueh.add(start);
		while(a[h-1][w-1]!='#' && !queueh.isEmpty()){
			int[] now = queueh.poll();
			int i = now[0];
			int j = now[1];
			if(i!=h-1 && a[i+1][j]!='#'){
				int[] tmp = {i+1,j};
				queueh.add(tmp);
				b[i+1][j]=b[i][j]+1;
				a[i+1][j]='#';
			}
			if(i!=0 && a[i-1][j]!='#'){
				int[] tmp = {i-1,j};
				queueh.add(tmp);
				b[i-1][j]=b[i][j]+1;
				a[i-1][j]='#';
			}
			if(j!=w-1 && a[i][j+1]!='#'){
				int[] tmp = {i,j+1};
				queueh.add(tmp);
				b[i][j+1]=b[i][j]+1;
				a[i][j+1]='#';
			}
			if(j!=0 && a[i][j-1]!='#'){
				int[] tmp = {i,j-1};
				queueh.add(tmp);
				b[i][j-1]=b[i][j]+1;
				a[i][j-1]='#';
			}
			
		}
		if(a[h-1][w-1]!='#'){
			System.out.println(-1);
			return;
		}
		System.out.println(h*w-b[h-1][w-1]-black);
	}
}


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

typedef long long ll;

main()
{
    int a, b, sum, c = 1;
    cin >> a >> b;
    sum = a;
    if(b == 1){
        cout << 0;
    }
    else if(b <= a){
        cout << 1;
    }
    else{
        while(1){
            sum = sum + (a - 1);
            c++;
            if(sum >= b){
                break;
            }
        }
        cout << c;
    }


}





///promy_pompom
//hello world


Measured memory_bytes: 3600
def s0():return input()
def s1():return input().split()
def s2(m):return [input() for x in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

x=n0()

a=x//500
b=(x-500*a)//5
print(a*1000+b*5)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int x,y;
    cin>>x>>y;
    cout<<x*y<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(all(a));
    cout<<a[2]*10+a[1]+a[0]<<endl;
}

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

int main() {
    int N;
    map<string, int> scount;
    vector<string> status = {"AC", "WA", "TLE", "RE"};
    cin >> N;
    for (int i = 0; i < N; i++) {
        string temp;
        cin >> temp;
        scount[temp]++;
    }
    for (int i = 0; i < 4; i++) {
        cout << status[i] << " x " << scount[status[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

ll dp[22][(1<<22)];
int solve(vector<vector<int>>& compat, int i, int womenSubset, int N)
{
    if(i == N+1)
    {
        if(womenSubset == 0)
            return 1;
        return 0;
    }

    if(dp[i][womenSubset] != -1)
        return dp[i][womenSubset];
    ll ans = 0;
    for(int women = 0; women < N; women++)
    {
        bool available = (((1<<women)&(womenSubset)) == 0) ? 0 : 1;
        if(available && compat[i][women + 1])
        {
            ans = (ans + solve(compat, i+1, womenSubset ^ (1<<women), N)) % mod;
        }
    }
    return dp[i][womenSubset] = ans;
}

int main() {
   int n;
   cin >> n;
   vector<vector<int>> compat(n+1, vector<int>(n+1));
   memset(dp, -1, sizeof dp);
   for(int i = 1; i<=n; i++)
        for(int j = 1; j <= n; j++)
            cin >> compat[i][j];
   cout<<solve(compat, 1, ((1<<(n)) - 1), n);
   return 0;
}


Measured memory_bytes: 724468
//#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>  
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<time.h>
#include<set>
#include <random>
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define fore(i,fa,fb) for(i=fa;i<=fb;++i)
#define all(n) (n.begin(),n.end())
#define F first
#define S second
typedef long long ll;
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int i, j, k, m, n;
	char a, b;
	cin >> a >> b;
	if (a == b)
		cout << "H";
	else cout << "D";
	/*
	if (a == 'H')
	{
		if (b == 'H')
			cout << 'H';
		else cout << 'D';
	}
	else
	{
		if (b == 'H')
			cout << 'D';
		else cout << 'H';
	}
	*/
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n, m, a, h, p, q;
	while (cin >> n >> m >> a) {
		if (n == 0)break;
		int ami[101];
		for (int i = 0; i < 101; i++)ami[i] = i;
		pair<int, P> c[1001];
		for (int i = 0; i < m; i++) {
			cin >> h >> p >> q;
			c[i] = make_pair(h, make_pair(p, q));
		}
		sort(c, c + m,greater<pair<int,P>>());
		for (int i = 0; i < m; i++) {
			swap(ami[c[i].second.first], ami[c[i].second.second]);
		}
		for (int i = 1; i <=n; i++) {
			if (ami[i] == a) {
				cout << i << endl; break;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3020
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
 
ll Q, H, S, D, N;
 
int main(void) {
  cin >> Q >> H >> S >> D >> N;
 
  H = min(H, 2 * Q);
  S = min(S, 2 * H);
  D = min(D, 2 * S);
 
  ll ans = 0;
  ans += (N / 2) * D;
  N %= 2;
  ans += N * S;
 
  cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    s = input()
    if s == "-":
        break
    s = list(s)
    m = int(input())
    for i in range(m):
        h = int(input())
        st = s[h:]
        for i in range(h):
            st.append(str(s[i]))
        s = st
    print("".join(s))
		

Measured memory_bytes: 7612
#include<iostream>
using namespace std;
int main ()
{
   int A,B,T;
   float t,a,b,k=0,res=0,c=0,i=1;
   cin>>A>>B>>T;
   t=(float)T+0.5;
   a=(float)A;
   b=(float)B;
  while(t>k)
  {
      k=a*i;
      if(t>k)
      {
          c++;
      }

      i++;
  }
 if(c>=1)
 {
     res=b*c;
 }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	int n,ans=0;
	long long sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
	    if(i%3!=0 && i%5!=0){
	        sum+=i;
	    }
	}
	cout<<sum;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    int h, w;
    cin >> h >> w;
    cout << W * H - h * W - (H - h) * w << endl;
    //cout << W + H - 1 << endl;
    return 0;
}


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

int main(){
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = 0;
  if(A >= 2*C){
    ans += 2*X*C;
    Y -= X;
    X -= X;
    Y = max(0, Y);
  }
  if(B >= 2*C){
    ans += 2*Y*C;
    X -= Y;
    Y -= Y;
    X = max(0, X);
  }
  if(A+B >= 2*C){
    ans += min(X, Y) * 2 * C;
    int d = min(X, Y);
    X -= d;
    Y -= d;
    //cout << d << endl;
  }
  if(X >= 0){
    ans += A*X;
    X -= X;
  }
  if(Y >= 0){
    ans += B*Y;
      Y -= Y;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=998244353;
const double EPS=1e-14;
const bool DEBUG=false;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////
void answer(){
    long N, M;
    cin>>N>>M;
    vector<int> count(N, 0);

    long a, b;
    for(int i=0; i<M; ++i){
        cin>>a>>b;
        count[a-1]++;
        count[b-1]++;
    }

    for(int i=0; i<N; ++i){
        cout<<count[i]<<endl;
    }

    return;
}

/////

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

    answer();

    return 0;
}


Measured memory_bytes: 3640
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<math.h>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>
// 追加１
#include <fstream>



using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main()
{
    int S, W;
    cin >> S >> W;

    if (S <= W)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll D,T,S;
  cin>>D>>T>>S;
  if(T*S>=D) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<int,pair<int,int> >PII;

int white[4010][4010], black[4010][4010], k, n;

inline int sum(int arr[][4010],int x, int y) 
{
	return arr[x + k][y + k] - arr[x][y + k] - arr[x + k][y] + arr[x][y];
}

int main() 
{
	int x, y,res=0;
	char color[3];
	isc(n);
	isc(k);
	rept(i,0,n) 
	{
		scanf("%d %d %s", &x,&y,color);
		if (color[0]=='W')white[x%(2*k)][y%(2*k)]++;
		else black[x%(2*k)][y%(2*k)]++;
	}
	
	loop(i,0,4*k)
	{
		loop(j,0,4*k) 
		{
			white[i][j]=white[i%(2*k)][j%(2*k)];
			black[i][j]=black[i%(2*k)][j%(2*k)];
		}
	}
	loop(i,1,4*k)
	{
		loop(j,1,4*k)
		{
			white[i][j]+=white[i-1][j]+white[i][j-1]-white[i-1][j-1];
			black[i][j]+=black[i-1][j]+black[i][j-1]-black[i-1][j-1];
		}
	}
	
	rept(i,0,2*k) 
	{
		rept(j,0,2*k) 
		{
			int t=sum(white,i,j)+sum(white,i+k,j+k)+sum(black,i,j+k)+sum(black,i+k,j);
			res=max(res, t);
		}
	}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 125696
"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;

function main(input) {
  var o = new I(input);

  var n = o.a();
  var m = o.a();
  var low = 0, high = 100000;
  for (var i = 0; i < m; i++) {
    var l = o.a();
    var r = o.a();
    if (l > low) low = l;
    if (r < high) high = r;
  }

  console.log(high >= low ? high - low + 1 :0);
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

typedef long long ll;
const double eps=1e-6,pi=acos(-1);
const int N=1e5+5,M=1e9+7,SEGM=4*N,OO=0x3f3f3f3f;
int t,n,m;
vector<int> adj[N];
int mem[N];

int getMax(int u){
    int &ret=mem[u];
    if(~ret) return ret;
    ret=0;
    for(int i=0,v;i<adj[u].size();++i){
        v=adj[u][i];
        ret=max(ret,getMax(v)+1);
    }
    return ret;
}

int main(){
    //freopen("myfile.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=0,u,v;i<m;++i){
        scanf("%d%d",&u,&v);
        adj[--u].push_back(--v);
    }
    memset(mem,-1,sizeof mem);
    int ans=0;
    for(int i=0;i<n;++i)
        ans=max(ans,getMax(i));
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 11672
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>

typedef long long ll;
using namespace std;

int main(){
	char c[101][101],d[101][101],e[101][101];
	int h,w,a[200],b[200],o=0,ans=0;
	for(int i=0;i<101;i++){
		a[i]=0;
		b[i]=0;
	}

	cin >> h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> c[i][j];
			if(c[i][j]=='#'){
				a[i]++;
			}
		}
		if(a[i]!=0){
			for(int u=0;u<w;u++){
				d[o][u]=c[i][u];
			}
			o++;
		}
	}
	h=o;
	for (int i=0;i<w;i++)
	{
		for(int j=0;j<o;j++){
			if(d[j][i]=='#'){
				b[i]++;
			}
		}
		if(b[i]!=0){
			for(int u=0;u<h;u++){
				e[u][ans]=d[u][i];
			}
			ans++;
		}
	}
	w=ans;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout << e[i][j];
		}
		cout << endl;
	}
  return 0;
}



Measured memory_bytes: 256
mo = []
for i in range(10):
    h = int(input())
    mo.append(h)

for i in range(10):
    for j in range(9,i,-1):
        if mo[j] < mo[j-1]:
            mo[j],mo[j-1] = mo[j-1],mo[j]

print(mo[9])
print(mo[8])
print(mo[7])


Measured memory_bytes: 5596
from collections import*
n,*a=map(int,open(0).read().split())
a.sort()
d=len(a)//2
flag=0
if len(a)%2==1:
    b=a[:d+1]
    c=a[d+1:]
    flag=1
else:
    b=a[:d]
    c=a[d:]
l=[]
for i in range(d):
    l.append(c[i])
    l.append(b[i])
if flag:
    if abs(l[-1]-b[-1])>abs(l[0]-b[-1]):
        l.append(b[-1])
    else:
        l.insert(0,b[-1])
print(sum(abs(l[i+1]-l[i])for i in range(n-1)))


Measured memory_bytes: 14380
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

using ii = pair<int,int>;
using ll = long long;

const int N = 705;
const int mod = 1e9 + 7;

bool mat[N][N];
int n, m;
int cntParity[2];
void kill(){cout << -1 << '\n';	exit(0);}
vector<int> g[N];
int col[N];
void dfs(int x, int c){
	if(col[x] != -1){
		if(col[x] != c)
			kill();
		return;
	}
	col[x] = c;
	cntParity[c]++;
	for(auto v : g[x])
		dfs(v,1-c);
}
int calc(int x){return x * (x-1) / 2;}
int main(){
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif // ONLINE_JUDGE

	cin >> n >> m;

	for(int i = 0, u, v; i < m; i++){
		cin >> u >> v;
		mat[u][v] = mat[v][u] = 1;
	}

	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(i != j && !mat[i][j])
				g[i].push_back(j);

	vector<pair<int,int>> vp;	memset(col,-1,sizeof col);

	for(int i = 1; i <= n; i++)
		if(col[i] == -1){
			cntParity[0] = cntParity[1] = 0;
			dfs(i,0);
			vp.push_back({cntParity[0], cntParity[1]});
		}

	vector<int> vals = {0};

	for(auto x : vp){

		vector<int>nxt;

		for(auto v : vals)
			nxt.push_back(v + x.first),
			nxt.push_back(v + x.second);

		sort(nxt.begin(), nxt.end());
		nxt.resize(unique(nxt.begin(), nxt.end()) - nxt.begin());
		vals = nxt;
	}

	int ans = n * n;

	for(auto v : vals)
		ans = min(ans, calc(v) + calc(n - v));

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3072
n, p = map(int, input().split())
f = []
for i in range(1, int(p**0.5)+1):
        if p%i==0:
                f.append(i)
                f.append(p//i)
ans = 1
for i in f:
        if p%pow(i,n, 92709568269121)==0: ans = max(ans, i)
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

//Gift from the Goddess of Programming
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int[] s = new int[1000], in = new int[1000];
			boolean[] f = new boolean[1000];
			while(n--!=0){
				sc.next();
				String[] t = sc.next().split(":");
				int time = Integer.parseInt(t[0])*60+Integer.parseInt(t[1]);
				boolean I = "I".equals(sc.next());
				int id = sc.nextInt();
				if(I){
					f[id] = true; in[id] = time;
				}
				else{
					f[id] = false;
					if(id==0){
						for(int i=1;i<1000;i++)if(f[i])s[i]+=time-Math.max(in[0], in[i]);
					}
					else if(f[0])s[id]+=time-Math.max(in[0], in[id]);
				}
			}
			int res = 0;
			for(int i=1;i<1000;i++)res=Math.max(res, s[i]);
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
    int n;
    ll h;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> h;
    vector<ll>a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    ll ma = *max_element(a.begin(),a.end());
    ll sum = 0;
    int cnt = 0;
    sort(b.rbegin(),b.rend());
    rep(i,n){
        if(b[i] >ma){
            sum += b[i];
            cnt++;
            if(sum>=h){
                cout << cnt << endl;
                return 0;
            }
        }
    }
    h -=sum;
    if(h <=0){
        cout << cnt << endl;
    }else{
        cout << cnt + (h+ma-1)/ma << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int A, B;

int main()
{
    cin >> A >> B;
    A--, B--;

    vector<vector<char>> grid(100, vector<char>(100));
    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            if (i < 50)
                grid[i][j] = '#';
            else
                grid[i][j] = '.';
        }
    }

    for (int i = 0; i < 49 && A > 0; i += 2)
    {
        for (int j = 0; j < 100 && A > 0; j += 2)
        {
            grid[i][j] = '.';
            A--;
        }
    }

    for (int i = 51; i < 100 && B > 0; i += 2)
    {
        for (int j = 0; j < 100 && B > 0; j += 2)
        {
            grid[i][j] = '#';
            B--;
        }
    }

    puts("100 100");

    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            cout << grid[i][j];
        }
        cout << "\n";
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define N 102
int a[3][N],road[3][N],n;
// int dp[N][N];
int maxSum()
{
  int i,sum = 0;
  for(i = 1; i <= n; i++)
  road[1][i] = road[1][i-1]+a[1][i];
  for(i = n; i >= 1; i--)
  road[2][i] = road[2][i+1]+a[2][i];
  for(i = 1; i <= n; i++)
  {
    if(sum<road[1][i]+road[2][i])
    sum = road[1][i]+road[2][i];
  }
  return sum;
}


int main()
{
   // int dp[]
    // int a[2][01];
    int i,j;
    scanf("%d",&n);
    for( i = 1; i <= 2; i++)
    {
      for(j = 1; j <= n; j++){
      scanf("%d",&a[i][j]);
      }
    }
    printf("%d\n",maxSum());
    return 0;
}


Measured memory_bytes: 128
import java.lang.StringBuilder

fun main(args: Array<String>) {
    val length = readLine()!!.toInt()
    val sequence = mutableListOf<Int>()
    repeat(length) {
        sequence.add(readLine()!!.toInt())
    }

    val ans = StringBuilder()
    val max = sequence.max()
    if (sequence.count { it == max } >= 2) {
        repeat(length) {
            ans.append("$max\r\n")
        }
    } else {
        val next = sequence.filterNot { it == max }.max()
        for (i in sequence) {
            when (i) {
                max -> ans.append("$next\r\n")
                else -> ans.append("$max\r\n")
            }
        }
    }
    print(ans)
}


Measured memory_bytes: 64168
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}


signed main(){
int x,y,m;
cin>>x>>y>>m;
int ans=y/m-x/m;
if(x%m==0){ans++;}
out(ans);
}


Measured memory_bytes: 3628
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int[] a = new int[3];
	int f = 0;
	int s = 0;
	for(int i = 0; i < 3; i++) {
		a[i] = sc.nextInt();
	}
	for(int i = 0; i < 3; i++) {
		if(a[i] == 5) {
			f++;
		} else if(a[i] == 7) {
			s++;
		}		
	}
	if(f == 2 && s == 1) {
		System.out.println("YES");
	} else {
		System.out.println("NO");
	}
}
}

Measured memory_bytes: 21716
import java.util.*;

class Main {
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int[][] b = new int[3][3];
      for(int i = 0; i < 3; i++) {
          for (int j = 0; j < 3; j++) {
              b[i][j] = sc.nextInt();
          }
      }
      int N = sc.nextInt();
      for (int i = 0; i < N; i++) {
          int t = sc.nextInt();
          for (int j = 0; j < 3; j++) {
              for (int k = 0; k < 3; k++) {
                  if (b[j][k] == t) {
                      b[j][k] = 0;
                  }
              }
          }
      }
      String ret = "No";
      for(int i = 0; i < 3; i++) {
              if (bingo(b[i][0],b[i][1],b[i][2])) {
                  ret = "Yes";
                  break;
              }
              if (bingo(b[0][i],b[1][i],b[2][i])) {
                  ret = "Yes";
                  break;
              }
      }
      if (bingo(b[0][0],b[1][1],b[2][2]) || bingo(b[2][0],b[1][1],b[0][2])) {
          ret = "Yes";
      }
      System.out.println(ret);
  }
  static boolean bingo(int a, int b, int c) {
      return a == b && b == c;
  }
}


Measured memory_bytes: 23380
import sys

def solve():
    N = str(input())
    dig = len(N)
    ans = 0
    up = False
    for i in reversed(range(dig)):
        n = int(N[i])
        if 0 <= n <= 4: 
            if up: 
                ans += n + 1
                up = False
                if n == 4:
                    if i > 0:
                        if int(N[i-1]) >= 5: up = True
            else: 
                ans += n 
                up = False
        elif n == 5:
            if up: ans += 4
            else: 
                ans += 5
                if i > 0:
                    if int(N[i-1]) >= 5: up = True
        else: 
            if up: ans += 9 - n
            else: ans += 10 - n
            up = True
        #print(n, ans)
    if up: ans += 1
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 5492
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
#define DD 1
#else
#define DD 0
#endif
#define Debug if(DD) printf("line %d\n",__LINE__)
#define deb(x) if(DD) cerr<<#x<<'='<<x<<endl
#define debug if(DD) printf
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void gg1(){write2(-1);exit(0);}
	void gg2(){puts("NO");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int M=5e6+10;
	ll fac[M],facinv[M],Inv[M];ll C(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,M-1) fac[i]=fac[i-1]*i%MOD;
		facinv[M-1]=invm(fac[M-1]);fd(i,M-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,M-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=3e3+10;
	//------------------FIXED------------------
	
	void main()
	{
		ll I=qread(),O=qread(),T=qread(),J=qread(),L=qread();
		ll ans=(I/2)*2+(J/2)*2+(L/2)*2;
		if(I and J and L) I--,J--,L--,chmax(ans, (I/2)*2+(J/2)*2+(L/2)*2+3 );
		write(ans+O);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();//线性预处理模意义
	mine::main();
	if(DD) cerr<<"\n---------------------Zory---------------------\nTime: " <<1.0*clock()/CLOCKS_PER_SEC<<"s";
}

Measured memory_bytes: 117376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, C, K;
    cin >> N >> C >> K;
    vl T(N);
    rep(i, N) cin >> T[i];
    sort(all(T));

    ll ni = 0, ans = 0;
    while(ni<N){
        ll t = T[ni], cnt = 1;
        ni++;
        while (ni < N && cnt < C && T[ni] <= t + K) ni++, cnt++;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
ll a, b;
ll cal(ll x){
	if(x % 4 == 1)
		return 1;
	if(x % 4 == 2)
		return x + 1;
	if(x % 4 == 3)
		return 0;
	return x;
}
int main(){
	scanf("%lld%lld", &a, &b);
	a = max(a, 1LL);
	cout<<(cal(b) ^ cal(a-1));
	return 0;
}


Measured memory_bytes: 256
//Volume1-0118
import java.util.ArrayDeque;
import java.util.Scanner;

class El {
	public int x;
	public int y;
	public int r = 0;
	El(int x,int y){
		this.x = x;
		this.y = y;
	}
}

public class Main {

	//declare
	private static ArrayDeque<El> q = new ArrayDeque<El>();
	private static int            h,w,num,x,y;
	private static int    [][]    ck = {{-1,0},{0,-1},{1,0},{0,1}};
	private static char   [][]    orchard;
	private static boolean[][]    map;

	public static void main(String[] args) {

		String[] s;

        //input
        Scanner sc = new Scanner(System.in);
        while(true){
        	s = sc.nextLine().split("\\s");
        	h = Integer.parseInt(s[0]);
        	w = Integer.parseInt(s[1]);
        	if(h+w==0){break;}
        	orchard = new char   [h][w];
        	map     = new boolean[h][w];
        	for(int i=0;i<h;i++){
       			orchard[i] = sc.nextLine().toCharArray();
        	}

        	//calculate
        	num = 0;
        	for(int i=0;i<h;i++){
        		for(int j=0;j<w;j++){
        			if(!map[i][j]){
        				num++;
        				DFS(i,j,orchard[i][j]);
        			}
        		}
        	}

        	//output
        	System.out.println(num);
        }
	}

	public static void DFS(int y_,int x_,char c){

		x=x_;
		y=y_;

		do {
			if(c == orchard[y][x] && !map[y][x]){
				map[y][x] = true;
				q.push(new El(x,y));
			}
		} while (update());
	}

	private static boolean update(){

		El e;
		boolean ret = false;
		while(!q.isEmpty()){
			e = q.peek();
			if(e.r == 4){
				q.pop();
				continue;
			}
			if(e.x + ck[e.r][0] >= 0 && e.x + ck[e.r][0] < w &&
               e.y + ck[e.r][1] >= 0 && e.y + ck[e.r][1] < h ) {
				x = e.x + ck[e.r][0];
				y = e.y + ck[e.r][1];
				e.r++;
				ret = true;
				break;
			} else {
				e.r++;
			}
		}
		return ret;
	}
}

Measured memory_bytes: 25064
using System;

class Program
{
    public static void Main()
    {
        // スペース区切りの整数の入力
        int n = int.Parse(Console.ReadLine());
        int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), i => int.Parse(i));
        int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), i => int.Parse(i));

        long sum = 0;

        for (int i = 0; i < n; i++)
        {
            if (a[i] >= b[i])
            {
                sum += b[i];
            }
            else
            {
                sum += a[i];
                b[i] -= a[i];

                if (a[i + 1] >= b[i])
                {
                    sum += b[i];
                    a[i + 1] -= b[i];
                }
                else
                {
                    sum += a[i + 1];
                    a[i + 1] = 0;
                }

            }

        }

        Console.WriteLine(sum);

    }
}

Measured memory_bytes: 33228
N = int(input())
line = input().split(" ")
A = [int(i) for i in line]

answer = "APPROVED"

for a in A:
    if a % 2 == 1:
        continue
    if a % 3 == 0 or a % 5 == 0:
        continue
    else:
        answer = "DENIED"
        break

print(answer)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
	int N, a[405];
	ll dp[405][405] = {0};

	cin >> N;

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

	ll tmp;
	ll sum ;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < N - i; j++) {
			tmp = 0x7fffffffffffffff;
			sum = 0;
			for (int k = j; k < j + i; k++) {
				tmp = min(tmp, dp[j][k] + dp[k + 1][j + i]);
				sum += a[k];
			}
			sum += a[j + i];
			dp[j][j + i] = tmp + sum;
		}
	}

	cout << dp[0][N - 1] << endl;

	return 0;
}

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

int n;
ll a[3000];
ll memo[3001][3001];
bool used[3001][3001];

ll dfs(int l, int r)
{
  if(l > r) return 0;
  if(used[l][r]) return memo[l][r];
  used[l][r] = true;

  ll res;
  if((n-(r-l+1))%2 == 0){
    res = -linf;
    res = max(res, dfs(l+1, r) + a[l]);
    res = max(res, dfs(l, r-1) + a[r]);
  }else{
    res = linf;
    res = min(res, dfs(l+1, r) - a[l]);
    res = min(res, dfs(l, r-1) - a[r]);
  }

  return memo[l][r] = res;
}

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

  cout << dfs(0, n-1) << endl;

  return 0;
}


Measured memory_bytes: 78464
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////
using pii = vector<pair<int,int>>;

bool find_hw(const pii &targets, const pii &hps, const pii &wps, int M)
{
    auto hp2 = partition_point(begin(hps), end(hps), [&hps](pair<int,int> v){ return v.first == hps[0].first;}); 
    auto wp2 = partition_point(begin(wps), end(wps), [&wps](pair<int,int> v){ return v.first == wps[0].first;}); 

    if (distance(begin(hps), hp2) * distance(begin(wps), wp2) > M)
        return false;

    for (auto ih = hps.begin(); ih != hp2; ++ih)
    {
        for (auto iw = wps.begin(); iw != wp2; ++iw)
        {
            if (!binary_search(begin(targets), end(targets), make_pair(ih->second, iw->second)))
            {
                return false;
            }
        }
    }

    return true;
}

int main()
{
    int H, W, M;
    io >> H >> W >> M;

    vi hs(H), ws(W);
    vector<pair<int,int>> targets;
    for (int i = 0; i < M; i++)
    {
        int h, w;
        io >> h >> w;
        --h; --w;
        ++hs[h];
        ++ws[w];
        targets.push_back({h,w});
    }

    vector<pair<int,int>> hps(H), wps(W);
    for (int i = 0; i < H; i++)
        hps[i] = {hs[i],i};
    for (int j = 0; j < W; j++)
        wps[j] = {ws[j],j};
    

    using cmp_t = greater<pair<int,int>>;
    sort(begin(hps), end(hps), cmp_t());
    sort(begin(wps), end(wps), cmp_t());
    sort(begin(targets), end(targets));

    int ans = hps[0].first + wps[0].first;
    if (find_hw(targets, hps, wps, M)) ans--; 
    io << ans << BR;
}

Measured memory_bytes: 12660
import collections
N, K = map(int, input().split())
l = list(map(int, input().split()))

if len(list(set(l))) <= K:
    print(0)
else:
    result = 0
    
    ii =  len(list(set(l))) - K

    c = collections.Counter(l)
    l_r = c.most_common()
    for i in range(ii):
        c = i+1
        
        result += l_r[-1*c][1]
        
    print(result)
        


Measured memory_bytes: 55136
from collections import Counter
N=int(input())
a=list(map(int,input().split()))

a_=Counter(a)
num=0
for key in a_.keys():
    if key>a_[key]:
        num+=a_[key]
    elif key<a_[key]:
        num+=a_[key]-key
    else:
        continue
print(num)


Measured memory_bytes: 18672
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.answer"

int main() {

	string str;
	map<string, int>mp;
	while (getline(cin, str)) {
		string type = str.substr(str.find(',')+1);
		mp[type]++;
	}
	cout << mp["A"] << endl;
	cout << mp["B"] << endl;
	cout << mp["AB"] << endl;
	cout << mp["O"] << endl;
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if (a + b < n) {
    cout << min(a, b) << ' ' << 0 << '\n';
  } else {
    cout << min(a, b) << ' ' << (a + b) - n << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

#define REP(i, n) for ( int i = 0; i < n; i++ )
#define SIZE 100
#define INF INT_MAX

using namespace std;

/**
dp[0][8] = 1;

dp[0][0] > 0 !;
dp[0][1] > 0 !;
dp[0][$] > 0 !;
dp[0][$] > 0 !;
dp[0][$] > 0 !;
dp[0][$] > 0 !;
dp[0][$] > 0 !;
dp[0][$] > 0 !;
dp[0][8] > 0 OK
    v = 8 + a[1](3), v = 11;
    OK
        dp[1][11] += dp[0][8](1) = 1;
    v = 8 - a[1](3) = v = 5;
    OK
        dp[1][5] += dp[0][8](1) = 1;

*/

int main() {
    int n, a[101];
    cin >> n;

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

    unsigned long long int dp[100][21] = {0};

    dp[0][ a[0] ] = 1;

    for ( int i = 1; i < n - 1; i++ ) {
        for ( int j = 0; j <= 20; j++ ) {
            if ( dp[i-1][j] > 0 ) {
                int val = j + a[i];
                if ( val <= 20 ) dp[i][val] += dp[i-1][j];
                val = j - a[i];
                if ( val >= 0 ) dp[i][val] += dp[i-1][j];
            }
        }
    }
    cout << dp[n-2][ a[n-1] ] << endl;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int cnt=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[i]+a[k]>a[j]&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
                {
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

#jは0なら反転なし、1なら反転
dp=[[0,0] for _ in range(N)] 
dp[0][0]=A[0]+A[1]
dp[0][1]=-1*(A[0]+A[1])
for i in range(1,N-1):
  dp[i][0] = max( dp[i-1][0]+A[i+1],        dp[i-1][1]+A[i+1] )
  dp[i][1] = max( dp[i-1][0]-2*A[i]-A[i+1], dp[i-1][1]+2*A[i]-A[i+1])
  
#print(dp)
print(max(dp[-2]))

Measured memory_bytes: 24796
#include<cstdio>
int a;
int b[5];
int main(void)
{
    int n;
    scanf("%d" ,&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d" ,&a);
        b[a%4]++;
    }
    b[1]+=b[3];
    if(b[0]>=b[1] || (b[2]==0 && b[0]+1==b[1]))
        printf("Yes");
    else
        printf("No");
    return 0;
}


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

using namespace std;

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

int main(void) {
    int N, W;
    cin >> N >> W;
    vector<long long> w(N), v(N);
    vector<vector<long long>> dp(N + 1, vector<long long>(W + 1, -1));
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }
    for (int j = 0; j <= W; ++j) {
        dp[0][j] = 0;
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= W; ++j) {
            if (j >= w[i]) chmax(dp[i + 1][j - w[i]], dp[i][j] + v[i]);
            chmax(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << *max_element(dp[N].begin(), dp[N].end()) << endl;
}

Measured memory_bytes: 80256
#include<stdio.h>
int main(void){
	int i=0,j,max=0,max2=0;
	char s[10];

	scanf("%s",s);
	while(s[i]!='\0'){i++;}

	for(j=0;j<i;j++){
		if(s[j]=='A'){max++;}
		else if(s[j]=='C'){max++;}
		else if(s[j]=='G'){max++;}
		else if(s[j]=='T'){max++;}
		else if(max2<max){max2=max;max=0;}
	}
	if(max>max2){printf("%d\n",max);}
	else {printf("%d\n",max2);}

	return 0;
}


Measured memory_bytes: 128
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

warshallFloyd1 :: Int -> U.Vector (Int, Int, Int64) -> V.Vector (U.Vector Int64)
warshallFloyd1 !n !edges = runST $ do
  !arr <- V.replicateM n (UM.replicate n (10^9+1))
  U.forM_ edges $ \(a,b,c) -> do
    UM.unsafeWrite (arr `V.unsafeIndex` a) b c
    UM.unsafeWrite (arr `V.unsafeIndex` b) a c
  forM_ [0..n-1] $ \a -> do
    UM.unsafeWrite (arr `V.unsafeIndex` a) a 0
  forM_ [0..n-1] $ \k -> do
    let !a_k = arr `V.unsafeIndex` k
    forM_ [0..n-1] $ \i -> do
      let !a_i = arr `V.unsafeIndex` i
      forM_ [0..n-1] $ \j -> do
        a_ik <- UM.unsafeRead a_i k
        a_kj <- UM.unsafeRead a_k j
        UM.unsafeModify a_i (min (a_ik + a_kj)) j
  V.mapM U.unsafeFreeze arr

warshallFloyd2 :: Int -> Int -> V.Vector (U.Vector Int64) -> V.Vector (U.Vector Int)
warshallFloyd2 !n !l !graph = runST $ do
  !arr <- V.replicateM n (UM.replicate n (10^9+1))
  forM_ [0..n-1] $ \a -> do
    let !a_a = arr `V.unsafeIndex` a
    forM_ [0..n-1] $ \b -> do
      let v = graph `V.unsafeIndex` a `U.unsafeIndex` b
      when (v <= fromIntegral l) $ do
        UM.unsafeWrite a_a b 1
    UM.unsafeWrite a_a a 0
  forM_ [0..n-1] $ \k -> do
    let !a_k = arr `V.unsafeIndex` k
    forM_ [0..n-1] $ \i -> do
      let !a_i = arr `V.unsafeIndex` i
      forM_ [0..n-1] $ \j -> do
        a_ik <- UM.unsafeRead a_i k
        a_kj <- UM.unsafeRead a_k j
        UM.unsafeModify a_i (min (a_ik + a_kj)) j
  V.mapM U.unsafeFreeze arr

main = do
  [n,m,l] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM m $ do
    [a,b,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (a-1,b-1,fromIntegral c)
  let w1 = warshallFloyd1 n edges
      w2 = warshallFloyd2 n l w1
  q <- readLn
  queries <- U.replicateM q $ do
    [s,t] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (s,t)
  U.forM_ queries $ \(s,t) -> do
    let d = w2 `V.unsafeIndex` (s-1) `U.unsafeIndex` (t-1)
    print $ if d > 10^9 then -1 else d - 1


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

#define ll  long long


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,p;
    string s;
    cin>>n>>p>>s;
    ll  ans=0;
    if(p==2){
        for(int i=0;i<n;i++){
            if((s[i]-'0')%2==0)
                ans+=i+1;
        }

    }else if(p==5){
        for(int i=0;i<n;i++){
            if((s[i]-'0')%5==0)
                ans+=i+1;
        }
    }else{
        map<int,int> mp;
        ++mp[0];
        int t=0,p2=1;
        for(int i=n-1;~i;--i){
            t=(t+(s[i]-'0')*p2)%p;
            ans+=mp[t];
            mp[t]++;
            p2=p2*10%p;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 916