akhauriyash/Code-Regression huggingface dataset:
<?php
  	fscanf(STDIN, "%d %d %d %d", $sx, $sy, $tx, $ty);

	$diffX = abs($tx - $sx);
	$diffY = abs($ty - $sy);

	//route1
	echo str_repeat("U", $diffY);
	echo str_repeat("R", $diffX);
	echo str_repeat("D", $diffY);
	echo str_repeat("L", $diffX);

	//route2
	echo "L";
	echo str_repeat("U", $diffY + 1);
	echo str_repeat("R", $diffX + 1);
	echo "DR";
	echo str_repeat("D", $diffY + 1);
	echo str_repeat("L", $diffX + 1);
	echo "U";       
?>

Measured memory_bytes: 4604
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if(s.equals("AAA")||s.equals("BBB")){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
  

  
}

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

char s[101];
signed main()
{
	bool C=0,F=0;
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(register int i=1;i<=len;i++)
	{
		if(s[i]=='C') C=1;
		if(s[i]=='F'&&C) F=1;
	}
	puts(C&&F?"Yes":"No");
	return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
    let s: String = sc.next();
    let ans: usize = 7 - days.iter().position(|&d| d == s).unwrap();
    println!("{}", ans);
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

class BinaryIndexedTree {
    vector<int64_t> container;

public:
    BinaryIndexedTree(size_t size)
        : container(size + 1)
    {
        fill(container.begin(), container.end(), 0);
    }
    void add(size_t i, int64_t v)
    {
        size_t idx = i + 1;
        while (idx < container.size()) {
            container[idx] += v;
            idx += idx & -idx;
        }
    }
    int64_t find(size_t i)
    {
        size_t idx = i;

        int64_t result = 0;
        while (idx != 0) {
            result = container[idx] + result;
            idx -= idx & -idx;
        }
        return result;
    }
    size_t lower_bound(int64_t v)
    {
        if (v == 0) {
            return 0;
        }
        int64_t w = v;
        size_t x = 0;
        for (size_t k = msb(container.size() - 1); k > 0; k >>= 1) {
            if (x + k < container.size() && container[x + k] < w) {
                w -= container[x + k];
                x += k;
            }
        }
        return x + 1;
    }

private:
    size_t msb(size_t x)
    {
        x |= x >> 1;
        x |= x >> 2;
        x |= x >> 4;
        x |= x >> 8;
        x |= x >> 16;
        return (x + 1) >> 1;
    }
};

vector<vector<int>> children;
vector<int> etL, etR;

int init_et(int node, int idx)
{
    etL[node] = idx;

    int tmp = idx + 1;
    for (int ch : children[node]) {
        tmp = init_et(ch, tmp);
    }
    etR[node] = tmp + 1;
    return etR[node];
}

int main()
{
    int n;
    cin >> n;

    children.resize(n);
    rep(i, n)
    {
        int k;
        cin >> k;
        rep(j, k)
        {
            int c;
            cin >> c;
            children[i].push_back(c);
        }
    }

    etR.resize(n);
    etL.resize(n);
    init_et(0, 0);

    BinaryIndexedTree bit(2 * n);
    int q;
    cin >> q;
    rep(i, q)
    {
        int k;
        cin >> k;
        if (k == 0) {
            int v, w;
            cin >> v >> w;
            bit.add(etL[v], w);
            bit.add(etR[v], -w);
        } else {
            int u;
            cin >> u;
            cout << bit.find(etL[u] + 1) - bit.find(etL[0]) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 13580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  int b[n][30];
  rep(i,0,n){
    rep(j,0,30){
      if(a[i]%2==0) b[i][j]=0;
      else b[i][j]=1;
      a[i]/=2;
    }
  }
  int c[n][30];
  rep(j,0,30){
    int cnt=0;
    rep(i,0,n){
      if(b[i][j]==1) cnt++;
    }
    if(cnt%2==0){
      rep(i,0,n){
        c[i][j]=b[i][j];
      }
    }
    else{
      rep(i,0,n){
        c[i][j]=1-b[i][j];
      }
    }
  }
  int d[n];
  rep(i,0,n) d[i]=0;
  int cur=1;
  rep(j,0,30){
    rep(i,0,n){
      d[i]+=cur*c[i][j];
    }
    cur*=2;
  }
  rep(i,0,n){
    cout<<d[i]<<endl;
  }
}

Measured memory_bytes: 51944
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  string S;
  unordered_map<string, int> count;
  long result = 0;
  
  int i = 0;
  while(i < N) {
    cin >> S;
    sort(S.begin(), S.end());
    if (count[S] > 0 ) {
      result += count[S];
    }
    count[S]++;
    i++;
  }
 
  cout << result << endl;
}

Measured memory_bytes: 10660
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int sum=0;
	if(k<=a)sum+=k;
	else if(k<=a+b)sum+=a;
	else sum=a+a+b-k;
	cout<<sum;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int main(){
	int d;
	while(cin>>d){
		int s=0;
		for(int x=d;x<600;x+=d) s+=x*x*d;
			cout<<s<<endl;
	}
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
int main()
{
    string s;
    cin>>s;
    int ct=0;
    int maxi=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='R')
        ct++;
        else
        {
            maxi=max(maxi,ct);
            ct=0;
        }
        

    }
    maxi=max(maxi,ct);
    cout<<maxi<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef long double ld;
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define pb push_back
#define pf push_front
#define mp map<ll,ll>
#define INF 1000000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else
    {
        return gcd(b%a,a);   
    }
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int f(char c)
{
    return (int)c-96;
}
/**********************************************************************
***********************************************************************
*********************ACTUAL CODE BEGINS HERE***************************/
int main()
{   
    fast;
    int x;
    cin>>x;
    if(x>=30)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;   
    }
    return 0;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys
from itertools import accumulate
INF = float("inf")


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):

    V = [[0] for _ in range(4)]
    for ww, vv in zip(w, v):
        V[ww-w[0]].append(vv)
    V = [[0]+list(accumulate(sorted(v, reverse=True))) for v in V]

    m = 0
    M = N+1
    for i in range(M):
        if i*w[0] > W:
            break
        if len(V[0]) <= i:
            break
        for j in range(M-i):
            if i*w[0] + j*(w[0]+1) > W:
                break
            if len(V[1]) <= j:
                break
            for k in range(M-i-j):
                if i*w[0] + j*(w[0]+1) + k*(w[0]+2) > W:
                    break
                if len(V[2]) <= k:
                    break
                for l in range(M-i-j-k):
                    if i*w[0] + j*(w[0]+1) + k*(w[0]+2) + l*(w[0]+3) > W:
                        break
                    if len(V[3]) <= l:
                        break
                    tot = V[0][i]+V[1][j]+V[2][k]+V[3][l]
                    m = max(m, tot)
    print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<int, vector<int>, greater<int> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int k, t;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> k >> t;
    vii a(t);
    rep(i, 0, t) {
      cin >> a[i];
    }
    int x = *max_element(ALL(a));
    cout << max(0, x - 1 - (k - x)) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[100100],n,p,ans,temp,k,m,a,b;
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n,greater<int>());
    for(int i=0;i<k;i++)
        ans+=arr[i];
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
  int s=0;char ch=getchar();
  while(!isdigit(ch)) ch=getchar();
  while(isdigit(ch)) s=s*10+ch-'0',ch=getchar();
  return s;
}
typedef long long ll;
int L,R;

