akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define MAXN 300010 
#define MAXM 1000010 
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;

int read()
{
	int res=0; char ch=getchar();
	while(ch<'0' || ch>'9') ch=getchar();
	while(ch>='0' && ch<='9')
	{
		res=res*10+ch-'0'; ch=getchar();
	}
	return res;
}

struct Edge
{
	int from,to,next,com;
	Edge(){}
	Edge(int u,int v,int n,int c):from(u),to(v),next(n),com(c){}
	bool operator < (const Edge &rhs) const
	{
		return com<rhs.com;
	}
};

struct Node
{
	int d,u;
	bool operator < (const Node &rhs) const
	{
		return d>rhs.d;
	}
};

int n,m,cnt;
int vis[MAXN],dis[MAXN];
vector<int> comp[MAXM],G[MAXN];
vector<Edge> G1[MAXN];

set<int> dict;

void dijkstra(int s)
{
	for(int i=1;i<=n+cnt;++i) dis[i]=INF,vis[i]=0;
	priority_queue<Node> q;
	dis[s]=0;
	q.push((Node){0,s});
	while(!q.empty())
	{
		Node x=q.top(); q.pop();
		int u=x.u;
		if(vis[u]) continue;
		vis[u]=1;
		int len=G[u].size();
		for(int i=0;i!=len;++i)
		{
			int v=G[u][i];
			if(dis[v]>dis[u]+1)
			{
				dis[v]=dis[u]+1;
				q.push((Node){dis[v],v});
			}
		}
	}
}

int cur[MAXN];

int main()
{
	//freopen("03.txt","r",stdin);
	n=read(),m=read();
	for(int i=0;i!=m;++i)
	{
		int u,v,com;
		u=read(),v=read(),com=read();
		//buf[i].u=u,buf[i].v=v,buf[i].com=com;
		G1[u].push_back(Edge(u,v,-1,com));
		G1[v].push_back(Edge(v,u,-1,com));
		comp[com].push_back(u);
		dict.insert(com);
	}
	for(int i=1;i<=n;++i)
		sort(G1[i].begin(),G1[i].end());
	for(set<int>::iterator it=dict.begin();it!=dict.end();++it)
	{
		int com=*it;
		int len=comp[com].size();
		for(int i=0;i!=len;++i)
		{
			int u=comp[com][i];
			if(vis[u]==com) continue;
			vis[u]=com;
			queue<int> q;
			q.push(u);
			++cnt;
			while(!q.empty())
			{
				int u=q.front(); q.pop();
				int len=G1[u].size();
				for(int &i=cur[u];i!=len;++i)
				{
					Edge &e=G1[u][i];
					if(e.com!=com) break;
					if(vis[e.to]!=com)
					{
						vis[e.to]=com; q.push(e.to);
					}
				}
				G[u].push_back(n+cnt);
				G[n+cnt].push_back(u);
			}
		}
	}
	dijkstra(1);
	int ans;
	if(dis[n]==INF) ans=-1;
	else ans=dis[n]/2;
	printf("%d\n",ans);
}


Measured memory_bytes: 75512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

struct edge{
	int to;
	ll cost;
};

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll d[100100];
vector<edge> g[100100];
priority_queue< P, vector<P>, greater<P> > pq;

int main(void){
	int n,i,u,v;
	ll w;
	edge e;
	P p;
	cin >> n;
	for(i=1; i<n; ++i){
		cin >> u >> v >> w;
		--u; --v;
		e.cost = w;
		e.to = u;
		g[v].push_back(e);
		e.to = v;
		g[u].push_back(e);
	}
	fill(d,d+100100,INFLL);
	d[0] = 0ll;
	pq.push(P(d[0],0));
	while(!pq.empty()){
		p = pq.top();
		pq.pop();
		u = p.second; w = p.first;
		if(d[u] != w){
			continue;
		}
		for(i=(g[u].l_ength()-1); i>=0; --i){
			e = g[u][i];
			v = g[u][i].to;
			if(d[v] > w + e.cost){
				d[v] = w + e.cost;
				pq.push(P(d[v],v));
			}
		}
	}
	for(i=0; i<n; ++i){
		cout << d[i]%2 << endl;
	}
	return 0;
}


Measured memory_bytes: 8704
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#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 pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return 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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+100;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll,ll> m;
    rep(i,n){
        cin >> a[i];
        m[a[i]]++;
    }
    bool flag=true;
    rep(i,n){
        if(m[a[i]]>=2){
            flag=false;
            break;
        }
    }
    if(flag){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
} 

Measured memory_bytes: 14336
#include <iostream>
#include <string>

bool is_7()
{
    std::string N;
    std::cin >> N;
    for (auto &&txt : N)
        if (txt == '7')
            return true;
    return false;
}

