akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	long long D, G; cin >> D >> G;
	long long  ans = 114514;

	vector<long long> p(D), c(D);

	for (int i = 0; i < D; i++) {
		cin >> p[i] >> c[i];
	}

	for (int i = 0; i < (1 << D); i++) {
		long long sum = 0;
		long long t = 0;

		for (int j = 0; j < D; j++) {
			if (i & (1 << j)) {
				sum += (j + 1) * 100 * p[j] + c[j];
				t += p[j];
			}
		}

		if (sum < G) {
			for (int j = D - 1; j >= 0; j--) {
				if (!(i & (1 << j))) {
					for (int k = 1; k <= p[j]&&sum<G; k++) {
						sum += (j+1) * 100;
						t++;
					}
				}
			}
		}
		if (sum >= G) {
			ans = min(ans, t);
		}
	}
	cout << ans << endl;

	return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll k;
    cin >> k;
    ll a[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
              1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    k--;
    cout << a[k] << endl;
    return 0;
}



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

int main(){
    string S;
    cin >> S;
    if(S.at(0) == 'R' && S.at(1) == 'R' && S.at(2) == 'R') cout << 3 << endl;
    else if((S.at(0) == 'R' && S.at(1) == 'R') || (S.at(1) == 'R' && S.at(2) == 'R')) cout << 2 << endl;
    else if(S.at(0) == 'R' || S.at(1) == 'R' || S.at(2) == 'R') cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <climits>
using namespace std;
long long dp[100001];
long long a[100001];
int main()
{
  int n;
    
  scanf("%d", &n);
  fill(dp, dp+n, 10e8);
  for(int i=0; i<n; i++)
    scanf("%Ld", &a[i]);
    
  for(int i=0; i<n; i++)
    *lower_bound(dp, dp+n, a[i]) = a[i];
    
  printf("%Ld\n", lower_bound(dp, dp+n, 10e8) - dp);
    
  return 0;
}

Measured memory_bytes: 2588
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>


#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1e+9;;

using namespace std;

int main()
{
    //    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    ll N,T,res;
    cin >> N >> T;
    ll c,t;

    res = INF;
    REP(i,N)
    {
        cin >> c >> t;
        if(t <= T && c < res)
        {
            res = c;
        }
    }

    if(res == INF)
    {
        cout << "TLE" << endl;
    }
    else
    {
        cout << res << endl;
    }
    


    return 0;
}



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

int x[101][101]={};
int y[101]={};

int main(){
	int a,b;
	cin>>a>>b;
	for (int i=0;i<a;i++)for (int j=0;j<b;j++)cin>>x[i][j];
	for (int i=0;i<b;i++)cin>>y[i];
	for (int i=0;i<a;i++){
		int ans=0;
		for (int j=0;j<b;j++){
			ans+=x[i][j]*y[j];
		}
		cout<<ans<<endl;
	}	
}


Measured memory_bytes: 3144
N = int(input())
W = list(map(int,input().split()))

cumsum = [0]*N
for i in range(N):
    cumsum[i] = cumsum[i-1]+W[i]

ans = cumsum[-1]
for i in range(N-1):
    ans = min(ans,abs(cumsum[-1]-2*cumsum[i]))

print(ans)


Measured memory_bytes: 3060
N, K = map(int, input().split())

MOD = 10 ** 9 + 7
MAX = 4 * 10 ** 5 + 10
modinv = lambda a, mod=MOD: pow(a, mod - 2, mod)
fac, inv = [1] * MAX, [1] * MAX
for i in range(1, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = modinv(fac[i])
comb = lambda n, k: fac[n] * inv[k] * inv[n - k] % MOD

if K >= N - 1:
    print(comb(2 * N - 1, N - 1))
else:
    ans = 0
    for i in range(K + 1):
        ans = (ans + comb(N - 1, N - 1 - i) * comb(N, i)) % MOD
    print(ans)


Measured memory_bytes: 47340
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871; 
const int N = 405;
lli nums[N];
lli dp[N][N];
lli sums[N][N];
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> nums[i];
	for(int i = 1; i <= n; i++)
		for(int j = i; j <= n; j++)
			dp[i][j] = INF64;
	
	for(int i = 1; i <= n; i++)
		for(int j = i; j <= n; j++)
			sums[i][j] = sums[i][j-1] + nums[j];

	for(int l = n; l >= 1; l--) {
		dp[l][l] = 0;
		for(int r = l+1; r <= n; r++)
			for(int k = l; k < r; k++)
				dp[l][r] = min(dp[l][r], dp[l][k] + dp[k+1][r] + sums[l][k] + sums[k+1][r]);
	}
	
	cout << dp[1][n] << "\n";
	return 0;
}

Measured memory_bytes: 2816
//再帰を使ってみる
using System; 
public class Factorial 
{
	public static long Fac(long i) 
	{
		return ((i <= 1) ? 1 : (i * Fac(i-1))); 
	} 
}
class MainClass 
{
	public static void Main() 
	{
		string s = Console.ReadLine();
		try
		{
			long num = Int64.Parse(s);
			Console.WriteLine(Factorial.Fac(num)); 
		}
		catch (System.FormatException)
		{
			Console.WriteLine("Invalid input specified");
		}
	}
}

Measured memory_bytes: 5544
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		for(int i = a; i <= b; i++) {
			if(i % k == 0) {
				System.out.println("OK");
				return;
			}
		}
		
		System.out.println("NG");
	}
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define EPS 1e-8
using namespace std;

