akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

int N, K;
vector<i64> h;

i64 memo[305][305];
i64 dp(int i, int remK) {
    if (remK < 0) return LINF;
    if (i == N+1) return 0;

    auto &ret = memo[i][remK];
    if (~ret) return ret;

    ret = LINF;
    reps(jump, 1, K+1) {
        const int nxt = i + jump;
        if (nxt > N+1) continue;
        chmin(ret, dp(nxt, remK - (jump - 1)) + max<i64>(0, h[nxt] - h[i]));
    }

    return ret;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    read(N, K);

    h.resize(N + 5);
    reps(i, 1, N) read(h[i]);

    memset(memo, -1, sizeof(memo));

    print(dp(0, K));

    return 0;
}


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

int main()
{

	int i = 0;
	int dataArr[10000];

	while( scanf( "%d", &dataArr[i] ), dataArr[i] ) i++;

	for( int j = 0; j <= i - 1; j++ ) printf( "Case %d: %d\n", j + 1, dataArr[j] ); 

	return 0;

}

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

int main() {
  int N,M;
  int i;
  int path;
  
  cin >> N >> M;
  
  vector<int> town(N+1,0);
  
  for(i=0;i<M;i++){
    cin >> path;
    town.at(path) += 1;
    cin >> path;
    town.at(path) += 1;
  }
  
  for(i=1;i<N+1;i++){
    cout << town.at(i) << endl;
  }
}




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

// <editor-fold>

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
// vector出力
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}
// 任意の個数の変数をスペース区切りで出力します
void dump() {
  cout << endl;
}
template <class Head, class... Tail>
void dump(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) != 0)
    cout << " ";
  dump(std::move(tail)...);
}
#define YES(n) printf("%s\n", ((n) ? "YES" : "NO"));
#define Yes(n) printf("%s\n", ((n) ? "Yes" : "No"));
#define yes(n) printf("%s\n", ((n) ? "yes" : "no"));
// </editor-fold>

// ===============================================

int main() {
  string s;
  cin >> s;
  int r = 0, b = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0')
      r++;
    else
      b++;
  }
  cout << min(r, b) * 2 << endl;
}


Measured memory_bytes: 512
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson (curpos<<1)
#define rson (curpos<<1|1)
/* namespace */
using namespace std;
/* header end */

const int lim = 1e6;
int k, x;

