akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
#define N 100000

typedef struct C{
    char pic;
    int num;
    int id;
}card;
 
int part(card arr[], int p, int r){
    int x, i, j;
    card tmp;
    x = arr[r].num;
    i = p-1;
     
    for(j = p; j < r; j++) {
        if(arr[j].num <= x) {
            i++;
            tmp = arr[i];
	    arr[i] = arr[j];
	    arr[j] = tmp;
        } 
    }
    tmp = arr[i+1];
    arr[i+1] = arr[r];
    arr[r] = tmp;
    return i + 1;
}
 
void quick(card arr[], int P, int R){
    int Q;
    if(P < R) {
        Q = part(arr, P, R);
        quick(arr, P, Q - 1);
        quick(arr, Q + 1, R);
    }
}
 
int isSta(card arr[], int n){
    int i;
    for(i=1; i<n; i++) {
        if(arr[i-1].num == arr[i].num) {
            if(arr[i - 1].id > arr[i].id) return 0;
        }
    }
    return 1;
}

int main(int argc,char *argv[]){
    int i, n;
    card arr[N];
    scanf("%d", &n);

    for(i=0; i<n; i++) {
      if(i<n)break;
    }
    
    for(i=0; i<n; i++) {
        scanf(" %c %d", &arr[i].pic, &arr[i].num);
        arr[i].id=i;
    }
    quick(arr, 0, n-1);
 
    if(isSta(arr, n)) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0; i<n; i++) {
        printf("%c %d\n", arr[i].pic, arr[i].num);
    }
    return 0;
}



