akhauriyash/Code-Regression huggingface dataset:
/*
	author: Ibrahim-Elsayed (Codeforces Handle)
	date: 8/28/2020
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
const double PI = acos(-1);
const int MOD = 1000000007;

const int mxN = 1e5;
int n, k;
int dp[mxN+1];
int arr[mxN+1];

int go(int i) { // min cost starting from stone i to reach stone n;
	if(i == n) {
		return 0;
	}
	if(i > n) {
		return int(1000000026);
	}
	if(dp[i] != -1) {
		return dp[i];
	}
	int ans = 1000000025;
	for(int kk = 1; kk <= k; kk++) {
		if(i+kk <= n) ans = min(ans, go(i+kk)+abs(arr[i] - arr[i+kk]));
	}
	return dp[i] = ans;
}

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

	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> arr[i];
	memset(dp, -1, sizeof(dp));
	cout << go(1);

	return 0;
}


Measured memory_bytes: 12192
#include<bits/stdc++.h>
using namespace std;
#define N 3333
#define mod 1000000007

int n,m,a[N],r[N],f[N][N];
char s[N];

void pls(int &x,int y){x=(x+y)%mod;}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();m=read();scanf(" %s",s+1);
	for (int i=1;i<=n;i++)
		a[i]=a[i-1]+(s[i]=='1');
	for (int i=1;i<=m;i++){
		int x=read(),y=read();
		r[x]=max(r[x],y);
	}
	for (int i=1;i<=n;i++)
		r[i]=max(max(r[i-1],r[i]),i);
	f[0][0]=1;
	for (int i=0;i<n;i++)
		for (int j=0;j<=n;j++){
			if (j+a[r[i+1]]-a[r[i]]) pls(f[i+1][j+a[r[i+1]]-a[r[i]]-1],f[i][j]);
			if (r[i+1]-i-j-a[r[i+1]]+a[r[i]]) pls(f[i+1][j+a[r[i+1]]-a[r[i]]],f[i][j]);
		}
	printf("%d\n",(f[n][0]+mod)%mod);
	return 0;
}

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

int main()
{
    int a,b,k;
    cin >> a >> b >> k;
    if(b - a + 1 < 2 * k){
        for(int i = a; i <= b; i++){
            cout << i << endl;
        }
    }else{
        for(int i = a; i < a + k; i++){
            cout << i << endl;
        }
        for(int i = b - k + 1; i <= b; i++){
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define _start  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb 		push_back
#define ss 		second
#define ff 		first
#define ll		long long
#define int     long long
#define mk      make_pair
#define ld 		long double
#define vi 		vector<int>
#define pi		pair<int,int>
#define mod 	1000000007
#define pqg     priority_queue<int>
#define pqs     priority_queue<int,vi,greater<int> >
#define forn(n) for(int i=0;i<n;i++)
#define w(t) 	int t; cin>>t; while(t--)
#define kick(t) int t; cin>>t; for(int p=0;p<t;p++)
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> oset;
ll powmod(ll base,ll exp,ll MOD=mod){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}

int32_t main(){
    _start

    int x,k,d;
    cin>>x>>k>>d;

    x=abs(x);
    int temp=x/d;
    if(temp>=k){
        x-=(k*d);
        k=0;
    } else {
        x-=(temp*d);
        k-=temp;
    }
    if(!k)
        cout<<x<<endl;
    else {
        if(k%2==0){
            cout<<x<<endl;
        } else {
            cout<<min(x+d,abs(x-d))<<endl;
        }
    }
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] m = new int[n];
		int count = 0;

		for (int i = 0; i < n; i++) {
			m[i] = sc.nextInt();
			x -= m[i];
		}

		Arrays.sort(m);

		count = x / m[0];

		System.out.println(count + n);
	}
}

Measured memory_bytes: 21588
import sys
n = map(int, sys.stdin.readline().split())
a = sys.stdin.readline().strip()
res = a
h = 0
for i in range (len(a)):
  if a[i] == '(':
    h += 1
  else:
    h -= 1
  if h < 0:
    res = '(' + res
    h = 0

print res + ')' * h





Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define endl '\n'
#define ll long long
int main()
{
    Hello
    int n;
    ll k;
    cin >> n >> k;
    int arr[n + 5];
    for(int i = 1; i <= n; i++)
        cin >> arr[i];
    int lst = -1, cur = 1;
    vector<int> all, first, second;
    map<int, bool> vis;
    while(true){
        if(vis[cur] == true){
            lst = cur;
            break;
        }
        else{
            vis[cur] = true;
            all.push_back(cur);
            cur = arr[cur];
        }
    }
    for(int i = 0; i < all.size(); i++){
        if(all[i] == lst){
            second.push_back(all[i]);
            continue;
        }
        if(second.size()) second.push_back(all[i]);
        else first.push_back(all[i]);
    }
    if(k < first.size()) cout << first[k];
    else{
        k -= first.size();
        cout << second[k % ((int)(second.size()))];
    }
    return 0;
}

Measured memory_bytes: 15440
import java.util.*;

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

        int N = sc.nextInt();
        int M = sc.nextInt();

        double ans = (1900 * M + 100 * (N - M)) * Math.pow(2.0, M);

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

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

using namespace std;

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

const int N = 2e5 + 5;
const int INF = 1e7;

int n,a[N],b[N],tree[N * 4];
ll ans;

int init(int ind,int l,int r) {
  if (l == r)
     return tree[ind] = a[l];
  int mid = (l + r) / 2;
  return tree[ind] = min(init(ind + ind,l,mid),init(ind + ind + 1,mid + 1,r));
}

int query(int ind,int l,int r,int lw,int rw) {
  if (l > rw || r < lw)
    return INF;
  if (l >= lw && r <= rw)
    return tree[ind];
  int mid = (l + r) / 2;
  return min(query(ind + ind,l,mid,lw,rw),query(ind + ind + 1,mid + 1,r,lw,rw));
}

void solve(int l,int r) {
  if (l > r)
    return;
  int mn = b[query(1,1,n,l,r)];
  ans += (ll) a[mn] * (mn - l + 1) * (r - mn + 1);
  solve(l,mn - 1);
  solve(mn + 1,r);
}

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

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

  init(1,1,n);

  solve(1,n);

  cout << ans << endl;

}

Measured memory_bytes: 11136
#include <stdio.h>

int main(void)
{
	int n;
	
	scanf("%d",&n);
	
	int d[200];
	
	for(int i=0;i<n;i++){
		scanf("%d",&(d[i]));
	}
	
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(d[i]==d[j]){
				d[j]=0;
			}
		}
	}
	
	int count=0;
	
	for(int i=0;i<n;i++){
		if(d[i]!=0){
			count++;
		}
	}
	
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            WriteLine(a - b < 0 ? 0 : a - b);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11220
import java.util.Scanner;
import java.util.Arrays;

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

        while (true) {
            int n = sc.nextInt();
            int r = sc.nextInt();
            if (n + r == 0) {
                break;
            }
            int[] rem = new int[n];
            for (int i=0; i<rem.length; ++i) {
                rem[i] = i+1;
            }

            for (int i=0; i<r; ++i) {
                int p = sc.nextInt();
                int c = sc.nextInt();
                int[] blue = Arrays.copyOfRange(rem, n-p+1, rem.length);
                int[] yellow = Arrays.copyOfRange(rem, n-p+1-c, n-p+1);
                int[] black = Arrays.copyOfRange(rem, 0, n-p+1-c);
                for (int v=0; v<black.length; ++v) {
                    rem[v] = black[v];
                }
                for (int v=black.length; v<black.length+blue.length; ++v) {
                    rem[v] = blue[v-black.length];
                }
                for (int v=black.length+blue.length; v<black.length+blue.length+yellow.length; ++v) {
                    rem[v] = yellow[v-black.length-blue.length];
                }
            }
            System.out.println(rem[rem.length-1]);
        }
        sc.close();
    }
}



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

int main()
{
    int H, N;
    cin >> H >> N;
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        sum += a;
    }
    if (H <= sum)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;

const int N = 205;
typedef long long ll;

struct Edge {
	int to, next, c;
	ll w;
} e[N<<1];
struct node {
	int pos, res;
	ll len;
	bool operator <(const node& x) const {
		return x.len < len;
	}
};
priority_queue <node> q;
int n, m, s, cnt, first[N], maxt;
ll dis[N][5005], c[N], d[N], ans[N];


void add(int u, int v, int c, ll w) {
	e[++cnt] = (Edge) {v, first[u], c, w};
	first[u] = cnt;
}

int calc(int x) {
	return min(x, maxt);
}

void Dijkstra() {
	memset(dis, 0x7f, sizeof(dis));
	dis[1][calc(s)] = 0;
	q.push((node) {1, calc(s), 0});
	while(!q.empty()) {
		node tem = q.top();
		q.pop();
		int u = tem.pos, res = tem.res;
		ll len = tem.len;
		if(len != dis[u][res]) continue;
		for(int i = 1; i; i++) {
			int now = calc(res + i*c[u]);
			ll k = i*d[u] + len;		
			if(dis[u][now] > k) {
				dis[u][now] = k;
				q.push((node) {u, now, k});
			}	
			if(now == maxt) break;
		}
		for(int i = first[u]; i; i = e[i].next) {
			int v = e[i].to;
			ll k = len + e[i].w;
			if(res < e[i].c) continue;
		    if(dis[v][res - e[i].c] > k) {
				dis[v][res - e[i].c] = k;
				q.push((node) {v, res - e[i].c, k});
			}
		}
	}
	memset(ans, 0x7f, sizeof(ans));
	for(int i = 2; i <= n; i++)
		for(int j = 0; j <= maxt; j++)
			ans[i] = min(ans[i], dis[i][j]);
}

int main() {
	cin>>n>>m>>s;
	for(int i = 1; i <= m; i++) {
		int u, v, x;
		ll y;
		cin>>u>>v>>x>>y;
		add(u, v, x, y);
		add(v, u, x, y);
		maxt = max(maxt, x);
	}
	maxt = maxt*(n + 1);
	for(int i = 1; i <= n; i++) 
		cin>>c[i]>>d[i];
	Dijkstra();
	for(int i = 2; i <= n; i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 44212
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU
import Data.List (sortBy)

main :: IO ()
main = do
  (n : m : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- VU.fromList . sortBy (flip compare) . map unsafeTextToInt . T.words <$> T.getLine :: IO (VU.Vector Int)
  let
    a0 = as VU.! 0 :: Int
    countAndSumGE :: Int -> (Int, Int)
    countAndSumGE k = fst . VU.foldr step ((0, 0), (0, 0)) $ as
      where
        step :: Int -> ((Int, Int), (Int, Int)) -> ((Int, Int), (Int, Int))
        step x = update
          where
            update :: ((Int, Int), (Int, Int)) -> ((Int, Int), (Int, Int))
            update ((c, s), (d, t)) = ((c', s'), (d', t'))
              where
                (d', t') = until p f (d, t)
                c' = c + d'
                s' = s + x * d' + t'
            p :: (Int, Int) -> Bool
            p = ((||) <$> (== n) <*> (< k - x) . (as VU.!)) . fst
    f :: (Int, Int) -> (Int, Int)
    f = (,) <$> succ . fst <*> ((+) <$> snd <*> (as VU.!) . fst)
    countGE :: Int -> Int
    countGE k = fst . VU.foldr step (0, 0) $ as
      where
        step x (c, l) = (c', l')
          where
            l' = until ((||) <$> (== n) <*> (< k - x) . (as VU.!)) succ l
            c' = c + l'
    k = unsafeBinaryMaxInt ((m <=) . countGE) (2, 2 * a0) :: Int
    (c, s) = countAndSumGE (succ k)
  print $ s + k * (m - c)

unsafeBinaryMaxInt :: (Int -> Bool) -> (Int, Int) -> Int
unsafeBinaryMaxInt p = check
  where
    check :: (Int, Int) -> Int
    check ij@(i, j) | p j       = j
                    | otherwise = search ij
    search :: (Int, Int) -> Int
    search = fst . until ((==) <$> succ . fst <*> snd) halve
      where
        halve (i, j) | p m       = (m, j)
                     | otherwise = (i, m)
          where
            m = (i + j) `div` 2

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 51580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
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; }

int main () {
  int n = in();
  int ma = 0;
  int sum = 0;
  rep(i,n) {
    int p = in();
    chmax(ma, p);
    sum += p;
  }
  int ans = ma/2 + sum-ma;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
N = 1000

#逆元テーブル
inv_t = [0]+[1]
for i in range(2, N):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]

#階乗計算
kai = [1, 1]
rev_kai = [1, inv_t[1]]
for i in range(2, N):
	kai.append(kai[-1] * i % mod)
	rev_kai.append(rev_kai[-1] * inv_t[i] % mod)

# コンビネーション計算
def cmb(n, r):
	return kai[n] * rev_kai[r] * rev_kai[n-r] % mod

tmp1 = 0
tmp2 = 0
mod = 10 ** 9 + 7
for ai in a:
    tmp1 += (ai ** 2) % mod
    tmp1 %= mod
    tmp2 += ai
    tmp2 %= mod

print((tmp2 ** 2 - tmp1) * inv_t[2] % mod)


Measured memory_bytes: 94152
n = int(input())
h = list(map(int, input().split()))

if n == 1:
    print("Yes")
else:
    for i in range(n-1):
        if h[i] > h[i+1]:
            print("No")
            exit()
        elif h[i] == h[i+1]:
            pass
        else:
            h[i+1] -= 1

    print("Yes")

Measured memory_bytes: 15020
// ~/atcoder/format/example.C
// g++ -g example.C -std=gnu++11 -pthread
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;

const ll mod = 1e9 + 7;

int main(int argc, char* argv[])
{
  ll N, M;
  ll mul;
  std::cin >> N >> M;


  if (N == M) {
    mul =  2;
  } else if (std::fabs(N - M) == 1) {
    mul =  1;
  } else {
    mul =  0;
  }

  // 順列を求める
  ll ans = 1;
  for (ll i = 1; i <= N; i++) {
    ans = (ans * i) % mod;
  }
  for (ll i = 1; i <= M; i++) {
    ans = (ans * i) % mod;
  }

  std::cout << (ans * mul) % mod << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<fstream>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
ll D;
ll c[26];
ll s[366][26];
ll t[366];

ll total_max_score;
ll ft[366];

//スコア計算
ll score(ll days){
	ll ans=0;
	ll last[26];
	rep(i,26)last[i]=0;
	for(ll d=1;d<=days;d++){
		ans+=s[d][t[d]];
		last[t[d]]=d;
		rep(i,26){
			ans-=c[i]*(d-last[i]);
		}
	}
	return ans;
}

ll whole_score;
ll score_typ[26];
void recalc(ll i){
	ll ans=0;
	ll last=0;
	for(ll d=1;d<=D;d++){
		if(t[d]==i){
			ans+=s[d][i];
			last=d;
		}
		ans-=c[i]*(d-last);
	}
	whole_score-=score_typ[i];
	score_typ[i]=ans;
	whole_score+=score_typ[i];
}
void change(ll d,ll q){
	ll b=t[d];
	t[d]=q;
	recalc(b);
	recalc(q);
	if(whole_score>total_max_score){
		total_max_score=whole_score;
		for(ll d=1;d<=D;d++){
			ft[d]=t[d];	
		}
	}
}
void init_score(){
	total_max_score=-1e17;
	whole_score=0;
	rep(i,26){
		score_typ[i]=0;
		recalc(i);
	}
}

//貪欲法
void greedy(){
	for(ll d=1;d<=D;d++){
		ll ma=-1e17,pt=0;
		rep(i,26){
			t[d]=i;
			ll res=score(d);
			if(ma<res){
				ma=res;
				pt=i;
			}
		}
		t[d]=pt;
	}
}

//日程を√cに応じて分配
void distribute(){
	vector<ll> v;
	rep(i,26){
		for(ll x=1;x*x<=c[i];x++){
			v.push_back(x);
		}
	}
	for(ll d=1;d<=D;d++){
		t[d]=v[rand()%(ll)v.size()];
	}
}

//局所探索_改
void local_search(){
	rep(u,50000){//日付を一つ選んで、コンテストを変更
		ll d=rand()%D+1;
		ll q=rand()%26;
		ll b=t[d];
		ll bef_score=whole_score;
		change(d,q);
		ll aft_score=whole_score;
		if(bef_score>aft_score){
			change(d,b);
		}
	}
	rep(u,50000){//日付を二つ選んで、コンテストをswap
		ll bef_score=whole_score;
		ll d1,d2;
		ll k=8;
		d1=rand()%(D-k)+1;
		d2=rand()%k+1+d1;
		ll p=t[d1],q=t[d2];
		change(d1,q);
		change(d2,p);
		ll aft_score=whole_score;
		if(bef_score>aft_score){
			change(d1,p);
			change(d2,q);
		}
	}
}


int main(){
	//ifstream ifs("input.txt");
	cin>>D;
	rep(i,26)cin>>c[i];
	for(ll d=1;d<=D;d++)rep(j,26)cin>>s[d][j];
	greedy();
	//distribute();
	init_score();
	local_search();
	//ofstream ofs("output.txt");
	for(ll d=1;d<=D;d++){
		cout<<ft[d]+1<<"\n";
	}
}


Measured memory_bytes: 3704
n=int(input())
a=[[0 for i in range(13)]for j in range(4)]
cnt=0
pattern=["S","H","C","D"]


while True:
    u,v=input().split()
    a[pattern.index(u)][int(v)-1]=1
    cnt+=1
    if cnt==n:
        break

for i in range(4):
    for j in range(13):
        if a[i][j]==0:
            print(pattern[i], j+1)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
int N,M,P,Y;
int tmp=1,counter=1;
//int ans[10010]={};

int main(){
  cin >> N >> M;
  pair<int,int> ans[M];
  //pair<pair<int,int>,int> a[10010];
  tuple<int,int,int> a[M];
  //tuple<int,int,int> ans[10010];
  for(int i=0;i<M;i++){
    //cin >> a[i].first >> a[i].second;
    cin >> P >> Y;
    a[i]=make_tuple(P,Y,i);
  }
  sort(a,a+M);
  for(int i=0;i<M;i++){
    if(get<0>(a[i])==counter){
      ans[get<2>(a[i])]=make_pair(counter,tmp);
      tmp++;
    }
    else{
      counter=get<0>(a[i]);
      tmp=1;
      ans[get<2>(a[i])]=make_pair(counter,tmp);
      tmp++;
    }
  }
  /*for(int i=0;i<M;i++){
  if(get<0>(a[i])==counter){

  get<0>(ans[i]) = get<2>(a[i]);
  get<1>(ans[i]) = counter;
  get<2>(ans[i]) = tmp;
  /*printf("%06d", counter); // "0012"（ゼロ埋め）
  printf("%06d\n", tmp);
  tmp++;
}
else{
counter=get<0>(a[i]);
tmp=1;

get<0>(ans[i]) = get<2>(a[i]);
get<1>(ans[i]) = counter;
get<2>(ans[i]) = tmp;
/*printf("%06d", counter); // "0012"（ゼロ埋め）
printf("%06d\n", tmp);
tmp++;
}
}*/
//sort(ans,ans+M);
for(int i=0;i<M;i++){
  printf("%06d", ans[i].first); // "0012"（ゼロ埋め）
  printf("%06d\n", ans[i].second);
}
return 0;
//cout << a[i].first << " " << a[i].second << endl;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int ans=n+1;
  int x[k];
  memset(x,0,sizeof(x));
  int cnt=0;
  int l=0;
  for(int i=0;i<n;i++){
    //cout<<i<<" "<<a[i]<<":"<<cnt<<endl;
    a[i]--;
    if(a[i]>=k) continue;
    x[a[i]]++;
    if(x[a[i]]==1) cnt++;
    while(cnt==k){
      if(a[l]>=k){
	l++;
	continue;
      }
      ans=min(ans,i-l+1);
      x[a[l]]--;
      if(x[a[l]]==0) cnt--;
      l++;
    }
  }
  if(ans>n) ans=0;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  int H, W, N;
  cin >> H >> W >> N;

  vector<int> min_reachable(W);
  vector<VI> cells_col(W);

  for (int i = 0; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    cells_col[y].PB(x);
  }

  for (int i = 0; i < W; ++i)
    sort(ALL(cells_col[i]));

  int answer = H;
  if (!cells_col[0].empty())
    mini(answer, cells_col[0][0]);

  min_reachable[0] = 0;
  for (int c = 1; c < W; ++c) {
    min_reachable[c] = min(H, min_reachable[c - 1] + 1);
    auto iter = lower_bound(ALL(cells_col[c]), min_reachable[c]);
    while (iter != cells_col[c].end() && *iter == min_reachable[c]) {
      ++min_reachable[c];
      ++iter;
    }

    const int top = iter == cells_col[c].end() ? H : *iter;
    mini(answer, top);
    debug(c, min_reachable[c], top);
  }

  cout << answer << "\n";
}



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

