akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main(){
    double n,m,s=0;
    cin >> n >> m;
    vector<double> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        s+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(), a.end());
    double hoge = 4 * m;
    double c = s/hoge;
    if(a[m-1] < c){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl; 
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll D;
    cin >> D;
    Vi c(26);
    matrix s(D,Vi(26));
    rp(i,26) cin >> c[i];
    rp(i,D){
        rp(j,26) cin >> s[i][j];
    }
    Vi t(D);
    vector<set<ll>> conte_days(26);
    rp(i,D) {
        cin >> t[i];
        t[i]--;
        conte_days[t[i]].insert(i);
    }
    ll score=0;
    Vi last(26,-1);
    rp(i,D){
        score+=s[i][t[i]];
        rp(j,26){
            if(j==t[i]) {
                last[t[i]]=i;
                continue;
            }
            score-=c[j]*(i-last[j]);
        }
    }
    
    ll m;
    cin >> m;
    rp(i,m){
        ll d,q;
        cin >> d >> q;
        d--; q--;
        ll l=-1,r=-1;
        for(ll c=d+1; c<D; c++){
            if(t[c]==t[d]) {
                r=c;
                break;
            }
        }
        if(r==-1) r=D;
        for(ll c=d-1; c>=0; c--){
            if(t[c]==t[d]){
                l=c;
                break;
            }
        } 
        score -= c[t[d]]*(d-l)*(r-d);
        l=-1; r=-1;
        for(ll c=d+1; c<D; c++){
            if(t[c]==q) {
                r=c;
                break;
            }
        }
        if(r==-1) r=D;
        for(ll c=d-1; c>=0; c--){
            if(t[c]==q){
                l=c;
                break;
            }
        }
        score += c[q]*(d-l)*(r-d);
        score += s[d][q]-s[d][t[d]];
        t[d]=q;
        print(score);
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3732
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in();
	map<ll, ll>mp; REP(i, n) { ll foo; scanf("%lld", &foo); ++mp[foo]; }
	ll m = in();
	REP(i, m) {
		ll foo; scanf("%lld", &foo);
		if (mp[foo]-- == 0) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 12800
n,m=gets.chomp.split.map(&:to_i)
x=gets.chomp.split.map(&:to_i).sort
if n>=m;puts "0";exit
elsif n==1;puts (x.max-x.min).abs;exit;end
dt = []
(x.size-1).times{|ii|dt<< x[ii+1]-x[ii]}
dt.sort!
(n-1).times{dt.pop};p dt.inject(:+)

Measured memory_bytes: 11376
n, m, x = list(map(int, input().split()))
a = list(map(int, input().split()))
cost1, cost2 = 0, 0
for i in range(m):
        if x < a[i]:
            cost1+=1
        if x > a[i]:
            cost2+=1
print(min(cost1,cost2))

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=610,mod=1e9+7;
inline void Add(int &x,int y) { x+=y; if(x>=mod) x-=mod; }
inline void Dec(int &x,int y) { x-=y; if(x<0) x+=mod; }
int f[N][N],g[N][N],h[N][N],fac[N];
int A[N],B[N];
int n,m;
bool In(int x,int l,int r) { return x>=l&&x<=r; }
int main() {
	rd(n),rd(m);
	for(int i=1;i<=m;++i) rd(A[i]),rd(B[i]);
	fac[0]=1;
	for(int i=2;i<=2*n;i+=2) fac[i]=fac[i-2]*(ll)(i-1)%mod;
	for(int i=1;i<=2*n;++i)
		for(int j=i+1;j<=2*n;j+=2) {
			int tot=0,flg=1;
			for(int k=1;k<=m;++k) {
				flg&=In(A[k],i,j)==In(B[k],i,j);
				tot+=In(A[k],i,j)+In(B[k],i,j);
			}
			if(!flg) continue;
			g[i][j]=fac[j-i+1-tot];
			h[i][j]=fac[2*n-m*2-(j-i+1-tot)];
//			cout<<2*n-m*2-(j-i+1-tot)<<' '<<g[i][j]<<' '<<g[j][i]<<endl;
		}
	int ans=0;
	for(int len=2;len<=2*n;len+=2)
		for(int i=1;i+len-1<=2*n;++i) {
			int j=i+len-1;
			f[i][j]=g[i][j];
			for(int k=i+1;k<j;k+=2)
				Dec(f[i][j],f[i][k]*(ll)g[k+1][j]%mod);
			Add(ans,f[i][j]*(ll)h[i][j]%mod);
		}
	printf("%d",ans);
	return 0;
}

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


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


	ll N;
	cin >> N;
	int M[20] = {};
	rep(i, 20) {
		M[i] = N % 10;
		N /= 10;
	}

	int dp[21][2] = {};
	rep(i, 21) rep(j, 2) dp[i][j] = -1;
	dp[0][0] = 0;

	rep(i, 20) {
		if (dp[i][0] != -1) {
			dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + M[19 - i]);
			dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + M[19 - i] - 1);
		}
		if (dp[i][1] != -1) dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + 9);
	}

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

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int d;
  cin>>d;

  vector<ll> p(26);
  rep(i,26) {
    cin>>p[i];
  }


  vector<vector<ll>> q(d,vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin>>q[i][j];
    }
  }

  ll pre=0;
  vector<int> r(26,0);
  rep(i,d-5){
    ll ans=-INF;
    ll memo;
    rep(j,26){
      ll sum=pre;
      auto last=r;
      sum+=q[i][j];
      last[j]=i+1;
      rep(k,26){
        sum-=2*p[k]*(i+1-last[k]);
      }
      if(sum>ans) {
        memo=j;
        chmax(ans,sum);
      }
    }
    cout << memo+1 << endl;
    pre=ans;
    r[memo]=i+1;
  }

  ll answer=-INF;
  ll A,B,C,D,E;
  vector<int> zen(5);
  rep(i,26){
    rep(j,26){
      rep(k,26){
        rep(l,26){
          rep(m,26){
            zen[0]=i;
            zen[1]=j;
            zen[2]=k;
            zen[3]=l;
            zen[4]=m;

            ll sum=0;
            auto last=r;
            rep(n,5){
              sum+=q[d-5+n][zen[n]];
              last[zen[n]]=d-5+n+1;
              rep(o,26){
                sum-=p[o]*(d-5+n+1-last[o]);
              }
            }

            if(sum>answer) {
              A=zen[0];
              B=zen[1];
              C=zen[2];
              D=zen[3];
              E=zen[4];
            }
            chmax(answer,sum);

          }
        }
      }
    }
  }

  cout << A+1 << endl;
  cout << B+1 << endl;
  cout << C+1 << endl;
  cout << D+1 << endl;
  cout << E+1 << endl;
  
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back