int main(){
  L=read(),R=read();
  if(R-L>=2019) puts("0");
  else {
    ll ans=0x3f3f3f3f;
    for(int i=L;i<=R;i++)
      for(int j=i+1;j<=R;j++)
      ans=min(ans,1ll*i*j%2019);
    cout<<ans;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
int main()
{
    int i,j,h,w,co=0;
    while(scanf("%d%d",&h,&w)==2)
    {
        char ara[h][w+1];
        for(i=0;i<h;i++)scanf("%s",ara[i]);
        for(i=0;i<h;i++)
        {
            for(j=0;j<w+1;j++)
            {
                if(ara[i][j]=='.')
                {
                    if(j+1<w+1)
                    {
                        if(ara[i][j+1]=='#')co++;
                        if(i-1>=0)
                        {
                            if(ara[i-1][j+1]=='#')co++;
                        }
                        if(i+1<h)
                        {
                            if(ara[i+1][j+1]=='#')co++;
                        }
                    }
                    if(j-1>=0)
                    {
                        if(ara[i][j-1]=='#')co++;
                        if(i-1>=0)
                        {
                            if(ara[i-1][j-1]=='#')co++;
                        }
                        if(i+1<h)
                        {
                            if(ara[i+1][j-1]=='#')co++;
                        }
                    }
                    if(i-1>=0)
                    {
                        if(ara[i-1][j]=='#')co++;
                    }
                    if(i+1<h)
                    {
                        if(ara[i+1][j]=='#')co++;
                    }
                     ara[i][j]=co+'0';
                     co=0;
                }
            }
        }
        for(i=0;i<h;i++)
        {
            printf("%s\n",ara[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	int m=a>c?a:c,n=b>d?d:b;
	printf("%d",m>=n?0:n-m);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

inline int min(int a, int b, int c) {
    return a<b ? (a<c ? a: c) : (b<c ? b: c);
}

int main () {
    char s1[1001], s2[1001];
    int **dist, *_dist, l1, l2, i, j;

    scanf("%s", s1);
    scanf("%s", s2);
    l1 = strlen(s1);
    l2 = strlen(s2);

    _dist = (int*)malloc(sizeof(int) * (l1+1) * (l2+1));
    dist = (int**)malloc(sizeof(int*) * (l1+1));
    for (i = 0; i <= l1; i++) {
        dist[i] = _dist + (l2+1) * i;
    }

    for (i = 0; i <= l1; i++) {
        dist[i][0] = i;
    }
    for (j = 0; j <= l2; j++) {
        dist[0][j] = j;
    }
    for (i = 1; i <= l1; i++) {
        for (j = 1; j <= l2; j++) {
            dist[i][j] = min(
                             dist[i-1][j] + 1,
                             dist[i][j-1] + 1,
                             dist[i-1][j-1] + (s1[i-1]!=s2[j-1]));
        }
    }
    printf("%d\n", dist[l1][l2]);

    free(dist);
    free(_dist);

    return 0;
}

Measured memory_bytes: 4488
def printRest(rest, str)
  rest.each do |r|
    printf "#{str} #{r}\n"
  end
end

S = (1..13).to_a
H = (1..13).to_a
C = (1..13).to_a
D = (1..13).to_a
s = []
h = []
c = []
d = []

n = gets.to_i
for i in 1..n do
  a = gets.chomp.split(' ')
  key = a[0].to_s
  val = a[1].to_i
  case key
    when "S"
      s.push val
    when "H"
      h.push val
    when "C"
      c.push val
    when "D"
      d.push val
    end
end

rS = S - s
rH = H - h
rC = C - c
rD = D - d

printRest(rS, "S")
printRest(rH, "H")
printRest(rC, "C")
printRest(rD, "D")

Measured memory_bytes: 6112
//****************************//
/**********  main *************/
//****************************//
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for(i = 0; i < n; i++)
#define FOR(i, a, b) for(i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())

double pi = 3.141592653589793;

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

int main() {

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

    int res;

    int x;

    cin >> x;

    if(400 <= x && x <= 599)
        res = 8;
    if(600 <= x && x <= 799)
        res = 7;
    if(800 <= x && x <= 999)
        res = 6;
    if(1000 <= x && x <= 1199)
        res = 5;
    if(1200 <= x && x <= 1399)
        res = 4;
    if(1400 <= x && x <= 1599)
        res = 3;
    if(1600 <= x && x <= 1799)
        res = 2;
    if(1800 <= x && x <= 1999)
        res = 1;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
#define FIRST first 
#define SECOND second
#define FRONT front
#define PUSH_BACK push_back
#define MAKE_PAIR make_pair 
#define EMPTY empty
#define size(x) ((int)(x).size()) 
#define PRIORITY_QUEUE priority_queue
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL;  
//head

const int maxn = 1123;
const int inf = 5e8;
int n, m;
int d[111][111];
int p[maxn], w[maxn];
int vis[maxn];
std::vector<int> G[maxn];

void init(int x){
	for(int i = 0; i < x; i++){
		G[i].clear();
	}
}

int dfs(int x){
	for(int i = 0; i < size(G[x]); i++){
		int u = G[x][i];
		if(!vis[u]){
			vis[u] = 1;
			if(p[u] < 0 || dfs(p[u])){
				p[u] = x;
				return 1;
			}
		}
	}
	return 0;
}

int match(int x){
	int num = 0;
	memset(p, -1, sizeof(p));
	for(int i = 0; i < x; i++){
		memset(vis, 0, sizeof(vis));
		if(dfs(i)){
			num++;
		}
	}
	return num;
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int L;
	while(cin >> n >> m >> L && n){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(i == j) d[i][j] = 0;
				else d[i][j] = inf;
			}
		}
		init(L);
		for(int i = 0; i < m; i++){
			int x, y, z;
			cin >> x >> y >> z;
			d[x][y] = z;
			d[y][x] = z;
		}
		for(int k = 0; k < n; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		for(int i = 0; i < L; i++){
			cin >> p[i] >> w[i];
		}
		for(int i = 0; i < L; i++){
			for(int j = 0; j < L; j++){
				if(d[p[i]][p[j]] + w[i] <= w[j] && i != j){
					G[i].push_back(j);
				}
			}
		}
		cout << L - match(L) << endl;
	}	
	return 0;
}


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, A, B; cin >> N >> A >> B;
    vl X(N); REP(i, N) cin >> X[i];
    ll ans = 0;
    REP(i, N-1) ans += min((X[i+1]-X[i])*A, B);
    cout << ans << endl;
}


Measured memory_bytes: 3996
#include<stdio.h>
int main(){
  int A,B,C,D;
  int a,b,c,d;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  a=A/D;
  b=A%D;
  if(b!=0)
    a=a+1;
  c=C/B;
  d=C%B;
  if(d!=0)
    c=c+1;
  if(a<c)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}

Measured memory_bytes: 1656
#include <iostream>
#include <cstring>
using namespace std;
char s[1111];
int ans = 0;

int main(){
	cin >> s;
  	int len = strlen(s), l = 0, r = len - 1;
  	while (l < r){
      if (s[l] != s[r]) ans++;
      l ++;
      r --;
    }
  	cout << ans << endl;
  	return 0;
}


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

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

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

pa p[N];

int main()
{
	int n;
	sc(n);
	fo(i, 1, n)
	{
		sc(p[i].first);
		p[i].second = i;
	}
	sort(p + 1, p + n + 1);
	fo(i, 1, n)
		cout << p[i].second << ' ';
	cout << endl;
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e9

signed main()
{
    int n;
    cin >> n;

    map<int, int> mp;

    int a;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a;
        ans += mp[i - a];
        mp[i + a]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 26340
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

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

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 




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

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

	int n, W;
	cin >> n >> W;
	vi w(n), v(n);
	f_v2I(w, v, n);
	vvi dp(n + 1, vi(100100,ll_INF));
	dp[0][0] = 0;
	f(i, 0, n) {
		f(j, 0, 100100) {
			if (v[i]<=j) {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
			}
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		}
	}
	int ans = 0;
	f(i, 0, 100100) {
		if (dp[n][i] <= W) {
			ans = i;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 80256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

ll llmin(ll a,ll b){
    if(a>=b) return b;
    return a;
}
ll llmax(ll a,ll b){
    if(a<=b) return b;
    return a;
}

int main(){

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

    cin >> A;
    cin >> B;
    cin >> C;

    cout << llmax(0,C-(A-B)) << endl;
    

}

Measured memory_bytes: 3660
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m;
int t[100010];
int w[100010];
int d[100010];
int main(){
	cin>>n;
	long long ans=0;
	for(int i=1;i<=n;i++){
		cin>>t[i];
		ans+=t[i];
	}
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>w[i]>>d[i];
		cout<<ans-t[w[i]]+d[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
function main(input){
  var str = 'abcdefghijklmnopqrstuvwxyz';
  var N=str.length;
  roop:{for(var i=0;i<N;i++){
    var reg = new RegExp(''+str[i],'g');
    var matched=input.match(reg);
    if(matched===null)matched=[];
    if((matched.length)%2===1){
      break roop;
    }
  }}
  console.log((i===N)?'Yes':'No');
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    ll bsum = 0, asum = 0, aminsum = 0;
    priority_queue<ll, vector<ll>, greater<ll>> maxque;
    priority_queue<ll> minque;
    ll Q;
    cin >> Q;
    maxque.push(2e9);
    ll SIZE = 0;
    for(ll q = 1; q <= Q; q++) {
        ll in;
        cin >> in;
        if(in == 2) {
            //cerr << "CHECK: " << minque.top() << " " << maxque.top() << endl;
            while(minque.top() > maxque.top()) {
                //cerr << "CHECK: " << minque.top() << " " << maxque.top() << endl;
                ll a = minque.top();
                ll b = maxque.top();
                minque.pop();
                maxque.pop();
                minque.push(b);
                maxque.push(a);
                aminsum += b - a;
            }
            ll x = minque.top();
            cout << x << " ";
            cout << (SIZE / 2) * (-x) + (asum - aminsum) + ((SIZE + 1) / 2) * x - aminsum + bsum << endl;
            continue;
        }
        ll a, b;
        cin >> a >> b;
        bsum += b;
        asum += a;
        SIZE++;
        if(SIZE % 2 == 1) {
            minque.push(a);
            aminsum += a;
        } else maxque.push(a);
    }
    return 0;
}


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

int main() {
	
	int n;
	cin >> n;
	int max = 0;
	int ans = 0;
	rep(i, n){
		int p;
		cin >> p;
		ans += p;
		if(max < p) max = p;
	}
	ans -= max / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// Atcoder
  // Practice Problems
  // B - Resale
  #include <bits/stdc++.h>
  #include <iostream>
  #include <map>
  #include <queue>
  #include <set>
  #include <string>   
  #include <vector>
  #include <numeric>
  using namespace std;
  typedef long long int ll;
  typedef pair<ll, int> PLI;
  typedef pair<int, int> PII;
  const ll mxsize = 1e5 + 5;
  #define fastIO                                                                 \
    ios_base::sync_with_stdio(false);                                            \
    cin.tie(NULL);                                                               \
    cout.tie(NULL);
  
  /******************************************* IMPORTANT CODE SNIPPETS ************************************************/ 
  
  ll pow(ll x, ll n) {
    if (n == 0)
      return 1ll;
    ll temp;
    temp = pow(x, n / 2);
    if (n % 2 == 0)
      return temp * temp;
    else
      return x * temp * temp;
  }

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

  int sum_digit(int val) {
    if (val < 0)
      return -1;
    if (val == 0)
      return 0;
    int ans = 0;
    while (val > 0) {
      ans = ans + val % 10;
      val = val / 10;
    }
    return ans;
  }

  ll count_div(ll l, ll r, ll val) {
    if (l % val == 0)
      return (((r / val) - (l / val)) + 1);
    else
      return ((r / val) - (l / val));
  }

  int powmod(int x, int y, int m) {
    int res = 1;
    // x = x % mod;
    while (y > 0) {
      if (y & 1)
        res = (res * x) % m;
      cout << res << endl;
      y = y / 2;
      cout << x << endl;
      x = (x * x) % m;
    }
    // cout << res << endl;
    return res;
  }
  /******************************************** CODE STARTS FROM HERE *************************************************/ 
  
  int main()
  {
    int N;
    cin >> N;
    int V[N] , C[N];
    for(int i = 0 ; i < N ; i++)
    cin >> V[i];
    for(int i = 0 ; i < N ; i++)
    cin >> C[i];
    int ans = 0;
    for(int i = 0 ; i < N ; i++)
    {
      if(V[i] - C[i] > 0) ans = ans + V[i] - C[i];
    }
    cout << ans;
  }

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 15;

/* typedef */

/* global variables */

char tbl[256];
int dp[MAX_N][MAX_N];

/* subroutines */

/* main */

int main() {
  memset(tbl, 0, sizeof(tbl));
  memset(dp, 0, sizeof(dp));

  tbl['('] = ')';
  tbl[')'] = '(';
  tbl['{'] = '}';
  tbl['}'] = '{';
  tbl['['] = ']';
  tbl[']'] = '[';

  string str;
  cin >> str;

  int len = str.length();
  int ln = 0, rn = 0;

  while (str[ln] != 'i') ln++;
  while (str[len - 1 - rn] != 'i') rn++;
  //printf("ln=%d,rn=%d\n", ln, rn);

  for (int i = 0; i <= ln; i++)
    for (int j = 0; j <= rn; j++) {
      int dij = dp[i][j];
      if (tbl[str[i]] == str[len - 1 - j]) {
	if (dp[i + 1][j + 1] < dij + 1) dp[i + 1][j + 1] = dij + 1;
      }
      else {
	if (dp[i + 1][j] < dij) dp[i + 1][j] = dij;
	if (dp[i][j + 1] < dij) dp[i][j + 1] = dij;
      }
    }
  //printf("dp=%d\n", dp[ln][rn]);

  cout << (3 + dp[ln][rn] * 2) << endl;

  return 0;
}

Measured memory_bytes: 1180
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		List<Double> list = new ArrayList<Double>();
		
		while (true) {
			int n = scan.nextInt();
			if (n == 0) {
				break;
			}

			int[] s = new int[n];
			int sum = 0;
			for (int i = 0; i < n; i++) {
				s[i] = scan.nextInt();
				sum += s[i];
			}
			double m = (double)sum / n;

			double alpha = 0;
			for (int i = 0; i < n; i++) {
				alpha += (s[i] - m) * (s[i] - m);
			}
			alpha = Math.sqrt(alpha / n);
			list.add(alpha);
		}

		for (Double alpha : list) {
			System.out.println(alpha);
		}
		
		scan.close();
	}

}

Measured memory_bytes: 23760
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	int n, y;
	cin >> n >> y;

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			int rem = y - 10000*i - 5000*j;
			if (rem < 0) continue;
			int k = rem / 1000;
			if (i+j+k == n) {
				cout << i << ' ' << j << ' ' << k << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 3536
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

signed main(){

	string s;
	cin >> s;

	if (s.length() == 1){
		cout << s << endl;
		return 0;
	}

	bool f = true;
	for (int i = 1; i < s.length(); i++){
		if (s[i] != '9'){
			f = false;
			break;
		}
	}
	if (f){
		int r = 0;
		for (int i = 0; i < s.length(); i++)
			r += s[i] - '0';
		cout << r << endl;
		return 0;
	}

	int r;
	r = s[0] - '0' - 1;
	r += (s.length() - 1) * 9;

	cout << r << endl;

	return 0;
}


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

int main() {
	string s;
	cin>>s;s="0"+s;
	int f=0,cnt=0;
	for(int i=s.size()-1;i>0;i--){
		int d=s[i]-'0'+f;
		int m=min(d,10-d);
		cnt+=m;
		f=(d>5||d==5&&s[i-1]-'0'>=5);
  	}
  	cout<<cnt+f<<endl;
  	return 0;
}

Measured memory_bytes: 2308
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using ll=long long;
using namespace std;
const auto mod=1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  ll k,n; cin >> k >> n;
  vector<ll> a(n),b(n); rep(i,0,n) cin >> a[i];
  sort(a.begin(),a.end());
  rep(i,0,n-1) b[i]=a[i+1]-a[i];
  b[n-1]=k-a[n-1]+a[0];
  sort(b.begin(),b.end());
  ll sum=0;
  rep(i,0,b.size()-1){
  	sum+=b[i];
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    ll mod = 1e9 + 7;
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    vector<ll> rsum(n + 1, 0);
    
    FOR(i,1,n+1){
        rsum[i] = i + rsum[i - 1];
    }

    FOR(i,k,n+2){
        ans = (ans + rsum[n] - rsum[max(n - i,0ll)] - rsum[i - 1] + 1)%mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4680
#include <stdio.h>
#include <stdlib.h>
#define MAX 20000

typedef struct{
	int top;
	int S[MAX];
} Stack;

void initialize( Stack* );
void push( int, Stack* );
int pop( Stack* );
int isEmpty( Stack* );
int isFull( Stack* );

int main( void ){
	char c;
	int i, j, sum, tmp;
	Stack s1,s2,s3;
	
	initialize(&s1);
	initialize(&s2);
	initialize(&s3);
	
	sum = 0;
	for( i = 0; ( c = getchar()) != EOF; i++ ){
		if( c == '\\'){
			push( i, &s1 );
		}
		else if( !isEmpty(&s1) && c == '/' ){
			j = pop(&s1);
			sum += i - j;
			tmp = i - j;
			
			while( !isEmpty(&s2) && s2.S[s2.top] > j ){
				pop(&s2);
				tmp += pop(&s3);
			}
			
			push( j, &s2 );
			push( tmp, &s3 );
		}
	}
	
	printf("%d\n", sum );
	printf("%d", s3.top );
	for( i = 1; i <= s3.top; i++ ){
		printf( " %d", s3.S[i] );
	}
	printf("\n");
	
	return 0;
}

void initialize(Stack *s){
	s->top = 0;
	s->S[s->top] = 0;
}

void push( int x, Stack *s ){
	if( isFull(s)){
		exit(1);
	}
	s->S[++s->top] = x;
}

int pop(Stack *s){
	if( isEmpty(s)){
		exit(1);
	}
	
	s->top--;
	return s->S[s->top+1];
}

int isEmpty(Stack *s){
	return s->top == 0;
}

int isFull(Stack *s){
	return s->top >= MAX+1;
}


Measured memory_bytes: 2144
A = list(map(int,input())) #リストにしておけば入力変わっても対応できるので
#print(A)
n = len(A) - 1
for i in range(2**n):
    pattern = ['-']*n #さきにーの配列にしておく＞条件満たしたら＋に
    ans= A[0]
    #print("num {} :".format(i), end = "" )
    for j in range(n):
        if ((i >> j) & 1):
            pattern[j]='+'  #pattern[n-j-1]だと，bit演算子順
            ans+=A[j+1]
        else:
            #pattern.append('-0')
            ans-=A[j+1]

    else:
        if ans == 7:
            print(A[0], end='')
            for k in range(n):
                print(pattern[k],end='')
                print(A[k+1],end='')
            else:
                print('=7')
            break

Measured memory_bytes: 3064
#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, M, X, Y, Z;
vector<vector<ll>> node(100001, vector<ll>(0, 0));
bool flag[100001] = {};
ll ans = 0;

void DFS(ll cur) {
	flag[cur] = true;
	for (int i = 0; i < node[cur].size(); i++) {
		if (flag[node[cur][i]])continue;
		DFS(node[cur][i]);
	}
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> X >> Y >> Z;
		node[X].push_back(Y);
		node[Y].push_back(X);
	}
	for (int i = 1; i <= N; i++) {
		if (flag[i])continue;
		DFS(i);
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
signed main(){
    int n; cin >> n;
    bool yes = true;
    rep(i,n){
        int a; cin >> a;
        if (a % 2 ==0){
            if(a%3==0 || a%5==0) continue;
            else yes = false;
        }
    }
    if(yes) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include<stdio.h>
#include<cctype>
#include<string>
using namespace std;

int main()
{
	string a;
	int b = 0;
	getline(cin, a);
	while (a[b]) {
		if (islower(a[b])) {
			a[b] = toupper(a[b]);
		}
		else if (isupper(a[b])) {
			a[b] = tolower(a[b]);
		}
		b++;
	}
	cout << a<<endl;
}

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

int main() {
  int h, w, n; cin >> h >> w >> n;
  int ans, bigger = max(h, w);
  ans = n / bigger;
  if (n%bigger != 0) ans++; 
  cout << ans << endl;
  return 0;
  cout << 112/12 << endl;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int INF = (int)1e9;
int n, x;
VI A;
LL numOperations()
{
	LL ret = 0;	
	for(int i = 0; i + 1 < n; ++i)
	{
		int sum = A[i] + A[i + 1];
		if(sum > x)
		{
			int sub = sum - x;
			ret += sub;
			int f = min(sub, A[i + 1]); 
			sub -= f; A[i + 1] -= f;
			if(sub > 0) {
				int s = min(sub, A[i]); 
				sub -= s; A[i] -= s;
			}
		}
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n >> x;

	A.resize(n);
	REP(i, 0, n) cin >> A[i];

	cout << numOperations() << endl;

	return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() string {
	return scanString(sc)
}

func resolve(s string) int {
	dp := make([]map[string]int, len(s)+1)
	dp[0] = map[string]int{"": 0}
	for i := 1; i <= len(s); i++ {
		dp[i] = map[string]int{}
		for _, j := range []int{1, 2} {
			if i-j < 0 {
				continue
			}
			cur := s[i-j : i]
			for s, v := range dp[i-j] {
				if cur == s {
					continue
				}
				if dp[i][cur] < v+1 {
					dp[i][cur] = v + 1
				}
			}
		}
	}
	max := 0
	for _, v := range dp[len(s)] {
		if max < v {
			max = v
		}
	}
	return max
}

// snip-scan-funcs
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

const long long INF = 1LL << 60;

int main() {
    int N, K; cin >> N >> K;
    vector<long long> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H.at(i);
    }
    sort(H.begin(), H.end());
    long long ans = INF;
    for (int i = 0; i < N-K+1; i++) {
        ans = min(ans, H.at(i+K-1) - H.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  int x;
  if(b/10 > 0){
    if(b/100 > 0) x = 1000;
    else x = 100;
  }
  else x = 10;
  int c = a*x + b;
  for(int i = 0; i < 1000; i++){
    if(c == i*i){
      cout << "Yes" << endl;
      break;
    }
    else if(i == 999) cout << "No" << endl;
  }
}
  
    

Measured memory_bytes: 3600
import sys
import math
import numpy as np
import copy
import collections

def main():
    n, x, y = map(int, input().split())
    x, y = x-1, y-1

    dist = []
    for i in range(n):
        for j in range(i+1, n):
            dist.append(min(j-i, abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1))

    cnt = collections.Counter(dist)
    for i in range(1, n):
        print(cnt[i])


    return 0

if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 76632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,W;
  cin>>N>>W;
  VI A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];
  VVL dp(N+1,VL(100100,-1));
  dp[0][0]=0;
  rep(i,N){
    auto X=[&](int A,int B,int C){
      if(A<=W) dp[i+1][A]=max(dp[i+1][A],dp[i][B]+C);
    };
    rep(j,100100){
      if(dp[i][j]!=-1){
        X(j,j,0);
        X(j+A[i],j,B[i]);
      }
    }
  }
  ll ans=0;
  rep(i,W+1) ans=max(ans,dp[N][i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 string a[102];
 int m,n,i;
 cin>>n>>m;
 for(i=0;i<n;i++)
    cin>>a[i];

    sort(a,a+n);

for(i=0;i<n;i++)
    cout<<a[i];

return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var k int
	var s string
	fmt.Scan(&k, &s)

	ans := exec(k, s)
	fmt.Println(ans)
}

func exec(k int, s string) string {
	l := strings.Split(s, "")

	if len(l) <= k {
		return s
	}

	var v string
	for i := 0; i < k; i++ {
		v += l[i]
	}
	return v + "..."
}


Measured memory_bytes: 1828
import java.util.Scanner;
 
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		Main m = new Main();
		long sum = 0;
		for(int i = 1;i <= k;i++){
			for(int j = 1;j <= k;j++){
				for(int l = 1;l <= k;l++){
					sum += m.gcd(i,j,l);
				}
			}
		}
 
		System.out.println(sum);
	}
	int gcd(int a, int b){
		if((a%b!=0)){
			return gcd(b,a%b);
		}
		return b;
	}
	int gcd(int a,int b,int c){
		return gcd(gcd(a,b),c);
	}
}

Measured memory_bytes: 27296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;
    string s;
    cin >> n >> s;
    ll cnt = 0;
    ll r = count(s.begin(), s.end(), 'R');
    string st = s.substr(0, r);
    ll tmp = count(st.begin(), st.end(), 'R');
    cout << r - tmp << endl;
}

Measured memory_bytes: 3736
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		while(true){
			int n=int.Parse(Console.ReadLine());
			if(n==0)break;
			Sol mySol =new Sol(n);
			mySol.Solve();
		}
	}
}

class Sol{
	public void Solve(){
		int[] A=ria();
		
		int cnt=0;
		int from=-1;
		List<String> L=new List<String>();
		for(int i=0;i<N;i++){
			if(cnt==0){
				from=i;
				cnt++;
				continue;
			}
			if(A[i]==A[i-1]+1){
				cnt++;
				continue;
			}
			if(cnt==1){
				L.Add(A[i-1].ToString());
			}else{
				L.Add(A[from].ToString() +"-"+A[i-1].ToString());
			}
			cnt=1;
			from=i;
		}
		if(cnt==1){
			L.Add(A[N-1].ToString());
		}else{
			L.Add(A[from].ToString() +"-"+A[N-1].ToString());
		}
		
		
		for(int i=0;i<L.Count;i++){
			Console.Write(i==0?"{0}":" {0}",L[i]);
		}
		Console.WriteLine("");
		
		
		
		
	}
	int N;
	public Sol(int n_){
		N=n_;
	}




	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Measured memory_bytes: 5932
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=205;
int p,n;
char s[N];
ll dp[N][4][2];
int main()
{
    scanf("%s",s+1);
    scanf("%d",&p);
    int n=strlen(s+1);
    dp[0][0][1]=1;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=3;j++)
            for(int k=0;k<=1;k++)
        {
            int up=k?s[i]-'0':9;
            if(j==p) up=0;
            for(int h=0;h<=up;h++)
                dp[i][j+(h!=0)][k&&(h==up)]+=dp[i-1][j][k];
        }
    printf("%lld\n",dp[n][p][0]+dp[n][p][1]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    if((A + B) > (C + D)){
        printf("Left\n");
    }
    else if((A + B) == (C + D)){
        printf("Balanced\n");
    }
    else {
        printf("Right\n");
    }

    return 0;
}

Measured memory_bytes: 256