akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

// デバッグ用
#define _DEBUG
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
// ここまで
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    REP(i, N) { cin >> v[i]; }
    SORT(v);
    int mi = INT_MAX;
    REP(i, N - K + 1) { chmin(mi, v[i + K - 1] - v[i]); }
    cout << mi;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	ll n,x,mod;
	slld(n);slld(x);slld(mod);
	vector<ll> sums;
	map<ll, int> m;
	m[x]=0;
	sums.pb(x);
	ll val=(x*x)%mod;
	int i=1;
	while(m.count(val)==0 && sums.size()!=n){
		sums.pb(sums.back()+val);
		m[val]=i;
		val = (val*val)%mod;
		i++;
	}
	if(sums.size()==n){
		cout<<sums.back();
	}else{
		int q=i-m[val];
		if(m[val]>0){
			//cout<<((n-m[val])/q)<<" "<<sums.back()-sums[m[val]-1]<<" "<<(n-m[val])%q<<" "<<(sums[n%q + m[val]]-sums[m[val]-1])<<" "<<sums[m[val]-1]<<endl;
			cout<<((n-m[val])/q)*(sums.back()-sums[m[val]-1]) + ((n-m[val])%q==0?0:(sums[(n-m[val])%q + m[val] -1 ]-sums[m[val]-1])) + sums[m[val]-1];
		}
		else{
			cout<<(n/q)*sums.back() + (n%q==0?0:sums[n%q-1]);
		}
	}
}

Measured memory_bytes: 6672
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;

  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  Int res=0;
  for(Int i=2;i<n;i++) res^=as[i];


  Int x=as[0],y=as[1];

  const Int INF = 1LL<<60;
  Int dp[2][2];
  dp[0][0]=dp[0][1]=INF;
  dp[1][0]=dp[1][1]=INF;

  Int mask=(1<<20)-1;
  for(Int q=0;q<(1<<20);q++){
    Int a=(x-q)&mask;
    Int b=(y+q)&mask;
    if(a^b^(res&mask)) continue;
    chmin(dp[(x>>20)!=((x-q)>>20)][(y>>20)!=((y+q)>>20)],q);
  }

  Int ans=x;
  for(Int i=0;i<2;i++){
    for(Int j=0;j<2;j++){
      if(dp[i][j]==INF) continue;
      Int q=dp[i][j];
      for(Int p=0;p<(1<<20);p++){
        Int z=(p<<20)|q;
        if(z>=x) continue;
        if((x-z)^(y+z)^res) continue;
        chmin(ans,z);
      }
    }
  }

  if(ans>=x) ans=-1;
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3624
A, B, C, K = list(map(int, input().split()))

ans = 0

if K >= A:
    K = K-A
    ans += A
    if K >= B:
        K= K-B
        if K >= C:
            K = K-C
            ans -= C
        else:
            ans -= K
            K=0

else:
    ans += K

print(ans)


Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if(a+b >= c){
    cout << b+c << endl;
    return 0;
  }else{
    cout << a+2*b+1 << endl;
    return 0;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

class program
{
    static public int mod = 1000000007;
    static void Main()
    {
        var nk = longa();
        long n = nk[0], k = nk[1];
        var item = new long[k];
        long ans = 0;
        for(long i = k; i > 0; i--)
        {
            item[i - 1] = pow(k / i, n);
            for(long j = 2 * i; j <= k; j += i)
            {
                item[i - 1] -= item[j - 1];
                if (item[i - 1] < 0) item[i - 1] += mod;
            }
            ans += i * item[i - 1];
            ans %= mod;
        }
        Write(ans);
    }

    static long pow(long a, long b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return value; }
    static string rstr() { return ReadLine(); }
    static int rint() { return int.Parse(ReadLine()); }
    static long rlong() { return long.Parse(ReadLine()); }
    static string[] stra() { return ReadLine().Split(' '); }
    static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); }
    static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } }
    static long LCM(long a, long b) { return a * b / GCD(a, b); }
    static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } }
    static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); }
}