void solve(){
    ll n; cin >> n;
    deque<ll> a(n);
    REP(i, n) cin >> a[i];

    deque<ll> b;
    
    if(n%2==0){
        while(!a.empty()){
            if(!a.empty()){
                b.push_back(a.front());
                a.pop_front();
            }
            if(!a.empty()){
                b.push_front(a.front());
                a.pop_front();
            }  
        }
    }
    else{
        while(!a.empty()){
            if(!a.empty()){
                b.push_front(a.front());
                a.pop_front();
            }
            if(!a.empty()){
                b.push_back(a.front());
                a.pop_front();
            }  
        }

    }


    REP(i, n){
        cout << b[i];
        if(i!=n-1){
            cout << " ";
        }
        else{
            cout << "\n";
        }
    }

}

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

Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
long long n,d,a;
long long x,h;
vector<pair<long long,long long>> v;
queue<pair<long long,long long>> l;
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>d>>a;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>h;
        v.push_back({x,h});
    }
    sort(v.begin(),v.end());
    long long ans=0;
    long long dif=0;
    for(int i=0;i<n;i++)
    {
        while(!l.empty() && v[i].first>l.front().first)
        {
            dif-=l.front().second;
            l.pop();
        }
        if(v[i].second-dif<=0) continue;
		int aux=v[i].second-dif;
        ans+=(aux+a-1)/a;
        dif+=((aux+a-1)/a)*a;
        l.push({v[i].first+d+d,((aux+a-1)/a)*a});
    }
    cout<<ans;
    return 0;
}


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

const int inf = 1001001001;
int n, m, a, b, c, d, s, g, v, p;
int K[32][32] = {};