double X1, Y1, X2, Y2, X3, Y3, X4, Y4, X5, Y5;
double xp[1], yp[1];
double x[4], y[4];

int main() {
	while (cin >> X1 >> Y1 >> X2 >> Y2 >> X3 >> Y3 >> X4 >> Y4)
	{
		X5 = X3 - (Y4 - Y3);
		Y5 = Y3 + (X4 - X3);
		X4 = X5;
		Y4 = Y5;
		x[0] = X1; x[1] = X2; x[2] = X3; x[3] = X4;
		y[0] = Y1; y[1] = Y2; y[2] = Y3; y[3] = Y4;
		xp[0] = x[0] - x[1];
		yp[0] = y[0] - y[1];
		xp[1] = x[2] - x[3];
		yp[1] = y[2] - y[3];
		if (fabs(xp[0]) < EPS && fabs(xp[1]) < EPS) { goto E; }
		if (fabs(yp[0]) < EPS && fabs(yp[1]) < EPS) { goto E; }
		if (fabs(yp[0]) < EPS && fabs(yp[1]) > EPS) { goto F; }
		if (fabs(yp[0]) > EPS && fabs(yp[1]) < EPS) { goto F; }
		if (fabs((xp[0] / yp[0]) - (xp[1] / yp[1])) < EPS) { goto E; }
		goto F;
	E:; cout << "YES" << endl;
		goto G;
	F:; cout << "NO" << endl;
	G:;

	}
}

Measured memory_bytes: 1216
#include <stdio.h>
int main ()
{
    int n, a, b, c, d;
    scanf("%d", &n);
    a = n % 10;
    n /= 10;
    b = n % 10;
    n /= 10;
    c = n % 10;
    n /= 10;
    d = n;
    if (a == b && b == c)
        printf("Yes");
    else if (d == c && c == b)
        printf("Yes");
    else
        printf("No");

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 500 + 10;
typedef long long int ll;
int main()
{
    string x;
    cin >> x;
    int val = 0;
    for (int i = 0; i < x.size(); i++)
        val += x[i] - '0';
    if (val % 9)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}
/*
3 4
1 0 0 0
0 0 0 0
0 0 0 2
*/

Measured memory_bytes: 3412
#include <stdio.h>

int main() {
	int w, h, x, y, r;
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

	if (x - r < 0 || w < x + r) {
		printf("No\n");
	} else if (y - r < 0 || h < y + r) {
		printf("No\n");
	} else {
		printf("Yes\n");
	}
}




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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

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

int main(void)
{
	string s;
	cin >> s;
	int n = s.size();
	vector<int> vs(n+1, -1);
	unordered_set<int> l;
	unordered_set<int> h;
	if (s[0] == '<') {
		vs[0] = 0;
		l.insert(0);
	}
	else {
		h.insert(0);
	}
	for (int i = 1; i < n; i++) {
		if (s[i] == '<' && s[i - 1] == '>') {
			vs[i] = 0;
			l.insert(i);
		}
		else if (s[i] == '>' && s[i - 1] == '<') {
			h.insert(i);
		}
	}
	if (s[n-1] == '>') {
		vs[n] = 0;
		l.insert(n);
	}
	else {
		h.insert(n);
	}

	for (auto e : l) {
		auto c = 1;
		for (int i = e - 1; i >= 0; i--) {
			vs[i] = max(vs[i], c);
			c++;
			if (h.find(i) != h.end()) {
				break;
			}
		}
		c = 1;
		for (int i = e + 1; i < vs.size(); i++) {
			vs[i] = max(vs[i], c);
			c++;
			if (h.find(i) != h.end()) {
				break;
			}
		}
	}
	ll sum = 0;
	for (auto e : vs) {
		sum += e;
	}
	cout << sum << endl;
	return 0;
}

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

typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=1e6+5,D=1e9+7;
s64 mi(s64 x,int y=D-2)
{
	s64 ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1;
	}
	return ans;
}

s64 jie[N],niv_jie[N],s[N];

int main()
{
	int n;cin>>n;
	jie[0]=1;
	rep(i,1,n)jie[i]=jie[i-1]*i%D;
	niv_jie[n]=mi(jie[n]);
	per(i,n,1)niv_jie[i-1]=niv_jie[i]*i%D;
	s64 ans=0;
	--n;
	rep(k,1,n)
	if(k*2>=n-1)
	{
		s[k]=jie[k-1]*jie[k]%D*niv_jie[2*k-n-1]%D;
		(ans+=k*(s[k]-s[k-1]))%=D;
	}
	cout<<(ans+D)%D;
}


Measured memory_bytes: 21632
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int N, K;