Measured memory_bytes: 33620
#include<bits/stdc++.h>
using namespace std;
int read()
{
	char s;
	int k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(s>='0'&&s<='9'));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(s>='0'&&s<='9')
	{
		k=k*10+(s-'0');
		s=getchar();
	}
	return k*base;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		write(-x);
	}
	else
	{
		if(x/10)write(x/10);
		putchar(x%10+'0');
	}
}
int n,m,X,Y,id;
int w[3];//1:白的/0:黑的
int	yb;//某白的和黑的有直连的边 
int to[200010];
int ne[200010];
int po[100010];
int vis[100010][2];//0:black 1:white
int Vis[200010];
int cd[100010];
long long cnt[3];
void add(int x,int y)
{
	id++;
	to[id]=y;ne[id]=po[x];po[x]=id;
}
void dfs(int d,int y,int fa)
{
	if (vis[d][y]) return;
	vis[d][y]++;
	w[y]++;
	int yy=1-y;
	for (int i=po[d];i;i=ne[i])
	{
		int v=to[i];
		if (v==fa) continue;
		if (vis[v][yy]) continue;
		if (Vis[i]) yb++;
		Vis[i]=1;
		dfs(v,yy,d);
	}
}
long long ans;
int main()
{
	n=read();m=read();
	for (int i=1;i<=m;i++)
	{
		X=read();Y=read();
		add(X,Y);
		cd[X]++;
		cd[Y]++;
		add(Y,X);
	}
	dfs(1,1,-1);
	ans=0;
	for (int i=1;i<=n;i++)
	{
		if (vis[i][0]&&(!vis[i][1])) cnt[0]++;
		if (vis[i][0]&&vis[i][1]) cnt[2]++;
		if (vis[i][1]&&(!vis[i][0])) cnt[1]++;
	}
	ans=cnt[0]*cnt[1]+cnt[0]*cnt[2]+cnt[1]*cnt[2]+(cnt[2]-1)*(cnt[2])/2-m;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);

  int N;
  cin >> N;
  vector<int> vec(N);
  int sum = 0;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    vec[i]=x;
    sum = sum xor x;
  }
  for(int i=0; i<N; i++){
    int result = sum xor vec[i];
    cout << result << endl;
  }
  return 0;
}


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

int main() {
  int N, K;

  cin >> N >> K;

  int result = 1;
  for (int i = 0; i < N; i++) {
    if (result * 2 < result + K) {
      result *= 2;
    } else {
      result += K;
    }
  }

  cout << result << endl;
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000


typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

struct edge{
	int from;
	int to;
	int nxt_edge;
};

const int N = 1e5+5;

int n, e;
struct edge edges[N];
int heads[N];
int dp[N];

int solve(int cur_edge_idx){
	if(cur_edge_idx == -1)
		return 0;
// 	cout << cur_edge_idx << endl;
	int & cur = dp[cur_edge_idx];
	if(~cur)
		return cur;
	cur  = solve(edges[cur_edge_idx].nxt_edge);
	if(edges[cur_edge_idx].to > 0)
	    cur = max(cur, 1 + solve(heads[edges[cur_edge_idx].to]));
	return cur;
}

int main()
{
    cin >> n >> e;
	clr(edges, 0);
	clr(heads, -1);
	clr(dp, -1);
    lp(i, e){
    	cin >> edges[i].from >> edges[i].to;
    	edges[i].nxt_edge = heads[edges[i].from];
    	heads[edges[i].from] = i;
    }
    int res = 0;
    lpi(i, 1, n+1)
    	res = max(res, solve(heads[i]));
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
//#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

map<char,int>mp[100];
map<char,int>::iterator it;

 int main(){

  long long n,c=0,d=0;
  char ch;
  string s,s1;
  cin>>n;

  for(int i=0;i<n;i++)
 {
    cin>>s;
    if(i == 0)s1 = s;
    for(int j=0;j<s.length();j++)
    {
        mp[i][s[j]]++;
    }
  }


  for(it = mp[0].begin();it!=mp[0].end();++it)
 {

    ch = it->first;
    d = it->second;
   // cout<<ch<<" ? "<<d<<endl;
     for(int i=1;i<n;i++){
 //       cout<<"character "<<mp[i][ch]<<endl;
        c = mp[i][ch];
        if(d>c){ d = c;}
     }
     // cout<<ch<<" // "<<d<<endl;
     for(int j=0;j<d;j++){
        cout<<ch;
     }

  }





 return 0;
 }



Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n,a[N],sz[N],p[N],cnt;
vector<int>v[N];
void ss(int n){
	for(int i=2;i<=n;i++){
		if(v[i].empty())
			for(int j=i;j<=n;j+=i) v[j].pb(i); 
	}
} 
map<int,int>mp;
int main(){
	ss(1e6); 
	scanf("%d",&n);
	int g=0,ou=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0) ou++;
		g=__gcd(g,a[i]);
		for(int j=0;j<v[a[i]].size();j++){
			 mp[v[a[i]][j]]++;
		} 
	}
	if(ou>1){
		puts(g==1?"setwise coprime":"not coprime");
	}
	else {
		int f=0;
		for(auto p:mp){
			if(p.se>1){
				f=1;
				break;
			} 
		}
		if(!f) puts("pairwise coprime");
		else puts(g==1?"setwise coprime":"not coprime");
	}
 	return 0;
}

