akhauriyash/Code-Regression huggingface dataset:
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
int ps4[4][2]={0,1,0,-1,1,0,-1,0};
int ps8[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,-1,-1,1};
inline int min(int a,int b,int c) {return min(a,min(b,c));}
inline int max(int a,int b,int c) {return max(a,max(b,c));}
inline int min(int a,int b,int c,int d){return min(min(a,b,c),d);}
inline int max(int a,int b,int c,int d){return max(max(a,b,c),d);}
//struct Edge{int p, next, w;}edge[maxn];
//inline add_edge(int u, int v, int w){edge[cnt]=Edge{v,head[u],w}; head[u]=cnt++;}
const int N=200005;
///Code begin..................................................................

LL A[N];

LL pow_mod(LL a, LL n, LL mod){
    LL ret=1, tmp=a%mod;
    while (n) {
        if (n&1) ret=ret*tmp%MOD;
        tmp=tmp*tmp%MOD;
        n>>=1;
    }
    return ret;
}
LL inv(LL a, LL mod){return pow_mod(a,mod-2,mod);}
void init(){
    A[0]=1; FOR(i,1,N-1) A[i]=A[i-1]*i%MOD;
}
LL C(int x, int y){
    return A[y]*inv(A[x]*A[y-x]%MOD,MOD)%MOD;
}
int main ()
{
    init();
    int H, W, A, B;
    scanf("%d%d%d%d",&H,&W,&A,&B);
    LL ans=0;
    FOR(i,1,W-B) ans+=C(H-A-1,B+H-A+i-2)*C(A-1,A+W-B-i-1)%MOD;
    printf("%lld\n",ans%MOD);
    return 0;
}

Measured memory_bytes: 1792
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=100005;
vector<LL> vj[N];
LL a[N],vz[N];
LL d(LL x,LL y,LL n){if (x>y) y+=n;return y-x;}
int main(){
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,j,n,m;LL cnt=0,ans=0;
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        if (i>=2){        
            LL t1=d(a[i-1],a[i],m),t2=a[i];
            if (t1>=t2) ans+=t2,cnt++; else ans+=t1;
            vj[a[i]].pb(t1);vz[a[i-1]%m+1]++;
        }
    }
    LL ans0=ans;
 //   printf("%d\n",ans);
    for (i=1;i<=m;i++){
        int sz=vj[i].size();
        if (i==1){
            cnt-=sz;
            for (j=0;j<sz;j++) ans+=vj[i][j]-1;
            continue;
        }
        ans-=cnt;
        ans0=min(ans0,ans);
   //     printf("%d\n",ans);
        cnt-=sz;
        for (j=0;j<sz;j++) ans+=vj[i][j]-1;
        cnt+=vz[i];
    }
    cout<<ans0<<endl; 
  //  system("pause");
    return 0;
}


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


void solve(long long N, long long K, vector<long long> V){
	long long res = 0;
	
	// l[0] = 0;
	// for (int i=1; i<=N; i++) {
	// 	l[i] += V[i-1];
	// }
	// r[0] = 0;
	// for (int i=1; i<=N; i++) {
	// 	r[i] += V[N-i];
	// }

	long long m[N+1][N+1][N+1];
	for (int i=0; i<=N; i++) {
		for (int j=0; j<=N; j++) {
			for (int k=0; k<=N; k++) {
				m[i][j][k] = 0;
			}
		}
	}
	for (int i=0; i<=N; i++) {
		for (int j=0; j<=N-i; j++) {
			vector<long long> v;
			int now = 0;
			for (int k=0; k<i; k++) {
				v.push_back(V[k]);
				now += V[k];
			}
			for (int k=0; k<j; k++) {
				v.push_back(V[N-k-1]);
				now += V[N-k-1];
			}
			// for (int k=0; k<(int)v.size(); k++) cout << v[k] << endl;
			// cout << endl;
			sort(v.begin(), v.end());
			m[i][j][0] = now;
			for (int k=1; k<=N; k++) {
				if (k <= (int)v.size()) m[i][j][k] = max(m[i][j][k-1], m[i][j][k-1]-v[k-1]); else m[i][j][k] = m[i][j][k-1];
			}
			
		}
	}
	for (long long i=K; i<=K; i++) {
		for (long long j=0; j<=min(i,N); j++) {
			for (long long k=0; k<=min(i,N)-j; k++) {
				// cout << j << " " << k << " " << i-j-k << " " << m[j][k][i-j-k] << endl;
				res = max(res, m[j][k][min(i-j-k,N)]);
			}
		}
	}
	cout << res << endl;
}