int main() {

  cin >> N >> K;

  double ans = 0;
  for (ll i = 1; i <= N; ++i) {
     ll t = 1;
     while (t*i < K) t *= 2;
     ans += 1.0/(double(t));
  }
  ans *= 1.0/(double(N));

  printf("%.14lf\n", ans);

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision;
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int  // ranges from (0 - twice of long long int)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,n,a) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007


void dfs(vector<ll>adj[],int s,bool vis[], int &count)
{
  vis[s]=true;
  count++;
  for(auto x: adj[s])
  {
    if(vis[x]==false)
    {
      dfs(adj,x,vis,count);
    }
  }
}


int main()
{
    boost;
    ll t=1;
    //cin>>t;
    while(t--)
  {
    ll v,e; cin>>v>>e;
    vector<ll>adj[v+1];
    while(e--)
    {
      ll a,b; cin>>a>>b;
      adj[a].pb(b);
     adj[b].pb(a);
    }
    
    // finding the connected component or can say island problem using bfs or  dfs

    // i am solving using the dfs method
    int maxa=0;
    bool vis[v+1]={false};
    for(int i=1;i<=v;i++)
    {
      if(vis[i]==false)
        {
			int count=0;
          dfs(adj,i,vis,count);
          maxa=max(maxa,count);
        }
    }
    
    cout<<maxa<<"\n";


  }

  return 0;
 
}


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

namespace Third
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();

            int c = int.Parse(n);

            string[] o = new String[c];
            for (int i = 0; i < c; i++)
            {
                o[i] = Console.ReadLine();
            }


            var d = o
                .GroupBy(i => i)
                .Select(g => new {number = g.Key, duplicationCount = g.Count() - 1})
                .ToList();

            Console.WriteLine(d.Count);
        }
    }
}

Measured memory_bytes: 71716
INTEGER H,W,V
CHARACTER(100),ALLOCATABLE,DIMENSION(:)::X
READ*,H,W
ALLOCATE(X(H+2))
x(1)=""
X(H+2)=""
DO M=2,H+1 
  READ*,X(M)
  X(M)="."//TRIM(X(M))//"."
END DO
DO I=2,H+1
  DO J=2,W+1
    IF(X(I)(J:J)==".")THEN
      V=0
      IF(X(I-1)(J-1:J-1)=="#")V=V+1
      IF(X(I-1)( J : J )=="#")V=V+1
      IF(X(I-1)(J+1:J+1)=="#")V=V+1
      IF(X( I )(J-1:J-1)=="#")V=V+1
      IF(X( I )(J+1:J+1)=="#")V=V+1
      IF(X(I+1)(J-1:J-1)=="#")V=V+1
      IF(X(I+1)( J : J )=="#")V=V+1
      IF(X(I+1)(J+1:J+1)=="#")V=V+1
      WRITE(X(I)(J:J),"(I0)")V
      ENDIF
  END DO
END DO
DO K=2,H+1
PRINT"(A)",X(K)(2:W+1)
ENDDO
END

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
const int N=1e5+5;
typedef long long LL;
int n,E,T,p[N];
LL dp[N];
int q[N],h,t;
int main(){
	scanf("%d%d%d",&n,&E,&T);
	for(int i=1;i<=n;++i)scanf("%d",p+i),dp[i]=0x7fffffffffffffff;
	int pre=0,mpos=0;
	for(int i=1;i<=n;++i){
		const int TL=T-2*p[i];
		while(h<t&&TL<=-2*p[q[h]+1])++h;
		int j=q[h];
		dp[i]=dp[j]-p[j]+std::max(TL,-2*p[j+1])+3LL*p[i];
		while(pre<i&&TL<=-2*p[pre+1]){
			if(dp[mpos]-p[mpos]-2LL*p[mpos+1]>dp[pre]-p[pre]-2LL*p[pre+1])
			mpos=pre;
			++pre;
		}
		j=mpos;
		dp[i]=std::min(dp[i],dp[j]-p[j]+std::max(TL,-2*p[j+1])+3LL*p[i]);
		while(h<=t&&dp[q[t]]-p[q[t]]>=dp[i]-p[i])--t;
		q[++t]=i;
	}
	printf("%lld\n",dp[n]+E-p[n]);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
// string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n;
  ll a[n];
  std::vector<ll> vec;
  for (int i = 0; i < n; ++i)
  {cin>>a[i];
    /* code */
  }
  for (ll i = 1; i < n-1; ++i)
  {
    std::vector<ll> v;
    v.pb(a[i-1]);
     v.pb(a[i]);
      v.pb(a[i+1]);
      sort(v.begin(), v.end());
      if(v[1]==a[i])
         vec.pb(a[i]);
     
  }
  c(vec.size());

}

signed main(){
    
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
four = len([a for a in A if a%4==0])
even = len([a for a in A if a%4!=0 and a%2==0])
if N-(four*2)<=even or four>=N//2:
    print("Yes")
else:
    print("No")

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

int main() {
	int N, C;
	cin >> N >> C;

	int cake = 0;
	for( int i = 0; i < C; ++i ) {
		int x;
		cin >> x;

		cake += x;
	}

	int result = cake / (N+1);
	if( cake % (N+1) ) {
		result += 1;
	}

	cout << result << endl;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s; cin >> s;
  vector<int> cnt(3,0);
  for(auto c: s) cnt[c-'a']++;
  sort(ALL(cnt));
  cout << (cnt[2]-cnt[0]<=1 ? "YES\n" : "NO\n");
  return 0;
}


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

int main()
{
	string W;
	string T;
	int sum = 0;

	cin >> W;
	while (1) {
		cin >> T;
		if (T == "END_OF_TEXT") break;
		else {
			for (int i = 0; i < T.size(); i++){
				T[i] = tolower(T[i]);
			}
			if (T == W) {
			    sum++;
			}
		}
	}
	cout << sum << endl;

	return 0;
}



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

int main(){
	int n,i,j;
  cin>>n;
  double p[n];
  for(i=0;i<n;i++)
    cin>>p[i];
  
  double dp[n+1][n+1];
  dp[0][0]=1.0;
  
  for(i=1;i<=n;i++){
  	for(j=0;j<=i;j++){
    	if(j==0)dp[i][j]=(dp[i-1][j])*(1.0-p[i-1]);
      else 
        dp[i][j]=(dp[i-1][j]*(1.0-p[i-1]))+(dp[i-1][j-1]*(p[i-1]));
    }
  }
  
    double res=0.0;
    for(i=(n+1)/2;i<=n;i++)
      res+=dp[n][i];
    printf("%0.10f\n",res);
  return 0;
}

Measured memory_bytes: 70272
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long h,n,s=0;
  cin>>h>>n;
  vector<long long> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    s=s+a[i];
  }
  if(s>=h)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 1024