int main() {
    cin >> k >> x;
    for (int i = x - k + 1; i <= x + k - 1; i++) {
        if (i < -lim || i > lim) continue;
        cout << i << " ";
    }
    puts("");
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
ll p[10];
ll q[10];
ll fac[10];
bool vis[10];
int main()
{
	ios;
	ll n,i,f=1,j,sum=0,sum1=0;
	fac[0]=1;
	for(i=1;i<=8;i++)
	{
		f=f*i;
		fac[i]=f;
	}
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>p[i];
	for(i=1;i<=n;i++)
		cin>>q[i];
	for(i=1;i<=n;i++)
	{
		f=0;
		for(j=1;j<p[i];j++)
		{
			if(!vis[j])
				f++;
		}
		sum+=f*fac[n-i];
		vis[p[i]]=true;
	}
	memset(vis,false,sizeof(vis));
	for(i=1;i<=n;i++)
	{
		f=0;
		for(j=1;j<q[i];j++)
		{
			if(!vis[j])
				f++;
		}
		sum1+=f*fac[n-i];
		vis[q[i]]=true;
	}
	//cout<<sum<<" "<<sum1<<endl;
	cout<<abs(sum-sum1)<<endl;
}


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

def main():
	a,b,c,x,y = map(int,input().split())
	if a+b < 2*c:
		# AピザとBピザ1枚ずつ用意するためにABピザ2枚より単体の方が安い場合
		print(a*x+b*y)
	else:
		# とりあえず必要数が少ない方に合わせて買う
		double = 2*c*min(x,y)
		if x < y:
			print((y-x)*min(b,2*c) + double)
		else:
			print((x-y)*min(a,2*c) + double)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
<?php
# 入力部
// fscanf(STDIN, "%s %s", $s, $t);
// fscanf(STDIN, "%d %d", $n, $m);
// fscanf(STDIN, "%s", $u);
fscanf(STDIN, "%d %d", $k, $x);
// $s1 = fgets(STDIN); //"\n"の2文字
// $s2 = fgets(STDIN);
// fscanf(STDIN, "%d", $n);
// fscanf(STDIN, "%s", $s);
// fscanf(STDIN, "%c", $c);
// fscanf(STDIN, "%s", $s2);
// fscanf(STDIN, "%d %d %d", $a, $b, $c);


# 処理部
// $arr = str_split($s);
// $arr2 = str_split($s2);
// $arr1 = explode(" ", $s1);
// $arr2 = explode(" ", $s2);
// for ($i = 0; $n > $x * $i; $i++) {
// }
// if (strpos($s, 'RRR') !== false) {
//   $r = 3;
// } elseif (strpos($s, 'RR') !== false) {
//   $r = 2;
// } elseif (strpos($s, 'R') !== false) {
//   $r = 1;
// } else {
//   $r = 0;
// }
// $s = "No";
// if ($x >= 30) {
//   $s = "Yes";
// }
// for ($i = 0; $i * 1000 < $n; $i++) {
// }
// $c = "a";
// if (ctype_upper($a)) {
//   $c = "A";
// }
// $s = "Yes";
// echo count($arr1);
// for ($i = 0; $i < strlen($s1); $i++) {
//   if ($arr1[$i] != $arr2[$i]) {
//     $s = "No";
//   }
// }
// $unit;
// switch ($n % 10) {
//   case 0:
//   case 1:
//   case 6:
//   case 8:
//     $unit = "pon";
//     break;
//   case 3:
//     $unit = "bon";
//     break;
//   default:
//     $unit = "hon";
//     break;
// }
// if ($s == "ABC") {
//   $r = "ARC";
// } else {
//   $r = "ABC";
// }
// $r = "NG";
// for ($i = $a; $i <= $b; $i++) {
//   if ($i % $k == 0) {
//     $r = "OK";
//   }
// }
// $r = "safe";
// if ($s <= $w) {
//   $r = "unsafe";
// }
// $r = "No";
// if (strpos($n, "7") !== false) {
//   $r = "Yes";
// }
// $r = "No";
// if ($arr[2] == $arr[3] && $arr[4] == $arr[5]) {
//   $r = "Yes";
// }
// $r = "Yes";
// if ($s == "AAA" || $s == "BBB") {
//   $r = "No";
// }
// if ($n % 2 == 0) {
//   $r = $n / 2;
// } else {
//   $r = ($n + 1) / 2;
// }
// if ($n < 10) {
//   $r += (10 - $n) * 100;
// }
// $arr = array($a, $b, $c);
// $arr = array_unique($arr);
// if (count($arr) == 2) {
//   $r = "Yes";
// } else {
//   $r = "No";
// }
// if ($s == $u) {
//   $a--;
// } else {
//   $b--;
// }
// for ($i = 0; $h > 0; $i++) {
//   $h -= $a;
// }
// $r = "No";
// if ($n == $m) {
//   $r = "Yes";
// }
$r = "No";
if ($k * 500 >= $x) {
  $r = "Yes";
}

# 出力部
// echo ($n * ($n - 1) / 2) + ($m * ($m - 1) / 2) . "\n";
// echo $z . " " . $x . " " . $y . "\n";
// echo ($i * 1000) - $n . "\n";
// echo json_encode($arr) . "\n";
echo $r . "\n";
// echo ++$c . "\n";
// echo $a . " " . $b . "\n";


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

using namespace std;

int main(void) {
	int A, B;
	string S;
	cin >> A >> B;
	cin >> S;
	for(int i = 0; i < S.length(); ++i) {
		if(i == A) {
			if(S[i] != '-') {
				cout << "No\n";
				return 0;
			}
		} else {
			if(S[i] == '-') {
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#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 print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 


int main() {
    string s;
    cin >> s; 
    if (s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int N,D,A,X[201010],H[201010];
ll buf[201010];

int main(){
    cin>>N>>D>>A;
    rep(i,N) cin>>X[i]>>H[i];
    D*=2;
    vector<pair<int,int>> xh;
    rep(i,N) xh.push_back({X[i],H[i]});
    sort(all(xh));

    ll ans=0;
    int R=0;
    rep(L,N){
        if(L) buf[L]+=buf[L-1];
        int x=xh[L].first;
        int h=xh[L].second;

        if(buf[L]<h){
            R=max(R,L+1);
            while(R<N && xh[R].first-x<=D) R++;

            ll d=h-buf[L];
            ll cnt=(d+A-1)/A;

            buf[L]+=cnt*A;
            buf[R]-=cnt*A;
            ans+=cnt;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 8056
#include<stdio.h>
int main(void){
int H,W,h,w;
while(1){
scanf("%d %d",&H,&W);
if(H==0&&W==0)break;
for(h=0;h<H;h++){
for(w=0;w<W;w++)printf("#");
printf("\n");
}
printf("\n");
}

return 0;
}


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

const int N = 1e5 + 100;

int n, d[N];
bool dead[N];
vector<int> nei[N];
queue<int> q;

void input() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		nei[--u].push_back(--v);
		nei[v].push_back(u);
	}
}

int match(int v) {
	for (int u: nei[v])
		if (dead[u] == false)
			return u;
	return -1;
}

bool have_matching() {
	if (n & 1)
		return false;
	for (int u = 0; u < n; u++)
		if ((d[u] = nei[u].size()) == 1)
			q.push(u);
	n >>= 1;
	while (n) {
		if (q.empty())
			return false;
		int v = q.front();
		q.pop();
		if (dead[v])
			continue;
		int u = match(v);
		if (u == -1)
			continue;
		dead[v] = dead[u] = true;
		for (int w: nei[u])
			if (dead[w] == false && --d[w] == 1)
				q.push(w);
		n--;
	}
	return true;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	input();
	if (have_matching())
		cout << "Second\n";
	else
		cout << "First\n";
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int K,X;
    cin >> K >> X;
    for(int i=X-K+1;i<=X+K-1;i++){
        cout  << i << endl;
    }




}


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

int main() {
    string s;
    cin >> s;
//    int year = (int)s[0] * 1000 + (int)s[1] * 100 + (int)s[2] * 10 + (int)s[3];
    int month = (s[5] - '0') * 10 + (s[6] - '0');
    int day = (s[8] - '0') * 10 + (s[9] - '0');
//    cout << month << endl;
    if(month >= 5) cout << "TBD" << endl;
    else if(month <= 4) cout << "Heisei" << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int X,Y,Z,a;
  scanf("%d %d %d",&X,&Y,&Z);
  a=X;
  X=Y;
  Y=a;
  a=X;
  X=Z;
  Z=a;
  printf("%d %d %d\n",X,Y,Z);
}

Measured memory_bytes: 128
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long long lcm(long long x, long long y){
  return x/__gcd(x,y)*y;
}

int main(){
  size_t N;
  cin >> N;
  vector<int> ans;
  int M = 3e4;
  vector<bool> used(M+1,false);
  ans.push_back(2);
  ans.push_back(3);
  used[2] = true;
  used[3] = true;
  int s = 5;
  for(int i = 4; i <= M; ++i){
    if(ans.size() >= N-1) break;
    if(i%2 and i%3) continue;
    used[i] = true;
    ans.push_back(i);
    s += i;
  }
  int r = 6 - s%6;
  for(int i = r; i <= M; i += 6){
    if(ans.size() == N) break;
    if(used[i]) continue;
    if(__gcd(s+i,i) == 1) continue;
    ans.push_back(i);
    s += i;
    break;
  }
  assert(ans.size() == N);
  for(auto e : ans) assert(__gcd(e,s) > 1);
  assert(*max_element(ans.begin(), ans.end()) <= M);
  //cerr << ans.back() << endl;
  for(auto e : ans) cout << e << " ";
  cout << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,x=0;
    scanf("%d",&N);
    char s[N];
    scanf("%s",s);
    int max=0;
    for(int i=0;i<N;i++)
    {
       if(s[i]=='I')
       {
           x++;
           if(max<x)
            max=x;
       }
       else if(s[i]=='D')
       {
           x--;
           if(max<x)
            max=x;
       }
    }
    printf("%d\n",max);


}


Measured memory_bytes: 256
import java.io.*
import java.util.*
import kotlin.math.*
//TLE
fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val i = f.readLine().toInt()
	val s = f.readLine()
	val n1 = s.length

	//CHECK THE MOD!!!
	val MOD : Long = 1000000007L
	val fac = LongArray(2000005)
	fac[0] = 1L
	for(k in 1 until 2000005){
		fac[k] = (fac[k-1]*k.toLong() + MOD)%MOD
	}

	fun exp(base : Long, power : Long) : Long{
		if(power == 0L) return 1L
		if(power == 1L) return (base + MOD)%MOD
		var ans = 1L
		var b = base
		var p = power
		while(p > 0L){
			if(p and 1L == 1L) ans = (ans*b+MOD)%MOD
			p = p shr 1
			b = (b*b + MOD)%MOD
		}
		return ans
	}
	fun modInverse(n : Long, p : Long) : Long{
		return exp(n,p-2)
	}
	fun choose (n : Int, r : Int) : Long{
		if(r == 0) return 1L
		if(n < r) return 0L
		return (((fac[n.toInt()] * modInverse(fac[r.toInt()], MOD) + MOD) % MOD) * modInverse(fac[(n-r).toInt()], MOD) + MOD) % MOD;
	}

	val pow25 = LongArray(1000005)
	val pow26 = LongArray(1000005)

	pow25[0] = 1L
	pow26[0] = 1L

	for(k in 1 until 1000005){
		pow25[k] = (pow25[k-1]*25L + MOD)%MOD
		pow26[k] = (pow26[k-1]*26L + MOD)%MOD
	}

	var answer = 0L

	for(k in 0..i){
		val prod1 = (pow26[i-k]*pow25[k] + MOD)%MOD
		val prod2 = (prod1 * (choose(k+n1-1,k)) + MOD)%MOD
		answer = (answer + prod2 + MOD)%MOD
	}

	println(answer)

}


Measured memory_bytes: 70404
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;
int a[5000];

int main(){
    cin >> N;
    rep(loop,N){   //100
        int m,d,v,s;
        cin >> m >> d >> v >> s;
        m--;
        d--;
        int st = m*30+d;
        int ed = st + v - 1;


        if(ed < 360){
            for(int i=0;i<st;i++){
                int n = 2000;
                chmin(n,abs(st-i));
                chmin(n,abs(i+360-ed));
                a[i] = max(a[i],s-n);
            }
            for(int i=st;i<=ed;i++) chmax(a[i],s);
            for(int i=ed+1;i<360;i++){
                int n = 2000;
                chmin(n,abs(i-ed));
                chmin(n,abs(st+360-i));
                a[i] = max(a[i],s-n);
            }
        }else{
            ed %= 360;
            for(int i=0;i<=ed;i++) chmax(a[i],s);
            for(int i=ed+1;i<st;i++){
                int n = 2000;
                chmin(n,abs(i-ed));
                chmin(n,abs(st-i));
                a[i] = max(a[i],s-n);
            }
            for(int i=st;i<360;i++) chmax(a[i],s);
        }
    }

    int mx = 2000;
    for(int i=0;i<360;i++) chmin(mx,a[i]);
    //rep(i,360) cout << i << " "<< a[i] << endl;
    cout << mx << endl;

}

Measured memory_bytes: 3088
#include <iostream>

using namespace std;

int main()
{
    int n, x;
    while (cin >> n >> x) {
        if (n == 0 && x == 0) break;
        int ans = 0;
        for (int i = 1; i <= n - 2; i++) {
            for (int j = i + 1; j <= n - 1; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    if (a + b == c || a + c == b || b + c == a) {
        puts("Yes");
    } else {
        puts("No");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

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

  vl a(N);
  rep(i, N) cin >> a[i];

  ll ans = 0;

  rep(i, N - 1){
    ll sum = a[i] + a[i + 1];

    if(sum > x){
      a[i + 1] -= min(a[i + 1], sum  - x);
      ans += (sum - x);
    }
  }

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

Measured memory_bytes: 1024
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum[200000], ans, dp[40000],a[200000],b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<LL>vec;
vector<edge>ed;
vector<LL>v;
map<LL,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

map<LL,LL> zip;
int unzip[200000];

int compress(vector<LL> &x) {
	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	for (int i = 0; i < x.size(); i++) {
		zip[x[i]] = i;
		unzip[i] = x[i];
	}
	return x.size();
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i] >> b[i];
		v.push_back(a[i]);
		v.push_back(b[i]);
	}
	compress(v);
	rep(i, n) {
		a[i] = zip[a[i]];
		b[i] = zip[b[i]];
		sum[a[i]]++;
		sum[b[i] + 1]--;
	}
	rep(i, 110000) {
		sum[i + 1] += sum[i];
		ans = max(sum[i], ans);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 20768
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int a, b;

	cin >> a >> b;

	int cnt = 0;
	for (i = 1; i < a; i++) {

	}
	i--;
	if (a <= b) {
		i++;
	}

	cout << i << endl;










	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,n,mod,dig=0,ans=1,te;
    cin>>a>>b;
    n=b;
    while(n!=0)
    {
         mod=n%10;
         dig++;
         n/=10;
    }

   for(int i=1;i<=dig;i++)
    ans*=10;
    ans=(ans*a) +b;
   te=sqrt(ans);
   if((te*te)==ans) cout<<"Yes\n";
   else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 256
/**
 * ??°?????????

?????????????????°???????????????????¨??????????????????°?????????????????????????????????

Input
?????°??????????????????????????\?????¨??????????????????????????????????????????????????????????????´??° x
?????????????????§?????????????????????

x ??? 1000 ?????\????????´??°??§??????

x ??? 0
?????¨?????\?????????????????¨??????????????????????????????????????????????????????????????£????????????????????????

Output
????????????????????????????????????x ???????????????????????????????????????????????????

Sample Input
123
55
1000
0
Sample Output
6
10
1
 */

#include <iostream>
#include <sstream>

int main(int argc, char const *argv[]) {
  std::string x;
  unsigned short NumberOfInt = 0;
  while (true) {
    while (true) {
      getline(std::cin, x);
      const auto result = x.find_first_not_of("0123456789");
      NumberOfInt = x.length();
      if (result != std::string::npos || NumberOfInt > 1200) {
        std::cout << "Error: Input string can only contain integer and must be "
                     "less than 1200 characters."
                  << std::endl;
      } else {
        break;
      }
    }
    if (x == "0") {
      break;
    } else {
      unsigned short Sum = 0;

      for (size_t i = 0; i < NumberOfInt; i++) {
        Sum += x[i] - '0';
      }

      std::cout << Sum << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3168
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	ma, mi := 0, math.MaxInt64
	for i := 0; i < n; i++ {
		a := readInt()
		ma = max(ma, a)
		mi = min(mi, a)
	}
	fmt.Println(ma - mi)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	char buf[5];

	scanf("%s",buf);

	for(int i = 0; buf[i] != '\0'; i++){
		if(buf[i] == '7'){

			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");

	return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<59)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed); cerr.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	ld pi = acos(-1);
	ld ang = abs(((11.0 * pi * m)/(ld)360.0) - (pi * h)/(ld)6);
	ld dx = sqrt((ld)a*a + (ld)b*b - (ld)2.0*a*b*cos(ang));
	SETF();
	cout<<setprecision(11)<<dx<<"\n";
	UNSETF();
	return;
}

int main(void)
{
	FLASH();
	//freopen("cowjog.in", "r", stdin);
	//freopen("cowjog.out", "w", stdout);
	int T;
	T = 1;

#ifndef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	//cin>>T;
	while(T--)
	solve(T);

#ifndef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cerr<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}

Measured memory_bytes: 4180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
小数の桁数を指定する
	cout << setprecision(8)<< mp[0]-mx << endl;
*/

int main()
{
	ll i,j,k,a,b;//,ans=0;
	char c;
	ll N,M,T, X,Y;
	ll tm[100010] = {0};
	cin >> N >> M >> T;
	N = MAX(N,M);
	cout << (T+N-1)/N << endl;

	return 0;
}




















Measured memory_bytes: 256
#include <iostream>
#include <float.h>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>
#include <stack>
#include <queue>
#include <sstream>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };




int main() {
	int n, m;
	cin >> n;
	map<int, int> d;
	rep(i, n) {
		int tmp;
		cin >> tmp;
		d[tmp]++;
	}

	cin >> m;
	vector<int> t(m);
	rep(i, m)
		cin >> t[i];

	bool ok = true;
	rep(i, m) {
		if (d[t[i]]-- == 0) {
			ok = false;
		}
	}
	if (ok)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;




}



Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;
int main()
{
    string s1, s2, u;
    int a, b; 
    cin >> s1 >> s2 >> a >> b >> u;
    if (s1 == u) a--;
    else b--;
    cout << a << ' ' << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    const long long mod = 1e9+7;
    int n;
    cin >> n;
    vector< long long > a(n+1, 0), b(n+1, 0);
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=n;i++) b[i] = (b[i-1] + a[i]) % mod;
    long long ans = 0;
    for(int i=1;i<=n;i++){
        ans += a[i] * (b[n]-b[i]+mod) % mod;
    }
    cout << ans%mod << endl;
}


Measured memory_bytes: 5996
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define inout freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)
#define swap(a,b) (a)+=(b);(b)=(a)-(b);(a)-=(b)
#define quicksort(a,n) qsort(a,n,sizeof(a[0]),cmp)
#define inputarr(a,n) for(int i=0;i<n;i++){scanf("%d",&a[i]);}
#define printarr(a,n) for(int i=0;i<n;i++){printf("%d ",a[i]);}puts("");
int cmp(const void *a,const void *b){return *(int *)a - *(int *)b;}


int main() {

	//inout;

	int n;

	scanf("%d", &n);

	int a = 0, b = 0, c = 0, d = 0;

	while(n--){

		char str[5];

		scanf("%s", str);

		if(str[0] == 'A'){
			a++;
		}

		if(str[0] == 'W'){
			b++;
		}

		if(str[0] == 'T'){
			c++;	
		}

		if(str[0] == 'R'){
			d++;
		}

	}

	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d", a, b,c,d);

}

Measured memory_bytes: 1728
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    vec<lint> bells(3);
    range(i, 0, 3) cin >> bells.at(i);
    sort(bells.begin(), bells.end());
    cout << bells.at(0) + bells.at(1) << "\n";
}

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

int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int max, min;
	max = a[0];
	min = a[0];
	for(int i=1;i<n;i++)
	{
		if(max < a[i])
			max = a[i];
		if(min > a[i])
			min = a[i];
	}
	cout<<max-min<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
const int INF = 1e9;


struct UnionFind {
    vector<int> parent;
    int size;
    UnionFind(int n) :parent(n, -1), size(n) {}
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y)return false;
        if (sizeOf(x) < sizeOf(y))swap(x, y);
        parent[x] += parent[y]; parent[y] = x; size--;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
    int sizeOf(int x) { return -parent[root(x)]; }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> from(m),to(m);
    REP(i,m){
        int f,t;
        cin >> f >> t;
        --f;--t;
        from[i] = f; to[i] = t;
    }
    int ans = 0;
    REP(i,m){
        UnionFind uf(n);
        REP(j,m) if(i!=j) uf.unite(from[j],to[j]);

        int cnt = 0;
        REP(j,n) if(j == uf.root(j)) ++cnt;
        if(1 < cnt) ++ans;
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int main(){
	int n;ll ans=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<a[i-1]&&i>0){
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans<<endl;
} 
 

Measured memory_bytes: 4348
#pragma comment(linker,"/STACK:1024000000,1024000000")
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define ios ios::sync_with_stdio(false)
#define ll long long
#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define of(i,a,b) for(int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof a)
#define uint unsigned int
#define vr vector<int>
#define pi acos(-1)

const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll N = 1e7 + 10;



int main()
{
	int n;
	sc(n);
	printf("%.7f\n", ceil(n * 1.0 / 2) * 1.0 / n);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	int l, r;
	vector<vector<int>> edges(N); // Nは番兵
	for (int i = 0; i < M; i++) {
		cin >> l >> r;
		edges[l - 1].emplace_back(r - 1);
	}

	int ans = 0, tmp = INF;
	for (int i = 0; i < N; i++) {

		if (!edges[i].empty()) {
			sort(edges[i].begin(), edges[i].end());
			tmp = min(tmp, edges[i].front());
		}

		if (tmp - 1 <= i) {
			tmp = INF;
			ans++;
		}

	}

	cout << ans << "\n";

	return 0;
}

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

int main() {
    lint n, m;
    cin >> n >> m;
    lint a = 0;
    for (int i = 0; i < m; i++) {
        lint t;
        cin >> t;
        a += t;
    }
    if (a <= n) {
        cout << n - a << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    string s;
    cin >> s;


    if(s.size() < 26){
        rep(i, 'a', 'z' + 1){
            ll flag = true;
            rep(j, 0, s.size()){
                if(s[j] == i){
                    flag = false;
                }
            }

            if(flag){
                cout << s << char(i) << endl;
                return 0;
            }
        }
    }else{
        rrep(i, s.size() - 2, 0){
            rep(j, s[i] + 1, 'z' + 1){
                rep(k, i + 1, s.size()){
                    if(j == s[k]){
                        rep(l, 0, i){
                            cout << s[l];
                        }
                        cout << s[k] << endl;
                        return 0;
                    }
                }
            }
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N = 100000;
    set<int> p;
    p.insert(2);
    FOR(i, 3, N + 1) {
        int t = (int)(sqrt((double)i));
        bool f = true;
        for (auto itr = p.begin(); itr != p.end(); ++itr) {
            if ((*itr) > t) break;
            else {
                if (i % (*itr) == 0) {
                    f = false;
                    break;
                }
            }
        }
        if (f) p.insert(i);
    }

    int resn[N + 1];
    REP(i, N + 1) resn[i] = 0;
    for (auto itr = p.begin(); itr != p.end(); ++itr) {
        int h = ((*itr) + 1) / 2;
        if (p.find(h) != p.end()) resn[(*itr)] = 1;
    }
    REP(i, N) {
        resn[i + 1] = resn[i + 1] + resn[i];
    }

    int Q;
    cin >> Q;
    REP(i, Q) {
        int l, r;
        cin >> l >> r;
        cout << resn[r] - resn[l - 1] << endl;
    }
    return 0;
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll N, Z, W;
    cin >> N >> Z >> W;

    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    if (N == 1) {
        cout << abs(W - A[N - 1]) << endl;
    } else {
        cout << max(abs(W - A[N - 1]), abs(A[N - 1] - A[N - 2])) << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	string s;
	int n;
	cin >> s >> n;
	for (int i = 0; i < s.size(); i += n) cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
SX, SY, TX, TY = map(int, input().split())

TX -= SX
TY -= SY
SX = 0
SY = 0

res = ""

res += "U"*TY
res += "R"*TX
res += "D"*TY
res += "L"*(TX+1)
res += "U"*(TY+1)
res += "R"*(TX+1)
res += "D"
res += "R"
res += "D"*(TY+1)
res += "L"*(TX+1)
res += "U"

print(res)

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

struct lazy_segment_tree {
  using T = i64;
  using L = i64;
  T t_ide() { return 0; }
  L l_ide() { return 0; }
  T ope(const T& a, const T& b) { return a + b; }
  T lazy_ope(const L& a, const L& b) { return a + b; }
  T effect(const T& t, const L& l, const i64 len) { return t + l * len; }

  i64 n;
  vector<T> node;
  vector<L> lazy;
  vector<bool> flag;

  lazy_segment_tree(i64 sz) {
    n = 1;
    while(n < sz) n *= 2;
    node.assign(n * 2, t_ide());
    lazy.assign(n * 2, l_ide());
    flag.assign(n * 2, false);
  }
  
  void eval(i64 l, i64 r, i64 k) {
    if(flag[k]) {
      node[k] = effect(node[k], lazy[k], r - l);
      
      if(r - l > 1) {
        lazy[k * 2 + 1] = lazy_ope(lazy[k * 2 + 1], lazy[k]);
        flag[k * 2 + 1] = true;
        lazy[k * 2 + 2] = lazy_ope(lazy[k * 2 + 2], lazy[k]);
        flag[k * 2 + 2] = true;
      }

      flag[k] = false;
      lazy[k] = l_ide();
    }
  }

  void update(i64 a, i64 b, L lx, i64 l = 0, i64 r = -1, i64 k = 0) {
    if(r < 0) r = n;
    eval(l, r, k);
    if(b <= l || r <= a) return;
    else if(a <= l && r <= b) {
      lazy[k] = lazy_ope(lazy[k], lx);
      flag[k] = true;
      eval(l, r, k);
    }
    else {
      update(a, b, lx, l, (l + r) / 2, k * 2 + 1);
      update(a, b, lx, (l + r) / 2, r, k * 2 + 2);
      node[k] = ope(node[k * 2 + 1], node[k * 2 + 2]);
    }
  }

  T get(i64 a, i64 b, i64 l = 0, i64 r = -1, i64 k = 0) {
    if(r < 0) r = n;
    eval(l, r, k);
    if(b <= l || r <= a) return t_ide();
    else if(a <= l && r <= b) return node[k];
    else return ope(get(a, b, l, (l + r) / 2, k * 2 + 1), get(a, b, (l + r) / 2, r, k * 2 + 2));
  }
};

int main() {
  i64 n, q;
  cin >> n >> q;
  lazy_segment_tree seg(n);
  for(int i = 0;i < q;i++) {
    i64 query;
    cin >> query;
    if(query == 0) {
      i64 s, t, x;
      cin >> s >> t >> x;
      seg.update(s - 1, t, x);
    }
    else {
      i64 s, t;
      cin >> s >> t;
      cout << seg.get(s - 1, t) << endl;
    }
  }
}



Measured memory_bytes: 7064