int main() {
  int H,W;
  cin >> H >> W;
  string S;
  string T;
  for (int i=0; i < W+2; i++){
    S.push_back('#');
  }
  cout << S << endl;
  for (int i=0; i<H; i++){
    cin >> T;
    cout << '#' << T << '#'<<endl;
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    ans = 0
    s = list(accumulate(a[::-1]))[::-1][1:]
    for i in range(n-1):
        ans += a[i]*s[i]%mod
        ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 115684
n = int(input())
x = [0] * n
u = [0] * n
for i in range(n):
  x[i], u[i] =input().split()
u=[s.replace("JPY","1") for s in u]
u=[s.replace("BTC","380000") for s in u]
s=0
for i in range(n):
  s=s+float(x[i])*int(u[i])
print(s)

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

const int MX=100005;

int main(){
  int n;
  cin>>n;
  vector<ll> cnt(MX);//{0,0,...,0}が初期値
  rep(i,n){
    int a;
    cin>>a;
    cnt[a]++;
  }
  ll tot=0;
  rep(i,MX) tot+=i*cnt[i];

  int q;
  cin>>q;
  rep(i,q){
    int b,c;
    cin>>b>>c;
    tot-=b*cnt[b];
    tot-=c*cnt[c];
    cnt[c]+=cnt[b];cnt[b]=0;
    tot+=b*cnt[b];
    tot+=c*cnt[c];
    cout<<tot<<endl;
  }
}

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

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<int> a(n);
    vector<int> b(m);
    ll t=0;
    rep(i,n) cin>>a[i];
    rep(i,m){
        cin>>b[i];
        t+=b[i];
    }
    int ans=0;
    int j=m;
    rep(i,n+1){
        while(j>0 && t>k){
            j--;
            t-=b[j];
        }
        if(t>k) break;
        ans=max(ans,i+j);
        if(i==n) break;
        t+=a[i];
    }
    
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 4800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  ll n,k,x,y;cin>>n>>k>>x>>y;
  ll ans=min(n,k)*x+max(0LL,n-k)*y;
  cout<<ans<<endl;
  return 0;
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<ll ,ll >
#define vi          vector<ll int>
#define vii         vector<pii>
#define mi          map<ll int,ll int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007 
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define take        rep(i,0,n) cin>>v[i];
#define MAXN        2000005

using namespace std;


void solve()
{
	ll n,k;
	cin>>n>>k;
	vi v(n);
	for(ll i=0;i<n;i++)
	{
		cin>>v[i];
	}

	ll id=0;
	ll f=0;
	
	for(ll i=k;i<n;i++)
	{
		ll s=v[id];
		ll ns=v[i];
		id++;
		if(s>=ns)
		{
			cout<<"No"<<endl;
			
		}
		else
		{
			cout<<"Yes"<<endl;
		}
		
	}

	
}
int main()
    {
      
        ll t;
        t=1;
        
    
    //cin>>t;
        while(t--)
        solve();
    }

Measured memory_bytes: 4832
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int[] h = new int[n];
    for (int i = 0; i < n; i++) {
      h[i] = scan.nextInt();
    }
    scan.close();

    System.out.println(minCost(h, 2));
  }

  private static int minCost(int[] heights, int maxSteps) {
    if (heights.length == 0)
        return 0;
    int[] dp = new int[heights.length];
    Arrays.fill(dp, Integer.MAX_VALUE);
    dp[0] = 0;

    for (int i = 1; i < heights.length; i++) {
        for (int j = Math.max(0, i - maxSteps); j < i; j++) {
            dp[i] = Math.min(dp[i], dp[j] + Math.abs(heights[i] - heights[j]));
        }
    }
    return dp[dp.length - 1];
  }
}


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