void show()
{
    for (int i = 1; i < n + 1; i++)
    {
        for (int j = 1; j < n + 1; j++)
        {
            cout << K[i][j];
            if (j != n)
            {
                cout << " ";
            }
        }
        cout << endl;
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < 32; i++)
    {
        for (int j = 0; j < 32; j++)
        {
            K[i][j] = inf;
        }
    }
    for (int i = 0; i < m; i++)
    {
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);
        //cerr << "read " << a << " " << b << " " << c << " " << d << endl;
        K[a][b] = c;
        K[b][a] = d;
    }
    scanf("%d,%d,%d,%d", &s, &g, &v, &p);
    // show();
    for (int k = 1; k < n + 1; k++)
    {
        for (int i = 1; i < n + 1; i++)
        {
            for (int j = 1; j < n + 1; j++)
            {
                if (K[i][j] > K[i][k] + K[k][j])
                {
                    K[i][j] = K[i][k] + K[k][j];
                }
            }
        }
    }
    //show();
    //cout << K[s][g] << K[g][s] << endl;
    cout << v - p - K[s][g] - K[g][s] << endl;
    return 0;
}



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

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var tbl = new int[n, n + 1];
            var csum = new int[n + 1];
            for (int i = 0; i < n; i++)
            {
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                var rsum = 0;
                for (int j = 0; j < n + 1; j++)
                {
                    if (j != n) csum[j] += int.Parse(line2[j]);
                    if (j == n) tbl[i, j] = rsum;
                    else
                    {
                        tbl[i, j] = int.Parse(line2[j]);
                        rsum += tbl[i, j];
                    }
                }
            }
            var allsum = csum.Sum();
            csum[n] = allsum;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n+1; j++)
                {
                    Console.Write("{0,5}", tbl[i, j]);
                    if (j == n) Console.WriteLine();
                }
            for (int i = 0; i < n+1; i++)
            {
                Console.Write("{0,5}", csum[i]);
                if (i == n) Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9668
#include<iostream>
using namespace std;
int main()
{
    int N, i;
    int t = 0, x = 0, y = 0;
    string ret = "Yes";
    cin >> N;
    for(i = 0; i < N; i++){
        int nt, nx, ny;
        int dt, dx, dy, d;
        cin >> nt >> nx >> ny;
        dt = nt - t;
        dx = nx - x;
        dy = ny - y;
        if(dx < 0) dx = -dx;
        if(dy < 0) dy = -dy;
        d = dx + dy;
        if(dt < d){
            ret = "No";
            break;
        }
        if((dt - d) % 2 == 1){
            ret = "No";
            break;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int>A(5);
  for(int i=0;i<5;i++)
    cin>>A.at(i);
  vector<int> B(5);
  for(int i=0;i<5;i++){
   if(A.at(i)%10!=0) B.at(i)=A.at(i)%10-1;
  else B.at(i)=9;
  
  }
  int min=10;
  for(int i=0;i<5;i++)
    if(B.at(i)<min)
      min=B.at(i);
  
  int ans=min-9;
  for(int i=0;i<5;i++)
    ans+=((A.at(i)-1)/10)*10+10;
  cout<<ans<<endl;
   return 0;
}

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

int main() {
  int N, M, Q; cin >> N >> M >> Q;
  int A[Q], B[Q], C[Q], D[Q];
  for (int i = 0; i < Q; i++) cin >> A[i] >> B[i] >> C[i] >> D[i];
  int R[N]; for (int i = 0; i < N; i++) R[i] = 1;
  int max_sum = 0;
  while (true) {
    int sum = 0;
    for (int q = 0; q < Q; q++)
      if (R[B[q]-1] - R[A[q]-1] == C[q])
        sum += D[q];
    max_sum = max(max_sum, sum);
    int i = N-1;
    while (i >= 0 && R[i] == M) i--;
    if (i < 0) break;
    R[i]++;
    for (int j = i+1; j < N; j++) R[j] = R[i];
  }
  cout << max_sum << endl;
}

Measured memory_bytes: 3600
#include <stdio.h>

long long K, A, B;

int main() {
    scanf("%lld %lld %lld", &K, &A, &B);
    if (A > B || K <= A - 1) {
        printf("%lld\n", K + 1);
    } else {
        long long ans1 = K + 1;
        K -= A - 1;
        long long ans2 = A;
        if (K % 2 == 1) {
            K--;
            ans2++;
        }
        ans2 += (B - A) * (K / 2);
        printf("%lld\n", ans1 > ans2 ? ans1 : ans2);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    int sum = 0;
    for (auto &a : A) {
        cin >> a;
        sum += a;
    }
    sort(A.begin(), A.end(), greater<int>());
    cout << ((A.at(M - 1) * 4 * M >= sum) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split( )))
q=int(input())
k=[]
for i in range(q):
    k1=int(input())
    k.append([k1,i])

a.sort()
k.sort()

ans = [n]*q
i = 0 #k
j = 0 #a

while i<q and j<n:
    try:#j=nの処理
        while k[i][0] > a[j]:
            j += 1
    except:
        pass

    ans[k[i][1]] = j
    i+=1

for i in range(q):
    print(ans[i])


Measured memory_bytes: 44676
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;


long long int gcd(long long int a, long long int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}




int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	string str;
	cin >> str;
	long long int ans = 0;
	for (long long int i = 0; i < str.size(); i++)
	{
		ans += str[i] - '0';
	}
	if (ans % 9 == 0)
		cout << "Yes" << endl;
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3696
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

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

  int N, Y;
  cin >> N >> Y;

  bool f = false;
  int z=0;
  FOR(i,0,N+1){
    FOR(j,0,N+1){
      if(i+j>N) continue;
      z = N - i - j;
      /*
      cout << "x:" << i << "y:" << j << "z:" << N-i-j << endl;
      cout << 10000*i + 5000*j + 1000*z << endl;
      */
      if(10000*i + 5000*j + 1000*z == Y) {
	cout << i << " " << j << " " << z << endl;
	f = true;
	break;
      }
    }
    if(f) break;
  }

  if(!f) cout << "-1 -1 -1" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n;
  V<ll> a;
  cin >> n;
  a.resize(n);


  bool include_zero = false;
  rep(i, n) {
    cin >> a[i];

    if(a[i] == 0) {
      include_zero = true;
    }
  }

  if(include_zero) {
    cout << 0 << endl;
    return 0;
  }

  ll product = 1;
  bool over = false;
  rep(i, n) {
    if(a[i] > 1'000'000'000'000'000'000 / product) {
      over = true;
      break;
    }

    product *= a[i];
  }

  if(over) {
    cout << -1 << endl;
  } else {
    cout << product << endl;
  }
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	int n,h,w;
	scanf("%i %i %i",&n,&h,&w);
	ll ans=(ll)(n-h+1)*(n-w+1);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n;
	ll p[110];
	cin>>n;
	ll ans=0;
	for(int i=0;i<n;i++)cin>>p[i];
	for(int i=1;i<n-1;i++){
		if((p[i-1]>p[i]&&p[i]>p[i+1])||(p[i-1]<p[i]&&p[i]<p[i+1]))ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#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 rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int modpow(int x, int n) {
    int ret = 1;
    while (n > 0) {
        if ((n & 1)) {
            ret = ret * x % mod;
        }
        x = x * x % mod;
        n >>= 1;
    }
    return ret;
}

void run(){
    int n,k;
    cin>>n>>k;
    vi a(k+1);
    int ans=0;
    for(int i=k;i>=1;i--){
        a[i]=modpow(k/i,n);
        for(int j=2*i;j<=k;j+=i)a[i]=(a[i]-a[j]+mod)%mod;
        ans+=i*a[i],ans%=mod;
    }
    cout<<ans<<endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
template <class Key, class T>
using gp_hash_table = __gnu_pbds::gp_hash_table<Key, T>;

using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#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

struct RollingHash {
  using u64 = unsigned long long;
  using u128 = __uint128_t;
  static const u64 mod = (1ULL << 61) - 1;
  const u64 base;
  vector<u64> hashed, power;

  RollingHash(const string& s, u64 base) : base(base) {
    int n = s.size();
    hashed.assign(n + 1, 0);
    power.assign(n + 1, 0);
    power[0] = 1;
    for (int i = 0; i < n; i++) {
      power[i + 1] = mul(power[i], base);
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
  }

  static u64 gen_base() {
    random_device seed_gen;
    mt19937_64 engine(seed_gen());
    uniform_int_distribution<u64> rand(1, mod - 1);
    return rand(engine);
  }

  // Returns the hash value for the [l,r) interval.
  u64 get(int l, int r) {
    return add(hashed[r], mod - mul(hashed[l], power[r - l]));
  }

 private:
  u64 add(u64 a, u64 b) {
    if ((a += b) >= mod) {
      a -= mod;
    }
    return a;
  }

  u64 mul(u64 a, u64 b) {
    u128 t = (u128)a * b;
    u64 na = t >> 61;
    u64 nb = t & mod;
    if ((na += nb) >= mod) {
      na -= mod;
    }
    return na;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  V<pair<size_t, string>> S(N);
  REP(i, N) {
    string s;
    cin >> s;
    S[i] = {s.size(), s};
  }
  sort(S.begin(), S.end());
  gp_hash_table<u64, V<int>> mp;
  const u64 B = RollingHash::gen_base();
  i64 ans = 0;
  REP(i, N) {
    int len = S[i].first;
    const string& ss = S[i].second;
    V<int> char_cnt(26);
    REP(j, len) {
      int ch = ss[j] - 'a';
      char_cnt[ch]++;
    }
    RollingHash rh(ss, B);
    for (int j = len - 1; j >= 1; --j) {
      REP(c, 26) {
        if (char_cnt[c] > 0) {
          auto it = mp.find(rh.get(j + 1, len));
          if (it == mp.end()) continue;
          ans += it->second[c];
        }
      }
      --char_cnt[ss[j] - 'a'];
    }
    int prefix = ss[0] - 'a';
    u64 shash = rh.get(1, len);
    auto ait = mp.find(shash);
    if (ait == mp.end()) {
      mp[shash].assign(26, 0);
    }
    mp[shash][prefix]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 70288
#include<bits/stdc++.h>
using namespace std;
void read(int &x)
{
    x=0;
    int y=1;
    char c=getchar();
    while (c>'9'||c<'0')
    {
        if (c=='-')
            y=-1;
        c=getchar();
    }
    while (c>='0'&&c<='9')
    {
        x=x*10+c-'0';
        c=getchar();
    }
    x*=y;
}
int n,m,ans,x;
int main()
{
	read(n);
	m=233333333;
	for (int i=1;i<=n;++i)
	{
		read(x);
		ans+=x;
		if (x%10!=0)
			m=min(m,x);
	}
	if (ans%10==0&&m<=1000)
		ans-=m;
	if (ans%10==0)
		ans=0;
	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn=1e5+10;
int a[maxn];
LL sum[maxn];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	LL res1=0,res2=0;
	LL ans1=0,ans2=0;
	for(int i=1;i<=n;i++)
	{
		if(i%2==0)
		{
			if(sum[i]+res1<=0)
			{
				ans1+=abs(1-(sum[i]+res1));
				res1+=(1-(sum[i]+res1));
			}
			if(sum[i]+res2>=0)
			{
				ans2+=abs(-1-(sum[i]+res2));
				res2+=(-1-(sum[i]+res2));
			}
		}
		else{
			if(sum[i]+res1>=0)
			{
				ans1+=abs(-1-(sum[i]+res1));
				res1+=(-1-(sum[i]+res1));
			}
			if(sum[i]+res2<=0)
			{
				ans2+=abs(1-(sum[i]+res2));
				res2+=(1-(sum[i]+res2));
			}
		}
	}
	printf("%lld",min(ans1,ans2));
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}
vector<int>divisor(int n) {
	vector<int>res;
	for (int i = 1; i*i <= n; ++i) {
		if (n%i == 0) {
			res.push_back(i);
			if (i != n / i) {
				res.push_back(n / i);
			}
		}
	}
	return res;
}
vector<int>key(1010, 0);
void prime(int n) {
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++key[i];
			n /= i;
		}
	}
	if (n != 1)key[n]++;
	return;
}
int main() {
	int n; cin >> n;
	ll ans = 1;
	for (int i = 2; i <= n; ++i) {
		prime(i);
	}
	for (int i = 2; i <= n; ++i) {
		ans *= (key[i] + 1);
		ans %= INF;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include  <iostream>
using namespace std;
 
int main() {
	int n,m;
	cin>>n;
m=n;
	if((m%10)==1)n+=8;

   else if((m%10)==9)n-=8;
m/=10;
if((m%10) == 1)n+=80;
   else if((m%10)==9)n-=80;
m/=10;
if((m%10)==1)n+=800;
   else if((m%10)==9)n-=800;
  
cout<<n<<endl;	
return 0;
}

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

int main(void){
    int a,b,c=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        if(i/10000 == i%10 and (i/1000)%10 == (i%100)/10) c++;
    }
    cout<<c<<endl;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  int c = 0, sum = 0;
  vector<int> A;
  for (int i=0; i<n; i++){
    int a;
    cin >> a;
    A.push_back(a);
    sum += a;
  }
  for (int i=0; i<n; i++){
    if (A[i]*4*m >= sum ) c++;
  }
  if (c >= m) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;


int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	vector<bool> visited(n,false);
	visited[0] = true;
	for(int i = 0; i < n; i++){
		int num;
		cin>>num;
		num--;
		a[i] = num;
	}
	bool ans = true;
	int next = a[0];
	int count = 1;
	while( next != 1){
		visited[next] = true;
		next = a[next];
		count++;
		if( next == 1){
			ans = true;
			break;
		}else if( visited[next] == false){
			// do nothing
		}else{
			ans = false;
			break;
		}
	}
	if( ans == true){
		cout<<count<<endl;
	}else{
		cout<<-1<<endl;
	}
	return 0;
}



Measured memory_bytes: 3396
#include <bits/stdc++.h>
#define MEM 1000005
#define sanic ios_base::sync_with_stdio(0)
using namespace std;
int n;
int dp[MEM] = {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};
main()
{
    sanic;
    cin >> n;
    cout << dp[n-1];
}


Measured memory_bytes: 256
import java.util.Scanner;
/**
 * @author saiyo
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		//int x = scan.nextInt();
		//int y = scan.nextInt();
		
		//Seisu s = new Seisu(x, y);
		//s.kouyaku();

		int con = scan.nextInt();
		
		int[] num = new int[con];
		for(int i = 0; i < con; i++){
			num[i] = scan.nextInt();
		}
		//Seisu s = new Seisu(num);
		//System.out.println(s.getProfit());
		
		//s.countSosu();
		///*
		Sort s = new Sort(num);
		int cnt = s.selectionSort();
		s.printSort();
		System.out.println(cnt);
		//*/
	}

}

class Seisu{
	private int x, y;
	private int snum[];
	
	Seisu(int x, int y){
		if(x >= y){
			this.x = x;
			this.y = y;
		}else{
			this.x = y;
			this.y = x;
		}
		
	}
	
	Seisu(int snum[]){
		this.snum = new int[snum.length];
		for(int i = 0; i < snum.length; i++){
			this.snum[i] = snum[i];
		}
	}
	
	public int getProfit(){
		int fstM = this.snum[0], sa, maxProfit = this.snum[1] - this.snum[0];
		for(int i = 1; i < this.snum.length; i++){
			sa = this.snum[i] - fstM;
			if(fstM > this.snum[i]){
				fstM = this.snum[i];
			}
			if(sa > maxProfit){
				maxProfit = sa;
			}
			
		}
		return maxProfit;
	}
	
	public void countSosu(){
		int con = 0;
		for(int nu: this.snum){
			con += isSosu(nu);
		}
		System.out.println(con);
	}
	
	public int isSosu(int num){
		for(int i = 2; i < Math.sqrt(num) + 1; i++){

			if(num % i == 0 && num != 2){
				return 0;
			}
			
		}
		return 1;
	}
	
	public void kouyaku(){
		System.out.println(modSeisu(this.x, this.y));
	}
	
	
	public int modSeisu(int x, int y){
		if(x % y == 0){
			return y;
		}else{
			return modSeisu(y , x % y);
		}
	}
}

class Sort{
	private int[] sorted;
	
	Sort(int[] sorted){
		this.sorted = new int[sorted.length];
		for(int i = 0; i < sorted.length; i++){
			this.sorted[i] = sorted[i];
		}
	}
	
	public int babbleSort(){
		boolean flag = true;
		int nullBox, cnt = 0;
		while (flag){
			flag = false;
			for(int i = this.sorted.length -1; i >= 1; i--){
				if(this.sorted[i] < this.sorted[i - 1]){
					nullBox = this.sorted[i];
					this.sorted[i] = this.sorted[i - 1];
					this.sorted[i - 1] = nullBox;
					flag = true;
					cnt++;
				}
			}
		}
		return cnt;
	}
	
	public int selectionSort(){
		int minj, cnt = 0, nullBox;
		for(int i = 0; i < this.sorted.length; i++){
			minj = i;
			for(int j = i; j < this.sorted.length; j++){
				if(this.sorted[j] < this.sorted[minj]){
					minj = j;
				}
			}
			if(i != minj){
				cnt++;
			}
			nullBox = this.sorted[i];
			this.sorted[i] = this.sorted[minj];
			this.sorted[minj] = nullBox;
		}
		return cnt;
	}
	
	public void insertionSort(){
		int v, j;
		for(int i = 1; i < this.sorted.length; i++){
			v = this.sorted[i];
			j = i - 1;
			while(j >= 0 && this.sorted[j] > v){
				this.sorted[j + 1] = this.sorted[j];
				j--;
			}
			this.sorted[j + 1] = v;
			printSort();
		}
	}
	
	public void printSort(){
		for(int i  = 0; i < this.sorted.length - 1; i++){
			System.out.print(this.sorted[i] + " ");
		}
		System.out.println(this.sorted[this.sorted.length - 1]);
	}
}



Measured memory_bytes: 26416
// AOJ ITP1_10_B Triangle
// 2018.4.28 bal4u
 
#include <stdio.h>
#include <math.h>
 
#define PI 3.141592653589793
 
int main()
{
    double a, b, c, s, C;
    double S, L, h; 
     
    scanf("%lf%lf%lf", &a, &b, &C);
    c = sqrt(a*a + b*b - 2*a*b*cos(C*PI/180));
    L = a+b+c;
    s = L/2;
    S = sqrt(s*(s-a)*(s-b)*(s-c));
    h = 2*S/a;
    printf("%.8lf\n%.8lf\n%.8lf\n", S, L, h);
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,px = 0,py = 0,pt = 0;
	bool flag = true;
	cin >> n;
	for(int i = 0;i < n;i++){
		int t,x,y,d;
		cin >> t >> x >> y;
		d = abs(x - px) + abs(y - py);
		if(!(d <= t - pt && d % 2 == (t - pt) % 2)) flag = false;
		px = x;
		py = y;
		pt = t;
	}
	if(flag) Yes();
	else No();
	return 0;
}

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


void solve(long long X, long long Y, long long Z){
    swap(X, Y);
    swap(X, Z);
    cout<<X<<" "<<Y<<" "<<Z<<endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    solve(X, Y, Z);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define elif else if
#define se second
#define fi first
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}

int main(){
    int n;cin>>n;
    double ans=0;
    vi v;
    rep(i,n)v.pb(i);
    vector<P> p(n);
    rep(i,n)cin>>p[i].fi>>p[i].se;
    do{
        double sum=0;
        rep(i,n-1){
            sum+=sqrt((p[v[i]].fi-p[v[i+1]].fi)*(p[v[i]].fi-p[v[i+1]].fi)+(p[v[i]].se-p[v[i+1]].se)*(p[v[i]].se-p[v[i+1]].se));
        }
        ans+=sum;
    }while(next_permutation(all(v)));
    int a=1;
    rep(i,n)a*=i+1;
  cout<<fixed<<setprecision(10);
    cout<<ans/a<<endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};



int main(){

    int n,k;
    cin >> n >> k;
    queue<int> q;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        if(i < k){
            q.push(a[i]);
        }
    }
    for(int i = k;i < n;++i){
        int t = q.front();
        q.pop();
        int tt = a[i];
        q.push(tt);
        if(t < tt){
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }



    return 0;
}


Measured memory_bytes: 4444
import sys

N, X = map(int, input().split())
A = list(map(int, sys.stdin.readline().rsplit()))
B = A[::]

for i in range(N - 1):
    a = A[i] + A[i + 1]
    if a > X:
        if A[i + 1] >= a - X:
            A[i + 1] -= a - X
        else:
            A[i] -= a - X - A[i + 1]
            A[i + 1] = 0

res = 0
for i in range(N):
    res += B[i] - A[i]

print(res)

Measured memory_bytes: 19864
import math
a,b,c,k=raw_input('').split()
a=int(a)
b=int(b)
c=int(c)
k=int(k)
mx=int(1e18)

if k%2==0:
    ans=a-b
else:
    ans=b-a

if abs(ans)>mx:
    print 'Unfair'
else:
    print ans

Measured memory_bytes: 2568
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<pair<int, int> > menu;
  int tmp;
  for (int i = 0; i < 5; i++) {
    cin >> tmp;
    int mod = (tmp % 10 == 0) ? 10 : tmp % 10;
    menu.push_back(make_pair(mod, tmp));
  }
  sort(menu.begin(), menu.end());
  int ans = 0;
  for (int i = 4; i >= 0; i--) {
    ans += menu[i].second;
    if (menu[i].first != 10 && i != 0) {
      ans += 10 - menu[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>

constexpr int MAX_N=100000;

int n,k;
int dp[MAX_N+1][2];//???????????????????????????????????°???????????????????´?????????????????????£???????????????
bool IsNum[MAX_N+1];
bool IsWhiteCard;

int main(){
	while(std::cin>>n>>k){
		if(n+k==0)
			break;
		std::memset(dp,0,sizeof(dp));
		std::memset(IsNum,0,sizeof(IsNum));
		int a;
		for(int i=0;i<k;++i){
			std::cin>>a;
			if(a==0)
				IsWhiteCard=true;
			else
				IsNum[a]=true;
		}

		for(int i=1;i<=n;++i) {
			if(IsNum[i]){
				dp[i][0]=dp[i-1][0]+1;
				dp[i][1]=dp[i-1][1]+1;
			}
		else if(IsWhiteCard)
			dp[i][1]=dp[i-1][0]+1;
		}
		int ans=0;
		for(int i=1;i<=n;++i){
			ans=std::max(ans,dp[i][1]);
		}
		std::cout<<ans<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int k;
  cin >> k;
  string s;
  cin >> s;
  k %= 26;
  fore(i, 0, SZ(s)) {
    int x = (int)s[i] - 'A';
    x += k;
    x %= 26;
    cout << (char)('A' + x);
  }
  cout << endl;

  return 0;
}

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

#define REP(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

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

  int h, w, n;
  cin >> h >> w >> n;
  int as[n];
  REP(i, n) {
    cin >> as[i];
  }

  int grid[h][w];
  // The number of colorized cells.
  int cnt = 0;
  REP(i, n) {
    int a = as[i];

    while (--a >= 0) {
      int x = cnt / h;
      int y = cnt % h;
      if (x % 2 == 1) {
        y = h - y - 1;
      }

      grid[y][x] = i + 1;

      ++cnt;
    }
  }

  REP(y, h) {
    REP(x, w) {
      cout << (x == 0 ? "" : " ") << grid[y][x];
    }

    cout << endl;
  }
}


Measured memory_bytes: 384
import math


A, B = map(int, input().split())

def solve(a, b):
  for n in range(1, 1250 + 1):
    if math.floor(n * 0.08) == A and math.floor(n * 0.1) == B:
      return n

  return -1  
  
print(solve(A, B))  

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

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

  if (C >= A && C <= B ) {
    cout << "Yes" << endl;
  }

  if (!( C >= A && C <= B )) {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <string.h>
using namespace std;

int main(void) {
	int N, Q, *S, x, num = 0;
	cin >> N;
	S = (int *)malloc(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> x;
		for (int j = 0; j < N; j++) {
			if (x == S[j]) {
				num++;
				break;
			}
		}
	}
	cout << num << endl;
	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, vs, n, m) vector<vector<T>> vs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]

using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    Sort(a);
    int x = a.back();
    a.pop_back();
    sort(Range(a), [x](auto a, auto b){ return abs(2*a-x) < abs(2*b-x); });
    printf("%d %d\n", x, a[0]);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 1000030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{
		ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
ll n,a,b;
cin>>n>>a>>b;
ll ans=0;
ans+=a*(n/(a+b));
ans+=min(a,n%(a+b));
cout<<ans;

}

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

int main(){
    int N, A, B;
    scanf("%d%d%d", &N, &A, &B);

    if((B-A)%2 == 1){
        printf("Borys");
    }else{
        printf("Alice");
    }
    return 0;
}


Measured memory_bytes: 892
import sys
H, W = map(int, input().split())
G = [sys.stdin.readline() for _ in range(H)]

counts = [[[-1] * 4 for _ in range(W + 1)] for _ in range(H + 1)]
for h in range(H):
    for w in range(W):
        if G[h][w] == ".":
            counts[h][w][0] = counts[h][w-1][0] + 1
            counts[h][w][1] = counts[h-1][w][1] + 1
        dih = H - h - 1
        diw = W - w - 1
        if G[dih][diw] == ".":
            counts[dih][diw][2] = counts[dih][diw+1][2] + 1
            counts[dih][diw][3] = counts[dih+1][diw][3] + 1
ans = 0
for h in range(H):
    for w in range(W):
        if G[h][w] == ".":
            ans = max(ans, sum(counts[h][w]) + 1)
print(ans)

Measured memory_bytes: 491764
n, a, b = map(int, input().split())

max_n = 2 * 10 ** 5


MOD = 10 ** 9 + 7
inv = [1] * (max_n + 1)
finv = [1] * (max_n + 1)
perm = [1] * (max_n + 1)
comb = [1] * (max_n + 1)

perm[1] = n
comb[1] = n

for i in range(2, max_n + 1):
	inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
	finv[i] = finv[i-1] * inv[i] % MOD
	perm[i] = perm[i-1] * (n - (i - 1)) % MOD
	comb[i] = perm[i] * finv[i] % MOD

def modpow(a, n, mod):
	res = 1
	while n > 0:
		if n & 1: res = res * a % MOD
		a = a * a % MOD
		n >>= 1

	return res


print((modpow(2, n, MOD) - 1 - comb[a] - comb[b]) % MOD)


Measured memory_bytes: 34676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N, M; cin >> N >> M;
    vel x(N), y(N), z(N); rep(i,N) cin >> x[i] >> y[i] >> z[i];
    vei v = {-1, 1};
    ll ans = 0;
    for(int i : v) for(int j : v) for(int k : v){
        vel A(N);
        rep(l,N) A[l] = i * x[l] + j * y[l] + k * z[l];   
        sort(rall(A));
        ll temp = 0;
        rep(l,M) temp += A[l];
        chmax(ans, temp);
    }
    cout << ans << endl;
}

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

int main()
{
	std::string mojiretu;
	std::cin >> mojiretu;
	if ((mojiretu[0] == mojiretu[1]) || (mojiretu[1] == mojiretu[2]) || (mojiretu[2] == mojiretu[3]))std::cout << "Bad" << std::endl;
	else
	{
		std::cout << "Good" << std::endl;
	}
}

Measured memory_bytes: 256