int main(){	
	long long K;
	long long N;
	scanf("%lld",&N);
	vector<long long> V(N-1+1);
	scanf("%lld",&K);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&V[i]);
	}
	solve(N, K, V);
	return 0;
}



Measured memory_bytes: 1280
import java.io.*;
import java.util.*;
import java.lang.*;

class Main {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        
        double x1 = scan.nextDouble();
        double y1 = scan.nextDouble();
        double x2 = scan.nextDouble();
        double y2 = scan.nextDouble();
        
        double x = x2 - x1;
        double y = y2 - y1;
        
        System.out.println(Math.sqrt(x * x + y * y));
    }
}


Measured memory_bytes: 27840
#include<stdio.h>
int main(void){
    int a,b;
    int c,d;
    int count;
    int countt;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    for(count=0;c>0;count++){
        c-=b;
    }
    for(countt=0;a>0;countt++){
        a-=d;
    }
    if(count<=countt){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1660
N,M=map(int,input().split())
LM=1
Rm=100000
for i in range(M):
    L,R=map(int,input().split())
    if LM<L:
        LM=L
    if Rm>R:
        Rm=R
if Rm<LM:
    ans=0
else:
    ans=Rm-LM+1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;

int main()
{
    int n;
    cin >> n;
    V<ll> a(n);
    rep(i,n) cin >> a[i];
    V<ll> dp(2, 0); //i番目まで足したとき、i+1番目の正負はa[i]と一致しているか
    dp[0] = a[0];
    dp[1] = -a[0];
    rep(i,n-1)
    {
        V<ll> dp2(2, 0);
        int ni = i+1;
        chmax(dp2[0], dp[0] + a[ni]); //a[i+1]はそのままで、+a[i] -> a[i+2]の正負はそのまま
        chmax(dp2[0], dp[1] - a[ni]); //a[i+1]に-1をかけて、-a[i] -> a[i+2]の正負は逆転
        chmax(dp2[1], dp[0] - a[ni]); //a[i+1]はそのままで、-a[i] -> a[i+2]の正負はそのまま
        chmax(dp2[1], dp[1] + a[ni]); //a[i+1]に-1をかけて、+a[i] -> a[i+2]の正負は逆転
        swap(dp2, dp);
        // cout << dp << endl;
    }
    cout << dp[0] << endl;

    return 0;
}

Measured memory_bytes: 3964
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    int H, W;
    cin >> H >> W;
    int h, w;
    cin >> h >> w;

    cout << H * W - (h * W + w * H - h * w) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define fi first
#define se second
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(int x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
void outputno(){
	puts("-1"),exit(0);
}
int n,m,a[100004],ret,b[100004];
pii a_[100004];
bool vis[100004],ans[200004];
vector<int>g[100004],num[100004];
bool dfs(int x){
	vis[x]=1;
	bool res=b[x];
	for (int i=0;i<g[x].size();i++)if (!vis[g[x][i]]) if(dfs(g[x][i])){
		res^=1;
		ans[num[x][i]]=1;
		ret++;
	}
	return res;
}
int main(){
	read(n),read(m);
	for (int i=1;i<=n;i++) read(a_[i].fi),read(a_[i].se);
	sort(a_+1,a_+1+n);
	for (int i=1;i<=n;i++)a[i]=a_[i].fi,b[i]=a_[i].se;
	a[n+1]=1000000001;
	for (int i=n+1;i>=2;i--) b[i]^=b[i-1];
	for (int i=1;i<=m;i++){
		int ld,rd;read(ld),read(rd);
		int l=lower_bound(a+1,a+n+2,ld)-a,r=upper_bound(a+1,a+n+2,rd)-a;
		g[l].push_back(r),g[r].push_back(l),num[l].push_back(i),num[r].push_back(i); 
	}
	for (int i=1;i<=n+1;i++) if (!vis[i]) if (dfs(i)) outputno();
	write(ret),puts("");
	for (int i=1;i<=m;i++) if (ans[i]) write(i),putchar(' ');
}

Measured memory_bytes: 20096
import java.util.*;

class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        int A[] = new int[N];
        int x[][] = new int[N][N];
        int y[][] = new int[N][N];
        for (int i=0;i<N;i++) {
            A[i] = sc.nextInt();
            for(int j=0;j<A[i];j++){
                x[i][j] = sc.nextInt();
                y[i][j] = sc.nextInt();
            }
        }
        //ここまで入力

        //bit全探索
        for(int bits=1; bits < (1 << N); bits++){
            boolean flag = true;
            for(int i=0; i<N; i++){
                //不親切な人の証言は考慮しない
                if((bits & (1 << i)) == 0) continue;
                for(int j=0; j<A[i]; j++){
                    if((((bits >> x[i][j]-1) & 1) ^ y[i][j]) == 1) flag = false;
                }
            }
            if(flag == true) ans = Math.max(ans, counter(bits));
        }
        System.out.println(ans);
    }

        //正直者の数を数えるメソッド
        public static int counter(int x){
            if(x == 0) return 0;
            return counter(x >> 1) + (x & 1);
        }
}

Measured memory_bytes: 22484
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		string num;
		cin >> num;
		for(int i=0;i<n;i++){
			string next;
			for(int j=0;j<num.size();){
				int c = 0;
				char alph;
				for(int k=0;k<=9;k++){					
					for(int len=1;j+len-1<num.size();len++){
						string tmp = num.substr(j,len);
						if(count(tmp.begin(),tmp.end(),'0'+k) == len){
							c++;
							alph = '0' + k;
						}
						else break;
					}
				}

				j+=c;
				
				char buf[32];
				sprintf(buf,"%d",c);
				string tmp = buf;
				next.append(tmp);
				next.push_back(alph);
			}
			num = next;
		}

		cout << num << endl;
	}
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int x,i,j,k=0,a,b;
	cin>>x;
	stack<int> s,r;
	s.push(2);
	s.push(3);
	if(x==2 || x==3) cout<<x;
	else
	{
	for(a=5;a<=x;a+=2)
	{
		k=0;
		r=s;
		b=r.size();
		for(i=0;i<b;i++)
		{
			j=r.top();
			r.pop();
			if(a%j==0)
			{
				k=1;
				break;
			}
		}
		if(k==0) s.push(a);
	}
	if(x==s.top()) cout<<x;
	else 
	{
		for(a=s.top()+2;;a+=2)
		{
			k=0;
			r=s;
			b=r.size();
		for(i=0;i<b;i++)
		{
			j=r.top();
			r.pop();
			if(a%j==0)
			{
				k=1;
				break;
			}
		}
		if(k==0)
		{
			cout<<a;
			break;
		}
		}
	}
	}
	return 0;
}

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