int a0, L;

int solve(vector<int>& A) {
    while (1) {
        string a = to_string(A[A.size() - 1]);
        string zeroKeta = "";
        for (int i = 0; i < L - a.size(); i++) {
            zeroKeta += "0";
        }
        a = zeroKeta + a;
        sort(a.begin(), a.end(), greater<char>());
        int aMax = stoi(a);
        sort(a.begin(), a.end());
        int aMin = stoi(a);
        int an = aMax - aMin;
        for (int i = 0; i < A.size(); i++) {
            if (an == A[i]) {
                cout << i << " " << an << " " << A.size() - i << endl;
                return 0;
            }
        }
        A.push_back(an);
    }
}

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

    while (1) {
        cin >> a0 >> L;
        if (!a0 & !L) break;
        vector<int> A;
        A.push_back(a0);
        solve(A);
    }
}


Measured memory_bytes: 3244
import std.stdio;

int gcd(int a, int b){
	return b?gcd(b, a%b):a;
}

void main(){
	int a, b;
	while(readf("%d %d\n", &a, &b)){
		writefln("%d %d", gcd(a, b), a / gcd(a, b) * b);
	}
}

Measured memory_bytes: 984
# input
N = int(input())
S = [int(input()) for _ in range(N)]

S = sorted(S)