Measured memory_bytes: 66560
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>










const int N = 2e5 + 10;
int n, a, c[N];



void solve()
{
	cin >> n;
	for(int i = 1; i <= n; i++)c[i] = 0;
	for(int i = 2; i <= n; i++)
	{
		cin >> a;
		c[a]++;
	}
	for(int i = 1; i <= n; i++)cout << c[i] << "\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 4452
#include <iostream>
#include <vector>

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

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

  int inf = 1000000007;
  std::vector<int> dp(N + 1000, inf);

  dp[0] = 0;
  for (int i = 0; i < N; ++i)
    for (int k = 1; k <= K; ++k)
      chmin(dp[i + k], dp[i] + std::abs(h[i] - h[i + k]));

  std::cout << dp[N - 1] << std::endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MOD 1000000007
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;

int main()
{
    int n, i;
    char s[100000];
    int count[26] = {0};
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0; i<n; i++) {
        char a[] = "a";
        int temp = strncmp(s+i, a, 1);
        count[temp]++;
    }
    lli ans = 1;
    for(i=0; i<26; i++) {
        ans = (lli)ans * (count[i]+1) % MOD;
    }
    ans = (ans==0?MOD-1:ans-1);
    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main() {
	string s;
	cin >> s;
	if (s == "Sunny")
		cout << "Cloudy";
	if (s == "Cloudy")
		cout << "Rainy";
	if (s == "Rainy")
		cout << "Sunny";
}

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



int main(void){
    long long N,K;
    scanf("%lld%lld", &N, &K);
    vector<int> a;
    for(int i=0;i<N;i++){
        int po;
        scanf("%d", &po);
        a.push_back(po);
    }
    vector<int> b = a;
    long long tento=0;
    for(int i=0;i<N-1;i++)for(int j=N-1;j>i;j--){
        if(b[j-1]>b[j]){
            int tmp=b[j];
            b[j]=b[j-1];
            b[j-1]=tmp;
            tento++;
        }
    }
    
    long long ans = (tento * K)%MOD;
    
    sort(a.begin(), a.end(), greater<int>());
    
    long long tmp2=0;
    for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)if(a[i]>a[j])tmp2++;
    ans += tmp2 * ((K * (K-1) / 2)%MOD) ;
    ans%=MOD;
    printf("%lld", ans);
    return 0;
}


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  int n=(int)s.size();
  bool flg=true;
  for(int i=0;i<(n-1)/2;i++){
    if(s[i]!=s[n-i-1])flg=false;
  }
  int m=(n-1)/2;
  if(m%2==1){
    for(int i=0;i<(m-1)/2;i++){
        if(s[i]!=s[m-i-1])flg=false;
        }
  }
  else {
    for(int i=0;i<m/2;i++){
        if(s[i]!=s[m-i-1])flg=false;
        }
  }
  if(flg)puts("Yes");
  else puts("No");
  return 0;
}


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