Measured memory_bytes: 2868
//
//  main.cpp
//  codeforces 1
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#define int long long
#define N 1500002
using namespace std;
signed main() {
    int n,d;
    cin>>n>>d;
    int x[n],y[n];
    for(int i=0;i<n;i++) {
        cin>>x[i]>>y[i];
    }
    int count = 0;
    for(int i=0;i<n;i++) {
        long double D=pow(x[i],2)+pow(y[i],2);
        D=pow(D,0.5);
        if(D<=d) {
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 6808
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define sum(x) accumulate(all(x),0)
#define gll greater<ll>()

void solve(){
 ll n;
  cin >> n;
  vll a(n);
  rep(i,0,n) cin >> a[i];
  sort(all(a),gll);
  
  ll ans=a[0];
  ll index=1;
  rep(i,0,n-2){
   ans+=a[index];
   if(i%2) index++;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 4768
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,k,n) for(int i=k;i<n;i++)

typedef long long lint;
int main (){
    string s;
    int a[4];
    cin >> s;
    rep(i,4){
        a[i] = int(s[i]-'0');
    }
    rep(bit,1<<3){
        int b = a[0];
        string c;
        c += to_string(a[0]);
        rep(k,3){
            if(bit & (1<<k)){
                b += a[k+1];
                c += "+" + to_string(a[k+1]);
            }else{
                b -= a[k+1];
                c += "-" + to_string(a[k+1]);
            }
        }
        if(b == 7){
            c += "=7";
            cout << c << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while (cin >> n) {
		long long  a[101];
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		for (int i = 0; i < n; i++) {
			if (i == 0) 
				sum += a[0];
			else {
				a[i] += a[i - 1];
				sum += a[i];
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3156
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn -- 2 <= n <= 10^5
  h <- V.fromListN n . map (read . BS.unpack) . BS.words <$> BS.getLine
  -- hi <= 10^4
  let dp = V.create $ do
        dp <- VM.new n
        VM.write dp 0 0
        VM.write dp 1 (abs (h V.! 0 - h V.! 1))
        forM_ [2..n-1] $ \i -> do
          c2 <- VM.read dp (i - 2)
          c1 <- VM.read dp (i - 1)
          let c2' = c2 + abs (h V.! i - h V.! (i - 2))
              c1' = c1 + abs (h V.! i - h V.! (i - 1))
          VM.write dp i (min c1' c2')
        return dp
  print (V.last dp :: Int)


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pl=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vs=vector<string>;

void solve() {
    int K;
    cin >> K;
    rep(i,K){
        cout << "ACL";
    }
    cout << '\n';

}   

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////

//期間内に働く日数を最大化するには前から貪欲に働く日を決めるのが最適
//したがって前から貪欲に働く日を決めた場合を考えることでx回目に働く日はL[x]日目以降
//という配列Lを求めることができる
//同様に後ろから貪欲に働く日を決めた場合を考えることでx回目に働く日はR[x]日目以前
//という配列を作ることができる
//i日目に必ず働くのはL[x]=R[x]=iとなるxが存在するときに限る
int L[200010];
int R[200010];
int main() {
	int N, K, C;
	string S;
	cin >> N >> K >> C;
	cin >> S;
	int cnt = 1;
	int now = 0;
	while (cnt <= K) {
		if (S[now] == 'o') {
			L[cnt] = now;
			cnt++;
			now += C+1;
		}
		else {
			now++;
		}
	}
	int cnt2 = K;
	int now2 = N - 1;
	while (cnt2 > 0) {
		if (S[now2] == 'o') {
			R[cnt2] = now2;
			now2 -= (C + 1);
			cnt2--;
		}
		else {
			now2--;
		}
	}
	vector<int>ans;
	for (int i = 1; i <= K; ++i) {
		if (L[i] == R[i]) {
			ans.push_back(L[i]+1);
		}
	}
	if (ans.size() != 0) {
		REP(i, ans.size()) {
			cout << ans[i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4216
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
    
    vector<vector<long long>> dp(N+1, vector<long long>(H+1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= H; ++j) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][min(j+A[i], H)], dp[i+1][j] + B[i]);
        }
    }
    cout << dp[N][H] << endl;
}

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

int top=0,S[100];

void push(int);
int pop();
int isEmpty();

int main(){
  int a,b,n;
  char s[100];
  
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else{
    n=atoi(s);
    push(n);
    }
  }
  printf("%d\n",S[1]);
  return 0;
}
int isEmpty(){
  return top==0;
}
void push(int x){
  top+=1;
  S[top]=x;
}
int pop(){
  if (isEmpty()) fprintf(stderr,"underflow\n");
  else
    top-=1;
  return S[top+1];
}

Measured memory_bytes: 548
#include<stdio.h>
int main()
{
	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);
	if(n>m)
	{
		int t=n;
		n=m;
		m=t;
	}
		if(m>k)
	{
		int t=k;
		k=m;
		m=t;
	}
		if(n>m)
	{
		int t=n;
		n=m;
		m=t;
	}
	if(n==m&&m!=k)
	printf("Yes\n");
	else if(m==k&&m!=n)
		printf("Yes\n");
	else 
		printf("No\n");
 } 

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N;
vector<int> A;

void init()
{
	cin >> N;
	CINV(A, N);
}

int X;

inline void add(int x, map<int, int>& m)
{
	m[x]++;
	if (m[x] == X) {
		m.erase(x);
		add(x-1, m);
	}
}

inline bool isok(int x)
{
	X = x;
	int pre = 0;
	map<int, int> m;
	rep(i, N) {
		if (pre < A[i]) {
			pre = A[i];
			continue;
		}
		pre = A[i];
		add(A[i], m);
		while (1) {
			auto itr = --m.end(); int x = (*itr).first;
			if (x > A[i]) m.erase(itr);
			else break;
		}
		if (m.count(0)) return false;
	}
	return true;
}

void solve()
{
	bool f = true;
	rep(i, N-1) {
		f &= A[i] < A[i+1];
	}
	if (f) {
		cout << 1 << endl;
		return;
	}
	int ok = 1000000000;
	int ng = 1;
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		if (isok(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}





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

int main()
{
    int n;
    cin >> n;
    map<string, int> mp;
    int max_cnt = 1;
    rep(i,n) {
        string si;
        cin >> si;
        if(mp.count(si)>0){
            mp[si]++;
            max_cnt = max(max_cnt, mp[si]);
        }
        else mp[si] = 1;
    }

    for(auto& mpi:mp) {
        if(mpi.second == max_cnt)
            cout << mpi.first << endl;
    }
    return 0;
}

Measured memory_bytes: 25216
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

if N % 2 == 1:
  cnt = set()
  for (key, value) in Counter(A).items():
    if key == 0:
      if value != 1:
        print(0)
        exit()

    else:

      if key % 2 != 0 or value != 2:
        print(0)
        exit()

      cnt.add(key)

else:
  cnt = set()
  for (key, value) in Counter(A).items():
    if key % 2 != 1 or value != 2:
      print(0)
      exit()

    cnt.add(key)

if len(cnt) != N // 2:
  print(0)
  exit()

print(2 ** len(cnt) % mod)

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

int main() {

    int N, M;
    cin >> N >> M;
    vector<vector<int>> jobs(M);  // day, price
    int a, b;
    for(int i=0;i<N;i++){
        cin >> a >> b;
        if(a-1 < M) {
            jobs.at(a - 1).push_back(b);
        }
    }
    priority_queue<int> prices;
    int total_price = 0;
    for(int i=0;i<M;i++){
        for(int j=0;j<jobs.at(i).size();j++){
            prices.push(jobs.at(i).at(j));
        }
        if(!prices.empty()){
            total_price += prices.top();
            prices.pop();
        }
    }
    cout << total_price << endl;
}

Measured memory_bytes: 5504
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        int maxA = 100000;
        int count[] = new int[maxA];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
            count[a[i]]++;
        }
        int kind = 0;
        int even = 0;
        for(int i=1;i<maxA;i++) {
            int c = count[i];
            if (c > 0) {
                kind++;
                if (c%2==0){
                    even++;
                }
            }
        }
        int answer;
        if (even%2==0){
            answer = kind;
        } else {
            answer = kind-1;
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 50272
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int MOD = 1000000000 + 7;

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

  int W, a, b;
  cin >> W >> a >> b;
  if(min(a,b) + W > max(a,b)){
    cout << 0 << endl;
  }else{
    cout << max(a,b) - min(a,b) - W << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)

int f(int a){
if(a%2==0)return a/2;
  else return 3*a+1;
}

int main(){
  int s,i=0;
  cin>>s;
  vector<int> v;
  v.push_back(s);
  while(1){
  v.push_back(f(v[i]));
    if(v[i]==4||v[i]==2||v[i]==1){cout<<i+4<<endl;break;}
    i++;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            int K = sc.nextInt();
            Map<Integer,Integer> map = new HashMap<>();

            for (int i = 0; i < N; i++) {
                int x = sc.nextInt();
                if (!map.containsKey(x)) {
                    map.put(x, 1);
                } else {
                    map.put(x, map.get(x) + 1);
                }
            }

            List<Integer> list = new ArrayList<>(map.values());
            Collections.sort(list);

            int ans = 0;

            for (int i = 0; i < list.size() - K; i++) {
                ans += list.get(i);
            }

            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 100944
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int dp[100005];

int main()
{
    int n, k; cin >> n >> k;
    vector<int> a;
    for(int i = 0; i <n; i++)
    {
        int x; cin >> x;
        a.push_back(x);
    }
    for(int i = 1; i < n; i++)
    {
        int m = 0;
        for(int j = max(i-k, 0); j < i; j++)
            if(j == max(i-k, 0)) m = dp[j] + abs(a[j]-a[i]);
            else m = min(m, dp[j] + abs(a[j]-a[i]));
        dp[i] = m;
    }
    cout << dp[n-1];
}

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

int main() {
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<ll> s(A + 1, -1e11), t(B + 1, -1e11);
  rep(i, A) cin >> s[i + 1];
  rep(i, B) cin >> t[i + 1];
  s.push_back(1e11);
  t.push_back(1e11);
  rep(i, Q) {
    ll x;
    cin >> x;
    int rs = lower_bound(s.begin(), s.end(), x) - s.begin();
    int rt = lower_bound(t.begin(), t.end(), x) - t.begin();
    ll rsd = s[rs] - x;
    ll rtd = t[rt] - x;
    ll lsd = x - s[rs - 1];
    ll ltd = x - t[rt - 1];
    ll dist = min(max(rsd, rtd), max(lsd, ltd));
    ll dist2 = min(rsd + ltd + min(rsd, ltd), rtd + lsd + min(rtd, lsd));
    cout << min(dist, dist2) << endl;
  }
  return 0;
}


Measured memory_bytes: 4448
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int p[N];
  for(int i=0; i<N ; i++){
    cin >> p[i];
  }
  sort(p,p+N);
  int ans =0;
  for(int i=0; i<K; i++){
    ans += p[i];
  }
  cout << ans << endl;
}

    


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

/*------------------------------------/
for library*/
template<typename T>
class TwoDimCumsum {
public:
    int H,W;
    vector<vector<T>> d;
    TwoDimCumsum(T _H, T _W):H(_H),W(_W),d(_H+1,vector<T>(_W+1,0)){}

    void add(int x, int y, int a){
        d[x][y]+= a;
    }
    void build(){
        for(int i = 1; i <= H; ++i){
            for(int j = 1; j <= W; ++j){
                d[i][j] += d[i-1][j];
                d[i][j] += d[i][j-1];
                d[i][j] -= d[i-1][j-1];
            }
        }
    }
    //[sx, gx] & [sy, gy]
    T query(int sx, int sy, int gx, int gy){
        return d[gx][gy] - d[sx-1][gy] - d[gx][sy-1] + d[sx-1][sy-1];
    }
    //confirm the 2d vector
    void debug(){
        for(int i = 0;i <= H;++i){
            for(int j = 0; j <= W; ++j){
                cerr<<d[i][j]<<((j == W) ? "\n":" ");
            }
        }
    }
};
/*
使い方
https://atcoder.jp/contests/abc106/submissions/9873594
1. インスタンス生成 縦横決める
TwoDimCumsum<int> Cumsum(H,W);
2. 座標に埋める
Cumsum.add(x, y, 1)
3. 二次元累積和計算
Cumsum.build()
4. 区間のクエリを受ける
Cumsumq.uery(p, q)
*/

/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N,M,Q;
    cin>>N>>M>>Q;
    TwoDimCumsum<int> d(N,N);
    rep(i,M){
        int l,r;
        cin>>l>>r;
        d.add(l,r,1);
    }
    d.build();
    while(Q--){
        int p,q;
        cin>>p>>q;
        cout<<d.query(p,p,q,q)<<endl;
    }
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXH 1000000001
#define MAXW 1000000007
#define INF 1000000007
#define MAXN 100001
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;


template<typename T>
T pow(T i, T n){
    T re;
    if(n == 0) return 1;
    re = pow(i, n / 2);
    if(n % 2 == 0){
        return re * re;
    }else{
        return i * re * re;
    }
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll N, x;
ll A[MAXN], B[MAXN] ;

string reverse_string(string s){
    string res;
    for(int i = 0;i < s.length();i++){
        res += s[s.length() - 1 - i];
    }
    return res;
}

int main(){
    string C[] = {
        "dream", "dreamer", "erase", "eraser"
    };

    string s;
    cin >> s;
    s = reverse_string(s);
    for(int i = 0;i < 4;i++){
        C[i] = reverse_string(C[i]);
    }

    bool flag;
    int pos = 0;
    while(pos != s.length()){
        flag = false;
        for(int j = 0;j < 4;j++){
            if(C[j] == s.substr(pos, C[j].length())){
                flag = true;
                pos += C[j].length();
                break;
            }
        }
        if(!flag){
            printf("NO\n");
            return 0;
        }
    }

    printf("YES\n");
    return 0;
}

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

int main()
{
	string oper;
	int n;
	priority_queue<int> Q;
	cin >> oper;
	while (oper!="end")
	{
		if (oper == "insert")
		{
			cin >> n;
			Q.push(n);
		}
		else if (!Q.empty()&&oper == "extract")
		{
			//n = Q.top();
			cout << Q.top() << endl;
			Q.pop();
		}
		cin >> oper ;
	}
}

Measured memory_bytes: 6936
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

internal class Program {
    static void Main() => CustomMain();

    static void Solve() {
        var n = ReadInt();
        WriteAnswer(800 * n - n / 15 * 200);
    }


    static void CustomMain() {
#if DEBUG
        // ファイルからテストケースを読み込む
        ChangeStdIn();
        // 時間計測
        var stopwatch = new Stopwatch();
        stopwatch.Start();
#endif
        // 出力高速化
        var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(streamWriter);
        // 回答
        Solve();
#if DEBUG
        stopwatch.Stop();
        Console.WriteLine(stopwatch.Elapsed);
#endif
        Console.Out.Flush();
    }

    static string ReadString() => Console.ReadLine().Trim();
    static int ReadInt() => int.Parse(ReadString());
    static long ReadLong() => long.Parse(ReadString());
    static float ReadFloat() => float.Parse(ReadString());
    static double ReadDouble => double.Parse(ReadString());

    static string[] ReadStringArray() => ReadString().Split(' ');
    static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
    static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
    static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
    static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

    static T TypeConversion<T>(string s) {
        if (typeof(T) == typeof(int)) {
            return (T) Convert.ChangeType(int.Parse(s), typeof(T));
        } else if (typeof(T) == typeof(long)) {
            return (T) Convert.ChangeType(long.Parse(s), typeof(T));
        } else if (typeof(T) == typeof(double)) {
            return (T) Convert.ChangeType(double.Parse(s), typeof(T));
        } else {
            return (T) Convert.ChangeType(s, typeof(T));
        }
    }

    static void ReadMulti<T, U>(out T a, out U b) {
        var str = ReadStringArray();
        a = TypeConversion<T>(str[0]);
        b = TypeConversion<U>(str[1]);
    }

    static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
        var str = ReadStringArray();
        a = TypeConversion<T>(str[0]);
        b = TypeConversion<U>(str[1]);
        c = TypeConversion<V>(str[2]);
    }

    static void WriteAnswer(object ans) => Console.WriteLine(ans);

    static bool IsOdd(long num) {
        return (num & 1) == 1;
    }

    static bool IsEven(long num) {
        return (num & 1) == 0;
    }

    static long GCD(long a, long b) {
        return b != 0 ? GCD(b, a % b) : a;
    }

    static long RoundUp(long a, long b) {
        return (a + b - 1) / b;
    }


    static void ChangeStdIn() {
        var path = "./../../TestCase.txt";
        var exStdIn = new System.IO.StreamReader(path);
        Console.SetIn(exStdIn);
    }
}

Measured memory_bytes: 11092
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


/*
* Problem : abc 160 - A
* Acknowledgement : None
* Author : deathnaught_
* GitHub : www.github.com/DeathNaughT-GitHub
* Complexity : O()
*/

// Bhid ki hahakar ke badle Sher ki ek dahad hai pyaare

public class Main
//public class Main
{

    public static void main(String[] args) 
    {
        FastReader sc = new FastReader();
        String s = sc.next();
        if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
            System.out.println("Yes");
        }
        else 
        System.out.println("No");
        
    }

    static class FastReader 
    { 

        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 

		boolean hasNext()
		{
		    return st == null ? false : true;
		}

        char nextChar()
        {
            return next().charAt(0);
        }
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];            
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];            
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    } 

}

Measured memory_bytes: 22100
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        h: [i64; n]
    }

    let mut dp = vec![1<<60; n];
    dp[0] = 0;
    for i in 0..n-1 {
        dp[i+1] = min(dp[i] + (h[i+1]-h[i]).abs(), dp[i+1]);
        if i != n-2 {
            dp[i+2] = min(dp[i] + (h[i+2]-h[i]).abs(), dp[i+2]);
        }
    }
    println!("{}", dp[n-1]);
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse2,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

const long long MOD = 998244353;

long long inv[10000005];
long long invFact[10000005];
long long fact[10000005];

long long powmod(long long a, long long b){
    long long x = 1;
    long long y = a;
    while(b){
        if(b&1){ x = (x*y)%MOD; }
        y = (y*y)%MOD;
        b >>= 1;
    }
    return x;
}

inline long long ncr(long long a, long long b){
    return fact[a]*((invFact[a-b]*invFact[b])%MOD)%MOD;
}

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

    inv[1] = 1;
    for(int i = 2; i <= N; i ++){
        inv[i] = inv[MOD%i]*(MOD-MOD/i)%MOD;
    }

    fact[0] = 1;
    invFact[0] = 1;
    for(int i = 1; i <= N; i ++){
        fact[i] = (fact[i-1]*i)%MOD;
        invFact[i] = (invFact[i-1]*inv[i])%MOD;
    }

    long long tempPow2 = 1;
    long long ans = 0;
    for(int i = N; i > (N>>1); i --){
        ans += tempPow2*ncr(N, i)%MOD;

        tempPow2 += tempPow2;
        if(tempPow2 >= MOD){tempPow2 -= MOD;}
    }
    //printf("ans(%d)=%lld\n", N, ans);
    ans = (ans+ans)%MOD;
    long long finalAns = (powmod(3, N)-ans+MOD)%MOD;

    printf("%lld", finalAns);
    return 0;
}


Measured memory_bytes: 234624
#include <stdio.h>

int left(int i) { return i*2; }
int right(int i) { return i*2+1; }

int H;

void maxHeapify(int *A, int i) {
    int l = left(i);
    int r = right(i);
    int largest;
    
    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= H && A[r] > A[largest]) largest = r;
    
    if(largest != i) {
        int tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        maxHeapify(A, largest);
    }
}

void buildMaxHeap(int *A) {
    for (int i=H/2; i>0; i--) {
        maxHeapify(A, i);
    }
}

int main() {
    scanf("%d", &H);
    int A[H*2+1];
    for (int i=0; i<=2*H; i++) A[i] = 0;
    for (int i=1; i<=H; i++) scanf("%d", &A[i]);
    
    buildMaxHeap(A);
    for (int i=1; i<=H; i++) printf(" %d", A[i]);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
	int w=0,i;
    char s[1000],b[10];
    scanf("%s",b);
	for(i=0;i<10;i++)b[i]=tolower(b[i]);
	while(1){
		scanf("%s",s);
		if(strcmp(s,"END_OF_TEXT") == 0)break;
		for(i=0;i<1000;i++)s[i]=tolower(s[i]);
		if(strcmp(s,b) == 0)w++;
	}
	printf("%d\n",w);
	return 0;
}

Measured memory_bytes: 552
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
aa = inpl()
MIN = min(aa)
MAX = max(aa)

if MAX-MIN > 1:
	print('No')
elif MAX == MIN:
	if MAX == N-1:
		print('Yes')
	elif MAX <= N//2:
		print('Yes')
	else:
		print('No')
else: #MAX-MIN == 1
	n_MIN = n_MAX = 0
	for a in aa:
		if a == MIN: n_MIN += 1
		if a == MAX: n_MAX += 1
	x_min = n_MIN + 1
	x_max = n_MIN + n_MAX//2
	if x_min <= MAX <= x_max:
		print('Yes')
	else:
		print('No')


Measured memory_bytes: 15596
//08
#include<iostream>
#include<algorithm>

using namespace std;

struct T{
  int i,u,a,p;
  T(){}
  T(int ii,int uu,int aa,int pp){
    i=ii;
    u=uu;
    a=aa;
    p=pp;
  }
  bool operator<(T x)const{
    if(a!=x.a){
      return a>x.a;
    }else if(p!=x.p){
      return p<x.p;
    }else{
      return i<x.i;
    }
  }
};

int main(){
  for(int n;cin>>n,n;){
    T team[300];
    for(int j=0;j<n;j++){
      int i,u,a,p;
      cin>>i>>u>>a>>p;
      team[j]=T(i,u,a,p);
    }
    sort(team,team+n);
    int ci[1001]={};
    for(int i=0,c=0;i<n&&c<26;i++){
      if(ci[team[i].u]<(c<10)+(c<20)+(c<26)){
	cout<<team[i].i<<endl;
	ci[team[i].u]++;
	c++;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1172
#include <stdio.h>

int main()
{
    int n,x,t,a,b,c;
    scanf("%d%d%d",&n,&x,&t);
    a=n/x;
    b=n%x;
    if(b > 0)
    {
        a++;
    }
    c=a*t;
    printf("%d",c);
    return 0;
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N, K; cin >> N >> K;
    vector<int> a(N);
    REP(i,N) cin >> a[i];
    vector<vector<bool>> dp1(N+1,vector<bool>(K,false)), dp2(N+1,vector<bool>(K,false));
    vector<vector<int>> v1(N+1),v2(N+1);
    // dp1[i][j] 1番目からi番目までのカードを使ってjをつくることができるかどうか
    // dp2[i][j] N-i+1番目からN番目までのカードを使ってjをつくることができるかどうか
    dp1[0][0] = true; v1[0].push_back(0);
    dp2[0][0] = true; v2[0].push_back(0);
    REP(i,N)REP(j,K){
        if(a[i]>j) {
            dp1[i+1][j] = dp1[i][j];
            if(dp1[i+1][j])v1[i+1].push_back(j);
        }
        else {
            dp1[i+1][j] = (dp1[i][j] || dp1[i][j-a[i]]);
            if(dp1[i+1][j])v1[i+1].push_back(j);
        }
        if(a[N-i-1]>j) {
            dp2[i+1][j] = dp2[i][j];
            if(dp2[i+1][j])v2[i+1].push_back(j);
        }
        else {
            dp2[i+1][j] = (dp2[i][j] || dp2[i][j-a[N-i-1]]);
            if(dp2[i+1][j])v2[i+1].push_back(j);
        }
    }
    int cnt = 0;
    FOR(i,1,N+1){
        bool flag = false;
        for(auto x:v1[i-1]){
          	int ind = lower_bound(all(v2[N-i]),K-a[i-1]-x)-v2[N-i].begin();
            if(ind != v2[N-i].size() && v2[N-i][ind] <K-x) {flag = true;break;}
        }
        if(!flag) cnt ++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 239744
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;

class bilist{
	long a[2000001];
	long L, R;
public:
	bilist(){ L = 0, R = -1; }
	long size(){
		return R - L + 1;
	}
	void insert(long x){
		a[++R] = x;
	}
	void deleteFirst(){
		while (L<R && a[R] == -1) --R;
		a[R--] = -1;
		while (L<R && a[R] == -1) --R;
	}
	void deleteLast(){
		while (L<R && a[L] == -1) ++L;
		a[L++] = -1;
		while (L<R && a[L] == -1) ++L;
	}
	void del(long x){
		long ite = R;
		for (; ite >= L; --ite){
			if (a[ite] == x){
				a[ite] = -1; return;
			}
		}
		if (ite < L) return;
	}
	void print(){
		bool Top = true;
		for (long i = R; i >= L; --i){
			if (a[i] == -1) continue;
			if (!Top) cout << ' ';
			Top = false;
			cout << a[i];
		}
		cout << '\n';
	}
};

bilist blist;
int main(){
	long n; scanf("%ld",&n);
	while (n--){
		char tmp[20]; scanf("%s",&tmp);
		string a; a = tmp;
		if (a == "insert" || a == "delete"){
			long b; scanf("%ld", &b);
			if (a == "insert"){
				blist.insert(b);
			}
			else{
				blist.del(b);
			}
		}
		else if (a == "deleteFirst"){
			blist.deleteFirst();
		}
		else if (a == "deleteLast"){
			blist.deleteLast();
		}
		//blist.print();
	}
	blist.print();
}

Measured memory_bytes: 9416
n=int(input())
a=list(map(int,input().split()))
even=[]
for i in range (0,n,2):
    even.append(a[i])
odd=[]
for i in range (1,n,2):
    odd.append(a[i])
if n%2==0:
    ans=odd[::-1]+even
else:
    ans=even[::-1]+odd
print (' '.join(map(str,ans)))

Measured memory_bytes: 31476
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

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

  return 0;
}




Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  priority_queue<int> que;
  rep(i, n){
    int a; cin >> a;
    que.push(a);
  }
  ll ans = 0;
  rep(i, m){
    int num = que.top();
    que.pop();
    que.push(num >> 1);
  }
  rep(i, n){
    ll num = que.top();
    que.pop();
    ans += num;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3864
import java.util.*;

class Edge {
    public int v;
    public int A;
    public int B;

    public Edge(int v, int a, int b) {
        this.v = v;
        A = a;
        B = b;
    }
}

class Node implements Comparable<Node> {
    public int u;
    public int coin;
    public long time;

    public Node(int u, int coin, long time) {
        this.u = u;
        this.coin = coin;
        this.time = time;
    }

    @Override
    public int compareTo(Node node) {
        return Long.compare(time, node.time);
    }
}

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    private void solve() {
        int N = sc.nextInt();
        int M = sc.nextInt();
        int S = sc.nextInt();

        List<List<Edge>> adj = new ArrayList<>();
        for (int i = 0; i < N + 1; ++i) {
            adj.add(new ArrayList<>());
        }
        for (int i = 0; i < M; ++i) {
            int u = sc.nextInt();
            int v = sc.nextInt();
            int A = sc.nextInt();
            int B = sc.nextInt();
            adj.get(u).add(new Edge(v, A, B));
            adj.get(v).add(new Edge(u, A, B));
        }

        int[] c = new int[N + 1];
        int[] d = new int[N + 1];

        for (int i = 1; i <= N; ++i) {
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }

        final int MAX_COIN = 50 * N;
        S = Math.min(S, MAX_COIN);
        Queue<Node> q = new PriorityQueue<>();
        q.add(new Node(1, S, 0));

        boolean[][] visit = new boolean[N + 1][MAX_COIN + 1];
        long[] ans = new long[N + 1];
        Arrays.fill(ans, Long.MAX_VALUE);
        while (!q.isEmpty()) {
            Node node = q.poll();
            if (visit[node.u][node.coin]) {
                continue;
            }
            visit[node.u][node.coin] = true;
            ans[node.u] = Math.min(ans[node.u], node.time);

            for (Edge e : adj.get(node.u)) {
                int coin = node.coin - e.A;
                if (coin >= 0) {
                    q.add(new Node(e.v, coin, node.time + e.B));
                }
            }

            int coin = Math.min(MAX_COIN, node.coin + c[node.u]);
            q.add(new Node(node.u, coin,node.time + d[node.u]));
        }

        for (int i = 2; i <= N; ++i) {
            System.out.println(ans[i]);
        }
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}


Measured memory_bytes: 64916
s=int(input())

l=[s]*(10**6)
for i in range(10**6):
    if l[i]%2==0:
        l[i+1]=l[i]//2
    else:
        l[i+1]=3*l[i]+1
    if l[i]==4:
        print(i+4)
        exit()
    if l[i]==1:
        print(i+4)
        exit()
    if l[i]==2:
        print(i+4)
        exit()


Measured memory_bytes: 46192
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
//#define pop pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846 
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGE
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    ll n,k;
    cin>>n>>k;
    ll r=n%k;
    ll ans=min(r,k-r);
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

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

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

    cout << ans << endl;

    return 0;
}

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

typedef long long 			ll;
typedef unsigned long long 	ull;

const int N = 2e5 + 20;

ll a[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	ll n, cnt = 0;
	cin >> n;
	while (n > 1) {
		cnt++;
		n /= 2;
	}
	cout << (ll)pow(2, ++cnt) - 1 << endl;
	return 0;
}


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


using namespace std;

int main() {


int long long n,k=0,sum=0;
    cin>>n;
    long long arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<n-1;i++)
    {
        if(arr[i]>=arr[i+1])
        {
            k++;
           
          sum = max(sum,k);
            
        }
        else
        {
            k=0;
        }
    }
    cout<<sum;


    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;

//2019 A
int main(void) {
	ll m, d;
	cin >> m >> d;
	ll ans = 0;
	rep(i, 4, m + 1) {
		for (ll j = 2; j * 10 < d; j++) {
			rep(k, 2, 10) {
				if (j * 10 + k > d) break;
				if (i == j * k) ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int fib(int n){
  int f[n+1];
  int i;
  f[0] = 1;
  f[1] = 1;
  for(i = 2; i <= n; i++){
    f[i] = f[i-2] + f[i-1];
  }
  return f[n];
}
  

int main(){
  int n, f;

  scanf("%d", &n);

  f = fib(n);

  printf("%d\n", f);

  return 0;
}



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

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

    LL ans = 0;

    LL x = min(a, c);
    ans += x;
    a -= x;
    c -= x;

    x = min(b, c);
    ans += 2*x;
    b -= x;
    c -= x;

    ans += b;
    ans += c > 0;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/****************************************************************************************************
                                        SUBMITTED BY-

                                               aish_07

****************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define sl set<ll>
#define vs vector<string>
#define pb push_back
#define vl vector<ll>
#define vi vector<int>
#define PI  3.14159265
#define mod 998244353
int main()
{
    float t,x;
    cin>>t>>x;

    printf("%0.9f\n",t/x);
    return 0;
}


Measured memory_bytes: 3724
n = int(input())
a = [int(x) for x in input().split()]

cnt_4 = 0
cnt_2 = 0
cnt_n = 0
for x in a:
    if x % 4 == 0:
        cnt_4 += 1
    elif x % 2 == 0:
        cnt_2 += 1
    else:
        cnt_n += 1

res = 'No'
if cnt_2:
    if cnt_4 >= cnt_n:
        res = 'Yes'
else:
    if cnt_4 >= cnt_n - 1:
        res = 'Yes'

print(res)


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

int main() {

  string S;
  cin >> S;
  string ans="Yes";

  for(int i=0; i<S.size(); i++) {
    if ((i % 2 == 0) && (S.at(i) == 'L')) {
      ans = "No";
      break;
    }
    else if ((i % 2 == 1) && (S.at(i) == 'R')) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;        
 
}


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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO;
	
	int x, n;
	cin >> x >> n;
	set<int> ar;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		ar.insert(a);
	}
	if (n == 0) {
		cout << x;
		return 0;
	}
	pair<int, int> sm = {-1, -1};
	for (int i = x; i >= 0; --i) {
		if (!ar.count(i)) {
			sm.first = abs(x - i);
			sm.second = i;
			break;
		}
	}
	
	for (int i = x; true; ++i) {
		if (!ar.count(i)) {
			if (abs(x-i) < sm.first) {
				sm.second = i;
			}
			break;
		}
	}
	
	cout << sm.second;
}	


Measured memory_bytes: 3616
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    else:
        ans = 0
        for i in range(1, n+1, 1):
            for j in range(2, n+1, 1):
                for k in range(3, n+1, 1):
                    if i+j+k == x and i < j < k:
                         ans += 1
    print(ans)


Measured memory_bytes: 5592
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    x , y =f()

    cnt = 0
    while x<=y:
        x *= 2
        cnt += 1
    
    print(cnt)

solve()


Measured memory_bytes: 2940
n = input()
honlist = ['2', '4', '5', '7', '9']
ponlist = ['0', '1', '6', '8']
bonlist = ['3']
if len(n) <= 3:
    if n[len(n) - 1] in honlist:
        print("hon")
    elif n[len(n) - 1] in ponlist:
        print("pon")
    else:
        print("bon")
else:
    print()


Measured memory_bytes: 9116
n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key=lambda x: x[1], reverse=True)
num = 0
kind = set()
changable = []
for i in range(k):
	num += sushi[i][1]
	if sushi[i][0] in kind:
		changable.append(sushi[i][1])
	else:
		kind.add(sushi[i][0])

num += len(kind)**2
ans = num

for i in range(k, n):
	if not changable:
		break

	if sushi[i][0] not in kind:
		num += sushi[i][1] + 2*len(kind)+1 - changable.pop()
		kind.add(sushi[i][0])
		ans = max(ans, num)

print(ans)

Measured memory_bytes: 30140