n = -1 # 10の倍数でない配点の最小値

for i in range(N):
    if S[i] % 10 != 0:
        n = i
        break

if n == -1: # 配点が全て10の倍数の場合
    print(0)
elif sum(S) % 10 != 0: # 全て足して10の倍数にならない場合
    print(sum(S))
else: # 全合計が10の倍数の場合
    print(sum(S) - S[n]) # 10の倍数ではない最小配点の問題に不正解

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,char>;
using ll=long long;

int main () {
  int N, M;
  cin >> N >> M;
  set<int> S, T;
  int a, b;
  for (int i=0; i<M; i++) {
    cin >> a >> b;
    if (a==1) {
      S.insert(b);
    }
    if (b==N) {
      T.insert(a);
    }
  }
  
  string ans="IMPOSSIBLE";
  for (int i=1; i<=N; i++) {
    if (S.count(i) && T.count(i)) {
      ans="POSSIBLE";
      break;
    }
  }
  cout << ans << endl;
}
 

Measured memory_bytes: 12976
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_bacm
#define mp mame_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    char c = getchar();
    cout << (char)(c+1) << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll n[21] = {}, s[21][101] = {}, sum[21] = {}, ans[21] = {}, num = 20;

int main() {
	for (int i = 1; i <= 20; i++) {
		cin >> n[i];
		if (n[i] == 0) {
			num = i - 1;
			break;
		}
		for (int j = 1; j <= n[i]; j++)cin >> s[i][j];
		stable_sort(s[i], s[i] + n[i] + 1);
		for (int j = 2; j < n[i]; j++)sum[i] += s[i][j];
		ans[i] = sum[i] / (n[i] - 2);
	}
	for (int i = 1; i <= num; i++)cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 3152
n,*A=map(int,open(0).read().split())
C=[0]*3
for a in A:
    for i in range(2,-1,-1):
        if a%2**i == 0:
            C[i] += 1
            break
print("Yes"*(C[0]<=C[2]or (C[0]==C[2]+1 and C[1]==0))or"No")

Measured memory_bytes: 14052
n = input()

# 上の段:その桁をピッタリ払った, 下の段:その桁を払わなかった(上の桁で1多く払った)
dp = [[0 for i in range(len(n))] for j in range(2)]

dp[0][0] = int(n[0])
dp[1][0] = 1 + 10 - int(n[0])

for i in range(1, len(n)):
    dp[0][i] = min(dp[0][i-1], dp[1][i-1]) + int(n[i])
    dp[1][i] = min(dp[0][i-1]+1+10-int(n[i]), dp[1][i-1]-1+10-int(n[i]))

print(min(dp[0][len(n)-1], dp[1][len(n)-1]))

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

#define int long long int 

int32_t main()
{
    int ans=0;
    int k,s;
    cin>>k>>s;
    int x,y,z;
    for(x=0;x<=k;x++)
    {
        for( y=0;y<=k;y++)
        {
        z=s-x-y;
        if(z>=0 && z<=k)
        ans++;
        }
    }
    cout<<ans<<endl;
}

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

typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,in,i,ans=0,j;
    vector<ll>x;
    cin>>n;
    for(i=0; i<n; i++) {
        cin>>in;
        x.push_back(in);
    }
    ll mn=(*min_element(x.begin(),x.end()));
    ll mx=(*max_element(x.begin(),x.end()));
    ll mid=(mn+mx)/2;
    ll fin=0;
    for(i=0;i<x.size();i++)
    {
        fin+=((x[i]-mx)*(x[i]-mx));
    }
    for(j=mx;j>=mn;j--){
            ans=0;
    for(i=0;i<x.size();i++)
    {
        ans+=((x[i]-j)*(x[i]-j));
    }
    fin=min(ans,fin);
    }
    cout<<fin<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

   switch(n%10){
   case 2:
   case 4:
   case 5:
   case 7:
   case 9:
      printf("hon\n");
      break;
   case 0:
   case 1:
   case 6:
   case 8:
      printf("pon\n");
      break;
   case 3:
      printf("bon\n");
      break;
   }
   return 0;
}
      