int main()
{
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	int p[3] = {0,0,0};
	char q[3] = {'A', 'B', 'C'};
	int t = 0;
	while (true)
	{
		if (p[t] == s[t].size())
		{
			cout << q[t] << endl;
			return 0;
		}
		p[t]++;
		t = s[t][p[t]-1] - 'a';
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main()
{
    int n, m; cin>>n>>m;
    priority_queue<P, vector<P>, greater<P>> que;
    for(int i=0; i<n; i++){
        ll a; cin>>a;
        que.push({a, 1});
    }
    for(int i=0; i<m; i++){
        int b; ll c; cin>>b>>c;
        int b0=b;
        while(b>0 && !que.empty()){
            P p=que.top();
            if(p.first>=c) break;
            que.pop();
            if(p.second>b){
                que.push({p.first, p.second-b});
                b=0;
            }else{
                b-=p.second;
            }
        }
        que.push({c, b0-b});
    }
    ll ans=0;
    while(!que.empty()){
        P p=que.top(); que.pop();
        ans+=p.first*p.second;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>

using namespace std;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b<=a+c && a+b<=b+c){
        cout<<a+b;
         return 0;
    }
    if(a+c<=a+b && a+c<=b+c){
        cout<<a+c;
         return 0;
    }
    if(c+b<=a+c && c+b<=b+a){
        cout<<c+b;
         return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>

struct Coordinate {
	int h, w;
	bool operator<(const Coordinate other) const {
		return h == other.h ? w < other.w : h < other.h;
	}
};
int main() {
	int height, width, bomb; std::cin >> height >> width >> bomb;
	std::vector<int> height_count(height, 0), width_count(width, 0);
	std::vector<Coordinate> bombs(bomb);
	for (auto& b : bombs) {
		std::cin >> b.h >> b.w;
		--b.h; --b.w;
	}
	for (const auto b : bombs) {
		height_count[b.h]++;
		width_count[b.w]++;
	}
	const auto max_height = *std::max_element(height_count.begin(), height_count.end());
	const auto max_width = *std::max_element(width_count.begin(), width_count.end());
	const auto count_h_max = std::count(height_count.begin(), height_count.end(), max_height);
	const auto count_w_max = std::count(width_count.begin(), width_count.end(), max_width);
	if (((long long int)count_h_max) * count_w_max > bomb) {
		std::cout << max_height + max_width << '\n';
	}
	else {
		std::set<Coordinate> set;
		std::vector<int> height_pos; height_pos.reserve(count_h_max);
		for (auto i = 0; i < height; ++i) {
			if (height_count[i] == max_height) {
				height_pos.push_back(i);
			}
		}
		for (auto i = 0; i < width; ++i) {
			if (width_count[i] == max_width) {
				for (const auto h : height_pos) {
					set.insert(Coordinate{ h, i });
				}
			}
		}
		for (const auto c : bombs) {
			set.erase(c);
		}
		if (set.empty()) {
			std::cout << max_height + max_width - 1 << '\n';
		}
		else {
			std::cout << max_height + max_width << '\n';
		}
	}
}

Measured memory_bytes: 22968
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#include <assert.h>
#include <stdio.h>
typedef long long int lld;

void table(int prev[], int new[]) {
  for (int i = 0; i <= 9; i++) {
    if (prev == NULL) {
      new[i] = 1;
    } else {
      new[i] = 0;
      for (int j = -1; j <= 1; j++) {
        if (i + j < 0 || i + j > 9) {
          continue;
        }
        new[i] += prev[i + j];
      }
    }
  }
}

int main() {
  int k;
  assert(scanf("%d", &k) == 1);

  int cnt[20][10], last;
  lld tmp = k - 1;
  for (int i = 0; i < 20; i++) {
    table(i > 0 ? cnt[i - 1] : NULL, cnt[i]);
    for (int j = 1; j <= 9; j++) {
      if (tmp >= cnt[i][j]) {
        tmp -= cnt[i][j];
      } else {
        last = j;
        printf("%d", last);
        for (int l = i - 1; l >= 0; l--) {
          for (int m = -1; m <= 1; m++) {
            if (last + m < 0 || last + m > 9) {
              continue;
            }
            if (tmp >= cnt[l][last + m]) {
              tmp -= cnt[l][last + m];
            } else {
              last = last + m;
              printf("%d", last);
              break;
            }
          }
        }
        goto exit;
      }
    }
  }
  exit:
  puts("");
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define int long long

const int MAX_NUM = 200000;
int N, nums[MAX_NUM+1];
signed main(){
    cin >> N;
    vector<int> A(N);
    rep(i,N){
        cin >> A[i];
        nums[A[i]]++;
    }
    int total = 0;
    rep(i,MAX_NUM+1){
        total += nums[i]*(nums[i]-1)/2;
    }
    rep(i,N){
        int before = nums[A[i]]*(nums[A[i]]-1)/2;
        int after = (nums[A[i]]-1)*(nums[A[i]]-2)/2;
        cout << total - before + after << endl;
    }
}

Measured memory_bytes: 4736
lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(lst[k-1])

Measured memory_bytes: 3060
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    var n = sc.nextLong

    var ans = ""
    while (n != 0) {
      if (n % 2 != 0) {
        n -= 1
        ans = "1" + ans
      } else {
        ans = "0" + ans
      }
      n = n / -2
    }

    if (ans == "") ans = "0"
    println(ans)
  }

  def solve2(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextLong

    val limit = 30 //仮に100桁
    for (mask <- 0 until (1 << limit)) {
      var num = 0L
      for (i <- 0 until limit) {
        if (((mask >> i) & 1) == 1) {
          num += math.pow(-2, i).longValue
        }
      }
      if (num == n) {
        println(mask.toBinaryString)
        return
      }
    }
  }
}


Measured memory_bytes: 25536
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;

priority_queue<int, vector<int>, less<int> > q;

int main(){
	ios::sync_with_stdio(false);
	int n,m,tmp,ans=0;
	cin>>n>>m;
	for(int i=0;i<n;++i){
		cin>>tmp;
		q.push(tmp);
	}
	for(int i=0;i<m;++i){
		ans+=q.top();
		q.pop();
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 500005
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define int ll
using namespace std;
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,ans,tong[N],a[N],vis[N],x,y;
inline void add(int x){
	if (x<=0) return;
	ans+=(++tong[x]==1);
}
inline void del(int x){
	if (x<0) return;
	ans-=(--tong[x]==0);
}
signed main(){
	n=read();m=read();
	F(i,1,n) a[i]=read(),vis[a[i]]++,add(a[i]-vis[a[i]]+1);
	F(i,1,m){
		x=read();y=read();
		del(a[x]-vis[a[x]]+1);vis[a[x]]--;add(y-vis[y]);vis[y]++;a[x]=y;
		wrn(n-ans);
	}
	return 0;
}
/*
10 3
8 4 2 9 10 2 10 1 9 4
8 1
1 8
7 7
*/

Measured memory_bytes: 11264
#include <iostream>
#include <algorithm>

using namespace std;
int top=0,s[1000];
void push (int x)
{
    s[++top]=x;
}

int pop() {
    
    return s[top--];
}

int main (){
    int a,b;
    top =0;
    char S[100];
    int i=0;
    while (cin >> S){
        if(S[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
            
        }
        else if(S[0]=='-'){
            b=pop();
            a=pop();
            push(a-b);
            
        }
        else if(S[0]=='*'){
            a=pop();
            b=pop();
            push(a*b);

        }
        else{
            push(atoi(S));
            
        }


    if(cin.eof()){
        break;
    }

    }
    int c=pop();
    cout <<c<<endl;
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

using mint = ModInt<MOD>;
int main() {
	int64_t n; cin >> n;
	int64_t c[n]; rep(i,n) cin >> c[i];
	sort(c, c + n);
	reverse(c, c + n);
	mint ans = 0, mul = 4;
	mul = mul.pow(n - 1);
	for(int i = 0; i < n; ++i) {
		ans += mul * (mint)c[i] * (mint)(i + 2);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
H = sorted([int(input()) for _ in range(N)])
l, r = 0, K-1
ans = 10**10
for _ in range(N-K+1):
    ans = min(ans, H[r]-H[l])
    l += 1
    r += 1
print(ans)

Measured memory_bytes: 8280
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    int ans = 1000000000;
    for(int i = 0; i < N; i++){
        int A; cin >> A;
        int cnt = 0;
        while(A >= 0){
            if(A % 2 != 0) break;
            A /= 2;
            cnt++;
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int num, length, arr[100000], i, check= 0, temp;

	scanf("%d%d", &num, &length);
	for(i= 0; i< num; i++)
	{
		scanf("%d", &arr[i]);
		if(i && arr[i- 1]+ arr[i]>= length)
		{
			check= 1;
			temp= i;
		}
	}

	if(check)
	{
		printf("Possible\n");
		for(i= 1; i< temp; i++)
			printf("%d\n", i);
		for(i= num- 1; i>= temp; i--)
			printf("%d\n", i);
	}
	else
		printf("Impossible\n");

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>

#define rep(i,n) for((i)=0;i<(int)(n);i++)
using namespace std;
int i, j, k;
int main(){
	int N, K;
	int *h = new int[100000];
	cin >> N >> K;
	rep(i, N) {
		cin >> h[i];
	}
	sort(h, h + N);
	long long delta = 10000000000;
	rep(i, N - K + 1) {
		delta = (h[i + K - 1] - h[i] > delta ? delta : h[i + K - 1] - h[i]);
	}
	cout << delta;
	return 0;
}



Measured memory_bytes: 640
n, d = map(int, input().split())
points = []
ints = 0

for i in range(n):
    points.append(tuple(map(int, input().split())))

for i in range(n):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += pow(points[i][k]-points[j][k], 2)
        dist = pow(dist, 1/2)
        if dist.is_integer():
            ints += 1

print(ints)


Measured memory_bytes: 3188
use std::cmp::{min,max};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main(){
    input!{
        s:chars,
    }
    let mut black = 0;
    let mut white = 0;
    for j in 0..s.len() {
        if j % 2 == 0 {
            if s[j] == '0'{
                black +=1;
            } else {
                white += 1;                
            }
        } else{
            if s[j] == '1' {
                black += 1;
            } else{
                white += 1;
            }
        }
    }
    println!("{}",min(white, black));
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int H;
int W;

int a[2001][2001];
bool used[2001][2001];
int b[2001][2001];
int c[2001][2001];
int dfs(int x,int y,int num){
	used[x][y]=true;
	if(y==W-1){
		b[x][y]=num;
		return num;
	}
	if(a[x][y+1]==1){
		b[x][y]=num;
		return num;
	}else{
		b[x][y]=dfs(x,y+1,num+1);
		return b[x][y];
	}
}
int dfs2(int x,int y,int num){
	used[x][y]=true;
	if(x==H-1){
		c[x][y]=num;
		return num;
	}
	if(a[x+1][y]==1){
		c[x][y]=num;
		return num;
	}else{
		c[x][y]=dfs2(x+1,y,num+1);
		return c[x][y];
	}
}

int main(){
	cin>>H>>W;
	REP(i,H){
		string S;
		cin>>S;
		REP(j,S.size()){
			if(S[j]=='#'){
				a[i][j]=1;
				b[i][j]=-1;
				c[i][j]=-1;
			}else{
				a[i][j]=0;
			}
		}
	}
	REP(i,H){
		REP(j,W){
			used[i][j]=false;
		}
	}
	REP(i,H){
		REP(j,W){
			if(used[i][j]==false&&a[i][j]==0){
				dfs(i,j,1);
			}
		}
	}
	REP(i,H){
		REP(j,W){
			used[i][j]=false;
		}
	}
	REP(i,W){
		REP(j,H){
			if(used[j][i]==false&&a[j][i]==0){
				dfs2(j,i,1);
			}
		}
	}
	int ans=0;
	REP(i,H){
		REP(j,W){
			//cout<<i<<" "<<j<<" "<<b[i][j]<<" "<<c[i][j]<<endl;
			ans=max(ans,b[i][j]+c[i][j]-1);
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 51072
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h, w, n; cin >> h >> w >> n;
    int x, y; cin >> x >> y;
    string s[2]; cin >> s[1] >> s[0];
    reverse(s[0].begin(), s[0].end());
    reverse(s[1].begin(), s[1].end());
    // LR
    int curl = 1; int curr = w;
    int curu = 1; int curd = h;
    for (int i = 0; i < n; i++) {
        int c = s[0][i];
        if (c == 'R') curl = max(1, curl-1);
        else if (c == 'L') curr = min(w, curr+1);
        else if (c == 'U') curd = min(h, curd+1);
        else if (c == 'D') curu = max(1, curu-1);
        c = s[1][i]; 
        if (c == 'R') curr--;
        else if (c == 'L') curl++;
        else if (c == 'U') curu++;
        else if (c == 'D') curd--;
        if (curr < curl || curd < curu) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if (curu <= x && x <= curd && curl <= y && y <= curr) {
        cout << "YES" << endl;
    } else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };





ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}

int main() {
	int R;
	cin >> R;
	if (R < 1200)cout << "ABC";
	else if (R < 2800)cout << "ARC";
	else cout << "AGC";
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000007;
const static int inf = INT_MAX;
const static llong INF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

template<typename T> T my_lcm(T a, T b){
    return a * b / my_gcd(a, b);    
}

void solve();

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

    solve();

    return 0;
}

void solve() {
    int a, b;
    cin >> a >> b;
    bool check[3] = {false, false, false};
    check[a - 1] = true;
    check[b - 1] = true;

    rep(i, 3) {
        if (! check[i]) {
            cout << i + 1 << endl;
            break;
        }
    }

    return;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m),c(n+1);
	bool ans = false;
	rep(i, 0, m) {
		cin >> a[i] >> b[i];
		if (a[i] == 1)c[b[i]]++;
		if (b[i] == n)c[a[i]]++;
	}
	rep(i, 2, n + 1) {
		if (c[i] == 2)ans = true;
	}
	if (ans)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 11234;
ll A[MAX_N];
ll B[MAX_N];

bool solve() {
  int N = nextInt();
  vector<ll> d;
  ll sumA = 0;
  ll sumB = 0;
  REP(i, N) A[i] = nextInt();
  REP(i, N) B[i] = nextInt();
  REP(i, N) {
    sumA += A[i];
    sumB += B[i];
    d.push_back(B[i] - A[i]);
  }
  sort(ALL(d));
  ll K = sumB - sumA;
  if (K < 0) return false;

  ll k = K;
  for (int i = 0; i < N; i++) {
    if (d[i] < 0) {
      if (-d[i] <= k) {
        k -= -d[i];
        d[i] = 0;
      } else {
        return false;
      }
    } else if (d[i] % 2 == 1) {
      if (1 <= k) {
        d[i] += 1;
        k -= 1;
      } else {
        return false;
      }
    }
  }
  if (k > 0) { d[N-1] += k; k = 0; }
  k = K;
  for (int i = 0; i < N; i++) {
    if (d[i] < 0) return false;
    if (d[i] % 2 == 1) return false;
    if (d[i]/2 <= k) {
      k -= d[i]/2;
      d[i] = 0;
    } else {
      return false;
    }
  }
  REP(i, N) if (d[i] != 0) return false;
  return true;
}

int main2() {
  cout << (solve() ? "Yes":"No") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BFirstSecond {
public:

    vector<vector<int>> graph;
    vector<vector<int>> dp;

    void dfs(string& s, int idx, int pos, vector<int>& now, vector<int>& cnt) {
      //cerr << s << endl;
      debug(idx, pos);
      int d = s[idx] - 'a';
      chmax(cnt[d], now[d]);

      if (idx+1 == s.size()) {
        dp[pos][s.back()-'a']++;
        debug(pos, s.back()-'a');
        int last = s.back()-'a';
        chmax(cnt[last], now[last]);
        return;
      }

      rep(i, 26) {
        if (dp[pos][i] > 0) debug(pos, i, dp[pos][i]);
        now[i] += dp[pos][i];
      }
      chmax(cnt[d], now[d]);

      if (graph[pos][d] == -1) {
        graph[pos][d] = graph.size();
        dp.emplace_back(vector<int>(26, 0));
        graph.emplace_back(vector<int>(26, -1));
        dfs(s, idx+1, graph[pos][d], now, cnt);
      } else {
        dfs(s, idx+1, graph[pos][d], now, cnt);
      }


    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<pair<int, string>> vec(n);
      rep(i, n) {
        cin >> vec[i].second;
        reverse(all(vec[i].second));
        vec[i].first = vec[i].second.size();
      }
      sort(all(vec));
      graph.emplace_back(vector<int>(26, -1));
      dp.emplace_back(vector<int>(26, 0));
      ll ret = 0;
      rep(i, n) {
        vector<int> now(26);
        vector<int> cnt(26);
        dfs(vec[i].second, 0, 0, now, cnt);
        rep(j, 26) {
          ret += cnt[j];
        }
      }
      cout << ret << endl;
    }
};

signed main() {
  BFirstSecond solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 371736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  int n,ans=0;
  cin >> n;

  printf("%f",(double)n*n*n/27);

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int t,n,s,f,i,j;
while(cin>>t){
if(t==0) return 0;
j=0;
cin>>n;
for(i=0;i<n;i++){
cin>>s>>f;
j+=f-s;
}
if(j>=t){
cout<<"OK"<<endl;
}
else if(j<t){
cout<<t-j<<endl;
}
}
         return 0;
      }

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

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

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

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

  int sum = 0;
  for(int i = 0; i < k; i++){
    sum += l[n-1-i];
  }

  cout << sum << endl;

  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int main(){
    int x=in(),y=in(),a=in(),b=in(),c=in();
    vecll p(a),q(b),r(c);
    rep(i,a)p[i]=in();
    rep(i,b)q[i]=in();
    rep(i,c)r[i]=in();
    sort(ALL(p),greater<ll>());
    sort(ALL(q),greater<ll>());
    sort(ALL(r),greater<ll>());
    vecll sumC(c+1);
    sumC[0]=0;
    rep(i,c)sumC[i+1]=sumC[i]+r[i];
    vecll ab(x+y);
    rep(i,x+y)ab[i]=i<x?p[i]:q[i-x];
    sort(ALL(ab),greater<ll>());
    vecll sumAB(x+y+1);
    sumAB[0]=0;
    rep(i,x+y)sumAB[i+1]=sumAB[i]+ab[i];
    ll ans=0;
    rep(i,x+y+1){
        if(x+y-i>c)continue;
        ans=max(ans,sumAB[i]+sumC[x+y-i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6144
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,m;

    private void solve() {
        try {
            n = sc.nextInt();
            m = sc.nextInt();
            long sum = 0;
            int[] a = new int[n];
            int[][] bc = new int[m][2];
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
                sum += a[i];
            }
            Arrays.sort(a);
            for (int i = 0; i < m; i++) {
                bc[i][0] = sc.nextInt();
                bc[i][1] = sc.nextInt();
            }

            Arrays.sort(bc, new Comparator<int[]>() {
                @Override
                public int compare(int[] ints, int[] t1) {
                    return t1[1] - ints[1];
                }
            });

            int index = 0;

            for (int i = 0; i < m; i++) {
                int b = bc[i][0];
                int c = bc[i][1];
                int j = index;
                while (j < n && j < index + b && a[j] < c) {
                    sum += c - a[j];
                    a[j] = c;
                    j++;
                }
                index = j;
            }

            System.out.println(sum);


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

    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: 58544
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::string s; cin >> s;
	int ans = 0;
	for(auto v : s) {
		if(v == '+') ans++;
		else ans--;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256