void dfs(int u, int p = -1, int depth = 0) {
    //cout << u << " " << p << " " << depth << endl;
    used[u] = true;
    if (depth % 2 == 0) X++;
    else Y++;
    int ret = 0;
    for(auto to: G[u]) {
        if (to == p) continue;
        if (used[to]) continue;
        dfs(to, u, depth + 1);
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int x[100010], y[100010];
    int ans = 0;
    rep(i, N) {
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
        G[x[i]].push_back(y[i] + 100000);
        G[y[i] + 100000].push_back(x[i]);
        ans--;
    }
    rep(i, 200010) {
        if (!used[i]) {
            X = 0, Y = 0;
            dfs(i);
            ans += X * Y;
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
  int ans=0;
  string s;
  while(cin>>s){
    for(int i=0;i<s.size();i++){
      int tmp=0;
      while((i<s.size())&&(s[i]<'0'||'9'<s[i]))i++;
      if(!(i<s.size()))continue;
      while((i<s.size())&&(!(s[i]<'0'||'9'<s[i]))){
        tmp=tmp*10;
        tmp=tmp+int(s[i]-'0');
        i++;
      }
      ans=ans+tmp;
    }
  }
  cout<<ans<<endl; 
}

Measured memory_bytes: 1184
A, B = map(int, input().split())


# 最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


# 最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)


print(lcm(A, B))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x.begin(),x.end())

int calc(ll num[4],string ope,int idx,int sum){
	ll ret=0;
    if(ope.at(idx)=='+'){
      if(idx==2){
	      ret=sum+num[idx];
      }
      else{
	      ret=calc(num,ope,idx+1,sum+num[idx]);
      }
    }
    else{
      if(idx==2){
	      ret=sum-num[idx];
      }
      else{
	      ret=calc(num,ope,idx+1,sum-num[idx]);
      }
    }
    return ret;
}

signed main(){
	ll n,num[4],idx;
  	cin>>n;
	num[0]=n/1000;
	num[1]=n/100%10;
	num[2]=n/10%10;
	num[3]=n%10;
	string ope[8]={"+++","++-","+-+","+--","-++","-+-","--+","---"};
	rep(i,8){
//      	cout<<i<<':'<<ope[i]<<endl;
		if(calc(&num[1],ope[i],0,num[0])==7){idx=i;break;}
	}
  	if(idx==8) cout<<"error"<<endl;
	cout<<num[0]<<ope[idx].at(0)<<num[1]<<ope[idx].at(1)<<num[2]<<ope[idx].at(2)<<num[3]<<"=7"<<endl;
	return 0;
}

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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

ll n;
ll a[maxs];
ll dp[maxs][4];
bool vis[maxs][4];

ll go(ll pos,ll have){
    if(pos >= n){
        if(have <= 1)
            return 0;
        return -oo;
    }
    ll& ans = dp[pos][have];
    if(vis[pos][have])
        return ans;
    vis[pos][have] = true;

    if(!have)
        ans =  a[pos] + go(pos+2,have);
    else
        ans = max(a[pos] + go(pos+2,have) , go(pos+1,have-1) );
    
    return ans;

}

void solve(){
    cin >> n;
    for(ll i=0;i<n;i++)
        cin >> a[i];
    
    ll ans;
    if(n&1){
        ans = max( go(0,2) , go(1,1) );
    }
    else{
        ans = max( go(0,1) , go(1,0) );
    }
    cout << ans << endl;
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define V vector
#define pb push_back
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

const int N=100005;

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t;cin>>t;while(t--)
    {
        int i,j,k,n,m,ans=0,cnt=0,sum=0;
        cin>>n>>k;
        cout<<n-k+1;       
    }
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#define i64 long long
#define vi32 vector<int>
#define vi64 vector<long long>
#define  ii pair<int,int>
const long long mod = 1000000007LL, inf = 1e9, linf = 1e18, base = 10;
using namespace std;
#define pb push_back
#define mp make_pair
#define N 1000006
using namespace std;

int n, m;
int f[N];
int p[N];
vector<vi32> adjlist;
vi32 dfs_num;
void dfs(int u)
{
	dfs_num[u] = 1;
	p[u] = f[m--];
	for (int i = 0; i < (int)adjlist[u].size(); i++)
	{
		int v = adjlist[u][i];
		if (!dfs_num[v])
		{
			dfs(v);
		}
	}

}
int main()
{
	cin >> n;
	adjlist.assign(n + 1, vi32());
	dfs_num.assign(n + 1, 0);
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		adjlist[u].pb(v);
		adjlist[v].pb(u);
	}
	i64 res = 0;
	for (int i = 1; i <= n; i++)cin >> f[i], res += f[i];
	sort(f + 1, f + n+1);
	res -= f[n];
	m = n;
	dfs(1);
	cout << res << endl;
	for (int i = 1; i <= n; i++)cout << p[i] << " ";
}

Measured memory_bytes: 3328
#include <stdio.h>

int main() {
  int a, b;
  int d, r;
  double f;
 scanf ("%d %d",&a ,&b);
 d = a/b;
 r = a%b;
 f = a*1.0/b;
 printf("%d %d %.8lf\n",d,r,f);
 return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		if(b < a) {
			System.out.println(a-1);
		}else {
			System.out.println(a);
		}
		
		}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	
	ll n,k;
	cin >> n >> k;
	double ans = 0;
	FOR(i,1,n+1){
		ll x = i;
		ll num = 0;
		while(x<k){
			x *= 2;
			num++;
		}
		double add = 1;
		FOR(j,0,num){
			add /= 2.0;
		}
		ans += add;
	}
	ans /= n;
	printf("%.10lf\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    std::cin >> n;
    int a[100001]={};
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    long long int ans=0;
    sort(a,a+n);
    int cnt=0;
    for (int i = 0; i < n; i++) {
        cnt++;
        if(a[i]!=a[i+1]){
            if(cnt>=a[i]){
                ans+=(long long int)abs(cnt-a[i]);
            }else{
                ans+=(long long int)cnt;
            }
            cnt=0;
        }
        
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 640
import heapq
import queue
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Info:
    def __init__(self,arg_name,arg_rest_time):
        self.name = arg_name
        self.rest_time = arg_rest_time


N,LIMIT = map(int,input().split())
Q = deque()


for _ in range(N):
    tmp = input().split()
    Q.append(Info(tmp[0],int(tmp[1])))

current_time = 0

while len(Q) > 0:
    info = Q.popleft()
    if info.rest_time > LIMIT:
        info.rest_time -= LIMIT
        current_time += LIMIT
        Q.append(info)
    else:
        current_time += info.rest_time
        print("%s %d"%(info.name,current_time))



Measured memory_bytes: 18680
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <stack>
#include <algorithm>
#include <random>
#include <bitset>
#include <map>
#include <ctime>
#include <cstdlib>

using namespace std;

typedef long long ll;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());
    int x = a[0];
    for (int i = 0; i < n - 1; ++i) {
        if (abs(a[i] - (a.back() - a[i])) < abs(x - (a.back() - x))) {
            x = a[i];
        }
    }
    cout << a.back() << " " << x << endl;
    return 0;
}


Measured memory_bytes: 768
# https://atcoder.jp/contests/agc003/tasks/agc003_b

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    tmp = 0
    ans = 0
    for i in range(1, n + 1):
        a = input_int()
        if a != 0:
            tmp += a
        else:
            ans += tmp // 2
            tmp = 0
    else:
        ans += tmp // 2
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 73776
#include <bits/stdc++.h>
int main()
{
    using namespace std;
    int N;
    cin >> N;
    int A[N - 1] = {0}, B[N + 1] = {0};
    for (int i = 0; i < N - 1; i++)
    {
        cin >> A[i];
        B[A[i]]++;
    }
    for (int i = 1; i <= N; i++)
    {
        cout << B[i] << endl;
    }
}

Measured memory_bytes: 5156
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
      
  if temp!=1:
    arr.append([temp, 1])
    
  if arr==[]:
    arr.append([n, 1])
    
  return arr

a = factorization(int(input()))
b = [1, 3, 6, 10, 15, 21, 28, 36, 43]

ans = 0

if len(a) == 1 and a[0][0] == 1:
  print(0)
  exit()
  
for i in a:
  for j in range(len(b)):
    if i[1] < b[j]:
      ans+=j
      break
    
print(ans)


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

int main(){
    long long a,b,n,x,y;cin>>a>>b>>n;
    x=n/b*b-1;y=x;
    if(x<0){x=0;y=n;}
    cout<<(a*y)/b-a*(x/b)<<endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> num_road(N,0);
  
  int a,b;
  for (int road=0;road<M;road++) {
    cin >> a >> b;
    num_road.at(a-1) += 1;
    num_road.at(b-1) += 1;
  }
  
  for (int city=0;city<N;city++) {
    cout << num_road.at(city) << endl;
  }
  
}


Measured memory_bytes: 256
H,W = map(int,input().split())

s=[list(str(input())) for _ in range(H)]

di=[1,-1,0,0]
dj=[0,0,1,-1]
for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            found=False
            for k in range(4):
                i2=i+di[k]
                j2=j+dj[k]
                if 0<=i2 and i2<H and 0<=j2 and j2<W:
                    if s[i2][j2]=='#':
                        found=True
            if not found:
                print('No')
                exit()

print('Yes')




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
vector<int> dx= {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
//const int INF=100000000;
//vector<vector<vector<int>>> dp(10001, vector<vector<int>>(51, vector<int>(51,0)));//幅、何個目、個数
int main(){
    int w,n,k;
    cin>>n;
    vector<vector<pair<int,int>>> test(n);
    for(int i =0; i<n; i++){
        int m;
        cin>> m;
        for(int j=0 ; j<m; j++){
            int a,b;
            cin>>a>>b;
            test.at(i).push_back(make_pair(a-1,b));
        }
    }
    int ans=0;
    for(int i =0; i<(1<<n); i++ ){
        bitset<16> bi = i;
        set<int> honest;
        for(int j =0; j<n; j++){
            if(bi.test(j)) honest.insert(j);
        }
        bool ok =true;
        int count = honest.size();
        while(ok&&!honest.empty()){
            int tt=*rbegin(honest);
            for(int j=0; j<test.at(tt).size(); j++){
                pair<int,int> tmp =test.at(tt).at(j);
                if(tmp.second!=bi.test(tmp.first)){
                    ok =false;
                    break;
                }
            }
            honest.erase(tt);
        }
        if(ok) ans = max(ans, count);
    }
    cout<<ans<<endl;
}

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

int main(){
    int H, W, h, w;
    std::cin >> H >> W;
    std::cin >> h >> w;

    std::cout << (H - h) * (W - w) << std::endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
L = []  # input


def prim():
    # 頂点を適当に選ぶ
    s = None
    for i in range(N):
        for j in range(N):
            if L[i][j] != -1:
                s = i
                break
        if s is not None:
            break
    p = {s}
    T = []
    k = 0
    while k < N - 1:
        # 最終のP内で一番短いやつを加える
        len = float("inf")
        lenside = []
        for sg in p:
            for i in range(N):
                isT = False
                for t in T:
                    if (t[0] == sg and t[1] == i) or (t[0] == i and t[1] == sg):
                        # print("ignore")
                        isT = True
                        continue
                if isT is False and i not in p and L[sg][i] != -1 and L[sg][i] < len:
                    len = L[sg][i]
                    lenside = [sg, i]

        p.add(lenside[0])
        p.add(lenside[1])
        T.append(lenside)
        k = k + 1
        #print(p,T,k)
    cnt = 0
    for t in T:
        cnt += L[t[0]][t[1]]
    print(cnt)


for i in range(N):
    L.append(list(map(int, input().split())))
prim()


Measured memory_bytes: 5924
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

/** GRL_3 : Strongly Connected Components **/
const int MAX_V = 10000;

class SCC {
public:
	int V;
	vector<int> G[MAX_V];
	vector<int> rG[MAX_V];
	vector<int> vs;
	bool used[MAX_V];
	int cmp[MAX_V];
	
	void init(int n)
	{
		V = n;
	}
	
	void add_edge(int from, int to)
	{
		G[from].push_back(to);
		rG[to].push_back(from);
	}
	
	void dfs(int v)
	{
		used[v] = true;
		for (int i=0; i<G[v].size(); i++) {
			if (!used[G[v][i]]) dfs(G[v][i]);
		}
		vs.push_back(v);
	}
	
	void rdfs(int v, int k)
	{
		used[v] = true;
		cmp[v] = k;
		for (int i=0; i<rG[v].size(); i++) {
			if (!used[rG[v][i]]) rdfs(rG[v][i], k);
		}
	}
	
	int scc()
	{
		memset(used, 0, sizeof(used));
		vs.clear();
		for (int v=0; v<V; v++) {
			if (!used[v]) dfs(v);
		}
		
		memset(used, 0, sizeof(used));
		int k=0;
		for (int i= (int)vs.size()-1; i>=0; i--) {
			if (!used[vs[i]]) rdfs(vs[i], k++);
		}
		return k;
	}
	
	bool same(int u, int v)
	{
		return cmp[u] == cmp[v];
	}
};

int main()
{
	int V, E;
	cin>>V>>E;
	
	SCC scc;
	scc.init(V);
	
	rep(i, E) {
		int s, t; cin>>s>>t;
		scc.add_edge(s, t);
	}
	
	scc.scc();
	
	int Q;
	cin>>Q;
	rep(i, Q) {
		int u, v;
		cin>>u>>v;
		cout << scc.same(u, v) << endl;
	}
}

Measured memory_bytes: 2628
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0

def sol(l,a,b):
    q=[[a,b]]
    while len(q):
        chk=q.pop()
        for y,x in xy:
            try:
                t1,t2=chk[0]+y,chk[1]+x
                if l[t1][t2]==1 and 0<=t1<12 and 0<=t2<12:
                    q.append([t1,t2])
                    l[t1][t2]=0
            except:
                pass
    return l
while 1:
    l=[]
    try:
        for i in range(12):
            l.append([int(x) for x in raw_input()])
        ans=0
        for i in range(12):
            for j in range(12):
                if l[i][j]==1:
                    l[i][j]=0
                    ans+=1
                    l=sol(l,i,j)
        print ans
        raw_input()
    except:
        break
exit()

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200)cout << s << endl;
  else cout << "red" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX = 1e5;

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

	//まずうまい塗り方を用意
	char s[100][100];

	rep(j, 100) s[0][j] = '#';
	rep1(i, 98)rep(j, 100) {
		if (j % 2==0)s[i][j] = '.';
		else s[i][j] = '#';
	}
	rep(j, 100)s[99][j] = '.';

	//白マスの連結部分を増やす
	//増やす量はAに応じて決める
	int wq = (A - 1) / 50;
	int wr = (A - 1) % 50;
	//wqの分2,4,6,..列目を黒く塗る
	for (int i = 2;i <= 2 * wq;i += 2)rep(j, 100) s[i][j] = '#';
	//wrの分20列目の偶数番号を黒く塗る
	rep(j, 2 * wr - 1) s[20][j] = '#';

	//黒マスの連結部分を増やす
	//増やす量はBに応じて決める
	int bq = (B - 1) / 50;
	int br = (B - 1) % 50;
	//bqの分97,95,93,..列目を白く塗る
	for (int i = 2;i <= 2 * bq;i += 2)rep(j, 100) s[99 - i][j] = '.';
	//brの分79列目の偶数番号を白く塗る
	rep(j, 2 * br - 1) s[79][99 - j] = '.';


	cout << 100 << ' ' << 100 << endl;
	rep(i, 100) {
		rep(j, 100)cout << s[i][j];
		cout << endl;
	}
}

Measured memory_bytes: 256
<?php

  $inp = trim(fgets(STDIN));
  if (empty($inp)) {
    echo "No";
    return;
  }

  $inp = explode('hi', $inp);

  foreach($inp as $i => $key) {
    if ($key != '') {
      echo "No";
      return;
    }
  }

  echo "Yes";
?>

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

using P = pair<int, int>;

constexpr int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return x ? mod - x : 0;}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}

  friend ostream& operator << (ostream& os, const mint& m) noexcept {
    return os << m.x;
  }

  friend istream& operator<< (istream& is, mint& m) noexcept {
    return is >> m.x;
  }
};

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

  ll n, m;
  cin >> n >> m;

  if (n < m) swap(n, m);

  if (n > m + 1) {
    cout << 0 << endl;
    return 0;
  }

  mint ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
  }
  for (int i = 1; i <= m; i++) {
    ans *= i;
  }

  if (n == m) ans *= 2;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> sv(n);
    rep(i, n) cin >> sv[i];
    sort(sv.begin(), sv.end());
    rep(i, n) {
        cout << sv[i];
    }
    cout << endl;
    return 0;
}


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