Measured memory_bytes: 1640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll mod = 1e9 + 7;


int main(){
	ll n;
	cin>>n;
	string s;
	cin>>s;
	if(n%2 == 1){
		cout<<"No"<<endl;
	}else{
		int flag = 0;
		int t = n/2;
		for(int i = 0; i < t; i++){
			if(s[i] != s[t+i]){
				flag = 1;
			}
		}
		if(flag){
			cout<<"No"<<endl;
		}else{
			cout<<"Yes"<<endl;
		}
	}
	


	return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	ll ans = 0;
	int n, x; cin >> n >> x;
	vi a(n);
	rep(i, n) cin >> a[i];
	rep(i, n - 1){
		int s = max(0, a[i] + a[i + 1] - x); //dbg(s);
		int t = min(a[i + 1], s);
		a[i + 1] -= t;
		ans += s;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>


using namespace std;


typedef struct node_t {
    unsigned long long c;
    vector<int> children;
} node;

node nodes[2 * 100000 + 1];
bool visited[2 * 100000 + 1];


void solve(int n)
{
    visited[n] = true;
    if (nodes[n].children.size() == 0)
        return;

    for (auto it = nodes[n].children.begin(); it != nodes[n].children.end(); ++it) {
        if (!visited[*it]) {
            nodes[*it].c += nodes[n].c;
            solve(*it);
        }
    }
}


int main(void)
{
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i <= N; i++) {
        nodes[i].c = 0;
        visited[i] = false;
    }
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        nodes[a].children.push_back(b);
        nodes[b].children.push_back(a);
    }

    for (int i = 0; i < Q; i++) {
        int p;
        unsigned long long x;
        cin >> p >> x;
        nodes[p].c += x;
    }

    solve(1);

    for (int i = 1; i <= N; i++)
        cout << nodes[i].c << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 21376
#include <iostream>
using namespace std;
int n, d, x;
int a[110];
int main() {
  cin >> n >> d >> x;
  int count = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    int c = 0;
    int tmp = 1;
    while (tmp <= d) {
      count++;
      c++;
      tmp = c * a[i] + 1;
    }
  }
  cout << count + x;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    long int n, a, b=0, s=10e10;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> a;
        b=max(b,a);
        s=min(s,a);
    }
    int ans=b-s;
    cout << ans << '\n';
}

