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


struct Ch{
	struct Ch *a;
	struct Ch *c;
	struct Ch *g;
	struct Ch *t;
	int end;
};

struct Ch *ghead;

int glen;

void init( )
{
	ghead = malloc( sizeof( struct Ch ) );
	ghead->a = ghead;
	ghead->c = ghead;
	ghead->g = ghead;
	ghead->t = ghead;
	ghead->end = 0;
}

int  searchStr( char *str )
{
	struct Ch *cur,*pre;
	int i;

	cur=ghead;
	i=0;
	while( i<glen ) {
		pre=cur;
		if( 'A' == str[i] ) {
			cur=cur->a;
		} else if( 'C' == str[i] ) {
			cur=cur->c;
		} else if( 'G' == str[i] ) {
			cur=cur->g;
		} else if( 'T' == str[i] ) {
			cur=cur->t;
		}
		if( ghead == cur ) { break; }
		i++;
	}
	return cur->end;
 }
 
void insertStr( char *str )
{
	struct Ch *x;
	struct Ch *cur,*pre;
	int i;

	cur=ghead;
	i=0;
	while( i<glen ) {
		pre=cur;
		if( 'A' == str[i] ) {
			cur=cur->a;
		} else if( 'C' == str[i] ) {
			cur=cur->c;
		} else if( 'G' == str[i] ) {
			cur=cur->g;
		} else if( 'T' == str[i] ) {
			cur=cur->t;
		}
		if( ghead == cur ) { break; }
		i++;
	}

	if( ghead == cur ) {
		while( i<glen ) {
			x = malloc( sizeof( struct Ch ) );
			x->a=ghead;
			x->c=ghead;
			x->g=ghead;
			x->t=ghead;
			if( 'A' == str[i] ) {
				pre->a=x;
			} else if( 'C' == str[i] ) {
				pre->c=x;
			} else if( 'G' == str[i] ) {
				pre->g=x;
			} else if( 'T' == str[i] ) {
				pre->t=x;
			}
			x->end=0;
			pre=x;
			i++;
		}
		x->end=1;
 	} else {
		cur->end=1;
	}
}

 
int main( void ) 
{
    int n;
 	char str[14];  
 	char com[8]; 
    int i;
   
	init( );
    scanf( "%d", &n );
    for( i=0; i<n; i++ ) {
        scanf( "%s%s", com, str );
    	glen = strlen( str ); 
        if( 'i' == com[0] ) {
        	insertStr( str );
        } else {
	        if( searchStr( str ) ) {
		        printf( "yes\n" );
		    } else {
		        printf( "no\n" );
		    }		    
	    }
    }
    return 0;
}

Measured memory_bytes: 16888
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<utility>

using namespace std;