using namespace std;

int main() {
    string a , b , c;
    cin>>a>>b>>c;
    reverse(a.begin() , a.end());
    reverse(b.begin() , b.end());
    reverse(c.begin() , c.end());
    string cur = a , last = "A";
   // cout<<cur<<endl;
    int x = 10;
    while(!cur.empty()){
        char top = cur.back();
        cur.pop_back();
        if(last == "A"){
            a = cur;
        }else if (last == "B"){
            b = cur;
        }else c = cur;
        if(top == 'a'){
            cur = a;
            last = "A";
        }else if (top == 'b'){
            cur = b;
            last = "B";
        }else {
            cur = c;
            last = "C";
        }
    }
    cout<<last<<"\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int p[n + 5];
  rep(i, n){
    cin >> p[i];
  }
  int memo[n + 5], ans = INF;
  rep(i, p[0] + 1){
    int sum = 0;
    rep(j, n){
      memo[j] = p[j];
    }
    sum += i;
    memo[0] -= i;
    rep(j, n - 1){
      //cout << memo[j] << " ";
      if(memo[j] > 0){
	sum += memo[j] * 2;
	memo[j + 1] -= memo[j];
      }
    }
    if(memo[n - 1] > 0){
      sum += memo[n - 1];
    }
    //cout << memo[n - 1] << '\n';
    ans = min(ans, sum);
  }
  cout << ans << '\n';
  return 0;
}



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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}


