akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

namespace ITP1_5_A
{
	class Program
	{
		static void Main(string[] args)
		{
			List<Tuple<int, int>> ts = new List<Tuple<int, int>>();

			while(true) {
				string[] vs = Console.ReadLine().Split(' ');

				int h = int.Parse(vs[0]);
				int w = int.Parse(vs[1]);

				if(h == 0 && w == 0) {
					break;
				}

				ts.Add(Tuple.Create(h, w));
			}

			foreach(Tuple<int, int> t in ts) {
				for(int i = 0; i < t.Item1; i++) {
					for(int j = 0; j < t.Item2; j++) {
						Console.Write("#");
					}
					Console.WriteLine();
				}

				Console.WriteLine();
			}
		}
	}
}



Measured memory_bytes: 15972
#include<cstdio>

const int MAX = 7500111;
int N, M;
int C[MAX];

int main() {
    for (int tt=1; scanf("%d%d", &M, &N), N|M; tt++) {
	int cur = M;

	for (int i=0; i<N; i++) {
	    while (C[cur] == tt) cur++;

	    for (int j=cur; j<MAX; j+=cur)
		C[j] = tt;
	}

	while (C[cur] == tt) cur++;
	printf("%d\n", cur);
    }

    return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  cout.precision(17);
  int t;cin>>t;  
  cout<<t*2*M_PI<<endl;
  return 0;
}


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

int N, arr[100005], l, r;
set<int> S;

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &arr[i]);
	for (int i = 0; i < N; i++) S.insert(arr[i]);
	if (S.size() > 2) {
		printf("No\n");
		return 0;
	}
	if (S.size() == 1) {
		int val = *S.begin();
		if (val == N - 1 || val * 2 <= N) printf("Yes\n");
		else printf("No\n");
		return 0;
	}
	int lower = *S.begin(), upper = *S.rbegin();
	if (lower + 1 != upper) {
		printf("No\n");
		return 0;
	}
	for (int i = 0; i < N; i++) {
		if (arr[i] == lower) l++;
		else r++;
	}
	int types = upper - l;
	if (types <= 0) {
		printf("No\n");
		return 0;
	}
	if (types * 2 <= r) {
		printf("Yes\n");
	} else printf("No\n");
}