int main(int argc, char *argv[])
{
    std::cout << (is_7() ? "Yes" : "No");
}


Measured memory_bytes: 3040
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL N,i,j,ans=INF,a=0,b=0;
  scanf("%lld",&N);
  LL X[N];
  rep(i,N)scanf("%lld",&X[i]);
  qsort(X,N,sizeof(LL),lcmp);
  a=(X[0]+X[N-1])/2;
  FOR(i,X[0],X[N-1]+1){
    b=0;
    rep(j,N)b+=(i-X[j])*(i-X[j]);
    ans=MIN(ans,b);
  }

  printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

LL N;
LL P;

void MAIN() {
    scanf("%lld%lld", &N, &P);

    LL g = 1;
    for (LL i=2; i*i<=P; i++) {
	int cnt = 0;
	while (P % i == 0) {
	    P /= i;
	    cnt++;
	}
	while (cnt >= N) {
	    g *= i;
	    cnt -= N;
	}
    }

    if (N == 1) g *= P;
    printf("%lld\n", g);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define ll long long
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 1e5 + 10;
const int inf = 1e9 + 7;

ll ans, dp[59][59][2508], a[100];

main()
{
    dp[0][0][0] = 1;

    int n, m;

    cin >> n >> m;
    for( int i = 1; i <= n; i ++ )
    {
        cin >> a[i];
    }
    for( int i = 1; i <= n; i ++ )
    {
        for( int j = 0; j <= i; j ++ )
        {
            for( int k = 0; k < 2501; k ++ )
            {
                dp[i][j][k] += dp[i - 1][j][k];
                if( j > 0 && a[i] <= k )
                    dp[i][j][k] += dp[i - 1][j - 1][k - a[i]];
            }
        }
    }
    for( int i = 1; i <= n; i ++ )
        ans += dp[n][i][m * i];
    cout << ans;
}

Measured memory_bytes: 57600
#include<iostream>
using namespace std; //宣言することで、std::を省略することができる。名前の重複に関するnamespaceの応用
#define MAX 100000//MAX値の設定
typedef long long Long; //longlongというデータ型をllongという名前で定義して使用する

int n,k;//nは荷物の個数、kはトラックの台数

Long T[MAX];//Long型でMAX値の配列を定義

int check(Long P){//最大積載量PのドラックK台が何個の荷物を詰めるのかを確かめる
    int i = 0;
    for(int j=0;j<k;j++){//トラックの台数分繰り返す
        Long s = 0;
        while(s + T[i] <= P){//P以下のとき繰り返す、呼び出されているのはsolveからなのでmidの値
            s += T[i];
            i++;
            if(i==n)return n;//iとnが一致した場合はその値を返す
        }
    }
    return i;
}

int solve(){
    Long left = 0;
    Long right = 100000 * 10000;//荷物の数[n]×1つの荷物における最大重量[wi]
    Long mid;
    while(right-left > 1){
        mid =(left + right)/2;
        int v = check(mid); //mid==pを決めて何個積載できるかを確かめる
        if(v>=n)right = mid;//繰り返す値を変更することで処理回数を減らしている
        else left = mid;
    }
    return right;//最終結果を返す
    }

int main(){
    cin >> n >> k;
    for(int i=0; i < n; i++) cin >> T[i];
    Long ans = solve();
    cout << ans << endl;
}


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

int main(void) {
  int N, x;
  cin >> N >> x;
  vector<ll> a(N);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum == x) {
    cout << N << endl;
    return 0;
  }
  sort(a.begin(), a.end());
  ll ans = 0;
  ll subs = 0;
  for (int i = 0; i < N; i++) {
    subs += a[i];
    if (subs <= x) {
      ans = i + 1;
    }
  }
  if (ans == N) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <queue>

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	
	int a[200000];
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	
	int b[200000];
	priority_queue<pair<int, int> > pq;
	for (int i = 0; i < n; i++) {
		scanf("%d", &b[i]);
		if (a[i] > b[i]) {
			puts("-1");
			return 0;
		}
		if (a[i] == b[i]) continue;	
		pq.push(make_pair(b[i], i));
	}
	
	long long cnt = 0;
	while (!pq.empty()) {
		int id = pq.top().second;
		pq.pop();
		int s = (id == 0) ? n-1 : id-1;
		int t = (id == n-1) ? 0 : id+1;
		if ((b[id]-a[id])%(b[s]+b[t]) == 0) {
			cnt += (b[id]-a[id])/(b[s]+b[t]);
			b[id] = a[id];
			continue;
		} else if (b[id] <= b[s]+b[t]) {
			puts("-1");
			return 0;
		} else {
			cnt += b[id]/(b[s]+b[t]);
			b[id] %= b[s]+b[t];
			pq.push(make_pair(b[id], id));
		}
	}
	
	printf("%lld\n", cnt);
	
	return 0;
}