signed main(){
    int N, M;
    cin >> N >> M;

    int odd_end = M+1;
    int even_begin = M+2, even_end = M+2+M-1;
    if(M % 2 == 0){
        odd_end = M;
        even_begin = M+1;
        // even_end = M+1+M;
    }

    int odd_begin = 1;
    while(odd_end - odd_begin > 0){
        cout << odd_begin << " " << odd_end << endl;
        odd_begin++;
        odd_end--;
    }

    while(even_end - even_begin > 1){
        cout << even_begin << " " << even_end << endl;
        even_end--;
        even_begin++;
    }

    return 0;
}


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

int main(){
  int N,X,L,i,bound=0,cnt=1;
  cin >> N >> X;
  for(i=0;i<N;i++){
    cin >> L;
    bound += L;
    if(X>=bound)
    cnt++;
    else
    break;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Queue []int

func (q *Queue) push(v int) {
	*q = append(*q, v)
}

func (q *Queue) pop() int {
	v := (*q)[0]
	*q = (*q)[1:]
	return v
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	paths := make([]int, nVerts+1)

	queue := Queue(make([]int, 0))
	queue.push(1)
	paths[1] = 1

	for len(queue) > 0 {
		u := queue.pop()
		d := paths[u] + 1
		for _, v := range graph[u] {
			if paths[v] == 0 {
				paths[v] = d
				queue.push(v)
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d\n", i, paths[i]-1)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}



Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int main(){
	int w, n, a[30][30], ans[30];
	cin >> w >> n;
	for(int i = 0;i < w;i++)
	for(int j = 0;j < n;j++)a[i][j] = -1;
	for(int i = 0;i < n;i++){
		int x, y;
		scanf("%d,%d", &x, &y);
		a[x-1][i] = y-1;
		a[y-1][i] = x-1;
	}
	for(int i = 0;i < w;i++){
		int x = i;
		for(int j = 0;j < n;j++){
			if(a[x][j] != -1)x = a[x][j];
		}
		ans[x] = i+1;
	}
	for(int i = 0;i < w;i++)cout << ans[i] << endl;
	return 0; 
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define se second
const int N = 2e5+5;
void solve(){
    string a,b; 
    cin>>a>>b; 
    cout<<b<<a<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int a[20];
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);

    int q;
    scanf("%d", &q);

    for (int i = 0; i < q; ++i) {
        int m;
        scanf("%d", &m);

        bool ok = false;
        for (int i = 0; i < (1 << n); ++i) {
            int s = 0;
            for (int j = 0; j < n; ++j)
                s += ((i >> j) & 1) * a[j];
            if (s == m)
                ok = true;
        }

        if (ok)
            puts("yes");
        else
            puts("no");
    }

    return 0;
}

Measured memory_bytes: 1008
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

f ss os= f' 0 ss os
f' t _ [] = t
f' t la@(l:ls@(r:_)) xa@(x:xs)
  | x>r = f' t ls xa
  | otherwise = f' (t + min (x-l) (r-x)) la xs

main = do
    d <- getInt
    when (d/=0) $ do
        n <- getInt
        m <- getInt
        ss <- sort . (0:) . (d:) <$> replicateM (n-1) getInt
        os <- sort <$> replicateM m getInt
        print $ f ss os
        main

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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans;

    if (K <= A) ans = K;
    else if (K > A + B) ans = A - (K - (A + B));
    else ans = A;
    cout << ans << endl;
}


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

// DAME:
// 文字列の辞書順: abc > 次の単語のabc >>　単語のながさ 
int main() {
    string s;
    int n, k;
    cin >> s >> k;
    n = s.size();
    set<string> ss;
    for(int i=0; i<n; i++){
        string sss;
        for(int j=i; j<min(i+k, n); j++){
            sss += s[j];
            ss.insert(sss);
        }
    }
    auto itr = ss.begin();
    for(int i=0; i<k-1; i++){
        ++itr;
    }

    cout << *itr << endl;
    return 0;
}

Measured memory_bytes: 1664