akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=105;
int n,a[maxn],m,b[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline bool cmp(int a,int b){
	return a%2 > b%2;
}

int main(){
	n=rd(); m=rd();
	go(i,m+1,1) a[i]=rd();
	sort(a+1,a+m+1,cmp);
	int t=0;
	while(a[t+1]%2 == 1) t++;
	if(t > 2){ printf("Impossible"); return 0; }
	if(t == 2) swap(a[m],a[2]);
	go(i,m+1,1) printf("%d ",a[i]); puts("");
	go(i,m+1,1) b[i]=a[i]; 
	if(m == 1) m++;
	b[1]--; b[m]++;
	if(b[1] == 0){
		printf("%d\n",m-1);
		go(i,m+1,2) printf("%d ",b[i]);
	}else{
		printf("%d\n",m);
		go(i,m+1,1) printf("%d ",b[i]);
	}
	return 0;
}//Faze


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int main(){
    
    int N,t[50]={};

    string X,s[50]={};

    int ans=0;
    bool f=false;

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

    for(int i=0;i<N;i++){
        if(f==true){
            ans+=t[i];
        }
        
        if(X==s[i]){
            f=true;
        }
    }


    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  LL A, B, K; std::cin >> A >> B >> K;

  if (A + B < K) std::cout << "0 0" << std::endl;
  else if (A < K) std::cout << "0 " << B+A-K << std::endl;
  else            std::cout << A-K << " " << B << std::endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll n;
    cin>>n;
    vector<tuple<string,ll,ll>> tp(n);
    rep(i,n){
        string s;
        ll p;
        cin>>s>>p;
        tp[i]=mt(s,p,i+1);
    }
    sort(all(tp));
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(get<0>(tp[i])==get<0>(tp[j])&&get<1>(tp[i])<get<1>(tp[j])){
                ll tmp=get<2>(tp[i]);
                get<2>(tp[i])=get<2>(tp[j]);
                get<2>(tp[j])=tmp;
            }
        }
    }
    rep(i,n){
        cout<<get<2>(tp[i])<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    int N,M,tmp,i,j,a,b;
    ll ans=0;

	cin >> N >> M;

    vector<pair<ll,ll>> ar(N);

    rep(i,0,N){
        cin >> ar[i].first >> ar[i].second;
        /*cin >> a >> b;
        ar[i] = {a,b};
        j=i;
        while(A[j-1] > A[j]){
                tmp = A[j-1];
                A[j-1] = A[j];
                A[j] = tmp;
                tmp = B[j-1];
                B[j-1] = B[j];
                B[j] = tmp;
                j--;
            }*/
    }

    sort(ar.begin(),ar.end());

    rep(i,0,N){
        if(M>=ar[i].second){
            ans += ar[i].first * ar[i].second;
            M -= ar[i].second;
        }
        else{
            ans += ar[i].first*M;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define toInt(x) (x - '0')
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

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

  int c, t;
  int min = INF;
  rep(i, N) {
    cin >> c >> t;
    if (t <= T) {
      if (c < min) min = c;
    }
  }

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

  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc063/tasks/arc075_a

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 100;
const int S_I_MAX = 100;
const int INF = 1e6;

int N;
int s[N_MAX];

int dp[N_MAX + 1][10];

void solve() {
  fill(dp[0], dp[N], -INF);
  dp[0][0] = 0;
  REP(i, N) REP(j, 10) {
    int j2 = (j + s[i]) % 10;
    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    dp[i + 1][j2] = max(dp[i + 1][j2], dp[i][j] + s[i]);
  }
  // DUMP2D(dp, N + 1, 10);
  int ans = 0;
  FOR(j, 1, 9) ans = max(ans, dp[N][j]);
  printf("%d\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", s + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░█▀▀▄░░░░░░░░░░░▄▀▀█░░░░
░░█░░░▀▄░▄▄▄▄▄░▄▀░░░█░░░░
░░░▀▄░░░▀░░░░░▀░░░▄▀░░░░░
░░░░░▌░▄▄░░░▄▄░▐▀▀░░░░░░░
░░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█░
░░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█░
░▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█░
░█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀░
░░▀▄░░▀░░▀▀▀░░▀░░░▄█▀░░░░
░░░░█░░░░░░░░░░░▄▀▄░▀▄░░░
░░░░█░░░░░░░░░▄▀█░░█░░█░░
░░░░█░░░░░░░░░░░█▄█░░▄▀░░
░░░░█░░░░░░░░░░░████▀░░░░
░░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

void solve(){
    ll a,b; cin>>a>>b;

    ll num = 1;
    ll req = 0;
    while(num < b){
        num -= 1;
        num += a;
        req++;
    }

    cout<<req<<endl;
} 
 
signed main(){
 
   FastRead;    
 
    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 256
/*input
1000000000000000000 1
*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<long,long>
#define vi          vector<long long>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repi(i,a,b) for(ll i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define clr(x) memset(x, 0, sizeof(x))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
//#define ordered_set tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update>;

ll sub(ll a, ll b){return (a-b+hell)%hell;}
ll add(ll a, ll b){return (a+b)%hell;}
ll mul(ll a, ll b){return (a*b)%hell;}
vector<ll>adj[100005];
bool vis[100005];
ll siz,edges;
void dfs(ll i)
{
	vis[i]=1;
	//siz++;
	for(ll j=0;j<adj[i].size();j++)
	{		
		edges++;
		if(!vis[adj[i][j]])
			dfs(adj[i][j]);
	}
}
const ll mod = 1000000007;
ll mpow(ll base, ll exp) {
  base %= mod;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

int main()
{
fIO;
ll n,sum=0,t=1,m,ans,a,b,c;

//cin >> t;
while(t--){
	cin>>n>>m;
	ll x=n/m;
	x++;
	x*=m;
	cout<<min(n%m,(x-n)%m);












}
	
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,h[200005],k,s;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>h[i];
	sort(h+1,h+n+1);
	for(int i=1;i<=n-k;i++)s+=h[i];
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1792
import sys
from heapq import heapify,heappop,heappush
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


ans = 0
left,right = [],[]
heapify(left)
heapify(right)
r = 0

Q = I()
for _ in range(Q):
    q = LI()
    if q[0] == 1:
        a,b = q[1:]
        ans += b
        if r == 0:
            heappush(left,-a)
        elif r == 1:
            x1 = -heappop(left)
            ans += abs(a-x1)
            if x1 < a:
                x1,a = a,x1
            heappush(left,-a)
            heappush(right,x1)
        else:
            x1 = -heappop(left)
            x2 = heappop(right)
            if r % 2 == 0:
                ans += max(0,x1-a,a-x2,0)
                heappush(left,-x1)
                if a <= x2:
                    heappush(left,-a)
                    heappush(right,x2)
                else:
                    heappush(left,-x2)
                    heappush(right,a)
            else:
                ans += abs(x1-a)
                heappush(right,x2)
                if a <= x1:
                    heappush(left,-a)
                    heappush(right,x1)
                else:
                    heappush(left,-x1)
                    heappush(right,a)
        r += 1
    else:
        x = -heappop(left)
        print(x,ans)
        heappush(left,-x)


Measured memory_bytes: 90144
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my ($a, $b, $c) = split / /, <STDIN>);
if ($a&1==1 || $b&1==1 || $c&1==1) {
  say 0;
  exit;
} elsif ($a==$b && $b==$c) {
  say -1;
  exit;
}
my ($ans, $ef) = (0, 1);
while ($ef) {
  my $x = ($b + $c) / 2;
  my $y = ($a + $c) / 2;
  my $z = ($a + $b) / 2;
  ($a, $b, $c) = ($x, $y, $z);
  $ef = 0 if $a&1==1 || $b&1==1 || $c&1==1;
  $ans++;
}
say $ans;

Measured memory_bytes: 896
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n; cin >> n;
  vector<int> a(n),b(n);
  rep(i,n){
    cin >> a[i];
    b[i] = a[i];
  }
  
  sort(b.begin(),b.end());
  
  int cnt = 0;
  for(int i = 0; i<n;i++){
    if(a[i] != b[i]) cnt++;
  }
  
  if(cnt < 3) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools

n, m = map(int, input().split())
lsts = []
for _ in range(m):
  lsts.append(list(map(int, input().split())))
m = list(range(2, n + 1))
all = []
for v in itertools.permutations(m):
  l = [1] + list(v)
  all.append(l)
#print(all)

count = 0
for each in all:
  for i in range(n - 1):
    flag = False
    pos_1 = each[i]
    pos_2 = each[i + 1]
    for lst in lsts:
      if (pos_1 == lst[0] and pos_2 == lst[1]) or (pos_1 == lst[1] and pos_2 == lst[0]):
        flag = True
        break
    if not flag:
      break
  if flag:
    count += 1
print(count)

Measured memory_bytes: 9492
#include <stdio.h>


typedef struct {
    char *grade;
    int m500;
    int m1000;
} DATA;

int main(void)
{
    DATA data[] = {
        {"AAA", 3550,  7100},
        {"AA",  3750,  7700},
        {"A",   4000,  8300},
        {"B",   4300,  8900},
        {"C",   5000, 10500},
        {"D",   5500, 11600},
        {"E",   7000, 14800},
        {"NA",     0,     0},
    };
    
    float m500, m1000;
    int i;
    
    while (scanf("%f%f", &m500, &m1000) != EOF){
        m500 *= 100;
        m1000 *= 100;
        for (i = 0; i < 7; i++){
            if (m500 < data[i].m500 && m1000 < data[i].m1000){
                break;
            }
        }
        printf("%s\n", data[i].grade);
    }
    
    return (0);
}

Measured memory_bytes: 0
package main

import (
	"fmt"
	"strconv"
)

func pop(s []int) (int, []int) {
	var x int
	x, s = s[len(s)-1], s[:len(s)-1]
	return x, s
}

func main() {
	var x string
	var a, b int
	stack := make([]int, 0)
	for {
		_, err := fmt.Scan(&x)
		if err != nil {
			break
		}

		i, err := strconv.Atoi(x)
		if err == nil {
			stack = append(stack, i)
			continue
		}

		b, stack = pop(stack)
		a, stack = pop(stack)

		switch x {
		case "+":
			stack = append(stack, a+b)
		case "-":
			stack = append(stack, a-b)
		case "*":
			stack = append(stack, a*b)
		case "/":
			stack = append(stack, a/b)
		}

		// fmt.Println(stack)
	}

	fmt.Println(stack[0])
}



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

int main(){
    int N; cin >> N;
    vector<int> H(100010,0);
    rep(i,N) cin >> H[i];
    
    // dp[i]:足場iまでのコストの最小値
    vector<int> dp(100010);
    dp[0] = 0; dp[1] = abs(H[1]-H[0]);

    for(int i = 2; i<N; i++){
        int cand1 = dp[i-1] + abs(H[i]-H[i-1]);
        int cand2 = dp[i-2] + abs(H[i]-H[i-2]);
        //cout << cand1 << " " << cand2 << endl;
        dp[i] = min(cand1, cand2);
    }

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

Measured memory_bytes: 1024
raw1 = gets.split(" ").map{|n|n.to_i}
largeh = raw1[0]
largew = raw1[1]
raw2 = gets.split(" ").map{|n|n.to_i}
smallh = raw2[0]
smallw = raw2[1]

ans = (largeh - smallh)*(largew-smallw)
puts ans.to_s()

Measured memory_bytes: 3836
N = int(input())
A_list = list(map(int, input().split()))

sum_list = [0]
for a in A_list:
    sum_list.append(sum_list[-1] + a)

sum_list.sort()
cnt = 0
same_cnt = 0
prev = 10**9
for v in sum_list:
    same_cnt = 0 if prev != v else (same_cnt + 1)
    cnt += same_cnt
    prev = v

print(cnt)

Measured memory_bytes: 25976
#include <iostream>
#include <algorithm>
#include<functional>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c;
	d = c - (a - b);
	if (d <= 0) {
		cout << 0;
	}
	else {
		cout << d;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define vi vector<int>
#define pi pair<int,int>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define ll long long 

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x){
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x){
	for(auto& i:x)
		input>>i;
	return input;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod=1e9+7;

int mul(int a,int b)
{
	return (a*1ll*b)%mod;
	}
	
	int add(int a,int b)
	{
		a+=b;
		if(a>=mod)return a-mod;
		return a;
		}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
		}
		return res;
	}



void solve()
{
int n,k;
cin>>n>>k;
int dp[n+1],h[n]={0};
for(int i=0;i<=n;i++)dp[i]=1e9;
dp[0]=0;
cin>>h[0];
for(int i=1;i<n;i++)
{
	cin>>h[i];
	for(int j=1;j<=k;j++)
	{
		if(i<j)break;
	dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
	//	if(i>1)dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
}
	}	
	cout<<dp[n-1];
}
	
	
int main()
{   ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
		}
	
	
	}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;

int n;
int a[100010];
LL sum=0;

int gcd(int x,int y){
        if(x==0)return y;
	if(x>y)return gcd(y,x);
	else return gcd(y%x,x);

}
bool ans(){
     if((sum-n)%2==1)return true;
     int odd=0;
     int fir;
     for(int i=0;i<n;i++){
         if(a[i]%2==1){
	    odd++;
	    if(odd==1)fir=i;
	 }   
	 if(a[i]==1)return (sum-n)%2==1; 
     }
     if(odd>=2)return false;
     //cout<<a[0]<<endl;
     a[fir]--,sum--;
     int G=a[0];
     for(int i=0;i<n;i++){
         G=gcd(G,a[i]);
     }
     for(int i=0;i<n;i++){
         a[i]=a[i]/G;
     }
     sum=sum/G;
     return !ans();
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
	sum+=a[i];
    }
    	
    	
	
    
    puts(ans()?"First":"Second");
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
const int maxn = 1e5+500;  //数据范围

const ll mod = 1e9+7;
string str;
int p[maxn];
ll dp[maxn][20];

int main(){
    int x,y;cin>>x>>y;
    if((x+y)%2!=0)puts("IMPOSSIBLE");
    else cout<<(x+y)/2<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
 


int main(){
 string s;
  string target="keyence";
  cin >>s;
  int n=s.size();
  bool a=false;
  int cnnt=0;
  if(s==target)a=true;
  rep(i,n){
    for(int j=i; j<n; j++){
      string S="";
      for(int k=0;k<n;k++){
        if(i<=k && k<=j)continue;
        else{
          S.push_back(s.at(k));
        }
      }
      if(S==target){
        a=true;
        break;
      }
    }
    if(a)break;
  }
  
        
  if(a) cout <<"YES" << endl;
  else cout << "NO" <<endl;
}

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

using namespace std;

int main()	{
  string s;
  string t;
  cin >> s >> t;
  if (s.length() < t.length())	{
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  bool doable = false;
  for (int i = s.length() - t.length(); i >= 0; i--)	{
    //try string matching
    bool failed = false;
    for (int j = i; j < i + t.length() && j < s.length(); j++)	{
      if (s[j] != '?' && s[j] != t[j - i])	{
        failed = true;
        break;
      }
    }
    if (!failed)	{
      doable = true;
      for (int j = i; j < i + t.length(); j++)	{
        s[j] = t[j - i];
      }
      for (int j = 0; j < s.length(); j++)	{
        if (s[j] == '?')	{
          s[j] = 'a';
        }
      }
    }
  }
  if (!doable)	{
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  cout << s << endl;
  return 0;
}

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

int main(){
   vector<int> a(4);
   for(int i=0;i<4;i++){cin>>a.at(i);}
   int q,w,e,r,s=0;
   for(q=0;q<4;q++){if(a.at(q)==1){
for(w=0;w<4;w++){if(a.at(w)==9){
for(e=0;e<4;e++){if(a.at(e)==7){
for(r=0;r<4;r++){if(a.at(r)==4){cout<<"YES"<<endl;s=1;}}}}}}}}
if(s==0){cout<<"NO"<<endl;}}

Measured memory_bytes: 256
import java.util.Scanner;

//time:: 17:02~17:29 18:10~18:20

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0) break;
			String gomi=sc.nextLine();
			String[] line = new String[n];
			for(int i=0;i<n;++i){
				line[i]=sc.nextLine();
			}
			for(int i=0;i<n-3;++i){
				boolean flag=true;
				int count=line[i].length(),num=0,j=i;
				while(flag){
					if(num==5){
						System.out.println(i+1);
						i=n;
						break;
					}else if(((num==0||num==2)&&5<count)||((num!=0&&num!=2)&&7<count)){
						flag=false;
					}else if(((num==0||num==2)&&5==count)||((num!=0&&num!=2)&&7==count)){
						count=0;
						num++;
					}else{
						j++;
						count+=line[j].length();
					}
				}
			}
		}
	}
}


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

//73で萎えた && 75の類題前あきらめた からこれは写経する。

const int limit=50;

int n,m;
int a[limit],b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v0){
    visited[v0]=true;
    for(int v1=0;v1<n;v1++){
        if(graph[v0][v1] == false) continue;
        if(visited[v1] == true) continue;
        dfs(v1);
    }
}

int main(){
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    int ans = 0;

    for(int i=0;i<m;i++){
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;

        for(int j=0;j<n;j++) visited[j]=false;

        dfs(0);

        bool bridge = false;
        for(int j=0;j<n;j++){
            if(visited[j]==false){
                bridge = true;
            }
        }
        if(bridge) ans++;

        graph[a[i]][b[i]] = graph[b[i]][a[i]]=true;
    }
    cout << ans << endl;

    return 0;
}

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

ll mod_pow(ll n, ll p, ll mod) {
    ll ret = 1;
    while (p > 0) {
        if (p & 1) ret = ret * n % mod;
        n = n * n % mod;
        p >>= 1;
    }
    return ret;
}

ll mod_inv(ll n, ll mod) {
    return mod_pow(n, mod-2, mod);
}

const ll mod = 1e9 + 7;
vector<vector<int>> G;
vector<int> sz, parent;

void dfs(int v, int p) {
    parent[v] = p;
    for (int c : G[v]) {
        if (c == p) continue;
        dfs(c, v);
        sz[v] += sz[c];
    }
}

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

    int N;
    cin >> N;
    G.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    sz.resize(N, 1);
    parent.resize(N, 0);
    dfs(0, -1);

    ll ans = 0;
    ll two_inv = mod_inv(2, mod);
    for (int v = 0; v < N; v++) {
        ll prob1 = 0;
        int s = 1;
        for (int c : G[v]) {
            if (c == parent[v]) continue;
            s += sz[c];
            prob1 += (1 - mod_pow(two_inv, sz[c], mod) + mod) * mod_pow(two_inv, N - sz[c], mod) % mod;
            prob1 %= mod;
        }
        prob1 += (1 - mod_pow(two_inv, N - s, mod) + mod) * mod_pow(two_inv, s, mod) % mod;
        prob1 %= mod;
        ll prob = (two_inv - mod_pow(two_inv, N, mod) - prob1 + mod * 2) % mod;
        ans = (ans + prob) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 24520
#include <iostream>

using namespace std;

int main()
{
   int a, b, temp, i;
   
   cin>> a >> b;
   
   for(i = 1; a != 0 || b != 0; i++){
   
   if(a > b){
   
   temp = a;
   
   a = b;
   
   b = temp;
   
   }
   
   cout<< a << " " << b << endl;
   
   cin>> a >> b;
   
   }
   
   return 0;
}


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


#define endl            '\n'
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vi              vector<int>
#define vl              vector<long>
#define vll             vector<ll>
#define vs              vector<string>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<'	'<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<'	'<<#y<<" "<<y<<'	'<<#z<<" "<<z<<endl;
#define debug1(x)       cerr<<#x<<" "<<x<<endl;
#define debug2(x,y)     cerr<<#x<<" "<<x<<'	'<<#y<<" "<<y<<endl;
#define debug3(x,y,z)   cerr<<#x<<" "<<x<<'	'<<#y<<" "<<y<<'	'<<#z<<" "<<z<<endl;
#define info(s)         cerr<<s<<" "<<endl;
#define fr(a,b,c)       for(auto a=b;b<c?a<c:a>c;b<c?a++:a--)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define clr(x)          memset(x, 0, sizeof(x))
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define SORT(a)         sort(all(a));
#define SORTR(a)        sort(all(a),greater<ll>());
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100050
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second


template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v);


template<typename T>
istream& operator>>(istream &in,vector<T> &v);





void solve()
{
    int n;cin>>n;vi v(n+1);for(int i=1;i<=n;i++)cin>>v[i];
    vi dp(n+1);
    dp[1]=0;dp[2]=abs(v[2]-v[1]);
    for(int i=3;i<=n;i++)
    dp[i]=min(abs(v[i]-v[i-1])+dp[i-1],abs(v[i]-v[i-2])+dp[i-2]);
    cout<<dp[n]<<endl;

    // for(int i=1;i<=n;i++ )
    // cout<<dp[i]<<" ";cout<<endl;
} 


int main()
{   
    FIO;
    ll test;test=1;
    // cin>>test;for(ll i=1;i<=test;i++)
    solve();
    return 0;
}





template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v){
    int i=0;
    for(T x:v){
        out<<x;
        (i++!=v.size())?out<<' ':out<<'\n';    
    }
    return out;
}


template<typename T>
istream& operator>>(istream &in,vector<T> &v){
    for(T &i:v)
        in>>i;
    return in;
}

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

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int INF = 1000000007;
const ll INFLL = 1000000000000000007;

#define st first
#define nd second
#define pb push_back
#define _boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// ***************************** CODE ***************************** //

const int mod = 1e9 + 7;

void add(int& a, int b)
{
    a += b;
    if(a >= mod)
        a -= mod;
}

int main() {
    _boost;

    string k; int d;
    cin >> k >> d;
    int len = k.size();

    vector <vector<int>> dp(d, vector<int>(2));
    dp[0][0] = 1;
    for(int i = 0; i < len; i++)
    {
        vector <vector<int>> new_dp(d, vector<int>(2));
        for(int sum = 0; sum < d; sum++)
        {
            for(int j = 0; j < 2; j++)
            {
                for(int digit = 0; digit < 10; digit++)
                {
                    if(digit > k[i]-'0' && j == 0)
                        break;
                    if(j == 1 || digit < k[i]-'0')
                        add(new_dp[(sum+digit)%d][1], dp[sum][j]);
                    else
                        add(new_dp[(sum+digit)%d][0], dp[sum][j]);
                }
            }
        }
        dp = new_dp;
    }
    int ans = (dp[0][0] + dp[0][1]) % mod;
    ans--;
    if(ans <= -1)
        ans = mod - 1;
    cout << ans;


    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N;
	cin >> N;
	if (N == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int A, B;
		cin >> A >> B;
		cout << A + B << endl;
	}
}



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

using namespace std;
int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
    --a.at(i);
  }
  vector<bool> seen(n);

  vector<int> hist;
  
  int v = 0;
  vector<int> x(n, -1);
  for (int i = 0; i <= n; ++i) {
    seen.at(v) = true;
    hist.push_back(v);
    x.at(v) = i;
    v = a.at(v);
    if (seen.at(v)) {
      break;
    }
  }
  if (k < x.at(v)) {
    cout << hist.at(k) + 1 << endl;
  }  else {
    cout << hist.at((k-x.at(v)) % (hist.size() - x.at(v)) + x.at(v)) + 1 << endl;
  }
 
  return 0;
}


Measured memory_bytes: 5916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef double ld;

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

	int n;
	cin >> n;

	vi a(n+1), b(n+1), c(n+1);

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}

	vi dp_a(n + 1, 0), dp_b(n + 1, 0), dp_c(n + 1, 0);


	for (int i = 1; i <= n; i++)
	{
		dp_a[i] = a[i] + max(dp_b[i - 1], dp_c[i - 1]);
		dp_b[i] = b[i] + max(dp_a[i - 1], dp_c[i - 1]);
		dp_c[i] = c[i] + max(dp_a[i - 1], dp_b[i - 1]);
	}


	cout << max(dp_a[n], max(dp_b[n], dp_c[n]));

	return 0;

}

Measured memory_bytes: 5164
d = [int(input()) for i in range(5)]
k = int(input())
all_dis  = []
for i in range(4):
    for j in range(i+1,5):
        all_dis.append(d[j]-d[i])
for i in all_dis:
    if i > k:
        print(':(')
        exit()
print('Yay!')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int a, b, c;
  cin >> a >> b >>c;

  cout << min(b/a, c) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
  ll n;
  ll sum = 0;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++){
    cin >> a[i];
    sum += a[i];
  }
  ll temp = a[0];
  ll ans = abs(sum-2*temp);
  for(ll i=1;i<n-1;i++){
    temp+=a[i];
    ans = min(ans, abs(sum-2*temp));
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	string S, T;
	while (cin >> S >> T) {
		int a = S.size(), b = T.size();
		vector<vector<int>> dp(a + 1, vector<int>(b + 1));
		int res = 0;
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				dp[i + 1][j + 1] = S[i] == T[j] ? dp[i][j] + 1 : 0;
				res = max(res, dp[i + 1][j + 1]);
			}
		}
		cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 65792
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <cctype>
#include <algorithm>
using namespace std;
int main(void){
    int n ;
    cin >> n ;
    int ans = 0 ;
    for(int i = 0; i < n ; i++){
        ans += i+1 ;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int N = S.size();
  int num0 = 0;
  int num1 = 0;
  for (int i = 0; i < N; i++){
    if (S.at(i) == '0'){
      num0++;
    } else {
      num1++;
    }
  }
  cout << N - abs(num0 - num1) << endl;
  return 0;
}

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

// types - only for stuff used a lot 
using vi = vector<int>;
using ll = long long;
#define vv vector
#define Pp pair

// IO
#define get(x) scanf("%d",&x)
#define getl(x) scanf("%lld",&x);

// Operations
#define pb push_back
#define pob pop_back
#define sz(a) int(a.size()) 
#define re(a,b) a=max(a,b) // relax
#define ri(a,b) a=min(a,b) // relaxi

// Debugging

#ifndef LOCAL
#define cerr if (0) cerr
#else
#define cerr cout
#endif

#define print(arr,n) {for (int _ = 0; _ < n; _++) cerr<<arr[_]<<" "; cerr << endl; }
#define printv(vec)  {for (int _ : vec) cerr<<_<<" "; cerr<<endl;}

const int mod = 1e9+7, oo = 1e9;
const ll loo = 1e18;

// Functions 
ll modpow(ll a, ll b) {
	ll ans = 1; // faster modpow than recursive
	for (; b; b/=2,a=a*a%mod)
		if (b&1) ans = (ans*a)%mod;
	return ans;
}
ll gcd(ll a, ll b) {
	while (a) b%=a,swap(a,b);
	return b;
}
#define bitcount __builtin_popcountll
#define f(i,a,b) for (int i = a; i < b; i++)
#define fr(i,a,b) for (int i = b-1; i >= a; i--)


/* 

   ALRIGHT HACKERS, THIS IS WHERE THE ACTUAL CODE BEGINS

 */

const bool DEBUG = 1;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	if (DEBUG) freopen("input.txt", "r", stdin);
	if (DEBUG) freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n;
	cin>>n;
	int b[n];
	f(i,0,n) cin>>b[i];
	vi ans;
	bool take[n];
	fill(take,take+n,0);
	fr(i,0,n) {
		bool found = 0;
		fr(j,0,n) if (!take[j]) {
			int x = 0;
			f(k,0,j+1) x += !take[k];
			if (x == b[j]) {
				take[j] = 1;
				ans.pb(b[j]);
				found = 1;
				break;
			}
		}
		if (!found) {
			cout << -1 << endl;
			return 0;
		}
	}
	fr(i,0,n) cout << ans[i] << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,d,x;cin>>n>>d>>x;
  vi a(n);
  rep(i,n)cin>>a[i];
  int ans=n+x;
  rep(i,n){
    ans+=(d-1)/a[i];
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <stdio.h>
#include <math.h>

#define MAX 1000

typedef long long ll;

using namespace std;
int N;
vector<int> data;

//提出時には消す
#include <fstream>

int main()
{
    int n;
    string s;
    cin >> N;

    int C0 = 0;
    int C1 = 0;
    int C2 = 0;
    int C3 = 0;
    int C4 = 0;

    for (int i = 0; i < N; i++)
    {
        cin >> s;

        if (s == "AC")
        {
            C0++;
        }else if(s == "WA"){
            C1++;
        }
        else if (s == "TLE")
        {
            C3++;
        }
        else if (s == "RE")
        {
            C4++;
        }
    }

    cout << "AC x " << C0 << "\n";
    cout << "WA x " << C1 << "\n";
    cout << "TLE x " << C3 << "\n";
    cout << "RE x " << C4 << "\n";

    return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main() {
	long long n, x;
	cin >> n >> x;
	vector<long long> a(n);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	long long ans = 0;
	if (a[0] > x) {
		a[0] = x;
	}
	for (int i = 1; i < n; i++) {
		a[i] = min(a[i], x - a[i - 1]);
	}
	for (int i = 0; i < n; i++) ans += a[i];
	cout << sum - ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// Greatest Common Divisor 最大公約数
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

// least common multiple 最小公倍数
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}
int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll a = (B / C)-((A-1) / C);
    ll b = (B / D)-((A-1) / D);
    ll l = lcm(C, D);
    ll c = (B / l)-((A-1) / l);
    cout << (B - A + 1) - (a + b - c) << endl;
    return 0;
}

Measured memory_bytes: 256
(* O(n log(max xs)) *)
let n, x0 = Scanf.scanf " %d %d" @@ fun a b -> a, b
let xs = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let rec gcd a b = if b = 0 then a else gcd b @@ a mod b
let _ = Array.fold_left (fun g x -> gcd g @@ abs @@ x0 - x) 0 xs |> Printf.printf "%d\n"

Measured memory_bytes: 5248
<?php
//https://atcoder.jp/contests/abc160/submissions/11320459
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$X,$Y) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));
$X--;$Y--;
$ans=array_fill(0,$N,0);
for($sv=0;$sv<$N;$sv++) {
  $dist = array_fill(0, $N, PHP_INT_MAX);
  $q = new SplQueue();
  push($sv,0);
  while(!$q->isEmpty()) {
    $v=$q->dequeue();
    $d=$dist[$v];
    if ($v-1>=0) push($v-1,$d+1);
    if ($v+1<$N) push($v+1,$d+1);
    if ($v == $X) push($Y,$d+1);
    if ($v == $Y) push($X,$d+1);
  }
  for($i=0;$i<$N;$i++) {
    $ans[$dist[$i]]++;
  }
}
for($i=0;$i<$N;$i++) {
  $ans[$i] /= 2;
}
for($i=1;$i<=$N-1;$i++) {
  printf("%d\n",$ans[$i]);
}

function push($v,$d)
{
  global $dist,$q;
  if ($dist[$v] !== PHP_INT_MAX) return;
  $dist[$v]=$d;
  $q->enqueue($v);
}


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    //以下を考えても同値
    b-=a;
    a=0;
    //
    bool f=false;
    for(int i=0;i<n;i++){
        ll up=(n-1-i)*d-i*c;
        ll lw=(n-1-i)*c-i*d;
        if(lw<=b&&b<=up) f=true;
    }
    cout<<(f?"YES":"NO")<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
t = [0]
x = [0]
y = [0]
for i in range(N):
  ti, xi, yi = map(int, input().split())
  t.append(ti)
  x.append(xi)
  y.append(yi)

for i in range(1, N+1):
  can = False
  dist = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])
  dt = abs(t[i] - t[i-1])
  if dist <= dt:
    if dist % 2 == dt % 2:
      can = True
  if can == False:
    break
if can == True:
  print('Yes')
else:
  print('No')

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

#define FOR(i,b,e) for(ll i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(ll i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    string s;
    cin >> s;
    
    int n = SIZE(s);
    
    VI dp(n+1, n);
    dp[0] = 0;
    
    int mask = 0;
    map <int,int> firstForMask;
    
    const int ALPH = 'z' - 'a' + 1;
    
    firstForMask[0] = 0;
    
    FOR(i,1,n) {
        mask ^= 1 << (s[i-1] - 'a');
        
        if (firstForMask.count(mask)) {
            dp[i] = min(dp[i], 1 + firstForMask[mask]);
        }
        
        FOR(bit,0,ALPH-1) {
            int other = mask ^ (1 << bit);
            
            if (firstForMask.count(other)) {
                dp[i] = min(dp[i], 1 + firstForMask[other]);
            }
        }
        
        if (!firstForMask.count(mask)) {
            firstForMask[mask] = dp[i];
        } else {
            firstForMask[mask] = min(firstForMask[mask], dp[i]);
        }
    }
    
    cout << dp[n];

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 10644
<?php
list($n, $k) = ints();
$a = ints();
$gcd = gcdAll($a);
for ($i = 0; $i < $n; ++$i)
    if ($a[$i] >= $k && ($a[$i] - $k) % $gcd === 0) exit('POSSIBLE');
echo 'IMPOSSIBLE';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 最大公約数（2つ）
function gcd($m, $n)
{
    if (!$n) return $m;
    return gcd($n, $m % $n);
}

// 最大公約数（3つ以上）
function gcdAll($arr)
{
    $gcd = array_pop($arr);
    foreach ($arr as $a) {
        $gcd = gcd($gcd, $a);
    }
    return $gcd;
}

// 最小公倍数（2つ）
function lcm($m, $n)
{
    return (int) ($m / gcd($m, $n) * $n); // オーバーフローしないように先に割り算
}

// 最小公倍数（3つ以上）
function lcmAll($arr)
{
    $lcm = array_pop($arr);
    foreach ($arr as $a) {
        $lcm = lcm($lcm, $a);
    }
    return $lcm;
}


Measured memory_bytes: 27236
#include <stdio.h>
main(){
  int len,a[100],tmp,count=0,i,j;

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

  for(i=0; i<len-1; i++){
    for(j=len-1; j>i; j--){
      if(a[j]<a[j-1]){
	tmp=a[j-1];
	a[j-1]=a[j];
	a[j]=tmp;
	count++;
      }
    }
  }

  for(i=0; i<len; i++){
    if(i>=0 && i<len-1) printf("%d ",a[i]);
    else printf("%d\n",a[i]);
  }

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
X, K, D = map(int, input().split())

X= abs(X)
min_pos = X%D
min_neg = min_pos - D

if(X/D >= K):
  print(X-D*K)
else:
  if((K - (X-min_pos)/D)%2 == 0):
    print(min_pos)
  else:
    print(abs(min_neg))
    

Measured memory_bytes: 9164
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long A, long long B){
    vector< vector<char> > ret(96, vector<char>(99, '.'));
    for (int i = 0; i < 48; i++) {
        for (int j = 0; j < 99; j++) {
            ret[i][j] = '#';
        }
    }
    A--;
    B--;
    int x = 1;
    int y = 1;
    while (A > 0) {
        ret[x][y] = '.';
        A--;
        x += 2;
        if (x >= 47) {
            y += 2;
            x = 1;
        }
    }
    x = 49;
    y = 1;
    while (B > 0) {
        ret[x][y] = '#';
        B--;
        x += 2;
        if (x >= 95) {
            y += 2;
            x = 49;
        }
    }
    std::cout << 96 << ' ' << 99 << std::endl;
    for (int i = 0; i < 96; i++) {
        for (int j = 0; j < 99; j++) {
            std::cout << ret[i][j];
        }
        std::cout << std::endl;
    }
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long A;
    long long B;
    scanf("%lld",&A);
    scanf("%lld",&B);
    solve(A, B);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 888
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
    score = i
    count = 0
    for j in range(1, 31):
        if score < k:
            score *= 2
            count += 1
    ans += 1/n * (1/2)**count
print(ans)

Measured memory_bytes: 40428