Measured memory_bytes: 384
s=string.gsub(io.read()," ","")
q=io.read("*n","*l")
should_reverse=0
left,right={},{}
for i=1,q do
    t=io.read("*n")
    if t==1 then
        should_reverse=should_reverse+1
    else
        f=io.read("*n")
        c=string.gsub(io.read()," ","")
        if f==1 then
            if should_reverse%2==1 then
                table.insert(right,c)
            else
                table.insert(left,c)
            end
        else
            if should_reverse%2==1 then
                table.insert(left,c)
            else
                table.insert(right,c)
            end
        end
    end
end

s=string.reverse(table.concat(left,""))..s..table.concat(right,"")
print(should_reverse%2==1 and string.reverse(s) or s)

Measured memory_bytes: 6768
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main(){
    int N,x,y,sum=0;
    cin >> N;
    while(N--){
        cin >> x >> y;
        sum+=(y-x+1);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int c[3][3];
    for (size_t i = 0; i < 3; ++i) {
        for (size_t j = 0; j < 3; ++j) {
            cin >> c[i][j];
        }
    }
    int a[3] = {-1};
    int b[3] = {-1};

    for(size_t i = 0; i <= c[0][0]; ++i) {
        b[0] = c[0][0] - i;
        a[1] = c[1][0] - b[0]; if (a[1] < 0) continue;
        a[2] = c[2][0] - b[0]; if (a[2] < 0) continue;
        b[1] = c[0][1] - i; if (b[1] < 0) continue;
        if (a[1] + b[1] != c[1][1]) continue;
        if (a[2] + b[1] != c[2][1]) continue;
        b[2] = c[0][2] - i; if (b[2] < 0) continue;
        if (a[1] + b[2] != c[1][2]) continue;
        if (a[2] + b[2] != c[2][2]) continue;
        a[0] = i;
        break;
    }
    cout << (a[0] >= 0 ? "Yes" : "No") << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
s = input()
n = len(s)

ans = [0, 0]
for i in range(n):
    if i % 2 == 0 and s[i] == '0':
        ans[1] += 1
    elif i % 2 == 0 and s[i] == '1':
        ans[0] += 1
    elif i % 2 == 1 and s[i] == '0':
        ans[0] += 1
    elif i % 2 == 1 and s[i] == '1':
        ans[1] += 1

print(min(ans))


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
typedef long long ll;
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> pii;typedef vector<pii> vpii;

ll dp[51][51][2501];

void Main() {
  int N, A;
  scanf("%d%d", &N, &A);
  vi X(N);
  rep(i, N) scanf("%d", &X[i]);

  sort(ALL(X));

  dp[0][0][0] = 1;

  rep(i, N) rep(j, N) rep(s, 2500) if (dp[i][j][s]) {
    dp[i+1][j][s] += dp[i][j][s];
    dp[i+1][j+1][s+X[i]] += dp[i][j][s];
  }

  ll ans = 0;
  rep(j, 1, N+1) {
    //_p("dp[%d][%d][%d]:%lld\n", N, j, A*j, dp[N][j][A*j]);
    ans += dp[N][j][A*j];
  }

  _p("%lld\n", ans);
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 8704
s =list(map(int,input().split('/')))

if s[0] <= 2018:
    print('Heisei')
elif s[0] == 2019 and s[1] <=4:
    print('Heisei')
elif s[0] == 2019 and s[1] >= 5:
    print('TBD')
elif s[0] >= 2020:
    print('TBD')


Measured memory_bytes: 2940
using System;

namespace ITP1_4_D {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            s = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for(int i = 0; i < s.Length; i++) {
                a[i] = int.Parse(s[i]);
            }
            long sum = 0;
            foreach(int i in a)
                sum += i;
            Array.Sort(a);
            Console.WriteLine("{0} {1} {2}", a[0], a[n-1], sum);
        }
    }
}

Measured memory_bytes: 10136
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from itertools import accumulate
    import heapq
    N, K = MI()
    V = LI()
    left_cum = [0]+list(accumulate(V))
    right_cum = [0] + list(accumulate(V[::-1]))

    minus_left = [[0]*N]
    minus_right = [[0]*N]
    now_minuses = [0]*N

    for i, v in enumerate(V):
        heapq.heappush(now_minuses, v)
        minus_left.append(list(now_minuses))

    now_minuses = [0]*N
    for i in range(N)[::-1]:
        heapq.heappush(now_minuses, V[i])
        minus_right.append(list(now_minuses))

    # print(*minus_left[1])
    # print(*minus_right)

    ans = 0
    for left in range(N+1):
        for right in range(N+1):
            if left + right > N or left + right > K:
                break
            ans_ = left_cum[left] + right_cum[right]
            l, r = list(minus_left[left]), list(minus_right[right])
            for i in range(K - right - left):
                if l[0] > r[0]:
                    pop_item = heapq.heappop(r)
                else:
                    pop_item = heapq.heappop(l)
                if pop_item >= 0:
                    break
                else:
                    """print(left, right, left_cum[left],
                          right_cum[right], K, ans_, pop_item)"""
                    ans_ -= pop_item
            #print(left, right, left_cum[left], right_cum[right], K, ans_)

            ans = max(ans, ans_)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47068
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
for _ in range(N):
  A[_][0], A[_][1], A[_][2] = A[_][2], A[_][0], A[_][1]
A.sort(reverse=True)
if sum(A[_][0] for _ in range(N)) == 0:
  print(0, 0, 1)
else:
  for i in range(101):
    for j in range(101):
      H = abs(A[0][1] - i) + abs(A[0][2] - j) + A[0][0]
      flg = 1
      for k in range(N):
        if max(H - abs(A[k][1] - i) - abs(A[k][2] - j), 0) != A[k][0]:
          flg = 0
          break
      if flg == 1:
        Cx, Cy, cerH = i, j, H
        break
    if flg == 1:
      break
  print(Cx, Cy, cerH)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  vector<int> dp(1000001);
  for (int i = 1; i <= N; i++) {
    dp.at(A.at(i))++;
    if (dp.at(A.at(i)) == 1) {
      for (int j = A.at(i) * 2; j <= 1000000; j += A.at(i)) {
        dp.at(j)++;
      }
    }
  }
  int result = 0;
  for (int j : A) {
    if (dp.at(j) == 1) result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 7932