int main()
{
	long long int i, j, k, l, m,N,x, sum, flag, cc, cnt;
	sum = 0;
	flag = 1;
	cin >> N >> x;
	vector<long long int>A(N);
	vector<long long int>B(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = 0;
	}
	sort(A.begin(), A.end());
	B[0] = A[0];
	for (i = 1; i < N; i++) {
		B[i] = B[i - 1] + A[i];
	}
	for (i = 0; i < N; i++) {
		if (B[i] > x) {
			break;
		}
	}
	if (x > B[N - 1]) {
		cout << N - 1 << endl;
	}
	else
	cout << i  << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define var(n) int n; scn(n)
#define F first
#define S second 
#define pb push_back
const int N=1e5+5;
// const ll M = 998244353;
const ll M=1e9+7;
const ll inf=1e18;

vector<int> g[N];
int visit[N],val[N],ans;

void dfs(int node)
{
	visit[node]=1;
	for(auto it:g[node])
	{
		if(!visit[it])
		{
			dfs(it);
			val[node]=max(val[node],1+val[it]);
		}
		else
		{
			val[node]=max(val[node],val[it]+1);
		}		
	}
	ans = max(ans,val[node]);
}
int main()
{
	var(n);var(m);
	rep(i,0,m)
	{
		var(x);var(y);
		g[x].push_back(y);
	}
	for(int i=1;i<=n;i++)
	{
		if(!visit[i])
			dfs(i);
	}
	pri(ans);

}

Measured memory_bytes: 8576
#include <iostream>
using namespace std;
int main(){
  int y1,m1,d1,y2,m2,d2;
  int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  for(int i=0;i<12;month[i+1]+=month[i],i++);
  while(true){
    cin>>y1>>m1>>d1>>y2>>m2>>d2;
    if (y1==-1)break;
    int day=0;
    day+=d2-d1+month[m2-1]-month[m1-1]+(y2-y1)*365;
    if(m2<3)y2--;
    if(m1>2)y1++;
    day+=y2/4-(y1-1)/4-y2/100+(y1-1)/100+y2/400-(y1-1)/400;
    cout<<day<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
using System;

namespace abc115
{
    class MainClass
    {
        static long[] a;
        static long[] p;

        public static void Main(string[] args)
        {
            var nx = Console.ReadLine().Split();
            var n = long.Parse(nx[0]);
            var x = long.Parse(nx[1]);

            a = new long[n + 1];
            a[0] = 1;

            p = new long[n + 1];
            p[0] = 1;

            for (int i = 0; i < n; i++)
            {
                a[i + 1] = a[i] * 2 + 3;
                p[i + 1] = p[i] * 2 + 1;
            }

            var ans = m1(n, x);
            Console.WriteLine(ans);
        }

        static long m1(long n, long x)
        {
            if (x == 0) return 0;
            if (n == 0) return 1;

            var d = (a[n] + 1) / 2;
            if (x < d)
            {
                return m1(n - 1, x - 1);
            }
            else
            {
                return p[n - 1] + m1(n - 1, x - d) + 1;
            }
        }
    }
}


Measured memory_bytes: 13140
// BCC
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <queue>

// GCC
// #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define each(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define mp make_pair

typedef long long ll;

const int INF = 1 << 28;
const ll INFLL = 1ll << 56;

typedef int Cost;

struct Edge {
	int src, dst;
	Cost cost;
	bool operator < (const Edge &e) const {
		return cost > e.cost; // ???????????£??????????????¨?????¨???
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


/**
 * ???????§????????????? (Bellman Ford ???)
 * ?????????????????¨????????????
 * 
 * bellmanFord(graph, s) ?§???? s ????????????????????§????????¢?????????
 * ( ?????????????????????????????´???, ?????¢??? -INF ?????????????????¨?????? )
 * buildPath(t) ?§???????????????? t ?????§??????????????????
 */

vector<int> prev_;
bool negative_cycle;

vector<Cost> bellmanFord(const Graph &g, int s){
	vector<Cost> dist(g.size(), INF);
	prev_.assign(g.size(), -1);
	negative_cycle = false;
	
	dist[s] = 0;
	rep(k, g.size()){
		rep(i, g.size()){
			if (dist[i] >= INF) continue;
			each(e, g[i]){
				if (dist[e->dst] > dist[e->src] + e->cost){
					dist[e->dst] = dist[e->src] + e->cost;
					prev_[e->dst] = e->src;
					if (k == g.size() - 1){
						dist[e->dst] = -INF;
						negative_cycle = true;
					}
				}
			}
		}
	}
	
	each(d, dist){
		if (*d >= INF) *d = INF;
	}
	
	return dist;
}

vector<int> buildPath(int t){
	vector<int> res;
	for (int v = t; v != -1; v = prev_[v]){
		res.pb(v);
	}
	reverse(res.begin(), res.end());
	return res;
}



int main()
{
	int n, m, s;
	scanf("%d %d %d", &n, &m, &s);
	Graph g(n);
	rep(i, m){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		g[a].pb({a, b, c});
	}
	std::vector<int> res = bellmanFord(g, s);
	if (negative_cycle){
		puts("NEGATIVE CYCLE");
	}
	else each(x, res){
		if (*x == INF) puts("INF");
		else printf("%d\n", *x);
	}
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

LLI dp[2][3100][3100];
bool visit[2][3100][3100];

LLI rec(bool p, int f, int b, vector<LLI> &a){
  if(f>b) return dp[p][f][b] = 0;
  if(visit[p][f][b]) return dp[p][f][b];
  visit[p][f][b] = true;

  if(p){
    dp[p][f][b] = max(rec(!p,f+1,b,a)+a[f], rec(!p,f,b-1,a)+a[b]);
  }else{
    dp[p][f][b] = min(rec(!p,f+1,b,a)-a[f], rec(!p,f,b-1,a)-a[b]);
  }
  
  return dp[p][f][b];
}


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

  int N; cin >> N;
  vector<LLI> a(N); cin >> a;

  cout << rec(true,0,N-1,a) << endl;
  
  return 0;
}


Measured memory_bytes: 168448
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max();

int main() {
	int r;
	cin >> r;
	int area = pow(r, 2);
	cout << area << endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

double e[1001];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	for(int i = 1; i <= 1000; i++){
		e[i] = ((double)(i+1))/(double)2;
	}
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	rep(i,n){
		cin >> p[i];
	}
	double ans, cnt = 0;
	rep(i,k){
		cnt += e[p[i]];
	}
	ans = cnt;
	for(int i = k; i < n; i++){
		cnt -= e[p[i-k]];
		cnt += e[p[i]];
		chmax(ans, cnt);
	}
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)

int main(void) {
	string str1, str2, str3;
	cin >> str1 >> str2 >> str3;
	if (*(str1.end() - 1) == *(str2.begin()) && *(str2.end() - 1) == *(str3.begin()))
		cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define int long long
#define int long long
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 2e5+5, MOD = 1e9 + 7;
int t,n,m,k,x,y;

int modpow(int n,int p){
	int ret=1;
	while(p){
		if(p&1) ret=(ret*n)%MOD;
		p=p>>1;
		n=(n*n)%MOD;
	}
	return ret;
}

int32_t main(){
	cin>>n>>k;
	int ans=0;
	int gcd[k+1];
	gcd[k]=1;
	ans+=k;
	for(int i=k-1;i>=1;i--){
		int f=k/i;
		gcd[i]=modpow(f,n);
		for(int j=2*i;j<=k;j+=i)
			gcd[i]=(gcd[i]-gcd[j])%MOD,gcd[i]=(gcd[i]+MOD)%MOD;
		ans=(ans+i*1LL*gcd[i])%MOD;
	}
	cout<<ans<<ln;
}

Measured memory_bytes: 4372
// Problem : A - Payment
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	// && has higher precedence than ||
	ios_base::sync_with_stdio(0); cin.tie(0);    
	ll N;
	cin>>N;
	if(N%1000==0)
		cout<<0<<endl;
	else
		cout<<1000-N%1000<<endl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W = 1;
  
  while( W > 0){
    cin >> H >> W;
    if(H == 0 && W == 0){
      break;
    }
    else{
      for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cout << "#";
      }
      cout << endl;
      }
      cout << endl;
    }     
  }  
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
int A[maxn], B[maxn], C[maxn];
int main(int argc, char const *argv[])
{
	int n; scanf("%d", &n);
	
	for(int i = 0; i < n; i++){
		scanf("%d %d %d", &A[i], &B[i], &C[i]);
	}

	for(int i = 1; i < n; i++){
		int tmpA = A[i-1], tmpB = B[i-1], tmpC = C[i-1];

		A[i] += max(tmpB, tmpC);
		B[i] += max(tmpA, tmpC);
		C[i] += max(tmpA, tmpB);
	}
	printf("%d\n", max(max(A[n-1], B[n-1]), C[n-1]));
	
	return 0;
}

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

int main() {
    int n,x;

    while(cin >> n >> x, n || x) {
        int sum = 0;
        for(int i=1;i<n;i++)
        {
            for(int j=i+1;j<x-i;j++)
            {
                int k = x-i-j;
                if(j<k && k<=n) {
                    sum += 1;
                }
            }
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int a,b,c,f[100000],ans;
int main()
{
   cin>>a>>b>>c;
   for(int i=1;i<=a;i++)
   {
       int n;
       cin>>n;
       if(n<b||n>=c)ans++;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;
void solve(){
  int n; cin >> n;
  string s; cin >> s;
  int x = 0, ans = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'I') x++;
    else x--;
    ans = max(x, ans);
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
import itertools
import math
import fractions
import functools
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
subs = []
for i in range(1,n):
    subs.append(h[i]-h[i-1])

amount = [0]*(n)
sums = 0
for i in range(0,len(subs)):
    sums += subs[i]
    amount[i+1] = sums


minimum = 10**10
for i in range(k-1,n):
    minimum = min(minimum,amount[i]-amount[i-k+1])

print(minimum)

Measured memory_bytes: 82772
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner (System.in);
		//ArrayList
		ArrayList<String> array = new ArrayList<String>();
		//????????????????????°?????????
		int card = sc.nextInt();
		//???????????????????????°???????´? i <= card ??????????????¨???????????\?????????
		for(int i = 0; i <= card; i++){
			//??????????????? ArrayList?????¶???
			array.add(sc.nextLine());
		}

		//???S??? ???????????? ???????????????????????¨??? 1??????????????????????????§14?????§ ????????????????????°???1????????????13???
		for(int i = 1; i <= 13; i++){
			//???????????????????????¨("????????? " ????????????????????????)????????´????????????????????° -1??????????????? false??¨?????????-1?????????
			//-1(???????????????)????£?????????°??¨???
			if(array.contains("S " + i) ==false){
				System.out.println("S " + i);
			}
		}
		//???H??? ????????? ???????????????????????¨???
		for(int i = 1; i <= 13; i++){
			//???????????????????????¨("????????? " ????????????????????????)????????´????????????????????° -1??????????????? false??¨?????????-1?????????
			//-1(???????????????)????£?????????°??¨???
			if(array.contains("H " + i) ==false){
				System.out.println("H " + i);
			}
		}
		//???C??? ??????????????? ???????????????????????¨???
		for(int i = 1; i <= 13; i++){
			//???????????????????????¨("????????? " ????????????????????????)????????´????????????????????° -1??????????????? false??¨?????????-1?????????
			//-1(???????????????)????£?????????°??¨???
			if(array.contains("C " + i) ==false){
				System.out.println("C " + i);
			}
		}
		//???D??? ????????? ???????????????????????¨???
		for(int i = 1; i <= 13; i++){
			//???????????????????????¨("????????? " ????????????????????????)????????´????????????????????° -1??????????????? false??¨?????????-1?????????
			//-1(???????????????)????£?????????°??¨???
			if(array.contains("D " + i) ==false){
				System.out.println("D " + i);
			}
		}
	}
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0217

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		int mi = 0, mc = 0;
		for (int i = 0; i < n; i++) {
			int d, a, b;
			cin >> d >> a >> b;
			if ((a + b) > mc) {
				mc = a + b;
				mi = d;
			}
		}
		cout << mi << " " << mc << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n, q = [int(i) for i in input().split(" ")]

queue = []
for i in range(n):
    name, time = [i for i in input().split(" ")]
    time = int(time)
    queue.append((name, time))

et = 0
result = []
while len(queue) > 0:
    job = queue.pop(0)
    et += min(job[1], q)
    newJob = (job[0], job[1]-q)
    if newJob[1] > 0:
        queue.append(newJob)
    else:
        result.append((job[0], et))

for r in result:
    print(r[0] + " " + str(r[1]))



Measured memory_bytes: 13692
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#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(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int div_two(int n) {
    int cnt = 0;
    while(true) {
        if(n % 2 == 0) {
            n /= 2;
            cnt++;
        } else {
            break;
        }
    }
    return cnt;
}

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

    int div = 0;
    int num = 1;
    repi(i, 1, N + 1) {
        int cnt = div_two(i);
        if(cnt > div) {
            div = cnt;
            num = i;
        }
    }

    cout << num << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n,d,a = map(int,input().split())
xh = [list(map(int,input().split())) for _ in range(n)]

xh.sort()

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i+1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

class BitImos:
    """
    ・範囲すべての要素に加算
    ・ひとつの値を取得
    の2種類のクエリをO(logn)で処理
    """
    def __init__(self, n):
        self.bit = Bit(n+1)

    def add(self, s, t, x):
        # [s, t)にxを加算
        self.bit.add(s, x)
        self.bit.add(t, -x)

    def get(self, i):
        return self[i]

    def __getitem__(self, key):
        # 位置iの値を取得
        return self.bit.sum(key+1)

bit = BitImos(n)
ans = 0
att = [0]*n
cnt = 0

for i in range(n):
    tmp = xh[i][0] + 2 * d
    while cnt < n:
        if xh[cnt][0] <= tmp:
            cnt += 1
        else:
            break
    att[i] = min(cnt-1, n-1)

for i,xh1 in enumerate(xh):
    x,h = xh1
    if bit.get(i) < h:
        at = -(-(h - bit.get(i)) // a)
        ans += at
        bit.add(i, att[i]+1, at*a)

print(ans)


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri();
	std::set<int> set;
	for (auto i : a) set.insert(i);
	puts(n == (int) set.size() ? "YES" : "NO");
  	return 0;
}


Measured memory_bytes: 10368
import sys
import math
import itertools
import collections

def solve(N,M,X,C,A):
    ans = []
    for bit in range(2**N):
        total = 0
        dic = {key:0 for key in range(M)}
        for i in range(N):
            if(bit & (1 << i)):
                total += C[i]
                for n,a in enumerate(A[i]):
                    dic[n]+=a
        for m in range(M):
            if(dic[m] < X):
                break
        else:
            ans.append(total)
    return min(ans) if(ans != []) else -1
    # lis = [i for i in range(N)]
    # ans = []
    # for k,_ in enumerate(lis,1):
    #     for c in itertools.combinations(lis,r=k):
    #         tmp = 0
    #         dic = {key:0 for key in range(M)}
    #         for i in set(c):
    #             tmp += C[i]
    #             for n,a in enumerate(A[i]):
    #                 dic[n] += a
    #         for m in range(M):
    #             if(dic[m] < X):
    #                 break
    #         else:
    #             ans.append(tmp)
    # return min(ans) if(ans != []) else -1
def main():
    N,M,X = map(int,input().split())
    C = []
    A = []
    for _ in range(N):
        tmp = list(map(int,input().split()))
        C.append(tmp.pop(0))
        A.append(tmp)
    # solve()
    print(solve(N,M,X,C,A))

if __name__ == "__main__":
    main()


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

int main(void) {
  int H, W;
  cin >> H >> W;
  char m[H][W];

  for (int h = 0; h < H; h++) {
    string a;
    cin >> a;
    if (a.find('#') != string::npos) {
      for (int w = 0; w < W; w++) {
        m[h][w] = a[w];
      }
    } else {
      for (int w = 0; w < W; w++) {
        m[h][w] = 'x';
      }
    }
  }

  for (int w = 0; w < W; w++) {
    int cnt = 0;
    for (int h = 0; h < H; h++) {
      if (m[h][w] == '.' || m[h][w] == 'x') {
        cnt++;
      }
    }

    if (cnt == H) {
      for (int h = 0; h < H; h++) {
        m[h][w] = 'x';
      }
    }
  }

  for (int h = 0; h < H; h++) {
    bool out = false;
    for (int w = 0; w < W; w++) {
      if (m[h][w] != 'x') {
        cout << m[h][w];
        out = true;
      }
    }
    if (out) cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include <iomanip>
#include<math.h>
using namespace std;
using ll=long long;
int main() {
	vector<int> x;
	vector<int> y;
	int c, b;
	cin >> c >> b;
	x.push_back(c);
	y.push_back(b);
	for (int i = 1; i < 3; i++) {
		cin >> c;
		cin >> b;
		x.push_back(c-x[0]);
		y.push_back(b-y[0]);
	}
	vector<long double>a;
	x[0] = 0;
	y[0] = 0;
	for (int i = 0; i < 3; i++) {

		a.push_back(sqrt((x[i] - x[(i + 1) % 3]) * (x[i] - x[(i + 1) % 3]) + (y[i] - y[(i + 1) % 3]) * (y[i] - y[(i + 1) % 3])));
	}
	
	double cos[3];
	for (int i = 0; i < 3; i++) {

		cos[i] = (a[0 + i] * a[0 + i] + a[(1 + i) % 3] * a[(1 + i) % 3] - a[(2 + i) % 3] * a[(2 + i) % 3]) / (2 * a[0 + i] * a[(1 + i) % 3]);

	}
	double tan[3];
	for (int i = 0; i < 3; i++) {
		tan[i] = sqrt((1 + cos[i]) / (1 - cos[i]));
	}
	double r[3];
	for (int i = 0; i < 3; i++) {
		r[i] = a[i]/(tan[i]+2+tan[(i+2)%3]);
	}

	long double max=0;
	for (int i = 0; i < 3; i++) {
		if (max < r[i]) {

			max = r[i];
		}
	}
	cout << setprecision(12) <<max;
}


Measured memory_bytes: 256
#include <iostream>

bool ifEndValInput(int input_n1, int input_n2);
bool inputValRangeCheck(int input_n1, int input_n2);
void printLeapYear(int start_y, int end_y);
bool isLeapYear(int year);


int main()
{
    bool is_input_started = true;
    while (true) {
        int start_year, end_year;
        std::cin >> start_year >> end_year;
        if (ifEndValInput(start_year, end_year)) {
            break;
        }
        if (!is_input_started) {
            std::cout << std::endl;
        } else {
            is_input_started = false;

        }
        if (inputValRangeCheck(start_year, end_year)) {
            printLeapYear(start_year, end_year);
        }  
    }
    return 0;
}

bool ifEndValInput(int input_n1, int input_n2)
{
    if (input_n1 == 0 && input_n2 == 0) {
        return true;
    }
    return false;
}

bool inputValRangeCheck(int input_n1, int input_n2)
{
    if (input_n1 <= 0 || input_n1 > input_n2 || input_n2 >= 3000) {
        return false;
    }
    return true;
}


bool isLeapYear(int year)
{
    if (year % 400 == 0) {
        return true;
    } else if (year % 100 == 0) {
        return false;
    } else if (year % 4 == 0) {
        return true;
    } else {
        return false;
    }
}

void printLeapYear(int start_y, int end_y)
{
    bool does_leap_year_exist = false;
    for (int i = start_y; i <= end_y; i++) {
        if (isLeapYear(i)) {
            std::cout << i << std::endl;
            does_leap_year_exist = true;
        }
    }
    if (!does_leap_year_exist) {
        std::cout << "NA" << std::endl;
    }
}

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

using namespace std;

bool f(int n) {
  while (n > 0) {
    if (n % 10 != 0 && n > 10) return false;
    if (n == 1) return true;
    n /= 10;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  if (f(N)) {
    cout << 10 << '\n';
    return 0;
  }
  int res = 0;
  while (N > 0) {
    res += N % 10;
    N /= 10;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long[] a=new long[n];
		for(int i = 0; i<n; i++){
			a[i]= sc.nextLong();
		}
		Arrays.sort(a);
		int t=Arrays.binarySearch(a,a[n-1]/2);
		long b=0;
		if(t<0){
			t=-t-1;
			if(t-1>=0){
				if(a[t]-(a[n-1]/2)>(a[n-1]/2)-a[t-1]){
					b=a[t-1];
				}else{
					b=(a[t]==a[n-1])? a[t-1]:a[t];
				}
			}else{
				b=a[t];
			}
		}else{
			b=a[t];
		}
			System.out.println(a[n-1]+" "+b);
	}
}

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

using namespace std;

class Solve {
    private:
    bool solve(int *syllables) {
        int count5 = 0;
        int count7 = 0;
        for(int i = 0; i < 3; i++) {
            if(syllables[i] == 5) {
                count5++;
            } else if(syllables[i] == 7) {
                count7++;
            }
        }
        if(count5 == 2 && count7 == 1) {
            return true;
        } else {
            return false;
        }
    }
    public:
    void takeInput() {
        int syllableLen[3];
        for(int i = 0; i < 3; i++) {
            cin>>syllableLen[i];
        }
        cout<<(solve(syllableLen)?"YES":"NO")<<endl;
    }
};

int main() {
    Solve s;
    s.takeInput();
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,j=0,a[200000];
    //char s[100];
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0; i<n-1; i++)
    {
        if(a[i]==a[i+1])
        {
            j++;
        }
    }
    if(j==0)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >>d;
  int left = a+b;
  int right = c+d;

  if (left > right) {
      cout << "Left" << endl;
  }
  else if (left < right) {
      cout << "Right" << endl;
  }
  else {
      cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}
int dp[9]={};
int main(){
    fast_io
    
    ll n;
    ll y;
    cin>>n>>y;



    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            int k=n-i-j;
            if(i+j+k==n && i*10000+j*5000+k*1000==y){
                cout<<i<<" "<<j<<" "<<k<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

n = int(input())
h_list = list(map(int, input().split()))

inf = float('inf')
ans_list = [inf for _ in range(n)]
# ans_list = [0, 1, 2,..., n-1]
# h_list = [0, 1, 2,..., n-1]

def cmin(a, b):
    if a<b:
        return a
    else:
        return b

ans_list[0] = 0
ans_list[1] = abs(h_list[1] - h_list[0])
for i in range(2, n):
    ans_list[i] = cmin(ans_list[i], ans_list[i-1]+abs(h_list[i]-h_list[i-1]))
    ans_list[i] = cmin(ans_list[i], ans_list[i-2]+abs(h_list[i]-h_list[i-2]))

print(ans_list[-1])

Measured memory_bytes: 13908
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; ++i)cin >> h[i];
	if (h[0] != 0)h[0]--;
	for (int i = 1; i < n; ++i) {
		if (h[i] > h[i - 1])h[i]--;
		else if (h[i] < h[i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>

#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DIV_NUM (1000000007)

using namespace std;

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

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

    if (input[0] == input[1] && input[2] == input[3] && input[1] != input[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}




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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
//No change above here

const ll maxi = 2 * 1e5 + 5;
ll mod = 1e9+7;
double pi = 3.141592653589793238;

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll sum_digits(ll n)
{
	ll ret = 0;
	while (n)
	{
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

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

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

ll max_subarray(vector<int>& v)
{
	if (v.empty())
		return 0;
	ll glob = v[0], loc = v[0];
	for (int i = 1; i < v.size(); ++i)
	{
		loc = max(v[i] + 0LL, loc + v[i]);
		glob = max(loc, glob);
	}
	return glob;
}

long long num_digits(long long x)
{
	long long ans = 0;
	while (x)
	{
		++ans;
		x /= 10;
	}
	return ans == 0 ? 1 : ans;
}

vector<int> topological_sort(vector<vector<int>>& graph, int n, vector<int>& indegree)
{
	vector<int> ans;
	stack<int> s;
	for (int i = 0; i < n; ++i)
		if (indegree[i] == 0)
			s.push(i);
	while (!s.empty())
	{
		int x = s.top();
		s.pop();
		ans.push_back(x);
		for (auto& adj : graph[x])
			if (--indegree[adj] == 0)
				s.push(adj);
	}
	return ans;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }


//declare needed things here

//cabacc
//abc
int main()
{
	IOS;
	ll n;
	cin >> n;
	vector<ll> v(n);
	ll sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
		sum += v[i];
		sum %= mod;
	}
	sum = sum*sum;
	sum %= mod;
	ll sum2 = 0;
	for (int i = 0; i < n; ++i)
	{
		sum2 += (v[i] * v[i]) % mod;
		sum2 %= mod;
	}
	cout << (((sum+mod-sum2)*power(2,mod-2))%mod) << endl;
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

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

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

int main()
{
    string s; cin>> s;
    if (s[0] == s[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int a[30], b[30], n, max = 0, atai = 0;
    string s;
    cin >> n;
    cin >> s;
    for (int i = 1; i <= 26; i++) {a[i] = 0; b[i] = 0;}
    
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j <= i; j++) {
            a[s[j] - 'a' + 1]++;
        }
        for (int j = i + 1; j < n; j++) {
            b[s[j] - 'a' + 1]++;
        }
        for (int j = 1; j <= 26; j++) {
            if (a[j] > 0 && b[j] > 0) atai++;
        }
        if (atai > max) max = atai;
        for (int j = 1; j <= 26; j++) {a[j] = 0; b[j] = 0;}
        atai = 0;
    }
    
    cout << max;
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int R,RR[202];

ll mat[202][202];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>R;
	FOR(i,R) cin>>RR[i], RR[i]--;
	FOR(x,N) FOR(y,N) mat[x][y]=(x==y)?0:(1LL<<40);
	FOR(i,M) {
		cin>>x>>y>>r;
		x--,y--;
		mat[x][y]=min(mat[x][y],(ll)r);
		mat[y][x]=min(mat[y][x],(ll)r);
	}
	
	int z;
	FOR(z,N) FOR(x,N) FOR(y,N) mat[x][y]=min(mat[x][y],mat[x][z]+mat[z][y]);
	sort(RR,RR+R);
	
	ll ret=1LL<<40;
	do {
		ll tot=0;
		FOR(i,R-1) tot += mat[RR[i]][RR[i+1]];
		ret=min(tot,ret);
	} while(next_permutation(RR,RR+R));
	
	
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 640
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        odd.append(v[i])
    else:
        even.append(v[i])

if len(set(odd)) == len(set(even)) == 1 and set(odd) == set(even):
    print(n//2)
else:
    o = Counter(odd)
    e = Counter(even)
    mode_odd = o.most_common(2)
    mode_even = e.most_common(2)
    if mode_odd[0][0] != mode_even[0][0]:
        cnt = n - mode_odd[0][1] - mode_even[0][1]
    else:
        if mode_odd[0][1] == mode_even[0][1]:
            cnt = n - max(mode_odd[1][1], mode_even[1][1]) - mode_odd[0][1]
        elif mode_odd[0][1] > mode_even[0][1]:
            cnt = n - mode_odd[0][1] - mode_even[1][1]
        else:
            cnt = n - mode_even[0][1] - mode_odd[1][1]
    print(cnt)

Measured memory_bytes: 19160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N ;
  cin >> N;
  int M = N % 10;
  
  if(M == 2){
    cout << "hon" << endl;
    return 0;
  }
    if(M == 4){
    cout << "hon" << endl;
    return 0;
  }
    if(M ==5){
    cout << "hon" << endl;
    return 0;
  }
    if(M == 7){
    cout << "hon" << endl;
    return 0;
  }
    if(M == 9){
    cout << "hon" << endl;
    return 0;
  }
  else if(M == 0){
    cout << "pon" << endl;
    return 0;
  }
    else if(M == 1){
    cout << "pon" << endl;
    return 0;
  }
    else if(M == 6){
    cout << "pon" << endl;
    return 0;
  }
    else if(M == 8){
    cout << "pon" << endl;
    return 0;
  }
  else {
    cout << "bon" <<endl;
    return 0;
  }
}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '

#define lam [&]


signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int N; scanf("%d", &N);
    long i;
    for(i = 1; i <= N; i *= 2);
    cout << i/2;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#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 <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

struct edge
{
	int to;
	long long cost;
	edge(int to_, long long cost_) :
		to(to_), cost(cost_) {}
};
const long long INF = 123456789012345;
using P = pair<long long, int>;//first:cost,second:vertice
void dijkstra(vector<edge>graph_[], long long dist[], int n_, int s_)
{
	priority_queue<P, vector<P>, greater<P>>que;
	que.push({ 0,s_ });
	fill(dist, dist + n_, INF);
	dist[s_] = 0ll;
	while (!que.empty())
	{
		auto q = que.top();
		que.pop();
		long long thd = q.first;
		int thv = q.second;
		if (thd > dist[thv])
		{
			continue;
		}
		for (auto ed : graph_[thv])
		{
			if (dist[ed.to] > ed.cost + thd)
			{
				dist[ed.to] = ed.cost + thd;
				que.push({ dist[ed.to],ed.to });
			}
		}
	}
}


int h, w;
int g, p;
vector<int>sol;
vector<edge>graph[200 * 200];
LL dist[200 * 200];
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
int main()
{
	cin >> h >> w;
	for (int i = 0; i < h; ++i)
	{
		string s;
		cin >> s;
		for (int j = 0; j < w; ++j)
		{
			if (s[j] == '#')continue;
			for (int d = 0; d < 4; ++d)
			{
				int ii = i + dx[d];
				int jj = j + dy[d];
				if (ii < 0 || jj < 0 || ii >= h || jj >= w)continue;
				graph[i * w + j].push_back(edge(ii * w + jj, 1));
			}
			if (s[j] == '@')p = i * w + j;
			if (s[j] == '$')sol.push_back(i * w + j);
			if (s[j] == '%')g = i * w + j;
		}
	}
	dijkstra(graph, dist, h*w, g);
	LL shut = INT_MAX;
	for (int s : sol)
	{
		shut = min(shut, dist[s]);
	}
	if (shut > dist[p])
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}
}

Measured memory_bytes: 7092
#include <bits/stdc++.h>
using namespace std;
int h[100005];
int main(){
	int n;
	cin>>n;
	int a[n+1];
	int ans=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]>100001){
			ans++;
			continue;
		}
		h[a[i]]++;
	}
	for(int i=1;i<=100003;i++){
		if(h[i]<i){
			ans+=h[i];
			continue;
		}
		if(h[i])
			ans+=h[i]-i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int next = 1;
        int res = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            if (a == next) {
                next++;
            } else {
                res++;
            }
        }
        if (next != 1) {
            System.out.println(res);
        } else {
            System.out.println(-1);
        }

    }
}


Measured memory_bytes: 48360
#include <bits/stdc++.h> 
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define inrep(t) int t;cin>>t; while(t--)
#define pb push_back
#define mp make_pair 
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi; 
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;


int main(){
	ios_base::sync_with_stdio(false); 
	ll n,h; 
	cin>>n>>h; 
	int a[n]; ll sum=0; 
	int b[n]; 
	int pr=-1; 
	reu( i,0,n){
		cin>>a[i]>>b[i]; 
		pr=max(a[i],pr); 
	}	
	ll at=0; 
	sort(b,b+n); 
	for(int i=n-1;i>=0;i--){
		if(sum>=h){
			cout<<at; return 0; 
		}
		if(b[i]>pr) { 
			sum+=b[i];
			at++; 
		}

	}
	ll ans=ceil((h-sum)/(double)pr)+at; 
	cout<<ans; 
}

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

using mat = vector<vector<char>>;

int main(){
    int n; cin >> n;
    if(n == 2){ cout << -1 << endl; return 0; }
  	if(n == 3){
      cout << 'a' << '.' << '.' << endl;
      cout << 'a' << '.' << '.' << endl;
      cout << '.' << 'a' << 'a' << endl;
      return 0;
    }
    mat d4 = {{'a','a','d','c'},
              {'b','b','d','c'},
              {'c','d','b','b'},
              {'c','d','a','a'}};
    mat d5 = {{'a','a','b','b','a'},
              {'b','c','.','.','a'},
              {'b','c','.','.','b'},
              {'a','.','c','c','b'},
              {'a','b','b','a','a'}};
    mat d6 = {{'a','a','b','c','.','.'},
              {'b','.','b','c','.','.'},
              {'b','a','a','.','c','c'},
              {'c','.','.','a','a','b'},
              {'c','.','.','b','.','b'},
              {'.','c','c','b','a','a'}};
    mat d7 = {{'a','a','b','b','c','c','.'},
              {'d','.','.','d','.','.','c'},
              {'d','.','.','d','.','.','c'},
              {'.','d','d','.','d','d','b'},
              {'d','.','.','d','.','.','b'},
              {'d','.','.','d','.','.','a'},
              {'.','d','d','.','d','d','a'}};
    mat ans(n,vector<char>(n,'.'));
    int s1 = (n-4)/4, s2 = n-s1*4;
    rep(i,s1) rep(j,4) rep(k,4) ans[i*4+j][i*4+k] = d4[j][k];
  	if(s2 == 4) rep(j,4) rep(k,4) ans[s1*4+j][s1*4+k] = d4[j][k];
    if(s2 == 5) rep(j,5) rep(k,5) ans[s1*4+j][s1*4+k] = d5[j][k];
    if(s2 == 6) rep(j,6) rep(k,6) ans[s1*4+j][s1*4+k] = d6[j][k];
    if(s2 == 7) rep(j,7) rep(k,7) ans[s1*4+j][s1*4+k] = d7[j][k];
    rep(i,n){ rep(j,n) cout << ans[i][j]; cout << endl;}
    return 0;
}

Measured memory_bytes: 4580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll h,w;
    cin>>h>>w;
    if(h%3==0||w%3==0)
    {
        printf("0\n");
        return 0;
    }
    ll ans=min(h,w);
    for(ll i=1;i<h;i++)
    {
        ll s1=w*i;
        ll s2=((w+1)/2)*(h-i);
        ll s3=(w/2)*(h-i);
        ll temp=max(max(s1,s2),s3)-min(min(s1,s2),s3);
        ans=min(ans,temp);
    }
    for(ll i=1;i<w;i++)
    {
        ll s1=h*i;
        ll s2=((h+1)/2)*(w-i);
        ll s3=(h/2)*(w-i);
        ll temp=max(max(s1,s2),s3)-min(min(s1,s2),s3);
        ans=min(ans,temp);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 256