akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

int main()
{
  long long N, K;
  cin >> N >> K;
  vector<long long> H(N);
  for(long long i=0; i<N; i++)
    cin >> H[i];

  sort(H.begin(), H.end(), greater<long long>());

  long long sum=0;
  for(long long i=K; i<N; i++)
    {
     sum += H[i];
    }

  cout << sum << endl;
  
  
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	string a;
	int n,k;
	cin>>n>>a>>k;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]!=a[k-1])a[i]='*';
	}
	cout<<a;
	return 0;
} 

Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]); var wmax = int.Parse(line[1]);
        var vaL = new int[n + 1]; var w = new int[n + 1];
        var dp = new int[n + 1, wmax + 1];
        DpSet(dp, vaL, w);
        for (int i = 0; i < n; i++)
            for (int j = 0; j <= wmax; j++)
                if (j < w[i]) dp[i + 1, j] = dp[i, j];
                else dp[i + 1, j] = Math.Max(dp[i , j], dp[i + 1, j - w[i]] + vaL[i]);
        Console.WriteLine(dp[n, wmax]);
    }
    public static void DpSet(int[,] dp, int[] vaL, int[] w)
    {
        for (int i = 0; i < vaL.Length - 1; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            vaL[i] = int.Parse(line2[0]);
            w[i] = int.Parse(line2[1]);
        }
    }
}

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

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {
  ll n, a = 0, b = 0;
  cin >> n;

  for (int i = 1; i < 3501; i++) {
    for (int j = 1; j < 3501; j++) {
      a = 4 * (i * j) - n * i - n * j;
      b = n * i * j;
      if (a > 0 && b % a == 0) {
        cout << i << ' ' << j << ' ' << b / a;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<climits>

struct item{
	long long w;
	long long v;
};

int main(){
	int n, w;
	int maxVal= 100001;
	long long ans=0;
	std::cin>>n>>w;

	std::vector<item> itemList(n);
	std::vector<long long> dpList(maxVal, INT_MAX);

	for(int i=0; i<n; i++)
		std::cin>>itemList[i].w>>itemList[i].v;

//	std::stable_sort(itemList.begin(), itemList.end(),[](const item& x, const item& y){return x.v> y.v;});
//	std::stable_sort(itemList.begin(), itemList.end(),[](const item& x, const item& y){return x.w< y.w;});

	dpList[0]= 0;

	for(int i=0; i<n; i++){
		for(int j=maxVal-1; j>=0; j--){
			if(dpList[j]==INT_MAX)
				continue;

			if(dpList[j]+itemList[i].w >w)
				continue;

			dpList[j+ itemList[i].v]= std::min(dpList[j+ itemList[i].v], dpList[j]+itemList[i].w);
		}	
	}

	for(int i=0; i<maxVal; i++){
		if(dpList[i]!=INT_MAX)
			ans= i;
	}

	std::cout<<ans<<std::endl;

	return 0; 
}

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

int main()
{
    int x, y;
    cin >> x >> y;
    if (y % 2 == 1 || y > 4 * x || y < 2 * x)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <deque>
#include <cstring>
#include <algorithm>

using namespace std;

int visited[102][102][1<<5];
int co[102][102];
char f[102][102];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

class state{
	public:
	int x,y,co,st;
	
	state(){}	
	state(int _y, int _x, int _co, int _state){
		x = _x;
		y = _y;
		co = _co;
		st = _state;
	}
};

int main(){
	int w,h;
	int sx, sy, gx, gy;
	int m=0;
	memset(co, -1 , sizeof(co));
	fill((int *)visited, (int *)visited+102*102*(1<<5), 1 << 29);
	cin >> w >> h;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			co[i][j] = 1;
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin >> f[i][j];
			if(f[i][j] == '#'){
				for(int p=-2;p<=2;p++){
					for(int q=-2;q<=2;q++){
						if(0 <= i+p && i+p <= h && 0 <= j+q && j+q <= w){
							if((p == 0 && q == 0) || co[i+p][j+q] == -1){
								co[i+p][j+q] = -1;
							}else if(max(abs(p), abs(q)) == 2){
								co[i+p][j+q] = max(co[i+p][j+q],2);
							}else{
								co[i+p][j+q] = max(co[i+p][j+q],3);
							}
						}
					}
				}
			}else if(f[i][j] == 'S'){
				sy = i;
				sx = j;
			}else if(f[i][j] == 'G'){
				gy = i;
				gx = j;
			}else if(f[i][j] == 'M'){
				f[i][j] = m + '0';
				m++;
			}
		}
	}
	deque<state> q;
	state st;
	int tx,ty,tco,tstate,nx,ny,nstate;
	q.push_back(state(sy,sx,0,0));
	visited[sy][sx][0] = 0;
	while(!q.empty()){
		st = q.front();
		q.pop_front();
		tx = st.x;
		ty = st.y;
		tco = st.co;
		tstate = st.st;
		for(int i=0;i<4;i++){
			nx = tx + dx[i];
			ny = ty + dy[i];
			if(co[ny][nx] == -1) continue;
			if('0' <= f[ny][nx] && f[ny][nx] <= '9'){
				nstate = tstate | (1 << (f[ny][nx] - '0'));
				if(visited[ny][nx][nstate] > tco + co[ty][tx]){
					visited[ny][nx][nstate] = tco + co[ty][tx];
					q.push_back(state(ny,nx,tco+co[ty][tx],nstate));
				}
			}else{
				if(visited[ny][nx][tstate] > tco + co[ty][tx]){
					visited[ny][nx][tstate] = tco + co[ty][tx];
					q.push_back(state(ny,nx,tco+co[ty][tx],tstate));
				}
			}
		}
	}
	cout << visited[gy][gx][(1 << m) - 1] << endl;
}

Measured memory_bytes: 7300
#ABC-145-C
import itertools
N = int(input())
xy_list = []
for _ in range(N):
    x, y = map(int, input().split())
    xy_list.append((x, y))

def get_distance(x1, y1, x2, y2):
    return ((x1-x2)**2 + (y1-y2)**2)**0.5

#任意の二つの街の距離を先に計算してdistance_listに格納しておく。
distance_list = [[0] * N for i in range(N)]

for i in range(N):
    for j in range(N):
        if i ==j:
            continue
        distance_list[i][j] = get_distance(xy_list[i][0], xy_list[i][1], xy_list[j][0], xy_list[j][1])

machi_list = [i for i in range(N)]
travel_list = list(itertools.permutations(machi_list))

summed_distance = 0
for travel in travel_list:
    for i in range(N-1):
        summed_distance += distance_list[travel[i]][travel[i+1]]
        
print(summed_distance/len(travel_list))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

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

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

    string s;

    cin >> s;

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

    if (s.substr(0, 3) == "abc") {
        cout << YES;
    } else {
        cout << NO;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
struct Cmp{bool operator()(const string&a, const string&b)
{
	if(a.size()-b.size())
		return a.size()<b.size();
	if(a=="cw")
		return b=="ts";
	if(b=="cw")
		return a!="ts";
	return a<b;
}};
string F(char c){string s;s+=c;return s;}
int main()
{
	typedef map<string,int,Cmp>M;
	typedef map<string,M,Cmp>MM;
	char str[512];
	MM mm;
	string kan[12]={"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"}; 
	string s,t,u;
	vector<string>v;
	int i,j;
	for(scanf("%*d");~scanf("%s",str);)
	{
		s=str;
		v.clear();
		for(i=0;i<s.size();)
		{
			if(i+1<s.size()&&count(kan,kan+12,t=s.substr(i,2)))v.push_back(t),i+=2;
			else v.push_back(F(s[i])),++i;
		}
		for(i=0;i+1<v.size();++i)++mm[v[i]][v[i+1]];
	}
	string k[38];
	for(i=0;i<26;++i)k[i]=F(i+'a');
	for(i=0;i<12;++i)k[26+i]=kan[i];
	for(i=0;i<38;++i)
	{
		M&r=mm[k[i]];
		string a=F('a');
		int c=0;
		for(j=0;j<38;++j)
		{
			if(c<r[k[j]])
			{
				c=r[k[j]];
				a=k[j];
			}
		}
		printf("%s %s %d\n",k[i].c_str(),a.c_str(),c);
	}
}

Measured memory_bytes: 844
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
const ll MOD=1e9+7;
const int mxN=5e5+5;
ll fact[mxN];
int n,m;

ll mul(ll a,ll b) {
    a%=MOD;
    b%=MOD;
    return (a*b)%MOD;
}

void precompute() {
    fact[0]=1;
    FOR(i,1,mxN)
        fact[i]=mul(fact[i-1],i);
}

ll modPow(ll a,ll b) {
    if(b==0)
        return 1;
    ll res=modPow(a,b/2);
    if(b%2)
        return mul(res,mul(res,a));
    return mul(res,res);
}

ll comb(ll a,ll b) {
    if(b>a)
        return 0;
    ll num=fact[a];
    ll den=mul(fact[b],fact[a-b]);
    return mul(num,modPow(den,MOD-2));
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    precompute();
    cin >> n >> m;
    ll tot=mul(comb(m,n),fact[n]);
    ll cur=0;
    F0R(i,n+1) {
        if(i%2)
            cur=(cur-mul(comb(n,i),mul(comb(m-i,n-i),fact[n-i])))%MOD;
        else
            cur=(cur+mul(comb(n,i),mul(comb(m-i,n-i),fact[n-i])))%MOD;
        cur=(cur+MOD)%MOD;
    }
    cout << mul(tot,cur);

    return 0;
}


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

int main(){
    stack<pair<int64_t,int>> tp;
    priority_queue<int64_t> q;
    map<int, int64_t> ans;
    int n, m = 0;
    cin >> n;
    tp.emplace(0, -1);
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        q.push(a);
        if(i==0 || tp.top().first < a) tp.emplace(a, i+1);
    }
    while(tp.top().first > 0){
        int64_t t;
        int idx;
        tie(t, idx) = tp.top();
        tp.pop();
        int64_t cnt = m * (t - tp.top().first);
        while(!q.empty() && q.top() > tp.top().first){
            cnt += q.top() - tp.top().first;
            q.pop();
            ++m;
        }
        ans[idx] = cnt;
    }

    for(int i=1;i<=n;++i) cout << ans[i] << endl;
    
    return 0;
}

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

namespace arc090_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var A1l = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
            var A2l = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            long rm = 0;

            for(int i = 0; i < N; i++)
            {
                long r = 0;
                for (int j = 0; j < N; j++)
                {
                    if (i > j)
                        r += A1l[j];
                    else if(i == j)
                    {
                        r += A1l[j];
                        r += A2l[j];
                    }
                    else
                        r += A2l[j];
                }
                if (rm < r) rm = r;
            }
            Console.WriteLine(rm);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int N,c[20];

int f(int *c,int l){
	//if(!l)return 0;
	int res=l;
	//cout<<l<<": ";rep(i,20)cout<<c[i]<<(i<19?" ":"\n");
	rep(i,l){
		//cout<<"i"<<i<<" ";
		if(c[i]==-1)break;
		if(i%4<3&&c[i]==c[i+1]){
			if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		if(i/4<4&&c[i]==c[i+4]){
			if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<=i+2;j++)d[j]=d[j+1];
			for(int j=i+3;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		if(i%4<3&&i/4<4&&c[i]==c[i+5]){
			if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<=i+3;j++)d[j]=d[j+1];
			for(int j=i+4;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		if(i%4>0&&i/4<4&&c[i]==c[i+3]){
			if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<=i+1;j++)d[j]=d[j+1];
			for(int j=i+2;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		//if(!res)return 0;
	}
	//cout<<l<<"return "<<res<<endl;
	return res;
}

int main(){
	cin>>N;
	while(N--){
		rep(i,20)cin>>c[i];
		cout<<f(c,20)<<endl;
	}
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
int main(){
  string N;
  cin >> N;
  if(N[0] == N[1] == N[2] == N[3])
  {
    cout << "Yes" << endl;
  }
  else if(N[0] == N[1] && N[1] == N[2])
  {
    cout << "Yes" << endl;
  }
  else if(N[1] == N[2] && N[2] == N[3])
  {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 50;
set<string> s;
int n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(_, 0, n){
    string t;
    cin >> t;
    s.insert(t);
  }
  cout << sz(s) << endl;
}

Measured memory_bytes: 19240
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
using namespace std;
inline ll read(){
    ll x=0;char zf=1;char ch=getchar();
    while(ch!='-'&&!isdigit(ch))ch=getchar();
    if(ch=='-')zf=-1,ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt,ans;
int a[200010],num[200010],sta[200010],gg[200010],tot,top;
set<int>s;
bool check(int x){
	memset(num,0,sizeof(num));tot=0;
	for(rt i=1;i<=min(n+1,a[1]);i++)num[i]=1;top=0;s.clear();
	for(rt i=2;i<=n;i++)if(a[i]<=n+1){
		int pl=a[i];num[pl]++;
		while(num[pl]>=x){
			if(pl==1)return 0;
			num[pl]=1,num[pl-1]++;s.insert(pl-1);
			pl--;
		}
		while(top&&sta[top]>a[i]){
			num[sta[top]]=0;
			top--;
		}
		for(auto j:s)if(j>a[i])num[j]=0,gg[++tot]=j;
		for(rt j=1;j<=tot;j++)s.erase(gg[j]);tot=0;
		sta[++top]=a[i];
	}
	return 1;
}
int main(){
//	freopen("C.in","r",stdin);
	n=r;bool fla=1;
	for(rt i=1;i<=n;i++){
		a[i]=r;
		if(i>1&&a[i]<=a[i-1])fla=0;
	}
	if(fla)return cout<<1,0;
	int L=2,R=n;
	while(L<=R){
		const int mid=L+R>>1;
		if(check(mid+1))ans=mid,R=mid-1;
		else L=mid+1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 2560
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let mut a:i64 = read();
    let mut b:i64 = read();
    let mut c:i64 = read();
    let k:i64 = read();

    if k % 2 == 0 {
        println!("{}", a-b);
    } else {
        println!("{}", b-a);
    }

}


Measured memory_bytes: 4352
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#define REP(i, N) for(int i=0; i<N; i++)
using namespace std;

//#include "atcoder.hpp"

long long gcd(long long a, long long b) {
    if (a>b) swap(a,b);
    
    auto r = b % a;
    
    return (r ? gcd(r, a) : a);
}

int main() {
    int A,B;
    
    cin >> A >> B;
    
    if (B > A)
    swap(A,B);

    cout << ((A == B) ? A * 2 : A + (A - 1)) << endl;
    
    return 0;
}



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

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

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

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

int calc(int n) {
    string s = to_string(n);
    int ret = 0;
    REP(i, s.length()) {
        ret += s[i] - '0';
    }
    return ret;
}

signed main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for(int i = 1; i <= N; ++i) {
        int sum = calc(i);
        if(A <= sum && sum <= B) { ans += i; }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    p = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            if i == N-1:
                p[i] = p[i-1]
                p[i-1] = tmp
            else:
                p[i] = p[i+1]
                p[i+1] = tmp
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()

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


int main() {
  int A , B ; 
  cin >> A >> B ; 
  
  if (A   > 9 || B  > 9 ){
    cout << -1 << endl ; 
  }
  else {
     cout << A*B << endl ;  
  }
  
}


Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N, M, P;
vector<vector<pair<int, int>>> graph(N);
vector<bool> ok;

bool bellmanford(int s, int N, vector<vector<pair<int, int>>>& graph, vector<int>& d){
  d = vector<int>(N, INF);
  d[s] = 0;
  for(int i = 0; i < N; i++){
    for(int v = 0; v < N; v++){
      if(!ok[v]) continue;
      for(int k = 0; k < (int)graph[v].size(); k++){
        pair<int, int> e = graph[v][k];
        if(d[v] != INF && d[e.first] > d[v] + e.second){
          d[e.first] = d[v] + e.second;
          if(i == N-1) return true;
        }
      }
    }
  }
  return false;
}

signed main() {
  cin >> N >> M >> P;

  graph.resize(N);
  vector<vector<int>> back(N);
  REP(i, M){
    int u, v, d;
    cin >> u >> v >> d;
    u--; v--;
    graph[u].emplace_back(v, P-d);
    back[v].emplace_back(u);
  }

  ok.resize(N, false);
  ok[N-1] = true;

  queue<int> q;
  q.push(N-1);

  while(!q.empty()){
    int v = q.front(); q.pop();

    for(auto u : back[v]){
      if(ok[u]) continue;
      q.push(u);
      ok[u] = true;
    }
  }

  vector<int> dist(N);
  if(bellmanford(0, N, graph, dist)){
    cout << -1 << "\n";
  }else{
    cout << max(0ll, -dist[N-1]) << "\n";
  }

  return 0;
}


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

int main()
{
  int a, b;
  cin >> a >> b;
  
  int count = 0;
  for (int i = a; i <= b; i ++)
  {
    if ((i / 10000 == i % 10) && ( ((i / 1000) % 10) == ((i % 100) / 10) ) ) count ++;
  }
  
  cout << count;
  return 0;
}


Measured memory_bytes: 256
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int i = 0;
    while (a > 0 and c > 0) {
        if ((i++)%2 == 0) {
            c -= b;
        } else {
            a -= d;
        }
    }
    if (i%2 == 1)
        cout << "Yes" << "\n";
    else
    {
        cout << "No" << "\n";
    }
    
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int64_t a, b;
    cin >> a >> b;
    
    int64_t ans = min(a, b / 2);
    a -= ans;
    b -= 2 * ans;
    if (a == 0) {
        ans += b / 4;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> A(N+1); for(auto& in :A) cin >> in;
    vector<ll> B(N); for(auto& in:B) cin >> in;
    
    ll sum = accumulate(A.begin(),A.end(),0LL);
    
    for(int i = 0; i < N;i++){
        ll T = min(A[i],B[i]);
        A[i] -= T;
        B[i] -= T;
        
        ll T2 = min(A[i+1],B[i]);
        A[i+1] -= T2;
    }
    ll sum2 = accumulate(A.begin(),A.end(),0LL);
    res = sum - sum2;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >>s;
  int count=0;
  for(int i=0; i<s.size(); i++){
    if(s[i]=='p') count++;
  }
  int ans=s.size();
  ans/=2;
  ans-=count;
  cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int cur = 1;
		int K = 0;
		while(cur < B){
			cur = cur - 1;
			cur = cur + A;
			++K;
		}
		System.out.println(K);
	}
}


Measured memory_bytes: 23252
#include <stdio.h>
#include <string.h>
#define MAX 10000
int main(void)

{
	char str[MAX + 1];
	int joi;
	int ioi;
	int i;
	
	while (scanf("%s", str) != EOF){
		joi = 0;
		ioi = 0;
		for (i = 0; str[i + 2] != '\0'; i++){
			if (strncmp("JOI", &str[i], 3) == 0){
				joi++;
			}
			else if(strncmp("IOI", &str[i], 3) == 0){
				ioi++;
			}
		}
		printf("%d\n%d\n", joi, ioi);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int n,q,a[100000];
    string s;
    cin>>n>>q>>s;
    a[0]=0;
    for(int i=1;i<n;i++){
        a[i]=a[i-1];
        if(s[i-1]=='A'&&s[i]=='C'){
            a[i]++;
        }
    }
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        cout<<a[r-1]-a[l-1]<<endl;
    }
    
}


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

const int MAX_SIZE = 21;
typedef pair<int, int> P;

int calc(char f[][MAX_SIZE], queue<P> q, int W, int H) {
  int n = 0;
  while (q.size()) {
    n++;
    P p = q.front();
    q.pop();
    int di[] = {-1, 1, 0, 0};
    int dj[] = {0, 0, -1, 1};
    for (int k = 0; k < 4; ++k) {
      int i = p.first  + di[k];
      int j = p.second + dj[k];
      if (i >= 0 && j >= 0 && i < H && j < W && f[i][j] == '.') {
        f[i][j] = '#';
        q.push(P(i, j));
      }
    }
  }
  return n;
}
int main() {
  int W, H;
  char f[MAX_SIZE][MAX_SIZE];
  while (true) {
    queue<P> q;
    cin >> W >> H;
    if (W == 0 && H == 0) break;
    for (int i = 0; i < H; ++i) {
      cin >> f[i];
      for (int j = 0; j < W; ++j) {
        if (f[i][j] == '@') {
          q.push(P(i, j));
        }
      }
    }
    cout << calc(f, q, W, H) << endl;
  }
}

Measured memory_bytes: 1220
/*ex7-1 B-Ruined Square
ryo_1129*/
#include <stdio.h>
#define LIMIT 100

//頂点を表す構造体
typedef struct point{
    int x_elem;
    int y_elem;
}point;

//反時計周りで与えられた2頂点から3つ目の頂点を求める関数
point find_vertex(point pt1,point pt2){
    point pt3;
    int differ_x,differ_y;
    //ベクトル(x,y)の反時計回り90°回転したベクトルは(-y,x)
    differ_x = pt2.x_elem-pt1.x_elem;
    differ_y = pt2.y_elem-pt1.y_elem;
    pt3.x_elem = pt2.x_elem-differ_y;
    pt3.y_elem = pt2.y_elem +differ_x;
    return pt3;
}

int main(void){
    //頂点の定義
    point vertex1,vertex2,vertex3,vertex4;
    //入力
    scanf("%d %d",&vertex1.x_elem,&vertex1.y_elem);
    scanf("%d %d",&vertex2.x_elem,&vertex2.y_elem);
    //関数の呼び出し
    vertex3 = find_vertex(vertex1,vertex2);
    vertex4 = find_vertex(vertex2,vertex3);
    //出力
    printf("%d %d %d %d\n",vertex3.x_elem,vertex3.y_elem,vertex4.x_elem,vertex4.y_elem);
    return 0;
}

Measured memory_bytes: 1716
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
typedef long long ll;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	int A, B;
	cin >> A >> B;
	if (B == 1) return 0*puts("0");
	int ans = 1;
	while(ans*(A-1)+1 < B) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<double,double> P;
const double INF=(1<<29);
int main() {
  int n;
  while(cin >> n && n) {
    P a[n];
    for(int i=0; i<n; i++) scanf("%lf%lf",&a[i].F,&a[i].S);
    double l=0,r=333333;
    for(int t=0; t<50; t++) {
      double m=(l+r)/2;
      vector<P> v;
      for(int i=0; i<n; i++) {
        if(a[i].S<=m) continue;
        double x=sqrt(a[i].S*a[i].S-m*m);
        v.push_back(P(a[i].F-x,-1));
        v.push_back(P(a[i].F+x,1));
      }
      sort(v.begin(),v.end());
      int d[v.size()+1];
      memset(d,0,sizeof(d));
      for(int i=0; i<v.size(); i++) d[i+1]=d[i]-v[i].S;
      double x=-INF,y=0;
      for(int i=0; i<v.size()+1; i++) {
        if(x==-INF&&d[i]>0) x=v[i-1].F;
        if(d[i]==0) {
          if(x!=-INF) y=max(y,v[i-1].F-x);
          x=-INF;
        }
      }
      if(y>=m*2) l=m;
      else r=m;
    }
    printf("%.10f\n",l*2);
  }
  return 0;
}

Measured memory_bytes: 6008
/*
 *  Created on: 24-October-2019
 *      Author: ankur314
 */
#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define db double
#define ldb long double
#define vr vector
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb(n) push_back(n)
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007
#define INF 1000000005
 
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"
 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    int r, c;
    cin>>r>>c;
    char a[r][c];
    fi(i,0,r) fi(j,0,c) cin>>a[i][j];
    lli dp[r][c];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    fi(i,0,r)
    {
    	fi(j,0,c)
    	{
    		if(a[i][j] == '.')
    		{
    			if(i-1 >= 0) dp[i][j] += dp[i-1][j];
    			if(j-1 >= 0) dp[i][j] += dp[i][j-1];
    			dp[i][j] %= MOD;
    		}
    	}
    }
    cout<<dp[r-1][c-1];
    return 0;
}

Measured memory_bytes: 9088
#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;

int H[5050],P[5050],V[5050];

ll mi[5002][5002];

bool cmp(int l,int r) {
	return H[r]-P[l]>H[l]-P[r];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>H[i]>>P[i];
		V[i]=i;
	}
	
	FOR(x,N+1) FOR(y,N+1) mi[y][x]=1LL<<60;
	sort(V,V+N,cmp);
	
	mi[0][0]=0;
	int ma=0;
	FOR(x,N) {
		FOR(y,N+1) mi[x+1][y]=mi[x][y];
		FOR(y,N) if(mi[x][y]<=H[V[x]]) mi[x+1][y+1]=min(mi[x+1][y+1],mi[x][y]+P[V[x]]), ma=max(ma,y+1);
	}
	cout<<ma<<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: 195712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }
    int N, A, B, C;
    List<Integer> l = new ArrayList<>();

    private void solve() {
        try {
            N = sc.nextInt();
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            for (int i = 0; i < N; i++) {
                l.add(sc.nextInt());
            }
            System.out.println(dfs(0,0,0,0));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private int dfs(int cur, int a, int b, int c) {
        if (cur == N) {
            return Math.min(Math.min(a,b), c) > 0 ? Math.abs(a- A) + Math.abs(b - B) + Math.abs(c - C)-30 : 100000000;
        }
        int r0 = dfs(cur+1, a, b, c);
        int r1 = dfs(cur+1, a+l.get(cur), b, c)+10;
        int r2 = dfs(cur+1, a, b+l.get(cur), c)+10;
        int r3 = dfs(cur+1, a, b, c+l.get(cur))+10;
        return Math.min(r0, Math.min(r1, Math.min(r2, r3)));
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 23380
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,MAX_Q=2e5;
ll N,Q,S[MAX_N],T[MAX_N],X[MAX_N],ans[MAX_Q];
typedef pair<ll,ll> P;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>Q;
	REP(i,N)cin>>S[i]>>T[i]>>X[i];
	set<P> st;
	REP(i,Q){
		ll d;
		cin>>d;
		st.insert(P(-d,i));
	}
	vector<ll> stop;
	REP(i,N)stop.push_back(i);
	sort(stop.begin(),stop.end(),[](ll a,ll b){
		return X[a]<X[b];
	});
	REP(i,Q)ans[i]=-1;
	for(auto i:stop){
		ll s=S[i],t=T[i],x=X[i];
		auto ite=st.upper_bound(P(x-t,N));
		while(ite!=st.end()&&ite->first<=x-s){
			ans[ite->second]=x;
			ite=st.erase(ite);
		}
	}
	REP(i,Q)cout<<ans[i]<<endl;
}

Measured memory_bytes: 22384
#include<stdio.h>
int main()
{
int p, q, r, a, b, c;
scanf("%d%d%d",&p,&q,&r);
a=p+q;
b=q+r;
c=r+p;
if(a>b)
{
if(c>b)
{printf("%d",b);}
else
{printf("%d",c);
}
}
else
{if(c>a)
{printf("%d",a);}
else
{printf("%d",c);
}
}
return 0;
}



Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <utility>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<map<int, int>> cnt_map(2);
  for (int n = 0; n < N; ++n) {
    int v;
    cin >> v;
    ++cnt_map[n % 2][v];
  }
  vector<vector<pair<int, int>>> cnts(2, vector<pair<int, int>>(2, {0, 0}));
  for (int i = 0; i < 2; ++i) {
    for (const auto& p : cnt_map[i]) {
      if (p.second >= cnts[i][0].second) {
        cnts[i][1] = cnts[i][0];
        cnts[i][0] = p;
      } else if (p.second >= cnts[i][1].second) {
        cnts[i][1] = p;
      }
    }
  }
  if (cnts[0][0].first == cnts[1][0].first) {
    int res = max(cnts[0][0].second + cnts[1][1].second,
                  cnts[0][1].second + cnts[1][0].second);
    cout << N - res << endl;
  } else {
    cout << N - cnts[0][0].second - cnts[1][0].second << endl;
  }
      
  return 0;
}


Measured memory_bytes: 8256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){
  ll n,k;
  cin >> n >> k;
  ll cnt=1;
  while(pow(k,cnt)<=n){
    cnt++;
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <utility>
#include <cstring>
using namespace std;

int toInt(const string &s) {
  istringstream iss(s);
  int ret; iss >> ret;
  return ret;
}

struct Node {
  pair<int, int> date, time;
  string action;
  int id;
};

pair<int, int> toDate(const string &s) {
  int month, day;
  month = toInt(s.substr(0, 2));
  day   = toInt(s.substr(3, 2));
  return make_pair(month, day);
}

pair<int, int> toTime(const string &s) {
  int hour, minute;
  hour = toInt(s.substr(0, 2));
  minute   = toInt(s.substr(3, 2));
  return make_pair(hour, minute);
}

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<vector<Node>> input;
    map<int,int> spent;
    for(int i = 0; i < N; ++i) {
      string date_s, time_s, action_s, id_s;
      cin >> date_s >> time_s >> action_s >> id_s;
      if(input.empty() || input.rbegin()->begin()->date != toDate(date_s)) {
        input.push_back(vector<Node>());
      }
      input.rbegin()->push_back((Node){ toDate(date_s), toTime(time_s), action_s, toInt(id_s) });
      spent[toInt(id_s)] = 0;
    }
#if 0
    for(int i = 0; i < (int)input.size(); ++i) {
      cerr << input[i].begin()->date.first << "/" << input[i].begin()->date.second << endl;
      for(int j = 0; j < (int)input[i].size(); ++j) {
        cerr << input[i][j].time.first << ":" << input[i][j].time.second << " " << input[i][j].action << " " << input[i][j].id << endl;
      }
    }
#endif
    for(int i = 0; i < (int)input.size(); ++i) {
      static bool isOpen[60*24];
      memset(isOpen, 0x00, sizeof(isOpen));
      map<int, int> enter;
      for(int j = 0; j < (int)input[i].size(); ++j) {
        Node &node = input[i][j];
        if(node.id == 0) {
          if(node.action == "I") {
            enter[0] = node.time.first*60 + node.time.second;
          }
          else {
            // cerr << "open:" << enter[0] << " close:" << node.time.first*60 + node.time.second << endl;
            for(int k = enter[0]; k < node.time.first*60 + node.time.second; ++k) {
              isOpen[k] = true;
            }
          }
        }
      }
      for(int j = 0; j < (int)input[i].size(); ++j) {
        Node &node = input[i][j];
        if(node.id != 0) {
          if(node.action == "I") {
            enter[node.id] = node.time.first*60 + node.time.second;
          }
          else {
            for(int k = enter[node.id]; k < node.time.first*60 + node.time.second; ++k) {
              if(isOpen[k]) spent[node.id]++;
            }
          }
        }
      }
#if 0
      for(auto item : spent) {
        cerr << "id: " << item.first << " spent: " << item.second << endl;
      }
#endif
    }
    int ans = 0;
    for(auto item : spent) {
      ans = max(ans, item.second);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1360
#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250005
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define __ template<typename T, typename... Types>
void in() {rt;} __ void in(T &a, Types&... b){cin>>(a); in(b...);}
void o() {rt;}  __ void o(T a, Types... b){cout<<(a);sp; o(b...);}
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS],tem[AS];
int main()
{
    fast;
    in(n);
    fr(i,0,n-1)in(ar[i],br[i]);
    fr(i,0,n-3)
    {
        if(ar[i]==br[i] and ar[i+1]==br[i+1] and ar[i+2]==br[i+2]){o("Yes");rt 0;}
    }
    o("No");
}



Measured memory_bytes: 3656
#include <iostream>
#include <chrono>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <map>
#include <deque>
#include <string.h>
#include <set>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-a) : (a))
#define YesNo(flag) ((flag) ? "Yes\n" : "No\n")
#define YESNO(flag) ((flag) ? "YES\n" : "NO\n")

constexpr auto NMAX = (int)1e5 + 20;
constexpr auto INF_ULL = 18446744073709551615;
constexpr auto INF_INT = 2147483647;
constexpr auto PI = 3.14159265359;
constexpr auto MOD = 1000000007;

using namespace std;

typedef unsigned long long ull;

ull n;
vector<int> xors;
vector<int> ans;
int fullXor;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		int aux;
		cin >> aux;
		xors.push_back(aux);
		fullXor ^= aux;
	}

	for (int xr : xors) {
		int res = fullXor ^ xr;
		cout << res << ' ';
	}
	return 0;
}

Measured memory_bytes: 4204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AShrinking solver = new AShrinking();
        solver.solve(1, in, out);
        out.close();
    }

    static class AShrinking {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            String s = in.string();
            int[] n = new int[26];
            for (char c : s.toCharArray()) {
                n[c - 'a']++;
            }
            int min = 100000;
            for (char c = 'a'; c <= 'z'; c++) {
                String t = s;
                int ans = 0;
                while (t.chars().distinct().count() > 1) {
                    char[] ns = new char[t.length() - 1];
                    for (int i = 0; i < ns.length; i++) {
                        ns[i] = t.charAt(i) == c || t.charAt(i + 1) == c ? c : t.charAt(i);
                    }
                    t = String.valueOf(ns);
                    ans++;
                }
                min = Math.min(min, ans);
            }
            out.println(min);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 30192
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

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

  int H, N;
  cin >> H >> N;
  int A[N], B[N];
  rep(i,N){
    cin >> A[i];
    cin >> B[i];
  }
  int dp[N+1][H+1];
  rep(i,N+1){
    rep(j,H+1){
      dp[i][j] = INF;
    }
  }
  rep(i,N+1){
    dp[i][0] = 0;
  }
  rep(i,N){
    rep(j,H+1){
      if(A[i] > j)
        dp[i+1][j] = min(dp[i][j], dp[i+1][0] + B[i]);
      else{
        dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + B[i]);
      }
    }
  }
  cout << dp[N][H] << endl;
}

Measured memory_bytes: 78464
import math

n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
orderp=0
orderq=0

for i in range(n):
  orderp+=(p[i]-1)*math.factorial(n-i-1)
  orderq+=(q[i]-1)*math.factorial(n-i-1)
  for j in range(i+1,n):
    if p[j]>p[i]:
      p[j]-=1
    if q[j]>q[i]:
      q[j]-=1
  #print(orderp,orderq)
  #print(p,q)


print(abs(orderp-orderq))

Measured memory_bytes: 3064