# -*- coding utf-8 -*-

w,a,b=map(int,input().split())

a1=a+w
b1=b+w

if a<= b <= a+w or a<= b1 <= a+w:
    print(0)
else:
    x1=abs(b-a)
    x2=abs(b-a1)
    x3=abs(b1-a)
    x4=abs(b1-a1)
    print(min(x1,x2,x3,x4))




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

int main() {
    string sentence;
    int alphabetCount[26] = {};
    do {
        getline(cin, sentence);
        
        for (unsigned int i = 0; i < sentence.length(); i++) {
            if (sentence[i] >= 0x41 && sentence[i] <= 0x5A) { // 英小文字
                alphabetCount[sentence[i] - 0x41]++;
            }
            else if (sentence[i] >= 0x61 && sentence[i] <= 0x7A) { // 英大文字
                alphabetCount[sentence[i] - 0x61]++;
            }
            else {
            }
        }
    } while (sentence.length() != 0);

    for (int i = 0; i < 26; i++) {
        cout << static_cast<char>('a' + i) << " : " << alphabetCount[i] << endl;
    }
}

Measured memory_bytes: 1176
#include<stdio.h>
#define N1 8
#define N2 15
#define FREE 1
#define NOTFREE -1

void putQueen(int);
void printBoard();

int row[N1],col[N1],dpos[N2],dneg[N2],board[N1][N1];

int main(){
  int i,j,k,r,c;
  for(i=0;i<N1;i++){
    row[i]=FREE;
    col[i]=FREE;
    for(j=0;j<N1;j++){
      board[i][j]=0;
    }
  }
  for(i=0;i<N2;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    board[r][c]=1;
  }

  putQueen(0);
  return 0;
}

void putQueen(int i){
  int j;
  if(i==N1){
    printBoard();
    return;
  }
  for(j=0;j<N1;j++){
    if(col[j]==NOTFREE || dpos[i+j]==NOTFREE || dneg[i-j+N1-1]==NOTFREE){
      continue;
    }
    row[i]=j;
    col[j]=NOTFREE;
    dpos[i+j]=NOTFREE;
    dneg[i-j+N1-1]=NOTFREE;
    putQueen(i+1);
    col[j]=FREE;
    dpos[i+j]=FREE;
    dneg[i-j+N1-1]=FREE;
  }
}

void printBoard(){
  int i,j;
  for(i=0;i<N1;i++){
    for(j=0;j<N1;j++){
      if(board[i][j]==1&&row[i]!=j){
	return;
      }
    }
  }
  
  for(i=0;i<N1;i++){
    for(j=0;j<N1;j++){
      if(row[i]==j){
	printf("Q");
      }else{
	printf(".");
      }
    }
    printf("\n");
  }
}



Measured memory_bytes: 2088
#coding:utf-8
   
n, k = map(int, input().split())
backList = []
for i in range(n):
    backList.append(int(input()))

def capa(p,k):
    cnt = 0
    pcopy = p
    num = 0
    for back in backList:
        if back > p:
            break
        if back <= pcopy:
            pcopy -= back
            cnt += 1
            continue
        elif back > pcopy:
            if num == k-1:
                return cnt
            pcopy = p - back
            cnt += 1
            num += 1          
    return cnt


p_min = 0
p_max = 100000 * 10000
def biSearch(p_min, p_max):
    p = p_max - p_min
    if p_max - p_min <= 1:
        return p_max
    if p % 2 == 0:
        c = p_min + int(p/2)
    else:
        c = p_min + int((p+1)/2)
    v = capa(c,k)
    if v < n:
        p_min = c
    else:
        p_max = c

    return biSearch(p_min, p_max)
            

p = biSearch(p_min, p_max)
n_init = n
while n_init <= n:
    p -= 1
    n = capa(p,k)

print(p+1)