Measured memory_bytes: 5376
#include <iostream>
#include <string>
using namespace std;
int main() {
 string S;
  int out=0;
  cin>>S;
  int N=S.length();
for(int i=0;i<(N+1)/2;i++){
if(S[i]!=S[N-1-i]){out=1;}
}
int j,k,l;
j=((N-1)/2)/2;
k=(N+1)/2;
l=(N-1)/2-1;
for(int i=0;i<j;i++){
if(S[i]!=S[l-i]){out=1;}
if(S[i+k]!=S[l-i+k]){out=1;}
}
if(out==0){cout<<"Yes";}else{cout<<"No";}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define N 4010
#define inf 1000000000
using namespace std;

struct aa{int l, r;}a[N], b[N];
int n, ff, ans, flag[N], l, now;
char s1[N], s2[N];
vector<int>son[N];

inline int solve(int x){
	memset(flag, 0, sizeof(flag));
	for(int i=1; i<=n; i++)if(s1[i]!=s2[i+x-1])flag[i]=1;
	int ans=inf, ans1, L, x1, x2, now, l;
	L=n+2-x;
	//正
	l=0;
	for(int i=1; i<=n; i++)son[i].clear();
	for(int i=1; i<=n; i++)if(flag[i]){
		x1=b[i].l+1; x2=n+1-b[i].r;
		if(x2==n+1||x1<=L)continue;
		l++; son[x1].push_back(x2);
	}
	if(l){
		now=n+1; ans1=n-L;
		for(int i=n-1; i>=L; i--){
			for(int j=0; j<son[i+1].size(); j++)now=min(now, son[i+1][j]);
			ans1=min(ans1, i-L+n+1-now);
		}
	}else ans1=0;
	ans=min(ans, ans1*2+L-1);
	//反
	l=0;
	for(int i=1; i<=n; i++)son[i].clear();
	for(int i=1; i<=n; i++)if(flag[i]){
		x1=b[i].l+1; x2=n+1-b[i].r;
		if(x2>=L)continue;
		l++; son[x1].push_back(x2);
	}
	if(l){
		now=L; ans1=L-2;
		for(int i=L-2; i; i--){
			for(int j=0; j<son[i+1].size(); j++)now=min(now, son[i+1][j]);
			ans1=min(ans1, i-1+L-now);
		}
	}else ans1=0;
	ans=min(ans, ans1*2+n+1-L);
	for(int i=1; i<=n; i++)ans+=flag[i];
	return ans;
}

int main(){
	scanf("%s%s", s1+1, s2+1); n=strlen(s1+1);
	for(int i=1; i<=n; i++)s2[n+i]=s2[i];
	ff=0; for(int i=1; i<=n; i++)if(s2[i]=='1')ff=1;
	if(!ff){
		ff=0; for(int i=1; i<=n; i++)if(s1[i]=='1')ff=1;
		if(ff)printf("-1"); else printf("0");
		return 0;
	}
	now=n*2+1;
	for(int i=n*2; i; i--){if(s2[i]=='1')now=i; if(i<=n)b[i].r=now-i;}
	now=0;
	for(int i=1; i<=n*2; i++){if(s2[i]=='1')now=i; if(i>=n+1)b[i-n].l=i-now;}
	ans=inf; for(int i=1; i<=n; i++)ans=min(ans, solve(i));
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long arr[n];
    map<long long, long long> mp;
    cin>>arr[0];
    mp[arr[0]]++;
    for(int i=1;i<n;i++) cin>> arr[i];
    for(int i=1;i<n;i++) arr[i]+=arr[i-1], mp[arr[i]]++;
    map<long long, long long>::iterator it;
    long long ans=0;
    for(it= mp.begin(); it!=mp.end(); it++)
    {
        if(it->first==0) ans+=(it->second*(it->second+1))/2;
        else ans+=(it->second*(it->second-1))/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 14336
import numpy as np
H,W = map(int,input().split())
Map=[list(input()) for h in range(H)]
Map=[[1 if s=='.' else 0 for s in Map[h]] for h in range(H)]
Map=np.array(Map,dtype=int)
L=Map.copy()
R=Map.copy()
U=Map.copy()
D=Map.copy()
for w in range(1,W):
    L[:,w]=(L[:,w-1]+1)*Map[:,w]
    R[:,-(1+w)]=(R[:,-w]+1)*Map[:,-(1+w)]
for h in range(1,H):
    U[h,:]=(U[h-1,:]+1)*Map[h,:]
    D[-(1+h),:]=(D[-h,:]+1)*Map[-(1+h),:]
print((L+R+U+D).max()-3)

Measured memory_bytes: 251000
A, B, C, D = map(int, input().split())
dp = [[0]*3001 for _ in range(3001)]
MOD = 998244353

dp[A][B] = 1
for i in range(A, C+1):
    for j in range(B, D+1):
        if dp[i-1][j] and dp[i][j-1]:
            dp[i][j] = dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1)
        elif dp[i-1][j]:
            dp[i][j] = dp[i-1][j]*j
        elif dp[i][j-1]:
            dp[i][j] = dp[i][j-1]*i
        dp[i][j] %= MOD

print(dp[C][D])

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


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

	string a;
	cin >> a;
	string t;
	cin >> t;
	for (int i = 0 ; i < a.size() ; i++)
	{
		if (a[i] != t[i])
		{
			cout<<"No"<<endl;
			exit(0);
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
	int m,f,r;
	for(int i=1;i<=50;i++){
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1)break;
		if(m==-1||f==-1&&r>=-1||m+f<30)cout<<"F"<<endl;
		else if(m+f>=80)cout<<"A"<<endl;
		else if(m+f>=65&&m+f<80)cout<<"B"<<endl;
		else if(m+f>=50&&m+f<65||r>=50)cout<<"C"<<endl;
		else if(m+f>=30&&m+f<50)cout<<"D"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3032
#include<stdio.h>
int main(void){
	int n,m;
	int i,j;
	int hiyo[10000],kijun[10000];
	int cnt[10000],max=0,ban=0;
	for(i=1;i<10000;i++){
		cnt[i]=0;
	}
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%d",&hiyo[i]);
	}
	for(i=1;i<=m;i++){
		scanf("%d",&kijun[i]);
	}
	for(i=1;i<=m;i++){
		for(j=0;j<=n;j++){
			if(hiyo[i]<=kijun[j]){
				cnt[i]++;
				kijun[j]=-10000;
			}
		}
	}
	for(i=1;i<=n;i++){
		if(cnt[i]>max){
			max=cnt[i];
			ban=i;
		}
	}
	/*for(i=1;i<=n;i++){
		printf("cnt[%d]=%d\n",i,cnt[i]);
	}*/
	printf("%d\n",ban);
	return 0;
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main() {
    int n; cin >> n;
    vector<vector<int>> G(n);
    map<P,int> mp;
    for(int i=0; i<n-1; i++){
        int u,v,w;
        cin >> u >> v >> w;
        u--;v--;
        G[u].push_back(v);
        G[v].push_back(u);
        mp[P(u,v)]=w;
        mp[P(v,u)]=w;
    }
    stack<P> st;
    vector<int> used(n,0);
    vector<int> color(n,-1);
    vector<ll> sum(n);
    st.push(P(-1,0));
    while(!st.empty()){
        int pre=st.top().first;
        int now=st.top().second;
        st.pop();
        used[now]=1;
        if(sum[now]%2==0) color[now]=0;
        else color[now]=1;
        for(auto next: G[now]){
            if(used[next]) continue;
            st.push(P(now,next));
            sum[next]=sum[now]+mp[P(now,next)];
        }
    }
    for(int i=0; i<n; i++){
        cout << color[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 19968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    ll l,r,ans;cin>>l>>r;
    ans=114514;
    ll left=l;
    ll right=min(l+2019,r);
    for(ll i=left;i<=right;i++){
        for(ll j=i+1;j<=right;j++){
            ans=min(ans,(i*j)%2019);
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

const long long MAX_KEYS = 12, MAX_MASK = (1LL << 12), oo = 1e12;
long long minimum_cost[MAX_MASK];

int main()
{
    int no_of_boxes, no_of_keys;
    cin >> no_of_boxes >> no_of_keys;

    vector <long long> cost(no_of_keys + 1, 0);
    vector <int> no_of_openable_boxes(no_of_keys + 1, 0);
    vector <long long> mask(no_of_keys + 1, 0);

    for(int i = 1; i <= no_of_keys; i++)
    {
        cin >> cost[i] >> no_of_openable_boxes[i];

        for(int j = 1; j <= no_of_openable_boxes[i]; j++)
        {
            int key;
            cin >> key;

            key--;
            mask[i] |= (1 << key);
        }
    }

    long long oo = 1e12;
    int complete_mask = (1LL << no_of_boxes) - 1;
    vector <long long> minimum_cost(complete_mask + 1, oo);
    minimum_cost[0] = 0;

    for(int i = 1; i <= no_of_keys; i++)
    {
        for(int m = 0; m <= complete_mask; m++)
        {
            if((m&mask[i]) == mask[i])
            {
                minimum_cost[m] = min(minimum_cost[m], minimum_cost[m^mask[i]] + cost[i]);

                for(int sub_m = 0; sub_m <= complete_mask; sub_m++)
                {
                    if((mask[i]&sub_m) == sub_m)
                    {
                        minimum_cost[m] = min(minimum_cost[m], minimum_cost[m^sub_m] + cost[i]);
                    }
                }

            }

            //cout << "F(" << i << "," << m << ") = " << minimum_cost[m] << endl;
        }
    }

    cout << (minimum_cost[complete_mask] == oo ? -1 : minimum_cost[complete_mask]) << "\n";
    return 0;
}


Measured memory_bytes: 256
const readLines = (input) => input.split('\n')
const println = (value) => console.log(value)
const readInt = (input) => parseInt(input, 10)
const readIntList = (input) => input.split(' ').map(n => parseInt(n, 10))
const naturalOrder = (a, b) => {
    if (b == a) return 0
    return (a < b) ? -1 : 1
}

function main(input) {
    const lines = readLines(input)
    const n = readInt(lines[0])
    const aArray = readIntList(lines[1])
    const allXor = aArray.reduce((acc, a) => acc ^ a)
    const ans = aArray.map((a, i) => a ^ allXor).join(' ')
    println(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 67764
program main
implicit none
integer(8) :: i, j, k
integer(8) :: n, x, res
integer(8) , allocatable :: a(:), b(:)

read(*,*) n, x
allocate( a(n), b(n) )
read(*,*) a
res = sum( max(a(1:n)-x,0) )
do i = 2, n
   b(i) = min(x,a(i))
   if( min(x,a(i)) + min(x,a(i-1)) .ge. x ) then
      a(i) = x - min(x,a(i-1))
      res = res + b(i)-a(i)
   end if
end do
write(*,'(i0)') res


end program main


Measured memory_bytes: 2304
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 1000006
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    FASTIO;
    int n;
    ll gcd = 0;
    cin>>n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            for(int k = 1; k <= n; k++)
                gcd+=(__gcd(i, __gcd(j, k)));
    cout<<gcd<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a-b>=0)
	{
		cout<<a-b<<endl;
	 }
	 else
	 {
	 	cout<<0<<endl;
	  } 
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
int d,k,L,i,j,ten[15],a[25];
int s[25],mx,f[25];ll ans,an;
void dfs(int x,ll now){
	if (L-x>=k-1&&abs(now)>=10) return;
	if (now<0) return;
	int i;
	if (x>mx){
		an=a[s[1]+9]-(s[1]<=0);
		if (L&1) an*=10-(L==1);
		s[L]=-s[1];
		fo(i,2,mx) an*=a[s[i]+9],s[L-i+1]=-s[i];
		ll p=0;
		fd(i,L,1){
			p=p*10+s[i];
			if (p>d) return;
		}if (p==d) ans+=an;
		return;
	}
	fo(i,-9,9) s[x]=i,dfs(x+1,now*10-i);
}
int main(){
	ten[0]=1;
	fo(i,1,9) ten[i]=ten[i-1]*10;
	scanf("%d",&d);
	fo(i,1,9) if (d<ten[i]) break;
	k=i+1;
	fo(i,0,9)
	fo(j,0,9) a[i-j+9]++;
	fo(L,2,k<<1){
		mx=L>>1;
		memset(s,0,sizeof(s));
		dfs(1,0);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
count = int(input())
dataset = input().split(" ")

num = []
for i in range(len(dataset)):
    num.append(int(dataset[i]))

min = num[0]
max = num[0]
sum = 0

for n in num:
    if min > n:
        min = n
    if max < n:
        max = n
    sum += n

print("%d %d %d" % (min, max, sum))




Measured memory_bytes: 6604
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N;
  cin>>N;
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  int num = 0;
  for(int i=0;i<N;++i) {
    if(A[i]<0) num++;
  }
  ll ans = 0;
  if(num%2==0) {
    for(int i=0;i<N;++i) {
    ans += abs(A[i]);
    }
  }
  else {
    ll num = inf;
    for(int i=0;i<N;++i) {
      num = min(num, abs(A[i]));
    }
    for(int i=0;i<N;++i) {
      ans += abs(A[i]);
    }
    ans -= 2*num;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4400
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N;
	cin >> N;
	int cnt = 0;
	for_(i,0,N) {
		int a;
		cin >> a;
		if (a - 1 != i) ++cnt;
	}
	puts(cnt <= 2 ? "YES" : "NO");
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
cumul = 1
n = int(raw_input())
ais = map(int, raw_input().split(' '))
i = 0
ais.sort(key = lambda x:-x)
if ais[-1] == 0:
	cumul = 0
while(i < len(ais) and cumul <= 10 ** 18):
  cumul *= ais[i]
  i +=1
  if cumul == 0:
  	break

print cumul if cumul <= 10 ** 18 else -1

Measured memory_bytes: 88176
program main
implicit none
integer i,n,j,n_abc
character(50) s

read(*,*) n
read(*,*) s

n_abc=0
i=1
do while(i<n)
   j=index(s(i:),'ABC')
   if(j==0) exit
   n_abc = n_abc + 1
   i=i+j
end do
write(*,'(i0)') n_abc
end program main

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import qualified Data.Maybe as MA

main = do
    [a, b] <- fmap (fst . MA.fromJust . BS.readInt) . BS.words <$> BS.getLine
    let candidates = [ x | x <- [1..1000], floor (fromIntegral x * 0.08) == a && floor (fromIntegral x * 0.1) == b]
    let answer = if null candidates then -1 else minimum candidates
    putStrLn $ show answer


Measured memory_bytes: 508
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, bool> pib;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<double> vf;

typedef long double ld;

#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

#define printItr(A) for(auto itr = A.begin(); itr != A.end(); ++itr){cout << * itr << ", ";}cout << endl;

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

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

	vi S(N+1);
	rep(i, N + 1) {
		char c; cin >> c;
		S[N - i] = (c == '1');
	}

	vi A(0);

	ll dst = 0;
	ll next = 1;
	for (ll n = 0; n < N + 1;){
		bool ok = false;
		// cout << "n" << n << endl;

		for(ll m = next; m <= n + M && m <= N; m++){
			// cout << "m" << m << endl;
			if (S[m] == false) {
				dst = m;
				ok = true;
				// cout << "ok" << endl;
			}
		}

		next = n + M + 1;
		A.pb(dst - n);
		n = dst;

		if (ok == false) {
			cout << -1 << endl;
			return 0;
		}

		if (n == N) {
			break;
		}
	}
	for (ll i = A.size()-1; i >= 0; i--) {
		cout << A[i] << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 2168
H, W = map(int, input().split())
M = [input().split() for _ in range(H)]
for i in range(H):
    for j in range(W):
        if M[i][j] == 'snuke':
            print('ABCDEFGHIJKLMNOPQRSTUVWXYZ'[j] + str(i + 1))
            exit()

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


int main(){
	int n;
	cin>>n;
	vector<int> p(n);
	for(int i=0;i<n;i++)cin>>p[i];
	sort(p.begin(),p.end());
	//cout<<p[0]<<endl;
	p[p.size()-1] /=2;
	int ans =0;
	for(int i=0;i<n;i++)ans+=p[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[][] dp=new int[2][n];
    for(int i=0;i<2;i++){
      for(int j=0;j<n;j++){
        dp[i][j]=sc.nextInt();
      }
    }
    for(int i=1;i<n;i++){
      dp[0][i]=dp[0][i-1]+dp[0][i];
    }
    dp[1][0]=dp[0][0]+dp[1][0];
    for(int i=1;i<n;i++){
      dp[1][i]=dp[1][i]+Math.max(dp[0][i],dp[1][i-1]);
    }
    System.out.println(dp[1][n-1]);
  }
}

Measured memory_bytes: 24404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int N;
	cin >> N;
	vector<ll> cnt(N+1,0);

	for(int x = 1;x * x <= N;x++){
		for(int y = 1;y * y <= N;y++){
			for(int z = 1;z * z <= N;z++){
				int num = x * x + y * y + z * z + x * y + y * z + x * z;
				if(num <= N)cnt[num]++;
			}
		}
	}

	for(int i = 1;i <= N;i++)cout << cnt[i] << endl;
}


Measured memory_bytes: 3628
//T1 
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
#define d read()
ll l,r,k;
int main(){
	k=d,l=d,r=d;
	f(i,l,r)
		if(i%k==0){cout<<"OK";return 0;}
	cout<<"NG";
	return 0;
}


Measured memory_bytes: 3604
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
S = input()

l = 0
r = 0

for x in S:
	if x == "(":
		r += 1
	elif x == ")":
		if 0 < r:
			r -= 1
		else:
			l += 1

print("("*l + S + ")"*r)



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

int main(void) {
	int p,q;
	int count_s = 0;
	int count_t = 0;
	string s;
	string t;
	cin >> s;
	cin >> t;
	p = s.size() + t.size();
	for (int i = 1; i <= p; i++) {
		if (i % 2 == 1) {
			cout << s[count_s];
			count_s++;
		}
		else {
			cout << t[count_t];
			count_t++;
		}
	}
	cout << endl;;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


int main() {
  ll n; cin >> n;
  ll sum = 0;
  ll a;
  Rep(i, 1, n){
    sum += i;
    a = i;
    if(sum >= n) break;
  }
  Rep(i, 1, a){
    if(i != sum-n) cout << i << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
#define maxval 10003000
ll power(ll x,ll n,ll m)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%m;
        x=(x*x)%m;
        n=n/2;
    }
    return result%m;
}

int main(){
   IOS;
//ll t;t=1;//cin>>t;
ll n;cin>>n;
vector<ll> a,b;
for(ll i=0;i<n;i++){
    ll x,y;cin>>x>>y;
    a.pb(x+y);
    b.pb(x-y);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
cout<<max(b[n-1]-b[0],a[n-1]-a[0])<<"\n";
    
return 0;    
}


Measured memory_bytes: 6684
#include <bits/stdc++.h>
#include <string.h>
#define ll long long
using namespace std;
struct value
{
	ll x;
	ll y;
};
bool compare(value a, value b)
{
	//for descending order replace with a.roll >b.roll
	if (a.y < b.y)
		return 1;
	else
		return 0;
}
void pk()
{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	   cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	if(n==1)
	{
		cout<<0<<"\n";
		return;
	}
	if(n==2)
	{
		cout<<a[0]<<"\n";
		return;
	}
	ll sum=a[0];
	ll end;
	ll l=n-2;
	for(ll i=1;i<n;i++)
	{
		sum=sum+a[i]*2;
		end=a[i];
		l=l-2;
		if(l<=0)  break;

	}
	if((n-2)%2!=0) cout<<sum-end;
	else cout<<sum;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
		pk();
	
	
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b && a == c) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  for (int i = 0; i < N; i ++) {
  	int x;
    cin >> x ;
    //0からの距離とKからの距離
    int a0 = x ;
    int ak = K - x;
    if (ak < 0) {
      ak *= -1;
    }
    if (ak > a0) {
      sum += a0 * 2;
    } else {
      sum += ak * 2;
    }
  }
  cout << sum << endl;
  
}


Measured memory_bytes: 256
from itertools import accumulate
n,m,k=map(int,input().split())
A=list(accumulate(map(int,input().split()),initial=0))
B=list(accumulate(map(int,input().split()),initial=0))
r,j=0,m
for i in range(n+1):
  if A[i]>k:
    break
  while A[i]+B[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Measured memory_bytes: 45836
import java.util.*;
 
class Main {
    
	static int res=0,d,w,E[][]=new int[10][10];
	
    public static void main(String[] args) {
         
       Scanner cin=new Scanner(System.in);
       
       while(true) {
    	   String str=cin.nextLine();
    	   if(str.equals("."))break;
    	   char A[]=str.toCharArray();
    	   boolean jd=true;
    	   Deque<Character> B=new ArrayDeque<>();
    	   
    	   for(int i=0;i<A.length;i++) {
    		   if(A[i]==')' && (B.isEmpty() || B.getFirst()=='[')) {
    			   jd=false;
    			   break;
    		   }
    		   else if(A[i]==']' && (B.isEmpty() || B.getFirst()=='(')) {
    			   jd=false;
    			   break;
    		   }
    		   
    		   if(A[i]==']')B.pop();
    		   else if(A[i]==')')B.pop();
    		   else if(A[i]=='[')B.push('[');
    		   else if(A[i]=='(')B.push('(');
    	   }
    	   
    	   if(B.isEmpty() && jd)System.out.println("yes");
    	   else System.out.println("no");
       }
    }
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

struct town{
    ll x,y,id;
};

struct edge{
    ll u, v, cost;
};

bool comp_c(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}
bool comp_x(const town& t1, const town& t2){
    return t1.x < t2.x;
}
bool comp_y(const town& t1, const town& t2){
    return t1.y < t2.y;
}

int n, mi, ma;
string s[100010], mema[100010],  memb[100010];

int main(){
    cin >> n;
    for(int i = 0; i <= n; i++){
        cin >> s[i];
        mema[i] = memb[i] = s[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < s[i].length(); j++){
            if(mema[i][j] == '?'){
                mema[i][j] = 'a';
                memb[i][j] = 'z';
            }
        }
    }

    sort(mema, mema+n);
    for(int i = 0; i < n; i++){
        if(s[n] <= mema[i]){
            ma = i+1;
            if(mema[i] == s[n]){
                for(int j = i+1; j < n; j++){
                    if(mema[j] == s[n]) ma = j+1;
                    else{
                        ma = j+1;
                        break;
                    }
                }
                if(mema[n-1] == s[n])   ma = n+1;
            }
            break;
        }
        if(i == n-1)    ma = n+1;
    }

    sort(memb, memb+n);
    for(int i = 0; i < n; i++){
        if(s[n] <= memb[i]){
            mi = i+1;
            break;
        }
        if(i == n-1)    mi = n+1;
    }

    cout << mi;
    for(int i = mi+1; i <= ma; i++){
        cout << ' ' << i; 
    }
    cout << endl;
}

Measured memory_bytes: 4096
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int max = a;
        if(max < b){
            max = b;
        }
        if(max < c){
            max = c;
        }
        int answer = a+b+c-max +max*(int)(Math.pow(2,d));
        System.out.println(answer);
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,w;
    cin>>n>>w;
    vector<vector<int> > input(n,vector<int>(2));
    for(int i=0;i<n;++i){
        cin>>input[i][0]>>input[i][1];
    }
    ll ninf=LLONG_MIN;
    vector<vector<ll> > dp(n+1,vector<ll>(w+1,ninf));
    dp[0][0]=0;
    ll ans=ninf;
    for(int i=1;i<=n;++i){
        for(int j=0;j<=w;++j){
            int weight=input[i-1][0];
            int value=input[i-1][1];
            if(j-weight>=0) {
                dp[i][j] = max((dp[i - 1][j - weight] < 0 ? ninf : value + dp[i - 1][j - weight]),dp[i-1][j]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
            ans=max(ans,dp[i][j]);
        }
    }
//    for(int i=0;i<=n;++i){
//        for(int j=0;j<=w;++j){
//            cout<<dp[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    cout<<ans;
    cout<<endl;
}


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

int main(void){
	long long a, b, c, x, y, cost, ans;
	cin >> a >> b >> c >> x >> y;

	long long z = max(x, y);

	for(long long i=0; i<=z; i++){
		if(x-i>=0 && y-i>=0) cost = (x-i)*a + (y-i)*b + 2*i*c;
		if(x-i>=0 && y-i<0) cost = (x-i)*a + 2*i*c;
		if(x-i<0 && y-i>=0) cost = (y-i)*b + 2*i*c;

		if(i==0 || ans>cost) ans = cost;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <unordered_map>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <random>
#include <chrono>
#include <bitset>
#include <fstream>
#include <sstream>

using namespace std;

typedef long long ll;
typedef long double ld;

ll big = 1000000007ll;
ll n,m,k;

vector<vector<ll> > C(200000 , vector<ll>());
ll deg[200000] = {0};
bool mark[200000] = {0};
ll val[200000] = {0};
ll val2[200000] = {0};

ll mikl[200000] = {0};


ll bigel = 1333333333333337ll;

ll midfs(ll i, ll par){
ll mi;
if(mark[i] == 1){
    mi = val[i];
}
else{
    mi = bigel;
}
for(ll c1 = 0 ;c1 < deg[i]; c1++){
    ll b = C[i][c1];
    if(b != par){
        mi = min(mi , midfs(b,i) + 1);
    }
}
mikl[i] = mi;
return mi;
}

void dfs(ll i, ll par){

if(par == -1){
    val2[i] = val[i];
}
else{
    if(mikl[i]+1 == val2[par]){
        val2[i] = val2[par]-1;
    }
    else{
        val2[i] = val2[par]+1;
    }
}

for(ll c1 = 0; c1 < deg[i]; c1++){
    ll b = C[i][c1];
    if(b != par){
        dfs(b,i);
    }
}
}

bool check(ll i, ll par){


bool ans = 1;

if(mark[i] == 1 && val[i] != val2[i])return 0;

for(ll c1 = 0; c1 < deg[i]; c1++){
    ll b = C[i][c1];
    if(b != par){
        ans &= (abs(val2[i]-val2[b]) == 1);
        ans &= check(b,i);
    }
}
return ans;
}

int main()
{

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll a,b,c,d,e,f;
    ll c1,c2,c3;

    cin >> n;
    for(c1 = 0; c1 < n-1; c1++){
        cin >> a >> b;
        a--;
        b--;
        deg[a]++;
        deg[b]++;
        C[a].push_back(b);
        C[b].push_back(a);
    }

    cin >> m;
    ll root;
    for(c1 = 0; c1 < m; c1++){
        cin >> a >> b;
        a--;
        mark[a] = 1;
        val[a] = b;
        root = a;
    }

   midfs(root,-1);
   dfs(root,-1);

   if(!check(root,-1)){
    cout << "No\n";
   }
   else{
        cout << "Yes\n";
    for(c1 = 0; c1 < n; c1++){
        cout << val2[c1] << "\n";
    }
   }

    return 0;
}


Measured memory_bytes: 18176
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		
		boolean[] d = new boolean[4];
		for(int i=0; i<s.length; i++)
			d["NWSE".indexOf(s[i])] |= true;
		
		System.out.println((d[0]^d[2])||(d[1]^d[3]) ? "No" : "Yes");
		
		sc.close();
	}
}


Measured memory_bytes: 9940
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(int& a){printf("%d",a);}
void print(long long& a){printf("%lld",a);}
void print(double& a){printf("%.15lf",a);}
template<class T> void print(T& a){cout<<a;}
template<class T> void print(vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(Head& head, Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(T& a){cerr<<a;}
template<class T> void dprint(vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(Head& head, Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int x;
    for(int i=1;1;i++){
        in(x);
        if(x==0)break;
        printf("Case %d: %d\n",i,x);
    }
}


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

int main() {
	int n, y;
	cin >> n >> y;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (i + j > n) continue;
			if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y) {
				printf("%d %d %d", i, j, n - i - j);
				return 0;
			}
		}
	}
	printf("%d %d %d", -1, -1, -1);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		scan.close();
		int result = 0;
		for(int i = 1; i <= N; i++) {
			if(String.valueOf(i).length() % 2 == 1) {
				result++;
			}
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 27860
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, x;
	cin >> n >> x;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];

	ll ans = 0;
	for (ll i = 0; i < n / 2; i++) {
		if (a[i] + a[i + 1] > x) {
			if (a[i] <= x) {
				ans += a[i] + a[i + 1] - x;
				a[i + 1] = x - a[i];
			}
			else {
				ans += a[i] + a[i + 1] - x;
				a[i + 1] = 0;
				a[i] = x;
			}
		}
		if (a[n - 2 - i] + a[n - 1 - i] > x) {
			if (x >= a[n - 1 - i]) {
				ans += a[n - 2 - i] + a[n - 1 - i] - x;
				a[n - 2 - i] = x - a[n - 1 - i];
			}
			else {
				ans += a[n - 2 - i] + a[n - 1 - i] - x;
				a[n - 2 - i] = 0;
				a[n - 1 - i] = x;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
import * as fs from 'fs'

function solve() {
  const [A, B] = (require('fs').readFileSync("/dev/stdin", "utf8") as string).split(" ").map((x: string):number => +x);
  let plug = 1;
  let cnt = 0;
  while (plug < B) {
    plug += A - 1;
    cnt++;
  }
  console.log(cnt);
}

solve();


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

int main() {
  int N;
  int64_t sum=0;
  cin >> N;

  for (int i = 0; i < N+1; i++) {
      if(i%3!=0&&i%5!=0){
          sum+=i;
      }
}
  cout << sum << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// const int R = 5;
const int R = 320;

ll add[R][R]={};

const int N = 100010;
ll p[N];

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


    ll s = 0;
    int d = 0;

    rep(i,m){
        int a,b;
        scanf(" %d %d", &a, &b);

        if(b<R){
            int val = (a+1)%b;
            rep(j,b){
                add[b][j] += val;
                (val += 1) %= b;
            }
        }
        else{
            s += a+1;
            int st = b-a-1;
            for(int j=st; j<n; j+=b) p[j] += b;

            ++d;
        }
    }

    rep(i,N-1) p[i+1] += p[i];

    vector<ll> ans(n);
    rep(i,n){
        ans[i] += s;
        s += d;
        ans[i] -= p[i];
    }
    for(int i=1; i<R; ++i){
        rep(j,n){
            ans[j] += add[i][j%i];
        }
    }

    rep(i,n) printf("%lld\n", ans[i]);
    return 0;
}



Measured memory_bytes: 4548
#include <stdio.h>
#include <stdlib.h>

typedef struct node_s node;

struct node_s{
  int key;
  node *prev;
  node *next;
};

node *head;

void insert(int x){
  node *t=malloc(sizeof(node));
  t->key=x;
  t->next=head->next;
  t->prev=head;
  head->next->prev=t;
  head->next=t;
}
void delete(node *n){
  if (n==NULL)return;
  n->prev->next=n->next;
  n->next->prev=n->prev;
  free(n);
}

node *find(int key){
  node *p;
  for (p=head->next;p->key!=-1;p=p->next){
    if (p->key==key){
      return p;
    }
  }
  return NULL;
}

int main(){
  int i,n,x;
  char cmd[16];
  node *tp;
    
  head = malloc(sizeof(node));
  head->key=-1;
  head->prev=head;
  head->next=head;
  
  scanf("%d",&n);

  for (i=0;i<n;i++){
    scanf("%s", &cmd);
    if (cmd[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if (cmd[0]=='d'&&cmd[6]=='\0'){
      scanf("%d",&x);
      delete(find(x));
    }else if (cmd[0]=='d'&&cmd[6]=='F'){
      delete(head->next);
    }else if (cmd[0]=='d'&&cmd[6]=='L'){
      delete(head->prev);
    }
  }
  for (tp=head->next;tp->next->key!=-1;tp=tp->next)
    printf("%d " ,tp->key);
  printf("%d\n" ,tp->key);
  
  return 0;
}


Measured memory_bytes: 32972
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_VTX_MAX		100000									// 最大頂点数
#define D_EDGE_MAX		100000									// 最大辺数

// 内部構造体 - 辺情報
typedef struct Edge {
	int miVNo;													// 接続先頂点
	struct Edge *mzpNext;										// 次の辺
} Edge;

// 内部構造体 - 頂点情報
typedef struct Vtx {
	Edge *mzpEdge;												// 辺
	int miH;													// 高さ
} Vtx;

// 内部変数
static FILE *szpFpI;											// 入力
static Vtx sz1Vtx[D_VTX_MAX];									// 頂点
static int siVCnt;												// 頂点数
static Edge sz1Edge[D_EDGE_MAX * 2];							// 辺
static int siECnt;												// 辺数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 辺 - 追加
int
fAddEdge(
	int piVFNo					// <I> 頂点 - 元
	, int piVTNo				// <I> 頂点 - 先
)
{
	sz1Edge[siECnt].miVNo = piVTNo;
	sz1Edge[siECnt].mzpNext = sz1Vtx[piVFNo].mzpEdge;
	sz1Vtx[piVFNo].mzpEdge = &sz1Edge[siECnt];
	siECnt++;

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i, liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(sz1Vtx, 0, sizeof(sz1Vtx));
	siECnt = 0;

	// 頂点数・辺数 - 取得
	int liECnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siVCnt, &liECnt);

	// 高さ - 取得
	for (i = 0; i < siVCnt; i++) {
		fscanf(szpFpI, "%d", &sz1Vtx[i].miH);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 辺 - 取得
	for (i = 0; i < liECnt; i++) {
		int liVNo1, liVNo2, liLen;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d%d", &liVNo1, &liVNo2, &liLen);
		liVNo1--;
		liVNo2--;

		// 辺 - 追加
		fAddEdge(liVNo1, liVNo2);
		fAddEdge(liVNo2, liVNo1);
	}

	// 良い展望台数 - 取得
	int liCnt = 0;
	for (i = 0; i < siVCnt; i++) {

		// 辺でループ
		liRet = 0;
		Edge *lzpEdge = sz1Vtx[i].mzpEdge;
		while (lzpEdge != NULL) {

			// 比較
			if (sz1Vtx[i].miH <= sz1Vtx[lzpEdge->miVNo].miH) {
				liRet = -1;
				break;
			}

			// 次の辺へ
			lzpEdge = lzpEdge->mzpNext;
		}

		// 良い展望台数 - 加算
		if (liRet == 0) {
			liCnt++;
		}
	}

	return liCnt;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  vector<int> a(n);
  int i;
  rep(i,n)cin>>a[i];
  vector<int> dis(n-1);
  rep(i,n-1)dis[i]=a[i+1]-a[i];
  bool pos=false;
  bool neg=false;
  int ans=1;
  int lend=0;
  rep(i,n-1)
  {
    if(dis[i]>0&&!neg)pos=true;
    else if(dis[i]>0)
    {
      neg=false;
      pos=false;
      ans++;
    }
    if(dis[i]<0&&!pos)neg=true;
    else if(dis[i]<0)
    {
      neg=false;
      pos=false;
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>


using namespace std;


int main(){
    int a,b,c,N;
    cin >> N;
    a=N-N%100;
    a=a/100;
    N=N%100;
    b=N-N%10;
    b=b/10;
    c=N%10;
    if(a==7||b==7||c==7)cout << "Yes"<<endl;
    else cout << "No"<< endl;
    //float ;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

lli f[10000007];

int main()
{
    lli i,j,n,p,val;
    for(i=1;i<=10000000;i++)
    {
        for(j=i;j<=10000000;j+=i)
            f[j]++;
    }
    cin>>n;
    val=0;
    for(i=1;i<=n;i++)
    {
        val+=(i*f[i]);
    }
    cout<<val<<"\n";
    return 0;
}

Measured memory_bytes: 81724
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] A = new int[n+1];
		int[] H = new int[n];
		for(int i=1; i<n+1; i++){
			A[i] = sc.nextInt();
		}
		
		for(int i=1; i<n+1; i++){
			System.out.print("node " + i + ": key = " + A[i] + ", ");
			if(i>1) System.out.print("parent key = " + A[i/2] + ", ");
			if(i<=n/2) System.out.print("left key = " + A[2*i] + ", ");
			if(i<=(n-1)/2) System.out.print("right key = " + A[2*i+1] + ", ");
			System.out.println();
		}
	}
}



Measured memory_bytes: 26956
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define si set<int>
#define mp map<ll,ll>
#define mpi map<ii,ll>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#include <unordered_map> 
#define ump unordered_map<ll,ll>
int main()
{ 
	fast 
	ll n;
	string s;
	cin>>n;
	cin>>s;
	if(n>=3200)
	{
		cout<<s<<endl;
	}
	else
	{
		cout<<"red"<<endl;
	}
}

Measured memory_bytes: 256