Measured memory_bytes: 3700
/*
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░ЗАПУСКАЕМ ГУСЕЙ РАЗВЕДЧИКОВ░░░░░
░░░░░░░▄▀▀▀▄░░░░░▄▀▀▀▄░░░░░░░░░░░
░░▄███▀░◐░░░▌░░░▐░░░◐░▀███▄░░░░░░
░░░░░░▌░░░░░▐░░░▌░░░░░▐░░░░░░░░░░
░░░░░░▐░░░░░▐░░░▌░░░░░▌░░░░░░░░░░

*/
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>

using namespace std;

#define ll long long
#define ld long double
#define null NULL
#define prev prev228


inline int cnt(int n) {
	int res = 0;
	while (n % 2 == 0) {
		++res;
		n /= 2;
	}
	return res;
}



signed main() {
	int n;
	cin >> n;
	int res = 1, maxim = 0;
	for (int i = 1; i <= n; ++i) {
		if (cnt(i) > maxim) {
			maxim = cnt(i);
			res = i;
		}
	}
	cout << res << endl;
	return 0;
}















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n/2+10,0);
    for(int i = 0; i < n; i++){
        int aa;
        cin >> aa;
        a[aa/2]++;
    }

    for(int i = 0; i < (n+1)/2; i++){
        if(n % 2 == 0 && a[i] == 2) continue;
        if(n % 2 != 0 && (a[0] == 1 || (i != 0 && a[i] == 2))) continue;
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for(int i = 0; i < n/2; i++){
        ans *= 2;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define PI      	        2*acos(0.0)
#define INF     	        1e9
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; 


int main ()
{
    #ifdef Lollipop
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    #endif
    
    string s, t;
    cin >> s >> t;
    int len1 = s.size();
    int len2 = t.size();
    int dp[len1+1][len2+1];
    for (int i = 0; i<=len1; i++){
        for (int j = 0; j<=len2; j++){
            if (i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else if (s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    
    deque<char> lcs;
    int i = len1;
    int j = len2;
    
    while (i > 0 && j > 0){
        if (s[i-1] == t[j-1]){
            lcs.push_front(s[i-1]);
            i--;
            j--;
        }
        else if (dp[i-1][j] > dp[i][j-1]){
            i--;
        }
        else{
            j--;
        }
    }
    for (int i = 0; i<lcs.size(); i++){
        cout << lcs[i];
    }
    cout << endl;
    return 0;
}



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

int main()
{
    int t[9] = {
        111, 222, 333, 444, 555,
        666, 777, 888, 999,
    };

    int N;
    std::cin >> N;

    for (int i = 0; i < 9; i++) {
        if (N > t[i]) continue;
        std::cout << t[i] << std::endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//なんか嘘解法っぽかったので

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


	ll N, K;
	cin >> N >> K;
	
	int B[41] = {};
	rep(i, N) {
		ll A;
		cin >> A;
		rep(j, 41) {
			B[j] += A & 1ll;
			A /= 2;
		}
	}

	int K2[41] = {};
	rep(i, 41) {
		K2[i] = K & 1ll;
		K /= 2;
	}

	int OK = 0;

	ll dp[45][2] = {};
	rep(i, 45) dp[i][1] = -1;

	for (int i = 40; i >= 0; i--) {
		int kari = N - B[i];
		ll k = (1ll << i);
		if (dp[i + 1][1] != -1) dp[i][1] = max(dp[i][1], dp[i + 1][1] + k * max(B[i], kari));

		if (K2[i]) {
			dp[i][1] = max(dp[i][1], dp[i + 1][0] + k * B[i]);
			dp[i][0] = max(dp[i][0], dp[i + 1][0] + k * kari);
		}
		else {
			dp[i][0] = max(dp[i][0], dp[i + 1][0] + k * B[i]);
		}
	}

	co(max(dp[0][0], dp[0][1]));

	Would you please return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!

    val ss = mutableListOf<Int>()
    var prev = s[0]
    if(prev=='0') ss.add(0)

    var c=0
    for(i in 0..n-1){
        if(s[i]!=prev){
            ss.add(c)
            prev=s[i]
            c=1
        }else{
            c++
        }
    }
    ss.add(c)
    if(prev=='0')ss.add(0)

//    println(ss)

    val m = 2*k+1

    var r = ss.take(m).sum()
    var ans = r

    for(i in 2..ss.size-m step 2){
        r = r -ss[i-2]-ss[i-1]+ss[i+m-2]+ss[i+m-1]
        ans = Math.max(ans,r)
    }
    println(ans)
}


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

const int MAX = 3 * 100005;
int A[MAX];

int main() {
    int N;
    string s;
    scanf("%d", &N);
    cin >> s;
    for (int i = 1; i <= N; i++) {
        char c = s[i-1];
        if (c == 'W') A[i]++;
        A[i] += A[i-1];
    }
    int ans = MAX;
    for (int i = 1; i <= N; i++) {
        ans = min(ans, A[i-1] + (N - i) - (A[N] - A[i]));
    }
    printf("%d\n", ans);
    return 0;
}

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


def solve():
    N = int(input())
    l = [tuple(map(int, input().split())) for i in range(N)]
    l.sort(key=lambda x:(x[0], -x[1]))

    #1 [lmax, rmin] [*, *]
    #2 [lmax, *] [*, rmin]

    lmax = 0
    rmin = 10**12
    a, b = 0, 0

    for i in range(N):
        if lmax < l[i][0]:
            lmax = l[i][0]
            a = i
        if rmin > l[i][1]:
            rmin = l[i][1]
            b = i

    #1
    ans1 = 0
    for i in range(N):
        if i==a or i==b:
            continue
        ans1 = max(ans1, max(l[b][1]-l[a][0]+1, 0)+max(l[i][1]-l[i][0]+1, 0))

    #2
    ans2 = 0
    p = 10**18
    for i in range(1, N)[::-1]:
        p = min(p, l[i][1])
        ans2 = max(ans2, max(l[b][1]-l[i-1][0]+1, 0)+max(p-l[a][0]+1, 0))

    ans = max(ans1, ans2)
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 90524
/**
*    author:  yuya1234
*    created: 30.06.2020 10:21:49
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

    string s;
    cin>>s;

    string op[3];
    int sum;

    REP(i,2)
    {
        REP(j,2)
        {
            REP(k,2)
            {
                sum=0;
                if(i==0)
                {
                    op[0]="+";
                    sum=(int)(s[0]-'0')+(int)(s[1]-'0');
                }
                else
                {
                     op[0]="-";
                    sum=(int)(s[0]-'0')-(int)(s[1]-'0');
                }

                if(j==0)
                {
                    op[1]="+";
                    sum+=(int)(s[2]-'0');
                }
                else
                {
                     op[1]="-";
                    sum-=(int)(s[2]-'0');
                }

                if(k==0)
                {
                    op[2]="+";
                    sum+=(int)(s[3]-'0');
                }
                else
                {
                     op[2]="-";
                    sum-=(int)(s[3]-'0');
                }
                if(sum==7)
                {
                    cout<<s[0] + op[0] + s[1] + op[1] + s[2] + op[2] + s[3]<<"=7"<<endl;
                    i=j=k=2;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll N;
ll A[100005];
ll B[100005];
vector<P> v;
ll res[100005];
const int MAX = 100005;
// BIT
class BIT{
  int n,bit[MAX+1];

public:
  BIT(int n = MAX):n(n){
    fill(bit,bit+MAX+1,0);
  }

  // i番目にxを加える （1から数える）
  void add(int i, int x){
    while(i <= n){
      bit[i] += x;
      i += i & -i;
    }
  }

  // a1からaiまでの合計を求める
  int sum(int i){
    int s = 0;
    while(i > 0){
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
};

BIT bit;
int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A[i]; v.emplace_back( A[i],i );
  }
  sort( v.rbegin(), v.rend() );

  B[0] = 0;
  for(int i=0;i<N;i++)
    B[i+1] = max( A[i], B[i] );

  ll nex = B[N];
  ll id  = N;
  for(int i=0;i<N;i++){
    P p = v[i];
    nex = min( B[p.second], nex );
    bit.add( p.second+1, 1 );
    if( nex < p.first ){
      if( B[p.second] == nex ) {
        id = p.second;
        ll cnt = bit.sum(N) - bit.sum( id );
        ll x = p.first - nex;
        res[ id ] += x * cnt;
      } else {
        res[ id ] += p.first - nex;
      }
    }
  }
  for(int i=0;i<N;i++) cout << res[i] << endl;
  
}


Measured memory_bytes: 5488
unittest
{
	assert( [ "xabxa" ].parse.expand.solve == 2 );
	assert( [ "ab" ].parse.expand.solve == -1 );
	assert( [ "a" ].parse.expand.solve == 0 );
	assert( [ "oxxx" ].parse.expand.solve == 3 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	auto ans = 0L;
	auto l = 0L;
	auto r = s.length.signed - 1;
	while( l < r )
	{
		if( s[ l ] == s[ r ] )
		{
			l++;
			r--;
		}
		else if( s[ l ] == 'x' && s[ r ] != 'x' )
		{
			ans++;
			l++;
		}
		else if( s[ l ] != 'x' && s[ r ] == 'x' )
		{
			ans++;
			r--;
		}
		else
		{
			return -1;
		}
	}
	return ans;
}


Measured memory_bytes: 2968
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int N,D;
vector<int> X[30];

int solve(void) {
    int ans = 0;
    for(int i = 0;i < N-1;i++) {
        for(int j = i+1;j < N;j++) {
            double d = 0;
            for(int k = 0;k < D;k++) {
                    d += 1.0*(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            }
            if(ceil(sqrt(d)) == floor(sqrt(d)))
                    ans++;
        }
    }

    return ans;
}



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

    for(int i = 0;i < N;i++) {
        for(int j = 0;j < D;j++) {
            int t;
            cin>>t;
            X[i].push_back(t);
        }
    }

    cout<<solve()<<endl;

    return 0;
}





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

int main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	long long sum = 0, max = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > max)max = a[i];
		sum += max - a[i];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 4040
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    X = I()

    if X >= 30:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10104
import java.util.Scanner;

//Palindrome
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = 0;
		while(sc.hasNext()){
			String s = sc.next();
			if(s.equals((new StringBuffer(s)).reverse().toString()))c++;
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 10, INF = 1e9 * 1e5;

vector<bool> used;
vector<pair<ll, ll>> vec;
vector<tuple<ll, ll, ll>> vec1, vec2;

int main()
{
	fastInp;

	ll n;
	cin >> n;

	ll x = 0;
	for (int i = 0; i < n; i++) {
		ll l, r;
		cin >> l >> r;
		vec.push_back({ l, r });
		vec1.push_back({ l, r, i });
		vec2.push_back({ r, l, i });
	}

	sort(vec1.rbegin(), vec1.rend());
	sort(vec2.begin(), vec2.end());

	used.resize(n);
	ll i = 0, i2 = 0, ans = 0;
	while (i < vec1.size() && i2 < vec2.size()) {
		while ((i < vec1.size()) && used[get<2>(vec1[i])]) {
			i++;
		}
		while ((i2 < vec2.size()) && used[get<2>(vec2[i2])]) {
			i2++;
		}
		if (!(i < vec1.size() && i2 < vec2.size())) break;
		if (get<0>(vec1[i]) - x > x - get<0>(vec2[i2])) {
			if (get<0>(vec1[i]) - x > 0) {
				ans += get<0>(vec1[i]) - x;
				x = get<0>(vec1[i]);
			}
			used[get<2>(vec1[i])] = 1;
		}
		else {
			if (x - get<0>(vec2[i2]) > 0) {
				ans += x - get<0>(vec2[i2]);
				x = get<0>(vec2[i2]);
			}
			used[get<2>(vec2[i2])] = 1;
		}
	}

	ll a = abs(x) + ans, a2 = 0;
	used.resize(0);
	used.resize(n);
	i = 0, i2 = 0, ans = 0, x = 0;
	while (i < vec1.size() && i2 < vec2.size()) {
		while ((i < vec1.size()) && used[get<2>(vec1[i])]) {
			i++;
		}
		while ((i2 < vec2.size()) && used[get<2>(vec2[i2])]) {
			i2++;
		}
		if (!(i < vec1.size() && i2 < vec2.size())) break;
		if (i == 0 && i2 == 0) {
			if (get<0>(vec1[i]) - x < x - get<0>(vec2[i2])) {
				if (get<0>(vec1[i]) - x > 0) {
					ans += get<0>(vec1[i]) - x;
					x = get<0>(vec1[i]);
				}
				used[get<2>(vec1[i])] = 1;
			}
			else {
				if (x - get<0>(vec2[i2]) > 0) {
					ans += x - get<0>(vec2[i2]);
					x = get<0>(vec2[i2]);
				}
				used[get<2>(vec2[i2])] = 1;
			}
		}
		else {
			if (get<0>(vec1[i]) - x > x - get<0>(vec2[i2])) {
				if (get<0>(vec1[i]) - x > 0) {
					ans += get<0>(vec1[i]) - x;
					x = get<0>(vec1[i]);
				}
				used[get<2>(vec1[i])] = 1;
			}
			else {
				if (x - get<0>(vec2[i2]) > 0) {
					ans += x - get<0>(vec2[i2]);
					x = get<0>(vec2[i2]);
				}
				used[get<2>(vec2[i2])] = 1;
			}
		}
	}

	cout << max(a, ans + abs(x));
	return 0;
}

Measured memory_bytes: 9576
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define loop(i,a,b) for(ll i=a;i<b;i++)
const int inf=1e9+7;

int main()
{	
    string a,b;
    cin>>a>>b;
    ll n,m;
    n=a.length();
    m=b.length();
    ll dp[n+1][m+1];
    loop(i,0,n+1)
     dp[i][0]=0;
     loop(j,0,m+1)
     dp[0][j]=0;
     loop(i,1,n+1)
     {
     	loop(j,1,m+1)
     	{
     		if(a[i-1]==b[j-1])
     		dp[i][j]=dp[i-1][j-1]+1;
     		else
     		 dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		 }
	 }
//	 loop(i,0,n+1)
//	 {
//	 	loop(j,0,m+1)
//	 	{
//	 		cout<<dp[i][j]<<" ";
//		 }
//		 cout<<endl;
//	 }
	
	 string ans="";
	 ll x=n,y=m;
	 while(x && y)
	 {
	 	if(a[x-1]==b[y-1])
	 	{
	 		ans=ans+a[x-1];
	 		x--;
	 		y--;
		 }
		 else if(dp[x-1][y]>dp[x][y-1])
		  x--;
		 else
		 y--;
	 }
	 reverse(ans.begin(),ans.end());
	 cout<<ans;
    return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    cin>>n;
    int c[600],s[600],f[600];
    for(int i=0;i<n-1;i++) cin>>c[i]>>s[i]>>f[i];
    for(int i=0;i<n;i++){
        int ans=0;
        for(int j=i;j<n-1;j++){
            if(ans<s[j]) ans=s[j];
            else if(ans%f[j]!=0) ans+=f[j]-ans%f[j];
            ans+=c[j];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>

using namespace std;


int main(){
  long long N, T;
  long long t[20001];
  long long prev = 0;
  long long now;
  cin >> N >> T;
  cin >> prev;
  if(N == 1){
    cout << T << endl;
    return 0;
  }
  long long ans = 0;
  for(int i = 1; i <= N; i++){
    cin >> now;
    if(ans <= now){
      ans += min(now - prev, T);
    }
    prev = now;
  }
  cout << ans+T << endl;
  return 0;
} 


Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, m; cin >> n;
  m = n;
  ll K; cin >> K;
  vector<vector<ll>> v(m);
  rep(i, n) {
    ll t, d; cin >> t >> d; --t;
    v[t].pb(d);
  }
  vector<ll> v1, v2;
  rep(i, n) {
    if (v[i].size() == 0) continue;
    sort(all(v[i]), greater<ll>());
    v1.pb(v[i][0]);
    rep(j, 1, v[i].size()) {
      v2.pb(v[i][j]);
    }
  }
  sort(all(v1), greater<ll>());
  sort(all(v2), greater<ll>());
  vector<ll> S(v2.size()+1, 0);
  rep(i, v2.size()) {
    S[i+1] = S[i] + v2[i];
  }
  // cout << S << endl;
  ll ans = 0, sum = 0;
  rep(i, v1.size()) {
    sum += v1[i];
    if (v2.size() >= K-i-1) {
    // cout << i << " " << sum << " " << K << " " << S[K-i-1] << endl;
      chmax(ans, (i+1) * (i+1) + sum + S[K-i-1]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6904
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define loop(i,a,b) for(int i=a; i<b; i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
void solve()
{
     int a,v,b,w,t;cin>>a>>v>>b>>w>>t;
     a=abs(a-b);
     if(a<=(v-w)*t)cout<<"YES\n";
     else cout<<"NO\n";
	return;
}
int32_t main() 
{ 
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0; 
}

Measured memory_bytes: 3652
<?php
$count = trim(fgets(STDIN));
for ($i = 0; $i < $count; $i++) {
    list($a,$b,$c) = explode(" ",fgets(STDIN));
    if(pow(intval($a),2) + pow(intval($b),2) === pow(intval($c),2) ||
    pow(intval($b),2) + pow(intval($c),2) === pow(intval($a),2) ||
     pow(intval($c),2) + pow(intval($a),2) === pow(intval($b),2)
    ) {
        echo "YES".PHP_EOL;
    } else {
         echo "NO".PHP_EOL;
    }
}


Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;

int main(){
	int N;
	cin>>N;
	map<long long int, long long int> da;
	map<long long int, long long int> da2;
	map<long long int, long long int> da3;
	vector<long long int> da4;
	map<long long int, long long int> da5;
	long long int itr = 1;
	for(int i = 0; i < N; i++){
		long long int inp;
		cin>>inp;
		da4.push_back(inp);
		if(da2[inp] == 0){
			
			da[itr]++;
		da2[inp]=itr*(-1);
			itr++;
			
		}else{
			da[da2[inp]*(-1)]++;
		}
	}
	da3 = da;
	long long int ans;
	
	for(int i = 0; i < N; i++){
		if(da5[da[da2[da4[i]]*(-1)]] == 0){
			da3 = da;
			ans = 0;
			da[da2[da4[i]]*(-1)]-=1;
			//cout<<da2[da4[i]]*(-1)<<endl;
			for(int j = 1; j <= itr; j++){
			
			
				ans += (da[j]-1)*(da[j])/2;
			}
			da = da3;
			if(ans == 0){
				da5[da[da2[da4[i]]*(-1)]] = -1;
			}else{
				da5[da[da2[da4[i]]*(-1)]] = ans;
			}
		}
	}
	for(int i = 0; i < N; i++){
		if(da5[da[da2[da4[i]]*(-1)]] == -1){
			cout<<0<<endl;
		}else{
		cout<<da5[da[da2[da4[i]]*(-1)]]<<endl;
		}
	}
}


Measured memory_bytes: 26864
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main(){
  ll n, m;
  cin >> n >> m;

  if (n * 2 > m) {
    cout << m / 2  << endl;
    return 0;
  }
  else {
    m -= n * 2;
    m /= 4;
    cout << n + m << endl;
    return 0;
  }
}


Measured memory_bytes: 3616
n,m=map(int,input().split())
height=list(map(int,input().split()))

memo=[[]for i in range(n)]

for i in range(m):
    x,y=map(int,input().split())
    memo[x-1].append(y-1)
    memo[y-1].append(x-1)
ans=0

for i in range(n):
    if len(memo[i])==0:
        ans+=1
        continue
    
    for j in memo[i]:
        if height[j]>=height[i]:
            break
    else:
        ans+=1

print(ans)

Measured memory_bytes: 29488
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

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

    string ans = (A == B) ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.close();

        if(n%k == 0) {
            System.out.println(0);
        } else {
            System.out.println(1);
        }
    }
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size(); i++)
		if (s[i] == '1')
			ans++;
	cout << ans << endl;

	return 0;
}


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

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	unsigned N, C, A;
	cin >> N >> C;
	assert(1 <= N <= 500);
	assert(1 <= C <= 30);

	vector<vector<unsigned> > D(C, vector<unsigned>(C));
	for (unsigned i = 0; i < C; ++i) {
		for (unsigned j = 0; j < C; ++j) {
			cin >> D[i][j];
			if (i != j) assert(1 <= D[i][j] <= 1000);
			if (i == j) assert(0 == D[i][j]);
		}
	}
	vector<vector<unsigned> > distr(3, vector<unsigned>(C));
	for (unsigned i = 0; i < N; ++i) {
		for (unsigned j = 0; j < N; ++j) {
			cin >> A; assert(1 <= A && A <= C);
			++distr[(i + j) % 3][--A];
		}
	}
	unsigned ret = -1;
	for (unsigned i = 0; i < C; ++i) {
		for (unsigned j = 0; j < C; ++j) {
			for (unsigned k = 0; k < C; ++k) {
				if (i != j && j != k && k != i) {
					unsigned sum = 0;
					for (unsigned l = 0; l < C; ++l) {
						if (l != i) sum += distr[0][l] * D[l][i];
						if (l != j) sum += distr[1][l] * D[l][j];
						if (l != k) sum += distr[2][l] * D[l][k];
					}
					ret = min(ret, sum);
				}
			}
		}
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#define MOD 1000000007
typedef long long ll;

using namespace std;

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

    int l_num = 0;
    int r_num = 0;
    char tmp = ' ';
    for(int i = 0; i < n; i++) {
        if(i == 0) {
            if(s[i] == 'R') {
                r_num++;
                tmp = 'R';
            }
            if(s[i] == 'L') {
                l_num++;
                tmp = 'L';
            }
            continue;
        }
        
        if(tmp != 'R' && s[i] == 'R') {
            r_num++;
            tmp = 'R';
        }
        if(tmp != 'L' && s[i] == 'L'){
            l_num++;
            tmp = 'L';
        }
    }
    
    // cout << r_num << " " << l_num << endl;
    
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(i > 0 && s[i] == 'L' && s[i - 1] == 'L') {
            ans++;
        }
        if(i < n - 1 && s[i] == 'R' && s[i + 1] == 'R') {
            ans++;
        }
    }
    
    if(l_num <= k || r_num <= k) {
        cout << n - 1 << endl;
    }
    else {
        int ans1 = ans;
        int ans2 = ans;
        
        ans1 += 2 * k;
        ans2 += 2 * k;
        
        if(s[0] == 'L' && s[n - 1] == 'L' && l_num < k + 2) {
            ans1 -= l_num - k;
        }
        else if((s[0] == 'L' || s[n - 1] == 'L') && l_num < k + 1) {
            ans1--;
        }
        
        if(s[0] == 'R' && s[n - 1] == 'R' && l_num < k + 2) {
            ans2 -= r_num - k;
        }
        else if((s[0] == 'R' || s[n - 1] == 'R') && l_num < k + 1) {
            ans2--;
        }
        
        cout << max(ans1, ans2) << endl;
    }
    
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll S, W;
    cin >> S >> W;

    if (W >= S)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <set>
using namespace std;

vector<int> primes_under(int N) {
  vector<bool> pr(N + 1, true);
  vector<int> primes;
  for(int i = 2; i <= N; ++i) {
    if(pr[i]) {
      primes.push_back(i);
      for(int j = i + i; j <= N; j += i) {
        pr[j] = false;
      }
    }
  }
  return primes;
}
vector<pair<int, int>> fact;

int dp(int cur, int have) {
  if(have > 75) return 0;
  if(cur == fact.size()) return have == 75 ? 1: 0;
  int ans = 0;
  for(int i = 0; i <= fact[cur].second; ++i) {
    ans += dp(cur + 1, have * (i + 1));
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> primes = primes_under(N);
  for(int prime: primes) {
    int count = 0;
    int p = prime;
    while(p <= N) {
      count += (N / p);
      p *= prime;
    }
    if(count > 0) {
      fact.push_back(make_pair(prime, count));
    }
  }
  
  cout << dp(0, 1) << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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
 */

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int D = in.nextInt();
            String str = "Christmas";
            for(int i = 25; D < i; i--) {
            	str+=" Eve";
            }
            System.out.println(str);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll a, b, m;
  cin >> a >> b >> m;
  vector<ll> c(a), d(b);
  ll m1 = 1e18, m2 = 1e18;
  REP(i, a) {
    cin >> c[i];
    m1 = min(m1, c[i]);
  }
  REP(i, b) {
    cin >> d[i];
    m2 = min(m2, d[i]);
  }
  ll ans = m1 + m2;
  REP(i, m) {
    ll x, y, f;
    cin >> x >> y >> f;
    x--;
    y--;
    ans = min(ans, c[x] + d[y] - f);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(b%a == 0){
        cout << a + b << endl;
    }else{
        cout << b - a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int m=min(c,b);
	if(c+b>=a)	printf("%d %d\n",m,c+b-a);
	else		printf("%d %d\n",m,0);
	return 0;
 } 

Measured memory_bytes: 256
#include <stdio.h>

void change(int *a,int*b);

int main(void){
  int a,b,c;

  scanf("%d %d %d",&a,&b,&c);

  if(a>b) change(&a,&b);
  if(b>c) change(&b,&c);
  if(a>b) change(&a,&b);

  printf("%d %d %d\n",a,b,c);

  return 0;
}

void change(int *a,int *b){
  int tmp;

  tmp=*a;
  *a=*b;
  *b=tmp;

  return ;
}



  

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    string s; cin >> s;

    rep(i, s.size()){
        if(i%2==0){
            if(s[i]!='L') continue;
        }
        else{
            if(s[i]!='R') continue;
        }
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] data = s.toCharArray();
		int sum = 0;
		for (int i = 0; i < data.length; i++) {
			int a = Character.getNumericValue(data[i]);
			sum += a;
		}
		int a = Integer.parseInt(s);
		if (a % sum == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 22996
X, Y = map(int,input().split())
AnswerX = 0
AnswerY = 0
AnswerW = 0
if X*Y == 1:
  AnswerW = 400000
if X == 1:
  AnswerX= 300000
elif X==2:
  AnswerX = 200000
elif X==3:
  AnswerX = 100000
if Y == 1:
  AnswerY= 300000
elif Y==2:
  AnswerY = 200000
elif Y==3:
  AnswerY = 100000
  
Answer = AnswerX + AnswerY + AnswerW
print(Answer)


Measured memory_bytes: 3064
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var S string
	fmt.Scan(&S)

	ans := exec(S)
	fmt.Println(ans)
}

func exec(S string) int {
	s := strings.Split(S, "")

	var sum, tmp int
	for b := 0; b < (1 << uint(len(s)-1)); b++ {
		tmp = 0
		for i := 0; i < len(s); i++ {
			num, _ := strconv.Atoi(s[i])
			tmp = tmp*10 + num

			if b & (1<<uint(i)) > 0 {
				sum += tmp
				tmp = 0
			}
		}
		sum += tmp
	}

	return sum
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
typedef long long ll;
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

	ll n, a, b;
	cin>>n>>a>>b;
	ll p = min(a,b), q = a+b-n;
	if(q <= 0){
		cout<<p<<" "<<0<<"\n";
	}else{
		cout<<p<<" "<<q<<"\n";
	}
}



Measured memory_bytes: 256
# 練習のため再実装＠0623

N,d=gets.chomp.split(' ').map{|n| n.to_i}
h = {}
gets.chomp.split(' ').map{|n| n.to_i}.each{|a|
	h[a].nil? ? h[a] = 1 : h[a] += 1
}
sum = 0
h.each{|k,v|
	if(v-k < 0)
		sum += v
	else
		sum += v-k
	end
}

puts sum


Measured memory_bytes: 15492