Measured memory_bytes: 9516
#include<bits/stdc++.h>
using namespace std;
void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
long long A[1000], K, N, arr[1000000], len;
int main(){
  long long i, j, k, t;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  len = 0;
  for(i=0;i<N;i++){
    k = 0;
    for(j=i;j<N;j++){
      k += A[j];
      arr[len++] = k;
    }
  }
  for(k=50;k>=0;k--){
    j = 0;
    for(i=0;i<len;i++){
      if(arr[i]&(1LL<<k)){
        j++;
      }
    }
    if(j >= K){
      t = 0;
      for(i=0;i<len;i++){
        if(arr[i]&(1LL<<k)){
          arr[t++] = arr[i];
        }
      }
      len = t;
    }
    else{
      for(i=0;i<len;i++){
        if(arr[i]&(1LL<<k)){
          arr[i] ^= (1LL<<k);
        }
      }
    }
  }
  wt_L(arr[0]);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180730-1

// --- original code ---
// ll N, K, A[1000];
// ll arr[1d6], len;
// {
//   ll i, j, k, t;
//   rd(N,K,A(N));
// 
//   len = 0;
//   rep(i,N){
//     k = 0;
//     rep(j,i,N){
//       k += A[j];
//       arr[len++] = k;
//     }
//   }
// 
//   for(k=50;k>=0;k--){
//     j = 0;
//     rep(i,len) if(arr[i]&(1LL<<k)) j++;
//     if(j >= K){
//       t = 0;
//       rep(i,len) if(arr[i]&(1LL<<k)) arr[t++] = arr[i];
//       len = t;
//     } else {
//       rep(i,len) if(arr[i]&(1LL<<k)) arr[i] ^= (1LL<<k);
//     }
//   }
// 
//   wt(arr[0]);
// }


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー

int main(int argc,char* argv[]){
    int k, n;
    cin >> k >> n;

    vector<int> a(n);
    for(auto &x:a)
        cin >> x;
    
    sort(a.begin(), a.end());

    a.push_back(a.at(0)+k);

    vector<int> dist(n);
    int maxdist=-1;
    for(int i=0;i<n;i++){
        dist.at(i)=a.at(i+1)-a.at(i);
        maxdist=max(maxdist, dist.at(i));
    }

    cout << k-maxdist << endl;

    return 0;
}


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

int main(){
   int N,K;
   cin>>N>>K;
   vector<int> A(N+1,0);
   for(int i=0;i<K;i++){
       int kk;
       cin>>kk;
       for(int j=0;j<kk;j++){
           int ss;
           cin>>ss;
           A[ss]++;
       }
   }
   int ans=0;
   for(int i=1;i<N+1;i++){
       if(A[i]==0)ans++;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ

int main(){
    //input
    int N;cin >> N;
    const LL big = 1LL << 60; 
    vector<int> h(N);
    rep(i,N)cin >> h[i];

    //DP初期化
    LL DP[100010];
    rep(i,100010)DP[i] = big;

    //初期条件
    DP[0] = 0;

    //roop
    rep(i,N){
        if(i == 0)continue;
        if(i == 1)DP[1] = abs(h[1] - h[0]);
        chmin(DP[i],DP[i-1] + abs(h[i] - h[i-1]));
        chmin(DP[i],DP[i-2] + abs(h[i] - h[i-2]));
    }

    cout << DP[N-1] << endl;
}

Measured memory_bytes: 1408
from collections import deque
import sys

sys.setrecursionlimit(200000)

N, ko, oni = map(int, input().split())


class Node:
    def __init__(self):
        self.parent = -1
        self.child = []
        self.depth = -1

    def add_child(self, num):
        self.child.append(num)

    def set_parent(self, num):
        self.parent = num

    def set_depth(self, num):
        self.depth = num

    def children(self):
        for i in self.child:
            if i != self.parent:
                yield i


node_list = [Node() for _ in range(N + 1)]


def get_most_deep(parent_node):
    ret = -1

    if len(node_list[parent_node].child) == 1:
        return node_list[parent_node].depth

    for child_node in node_list[parent_node].children():
        ret = max(ret, get_most_deep(child_node))

    return ret


for _ in range(N - 1):
    A, B = map(int, input().split())
    node_list[A].add_child(B)
    node_list[B].add_child(A)

q = deque()
q.append([oni, 0])

while len(q) > 0:
    val = q.pop()
    parent = val[0]
    gen = val[1]
    node_list[parent].set_depth(gen)
    for child in node_list[parent].children():
        q.append([child, gen + 1])
        node_list[child].set_parent(parent)

ko_gen = node_list[ko].depth
up_count = (ko_gen - 1) // 2

point = ko

for _ in range(up_count):
    point = node_list[point].parent

ans = 0
ans += get_most_deep(point) - ko_gen
ans += ko_gen - 1

print(ans)

Measured memory_bytes: 145212
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=998244353;

const int MAX=2000010;

vll fac(MAX);
vll finv(MAX);
vll inv(MAX);

void combinit(ll m){
    fac[0]=1;fac[1]=1;
    finv[0]=1;finv[1]=1;
    inv[1]=1;
    rep2(i,2,MAX){
        fac[i]=fac[i-1]*i%m;
        inv[i]=m-inv[m%i]*(m/i)%m;
        finv[i]=finv[i-1]*inv[i]%m;
    }
}

ll combi(ll n,ll k,ll m=inf){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%m)%m;
}

int main(){
    ll r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
    combinit(inf);
    ll ans=(ll)0,tmp;
    for(ll j=c1;j<=c2;j++){
        tmp=combi(r2+j+(ll)1,r2)-combi(r1+j,r1-(ll)1);
        if(tmp<0)tmp+=inf;
        ans+=tmp;
    }
    cout<<ans%inf<<endl;
}

Measured memory_bytes: 50056
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.m(n);
  a = a.map(a=>a.map(a=>a-1));
  var ai = xArray(0,n);
  var q = Array(n).fill().map((a,i)=>i);
  var ans = -1;
  while(q.length){
    ans++;
    var q2 = [];
    var set = new Set();
    for(var i = 0; i < q.length; i++){
      var t = q[i];
      var pair = a[t][ai[t]];
      if(set.has(t) || set.has(pair) || ai[t] === n-1)continue;
      var pair = a[t][ai[t]];
      if(t === a[pair][ai[pair]]){
        ai[t]++;
        ai[pair]++;
        q2.push(t,pair);
        set.add(pair);
        set.add(t);
      }
    }
    q = q2;
  }
  for(var i = 0; i < n; i++){
    if(ai[i] !== n-1)return -1;
  }
  return ans;
}

Measured memory_bytes: 99124
N,M = map(int,input().split())
A = list(map(int,input().split()))
b = 0
d = {0:1}
ans = 0
for a in A:
    b = (b + a)%M
    ans += d.get(b,0)
    d[b] = d.get(b,0) + 1
print(ans)

Measured memory_bytes: 62576
/*
	最大公約数を求めるためにユークリッドの互除法を利用する。
	____概要____
	A=Bq+r
	という式が与えられた時
	「AとBの公約数はBとrの公約数であるからGCD(A,B)とGCD(B,r)は一致する」
	____________
	上の式を変形して
	A/B=q...r
	つまり
	r=A%B
	となることを考えれば良い
	*/


#include<stdio.h>

unsigned long gcd(unsigned long, unsigned long);	//最大公約数
unsigned long lcm(unsigned long, unsigned long);	//最小公倍数

int main(void){
	unsigned long a, b;
	int i;
	unsigned long g, l;	//最大公約数と最小公倍数


	while (scanf("%d %d",&a,&b)!=EOF){
		g = gcd(a, b);
		l = lcm(a, b);
		printf("%d %d\n", g, l);
	}
	return 0;
}

unsigned long gcd(unsigned long a, unsigned long b){	//最大公約数を求める関数
	unsigned long big, small;
	unsigned long r;	//big/smallの余りをrに代入

	if (a == b){
		return a;
	}else if (a > b){
		big = a; small = b;
	}
	else if (a < b){
		big = b; small = a;
	}

	while (big%small != 0){
		r = big%small;
		if (small > r){
			big = small;
			small = r;
		}
		else if (small < r){
			big = r;
		}
		else if (small == r){
			big = r;
		}
	}
	return small;
}

unsigned long lcm(unsigned long a, unsigned long b){
	unsigned long l, g;

	g = gcd(a, b);

	l = a*b / g;

	return l;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ls ch[x][0]
#define rs ch[x][1]
#define ll long long
using namespace std;

inline ll read(){
	ll num=0,neg=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')neg=-1;c=getchar();}
	while(isdigit(c)){num=(num<<3)+(num<<1)+c-'0';c=getchar();}
	return num*neg;
}

int prime[1000010],mi[1000010],a[1000010],cnt[1000010],g;
bool umprime[1000010];

inline void Eular(int n){
	for(int i=2;i<=n;i++)
	{
		if(!umprime[i]) prime[++prime[0]]=i,mi[i]=i;
		for(int j=1;j<=prime[0]&&i*prime[j]<=n;j++)
		{
			umprime[i*prime[j]]=1,mi[i*prime[j]]=min(mi[i],prime[j]);
			if(i%prime[j]==0)break;
		}
	}return;
}

inline void solve(int x){
	while(x>1){
		int tmp=mi[x];
		while(x%tmp==0)x/=tmp;
		cnt[tmp]++;
	}return;
}

inline int gcd(int x,int y){return y?gcd(y,x%y):x;}

int main(){
	Eular(1000000);
	int n=read();bool ispair=1;
	g=a[1]=read(),solve(a[1]);
	for(int i=2;i<=n;i++) a[i]=read(),solve(a[i]),g=gcd(g,a[i]);
	for(int i=1;i<=1000000;i++) ispair&=(cnt[i]<=1);
	if(ispair) printf("pairwise coprime\n");
	else if(g==1) printf("setwise coprime\n");
	else printf("not coprime\n");
	return 0;
}


Measured memory_bytes: 16456
package main

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

const (
	A = 0
	B = 1
	C = 2
)

func lib_MaxInt64(values ...int64) (max int64, err error) {
	if len(values) == 0 {
		return 0, errors.New("empty slice is given")
	}
	max = values[0]
	for _, value := range values {
		if max < value {
			max = value
		}
	}
	return
}
func lib_MustMaxInt64(values ...int64) (max int64) {
	max, err := lib_MaxInt64(values...)
	if err != nil {
		panic(err)
	}
	return max
}
func lib_New2DimInt64Slice(row, col int) [][]int64 {
	ret := make([][]int64, row)
	for r := 0; r < row; r++ {
		ret[r] = make([]int64, col, col)
	}
	return ret
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int64
	scanner.Scan()
	N, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	a := make([]int64, N)
	b := make([]int64, N)
	c := make([]int64, N)
	for i := int64(0); i < N; i++ {
		scanner.Scan()
		a[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		b[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		c[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}
	fmt.Println(solve(N, a, b, c))
}
func solve(N int64, a []int64, b []int64, c []int64) int64 {
	dp := lib_New2DimInt64Slice(int(N)+1, 3)
	dp[0][A], dp[0][B], dp[0][C] = 0, 0, 0
	for i := 1; i <= int(N); i++ {
		dp[i][A] = lib_MustMaxInt64(dp[i-1][B]+b[i-1], dp[i-1][C]+c[i-1])
		dp[i][B] = lib_MustMaxInt64(dp[i-1][A]+a[i-1], dp[i-1][C]+c[i-1])
		dp[i][C] = lib_MustMaxInt64(dp[i-1][A]+a[i-1], dp[i-1][B]+b[i-1])
	}
	return lib_MustMaxInt64(dp[N][A], dp[N][B], dp[N][C])
}


Measured memory_bytes: 8704
#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;
typedef vector<int> vi;

vector<int> to[200005];
vector<int> ans;

void dfs(int v,int p=-1){
  for(int u : to[v]){
    if(u==p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main(){
  int n,q;
  cin >> n >> q;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);//nullify
  rep(i,q){
    int p,x;
    cin >> p >> x;
    --p;
    ans[p]+=x;
  }
  dfs(0);
  rep(i,n){
    cout << ans[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 24212
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  int cnt = 0;
  int a[m],b[m];
  REP(i,m){
    cin >> a[i] >> b[i];
  }
  REP(i,m){
    vector<int> connected[n];
    REP(j,m){
      if(i!=j){
        connected[a[j]-1].push_back(b[j]-1);
        connected[b[j]-1].push_back(a[j]-1);
      }
    }
    queue<int> wait;
    wait.push(0);
    bool visited[n];
    REP(j,n){
      visited[j]=false;
    }
    visited[0]=true;
    int visitedcnt = 1;
    while(wait.size()>0){
      int node = wait.front();
      wait.pop();
      for(int k:connected[node]){
        if(visited[k]==false){
          wait.push(k);
          visited[k]=true;
          visitedcnt++;
        }
      }
    }
    if(visitedcnt!=n) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

int main (){
  int a, b;
  cin >> a >> b;
  if( 10 * b <= ceil(12.5 * a) && 10 * b + 10 > ceil(12.5 * a)){
    cout << ceil(12.5 * a);
  } else if ( 10 * b > ceil(12.5 * a) && 10 * b < ceil(12.5 * (a + 1))){
    cout << 10 * b;
  } else {
    cout << -1;
  }
  return 0;
}

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

using namespace std;

static void dfs (vector<vector<int>> &node, vector<bool> &visited, int cur, int past) {
    visited.at(cur) = true;
    for ( auto n : node.at(cur) ) {
        if ( n == past )
            continue;
        if ( visited.at(n) )
            continue;
        dfs(node, visited, n, cur);
    }
}

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

    vector<vector<int>> node(N);
    vector<pair<int, int>> edge(M);
    for ( int i = 0; i < M; i++ ) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        node.at(a).push_back(b);
        node.at(b).push_back(a);
        edge.at(i) = {a, b};
    }

    int ans = 0;
    for ( int i = 0; i < M; i++ ) {
        vector<bool> visited(N, false);
        int a = edge.at(i).first;
        int b = edge.at(i).second;
        dfs(node, visited, a, b);
        for ( int j = 0; j < N; j++ ) {
            if ( !visited.at(j) ) {
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<deque>

int main(void) {
	int n;
	std::cin >> n;
	std::deque<int> deq;
	bool isEven;
	int temp;
	if (n % 2 == 0) isEven = true;
	else isEven = false;

	if (isEven) {
		for (int i = 0; i < n; i++) {
			std::cin >> temp;
			if (i % 2 == 0) deq.push_back(temp);
			else deq.push_front(temp);
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			std::cin >> temp;
			if (i % 2 == 0) deq.push_front(temp);
			else deq.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		temp = deq.front();
		deq.pop_front();
		std::cout << temp;
		if (i != n - 1) std::cout << " ";
		else std::cout << std::endl;
	}
	return 0;
}


Measured memory_bytes: 2944
import java.io.PrintWriter
import java.util.NoSuchElementException

fun main(args: Array<String>) = IO().exec {
    val n = int()
    val a = LongArray(n){long()}
    val b = LongArray(n){long()}
    for (i in 0 until n) {
        a[i] -= b[i]
    }
    a.sort()
    val a2 = a.copyOf()

    var isOk = true
    var j = n-1
    var i = 0
    outer@while(a2[i] < 0) {
        while (a2[i] < 0) {
            if (a[j] <= 0) {
                isOk = false
                break@outer
            }
            val d = Math.min(Math.abs(a2[i]), a2[j])
            a2[i] += d
            a2[j] -= d
            if (a2[j] == 0L) j--
        }
        i++
    }

    if (isOk) println((0 until n).map { a[it] != a2[it] }.count { it })
    else println(-1)
}

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

Measured memory_bytes: 40376
import numpy as np
def main():
    N, M = map(int, input().split())
    maxl = -float('inf')
    minr = float('inf')
    for _ in range(M):
        l, r = map(int, input().split())
        if l >= maxl:
            maxl = l
        if r <= minr:
            minr = r
    val = minr - maxl + 1
    if val >= 0:
        print(val)
    else:
        print(0)
main()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 100000000000

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

	ll N;
	cin >> N;

	vector<ll> h(N);
	rep(i, N) {
		cin >> h[i];
	}

	bool do_continue = true;
	ll ans = 0;
	ll group = 1;
	ll toggle_cnt = 0;
	bool over0 = true;
	while (do_continue) {
		do_continue = false;
		toggle_cnt = 0;
		group = 0;
		over0 = h[0] > 0 ? true : false;
		if (over0) group++;
		rep(i, N) {
			if (over0 && h[i] <= 0) {
				over0 = false;
			}
			else if (!over0 && h[i] > 0) {
				over0 = true;
				group++;
			}
		}

		ans += group;
		rep(i, N) {
			h[i]--;
		}

		rep(i, N) {
			if (h[i] > 0) {
				do_continue = true;
				break;
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
import sys

n, k = map(int, sys.stdin.readline().split())

def main():
  m = n - 1
  cnt = (n - 1) * (n - 2) // 2
  if k > cnt: print(-1); return
  edges = [(1, v) for v in range(2, n + 1)]

  for u in range(2, n):
    for v in range(u + 1, n + 1):
      if cnt == k: break
      edges.append((u, v))
      m += 1
      cnt -= 1

  print(m)
  for u, v in edges:
    print(u, v)

if __name__ == '__main__':
  main()

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

int main(){
    int N;
    cin >> N;
    string s[N];
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }

    int count = 0;
    int b_count = 0;
    int a_count = 0;
    int ba_count = 0;
    for(int j = 0; j < N; j++){
        for(int i = 0; i < s[j].size() - 1; i++){
            if(s[j].substr(i, 2) == "AB"){
                count++;
            }
        }
        if(s[j].find_first_of('B') == 0){
                b_count++;
        }
        if(s[j].find_last_of('A') == s[j].size() - 1){
                a_count++;
        }
        if(s[j].find_first_of('B') == 0 && s[j].find_last_of('A') == s[j].size() - 1){
                ba_count++;
        }
    }

    if(b_count == ba_count && a_count == ba_count && ba_count != 0){
        count += min(b_count, a_count) - 1;
    }else{
        count += min(b_count, a_count);
    }

    cout << count << endl;

}

Measured memory_bytes: 768
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N = 100001;
int dp[N];
vector<vector<int>> v;
int n,m;
int solve(int ind)
{ vector<int> a=v[ind];
if(a.size()==0||ind==n+1) return dp[ind]=0;

int temp=0;
if(dp[ind]!=-1) return dp[ind];
	for(int i=0;i<a.size();i++)
	{
		if(dp[a[i]]!=-1) temp=max(temp,dp[a[i]]+1);
		else
		 temp= max(1+solve(a[i]),temp);
	}
	
	return dp[ind]=temp;
}
int main() {
	// your code goes here
	
	cin>>n>>m;
	
	vector<vector<int>> vec(n+1);
	int x,y;
	for(int i=0;i<=n+1;i++) dp[i]=-1;
	for(int i=0;i<m;i++)
	{
	cin>>x>>y;
	vec[x].push_back(y);
	}
	v=vec;
	int maxi=0;
	
	for(int i=1;i<=n;i++)
	maxi=max(maxi,solve(i));
	
	cout<<maxi;
	return 0;
}

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

using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 K;
  cin >> K;
  int i = 1;
  int m = 7;
  vector<bool> seen(K);
  for (;; ++i) {
    m %= K;
    if (m == 0) {
      cout << i << endl;
      return 0;
    }
    if (seen[m]) {
      cout << -1 << endl;
      return 0;
    }
    seen[m] = true;
    m = m * 10 + 7;
  }
}


Measured memory_bytes: 3740
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int n,d,itung=0;
	cin >> n >> d;

	int arr[n+10][d+10];

	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin >> arr[i][j];
		}
	}
// 3 2			
// 1 2
// 5 5
// -2 8

// 3 4
// -3 7 8 2
// -12 1 10 2
// -2 8 9 3
	for(int i=0;i<n;i++){
		int total=0;
		for(int k=i+1;k<n;k++){
			total=0;
			for(int j=0;j<d;j++){
				total += pow(abs(arr[k][j]-arr[i][j]),2);
			}
			if(sqrt(total)==trunc(sqrt(total))){
				itung++;
			}
		}
	}
	cout << itung << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int[] fuda = new int[n];
			for(int i = 0; i < n; i++){
				fuda[i] = n - i;
			}
			int r = sc.nextInt();

			if (n == 0 && r == 0) break;

			for(int i = 0; i < r; i++){
				int p = sc.nextInt();
				int c = sc.nextInt();
				int[] temp = new int[p-1];
				for(int j = 0; j < p-1; j++){
					temp[j] = fuda[j];
				}
				for(int j = 0; j < c; j++){
					fuda[j] = fuda[p+j-1];
				}
				for(int j = 0; j < p-1; j++){
					fuda[c+j] = temp[j];
				}				
			}
			System.out.println(fuda[0]);
		}
	}
}

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

int main() {
    int H,W;
    cin >> H >> W;
    vector<int> A(26,0);
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            char temp;
            cin >> temp;
            int num = (int)(temp-'a');
            A[num]++;
        }
    }

    if(H % 2 == 0 && W % 2 == 0) {
        for(int i=0; i<26; i++) {
            if(A[i] %  4 != 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    } else if(H % 2 == 0) {
        int cnt = 0;
        int limit = H / 2;
        for(int i=0; i<26; i++) {
            if(A[i] % 4 != 0 && A[i] % 2 == 0) {
                cnt++;
                if(cnt > limit) {
                    cout << "No" << endl;
                    return 0;
                }
            } else if(A[i] % 2) {
                cout << "No" << endl;
                return 0;
            }
        }
    } else  if(W % 2 == 0) {
        int cnt = 0;
        int limit = W / 2;
        for(int i=0; i<26; i++) {
            if(A[i] % 4 != 0 && A[i] % 2 == 0) {
                cnt++;
                if(cnt > limit) {
                    cout << "No" << endl;
                    return 0;
                }
            } else if(A[i] % 2) {
                cout << "No" << endl;
                return 0;
            }
        }
    } else {
        bool odd = false;
        int cnt = 0;
        int limit = (H - 1) / 2 + (W - 1) / 2;
        for(int i=0; i<26; i++) {
            if(A[i] % 2) {
                if(odd) {
                    cout << "No" << endl;
                    return 0;
                } else {
                    odd = true;
                }
            } else if(A[i] % 4 != 0 && A[i] % 2 == 0) {
                cnt++;
                if(cnt > limit) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

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

Measured memory_bytes: 256