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



int main() {
	string S;
	cin >> S;
	int Z = S.size();
	vector<char>vec(Z + 10, '*');
	rep(i, Z) {
		vec[i] = S[i];
	}
	rep(i, Z) {
		if (vec[i] == 'd' &&
			vec[i + 1] == 'r' &&
			vec[i + 2] == 'e' &&
			vec[i + 3] == 'a' &&
			vec[i + 4] == 'm') {
			vec[i] = '*';
			vec[i + 1] = '*';
			vec[i + 2] = '*';
			vec[i + 3] = '*';
			vec[i + 4] = '*';
		}
		else if (vec[i] == 'e' &&
			vec[i + 1] == 'r' &&
			vec[i + 2] == 'a' &&
			vec[i + 3] == 's' &&
			vec[i + 4] == 'e') {
			vec[i] = '*';
			vec[i + 1] = '*';
			vec[i + 2] = '*';
			vec[i + 3] = '*';
			vec[i + 4] = '*';
		}
	}
	rep(i, Z) {
		if (vec[i] == '*' &&
			vec[i + 1] == 'e' &&
			vec[i + 2] == 'r' &&
			vec[i + 3] == '*') {
			vec[i + 1] = '*';
			vec[i + 2] = '*';
		}
		else if (vec[i] == '*' &&
			vec[i + 1] == 'r' &&
			vec[i + 2] == '*') {
			vec[i + 1] = '*';
		}
	}
	rep(i, Z) {
		if (vec[i] != '*') {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}




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

int main() {
  string s;cin>>s;
  int ans=0;
  rep(i,4){
    if(s[i]=='+') ans++;
    else ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;long long arr[400005];int lowbit(int x){return x&(-x);}void add(int x,long long y){for (int i=x;i<=400005;i+=lowbit(i)) arr[i]+=y;}long long query(int x){long long s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}
long long n,m,i,j,l,r,mid,ans,num[400015],s[400015],sum[400015],f[400015];vector<long long> all;bool _(long long x){long long i,j,ans=0;	s[0]=200002;	for (int i=1;i<=n;i++)	{		if (num[i]<x) f[i]=-1;		if (num[i]>=x) f[i]=1;	}
for (int i=1;i<=n;i++) s[i]=s[i-1]+f[i];	memset(arr,0,sizeof(arr));	for (int i=n;i>=1;i--)	{		add(s[i],1);ans+=query(s[i-1]-1);	}return ans<((n*(n+1)/2)/2+1);}int main()
{	scanf("%lld",&n);	for (int i=1;i<=n;i++)	{		scanf("%lld",&num[i]);
		all.push_back(num[i]);	}	sort(all.begin(),all.end());	all.resize(unique(all.begin(),all.end())-all.begin());
	for (int i=1;i<=n;i++) num[i]=upper_bound(all.begin(),all.end(),num[i])-all.begin();
	l=ans=1;r=((int)all.size())+1;
	while (l<r)	{		mid=(l+r)/2;		if (_(mid))
		{			l=mid+1;
			ans=mid;		}		else r=mid;	}	cout<<all[ans-1]<<endl;
	return 0;
}

Measured memory_bytes: 9332
#include <bits/stdc++.h>
#define rep(i,a,b) for (i=a;i<b;i++)
#define rep2(i,a,b) for (i=a;i>=b;i--)
#define mod 1000000007
#define mod2 998244353
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF  1e9+5
#define f first
#define s second
#define endl '\n'
#define ll long long
#define ii pair <int,int>
#define pll pair <ll,ll>
#define vi vector <int>
#define vl vector <ll>
#define vvi vector < vi >
#define vii vector < ii >
#define vpl vector < pll >
#define vvii vector < vii >
#define vll vector < ll >
#define vb  vector <bool>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define pg priority_queue<ll, vector<ll>, greater<ll>>
#define pq priority_queue<ll>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define cset(a) __builtin_popcountll(a)
#define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b)
#define debug(x) cerr << #x << " is " << x << endl;
using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// unordered_map<long long, int, custom_hash> safe_map;
// FOR VIEWERS, CODE STARTS HERE
ll mex = 100005;
map<ll,vll>e;
vll d1(mex, INF), lg(mex, 0), lvl(mex);
ll ans1; 
void dfs1(ll u, ll par)
{
    ll tmp, val = INF;
    lvl[u] = lvl[par] + 1;
    for(auto p: e[u])
    {
        if( p == par)
            continue;
        dfs1(p, u);
        d1[u] = min(1 + d1[p], d1[u]);
        lg[u] = max(1 + lg[p], lg[u]);
    }
}
int main()
{
    // #ifndef ONLINE_JUDGE
    //  freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    // #endif
    FIO;
    ll t, q, n, m, prev, maxx,  i, j, k1, k2, k3, k, x, y, flag, sum, cnt, ans;
    cin>>n>>k1>>k2;
    rep(i,0,n-1)
    {
        cin>>x>>y;
        e[x].pb(y);
        e[y].pb(x);
    }
    d1[k1] = 0;
    lvl[0] = -1;
    dfs1(k2,0);
    ans = 0;
    rep(i,1,n+1)
    {
        if( d1[i] < lvl[i])
        {
            x = lvl[i] + lg[i];
            // y = d1[i] + lg[i];
            // error(i, lvl[i], d1[i], lg[i]);
            ans = max(ans, x - 1);
            
        }
    }
    cout<<ans<<endl;
    return 0;    
}

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

int main() {
	long long x;cin>>x;
	long long x2=x%11;
	long long ans=2*(x/11);
	if(x2){
		if(x2>6){
			ans+=2;
		}else{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <map>
using namespace std;
char str[20];
int a, b;

int main()
{
	int i;
	scanf("%d%d%s", &a, &b, str);
	bool ans = 1;
	for (i = 0; i < a; i++)
	{
		if (str[i]<'0'||str[i]>'9') ans = 0;

	}
	if (str[i] != '-')ans = 0;

	i++;
	for (; i < a + b + 1; i++)
	{
		if (str[i]<'0'||str[i]>'9') ans = 0;
		//if (ans == 0) printf("%d\n", i);
	}
	if (ans == 1) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = sc.nextInt();
		int [] in = new int [a];
       
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                            }
	
        for(int i=0;i<a-b;i++){if(in[i]<in[i+b]){System.out.println("Yes");
                                                 }
                               else{System.out.println("No");}
                            }
        
		
	}
}


Measured memory_bytes: 60036
#include <bits/stdc++.h>
using namespace std;
int main(){

    long long int x,y,z;
    cin >> x;

    y = 2 * (x / 11);
    z = x % 11;

    if(x < 7) {
        cout << 1 << endl;
        return 0;
    }else {
        if (z > 6 || z == 2) {
            y += 2;
        } else if(z == 0) {
            cout << y << endl;
            return 0;
        }else {
            y++;
        }
    }
    cout << y << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(cin>>H>>W){
        char ptr[105][105];
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cin>>ptr[i][j];
            }
        }//数据输入完毕
        //下面开始使出画框
       // 画框所需要的行数与列数为h+2,w+2行
        for(int i=0;i<W+2;i++){
            cout<<"#";
        }//第一行画框
        cout<<endl;
        for(int i=0;i<H;i++){
            cout<<"#";
            for(int j=0;j<W;j++){
                cout<<ptr[i][j];
            }
            cout<<"#"<<endl;
        }
        for(int r=0;r<W+2;r++){
                cout<<"#";
            }//第一行画框
        cout<<endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, Q;
  cin >> N >> Q;
  vector<int> S(N);
  vector<int> T(N);
  vector<int> X(N);
  REP(i, N) {
    cin >> S[i] >> T[i] >> X[i];
    S[i] -= X[i];
    T[i] -= X[i];
  }
  vector<int> D(Q);
  REP(i, Q) cin >> D[i];
  vector<int> time;
  REP(i, N) time.push_back(S[i]);
  REP(i, N) time.push_back(T[i]);
  REP(i, Q) time.push_back(D[i]);
  sort(ALL(time));
  map<int, int> mp;
  REP(i, time.size()) mp[time[i]] = i;
  vector<vector<pair<int, int>>> action(time.size(), vector<pair<int, int>>());
  REP(i, N) {
    action[mp[S[i]]].push_back(make_pair(0, X[i]));
    action[mp[T[i]]].push_back(make_pair(1, X[i]));
  }
  REP(i, Q) action[mp[D[i]]].push_back(make_pair(2, -1));
  vector<int> ans;
  multiset<int> ms;
  REP(i, time.size()) REP(j, action[i].size()) {
    if(action[i][j].first == 0) {
      ms.insert(action[i][j].second);
    } else if(action[i][j].first == 1) {
      ms.erase(ms.find(action[i][j].second));
    } else {
      if(ms.begin() == ms.end()) {
        ans.push_back(-1);
      } else {
        ans.push_back(*ms.begin());
      }
    }
  }
  REP(i, ans.size()) cout << ans[i] << "\n";
}

Measured memory_bytes: 79340
import java.awt.List;
import java.io.*;
import java.util.*;

public class Main {
	public static int minn(int i, int j) {
		if(i > j) {
			return j;
		}
		else {
			return i;
		}
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int times = in.nextInt();
		int[] k = new int[times];
		
		for(int i = 0; i < times; i++) {
			k[i] = in.nextInt();
		}
		int min = k[0];
		int max = Integer.MIN_VALUE;
		for(int j = 1; j <times; j++) {
			if(k[j] - min > max) {
				max = k[j] - min;
			}
			min = minn(k[j], min);
		}
		System.out.println(max);
		
	}
}




Measured memory_bytes: 101120
#include <bits/stdc++.h>
#define range(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define reversed_range(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;

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

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    sr -= 1; sc -= 1;
    string S, T;
    cin >> S;
    cin >> T;
    // int left_margin = sr;
    // int right_margin = H - 1 - sr;
    // int up_margin = sc;
    // int down_margin = W - 1 - sc;
    vec<int> margins = {sc, W - 1 - sc, sr, H - 1 - sr};
    // cout << margins << "\n";
    unordered_map<char, int> cnt_takahashi;
    unordered_map<char, int> cnt_aoki;
    string moves = "LRUD";
    unordered_map<char, int> move_to_int;
    range(i, 4) move_to_int[moves.at(i)] = i;
    unordered_map<char, char> counterpart;
    counterpart['L'] = 'R';
    counterpart['R'] = 'L';
    counterpart['U'] = 'D';
    counterpart['D'] = 'U';
    range(i, N) {
        char move_takahashi = S.at(i);
        char move_aoki = T.at(i);
        cnt_takahashi[move_takahashi] += 1;
        for (int j = 0; j < 4; j++) {
            char c = moves.at(j);
            int margin = margins.at(j);
            if (cnt_takahashi[c] > cnt_aoki[counterpart[c]] + margin) {
                // cout << c << "\n";
                // cout << i << " " << j << "\n";
                cout << "NO" << "\n";
                return 0;
            }
        }
        cnt_aoki[move_aoki] += 1;
        cnt_aoki[move_aoki] = min(cnt_aoki[move_aoki],
            margins.at(move_to_int[move_aoki]) + cnt_takahashi[counterpart[move_aoki]]);
        // for (int j = 0; j < 4; j++) {
        //     char c = moves.at(j);
        //     int margin = margins.at(j);
        //     if (cnt_takahashi[c] > cnt_aoki[counterpart[c]] + margin) {
        //         cout << c << "\n";
        //         cout << i << " " << j << "\n";
        //         cout << "NO" << "\n";
        //         return 0;
        //     }
        // }
    }
    cout << "YES" << "\n";
    return 0;
}

Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll> H(N);

    rep(i,N){
        cin>>H[i];
    }

    ll max = 0;
    ll ans = 0;
    rep(i,N){
        if(H[i]>=max){
            ans++;
            max = H[i];
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define INT long long int
#define MOD 998244353
#define oo 6*(1e18)
using namespace std;
INT n, a[501] = {0, 0, 1}, e[100010];
vector<INT> G[501];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    if( n == 1 )
    {
        cout<<"Yes\n2\n1 1\n1 1\n";
        return 0;

    }
    for(int i = 3 ; i <= 500 ; i++ )
    {
        a[i] = a[i-1] + i-1;
        if( a[i] <= 100000 ) e[a[i]] = i;
    }
    if( !e[n] ) cout<<"No\n";
    else
    {
        cout<<"Yes\n"<<e[n]<<"\n";
        for(int i = 1, p = 1 ; i <= e[n]-1 ; i++ )
            for(int j = i+1 ; j <= e[n] ; j++ )
                G[i].push_back(p), G[j].push_back(p++);
        for(int i = 1 ; i <= e[n] ; i++ )
        {
            cout<<G[i].size()<<" ";
            for(INT x: G[i]) cout<<x<<" ";
            cout<<"\n";
        }
    }
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using P   = pair<ll,ll>;
using vp  = vector<P>;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rall(x) (x).rbegin(), (x).rend()
const int mod = 998244353;

int main() {
    ll n; cin >> n;
    vp xd(n);
    rep(i,n) cin>>xd[i].first>>xd[i].second,xd[i].second+=xd[i].first;
    sort(rall(xd));
    vp v;
    for (auto robo : xd) {
        ll r = 1;
        while (v.size() and v.back().first < robo.second and ((r *= v.back().second) %= mod)) v.pop_back();
        v.push_back(P(robo.first, r + 1));
    }
    ll ans = 1;
    for (auto it : v) (ans *= it.second) %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5492
s = input()
t = input()

if s == s.lower():
  if t == t.lower():
    if s == t[:-1]:
      if len(s) <= 10:
        print('Yes')
      else:
        print('No')
    else:
      print('No')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 8964
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] s = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            HashSet<long> check = s.ToHashSet<long>();
            Console.WriteLine(check.Max() - check.Min());

        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);

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

int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        cout<<"a > b"<<'\n';
    }else if(a<b){
        cout<<"a < b"<<'\n';
    }else{
        cout<<"a == b"<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3020
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)

INF = 1 << 60

n = int(input())
h = list(map(int, input().split()))
dp = [INF] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    if i != 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
    # print(dp[i], h[i], h[i - 1], h[i - 2])
# for i in dp:
#     print(i)
print(dp[-1])


Measured memory_bytes: 16268
#define _CRT_SECURE_NO_WARNINGS
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define true 1
#define false 0

char s[100001];
int a = 0, b = 0, c = 0;
char temp[100001];

int dp(int a, int b, int c, int temp_num) {
	//すべて0になったら終了
	if (a == 0 && b == 0 && c == 0) {
		return 0;
	}

	

	int a1 = 1, b1 = 1, c1 = 1;

	//使えないやつを排除
	if (a == 0) {
		a1 = 0;
	}
	if (b == 0) {
		b1 = 0;
	}
	if (c == 0) {
		c1 = 0;
	}

	if (temp_num > 0) {
		if (temp[temp_num - 1] == 'a') {
			a1 = 0;
		}
		if (temp[temp_num - 1] == 'b') {
			b1 = 0;
		}
		if (temp[temp_num - 1] == 'c') {
			c1 = 0;
		}
	}
	if (temp_num > 1) {
		if (temp[temp_num - 2] == 'a') {
			a1 = 0;
		}
		if (temp[temp_num - 2] == 'b') {
			b1 = 0;
		}
		if (temp[temp_num - 2] == 'c') {
			c1 = 0;
		}
	}
	int ans = -1;
//	printf("a,b,c %d %d %d a1b1c1 %d %d %d\n", a, b, c, a1, b1, c1);
	if (a1 == 1) {
		if (b1 == 1) {
			if (c1 == 1) {
				//a,b,c
				temp[temp_num] = 'a';
				ans = dp(a - 1, b, c, temp_num + 1);
				if (ans == -1) {
					temp[temp_num] = 'b';
					ans = dp(a, b - 1, c, temp_num + 1);
				}
				if (ans == -1) {
					temp[temp_num] = 'c';
					ans = dp(a, b, c - 1, temp_num + 1);
				}
			}
			else {
				//a,b
				temp[temp_num] = 'a';
				ans = dp(a - 1, b, c, temp_num + 1);
				if (ans == -1) {
					temp[temp_num] = 'b';
					ans = dp(a, b - 1, c, temp_num + 1);
				}
			}
		}
		else {
			if (c1 == 1) {
				//a,c
				temp[temp_num] = 'a';
				ans = dp(a - 1, b, c, temp_num + 1);
				if (ans == -1) {
					temp[temp_num] = 'c';
					ans = dp(a, b, c - 1, temp_num + 1);
				}
			}
			else {
				//a
				temp[temp_num] = 'a';
				ans = dp(a - 1, b, c, temp_num + 1);
			}
		}
	}
	else {
		if (b1 == 1) {
			if (c1 == 1) {
				//b,c
				temp[temp_num] = 'b';
				ans = dp(a, b - 1, c, temp_num + 1);
				if (ans == -1) {
					temp[temp_num] = 'c';
					ans = dp(a, b, c - 1, temp_num + 1);
				}
			}
			else {
				//b
				temp[temp_num] = 'b';
				ans = dp(a, b - 1, c, temp_num + 1);
				
			}
		}
		else {
			if (c1 == 1) {
				//c
				temp[temp_num] = 'c';
				ans = dp(a, b, c - 1, temp_num + 1);
			}
			else {
				ans = -1;
			}
		}
	}

	return ans;
}

int main() {
	scanf("%s", s);
	for (int i = 0; i < 100001 && s[i] != NULL; i++) {
		if (s[i] == 'a') {
			a++;
		}
		else if (s[i] == 'b') {
			b++;
		}
		else {
			c++;
		}
	}
	//printf("%d %d %d\n", a, b, c);
	if (dp(a, b, c, 0) == 0) {
		printf("YES\n");
		return 0;
	}
	printf("NO\n");
	return 0;

}

/*
problem A

char s[51];
char origin[10] = "AKIHABARA";
int origin_num = 0;

int main() {
	for (int i = 0; i < 51; i++) {
		s[i] = '0';
	}
	scanf("%s", s);
	for (int i = 0; i < 50 && origin_num <= 9; i++) {
		//同じの場合
		if (s[i] == origin[origin_num]) {
			origin_num++;
		}
		//Aをひとつ飛ばしたら同じの場合
		else if (origin[origin_num] == 'A' && origin_num <= 8 && origin[origin_num + 1] == s[i]) {
			origin_num += 2;
		}
		else {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}*/

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

long long H, W, D, Q, d[100000], a, b;
pair<int, int> A[100000];

main(){
  scanf("%lld%lld%lld", &H, &W, &D);
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      scanf("%lld", &a);
      A[a] = {i, j};
    }
  }
  for(int i = H * W - D; i > 0;--i){
    d[i] = d[i + D] + abs(A[i].first - A[i + D].first) + abs(A[i].second - A[i + D].second);
  }
  scanf("%lld", &Q);
  for(int i = 0; i < Q; ++i){
    scanf("%lld%lld", &a, &b);
    printf("%lld\n", d[a] - d[b]);
  }
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(int i=n;i<=N;++i)
#define asd(i,n,N) for(int i=n;i< N;++i)
#define rap(i,n,N) for(int i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>> " << #x << " -> " << x << endl
#define mems(x,y) memset(x,y,sizeof x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define plll pair<pll,ll>
#define piii pair<pii,int>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl '\n'
const int MAX = 1e6+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll MOD2 = 1000005329;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 555;

ll n,ans,ri;
char x[MAX];

int main(){
//	cout<<fixed<<setprecision(10);
//	freopen("input.txt", "r", stdin);
//	freopen("astar.out","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    rep(i,1,n)cin>>x[i];
    ri = n;
    rep(i,1,n){
    	while(x[ri]=='W')--ri;
    	if(i>ri)break;
    	if(x[i]=='W')swap(x[i],x[ri]), ++ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3840
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int s = Math.abs(x-a);
    int t = Math.abs(x-b);
    if(s>=t){
      System.out.println("B");
    }else{
      System.out.println("A");
    }
  }
}

Measured memory_bytes: 20692
import qualified Data.ByteString.Char8  as C
import Data.List
import Data.Ord

main = sol <$> get >>= put
get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines <$> C.getContents
put = mapM_ print

sol ([n,m]:xys) = fmap f ab
  where
  (ab,cd) = splitAt n xys
  cs = zip cd [1..]
  f [x,y] = snd $ minimumBy (comparing (dist [x,y]) `mappend` compare) cs
  dist [x,y] ([x',y'],_) = abs (x-x') + abs (y-y')


Measured memory_bytes: 636
# import math
# import time

def a():
    l, r, d = map(int, input().split())
    count = 0
    for i in range(l, r+1):
        if i % d == 0:
            count += 1
    print(count)


def b():
    n = int(input())
    a = list(map(int, input().split()))
    count = 0
    for i in range(0, n, 2):
        if a[i] % 2 == 1:
            count += 1
    print(count)


def c():
    n = int(input())
    f = [0]*n
    for x in range(1, 100):
        for y in range(x, 100):
            for z in range(y, 100):
                result = pow(x, 2)+pow(y, 2)+pow(z, 2)+x*y+y*z+x*z
                if result <= n:
                    if x == y == z:
                        f[result-1] += 1
                    elif x == y or y == z or x == z:
                        f[result-1] += 3
                    else:
                        f[result-1] += 6
                else:
                    break
    for i in f:
        print(i)


def d():
    print('')


# start = time.time()
c()
# t = time.time() - start
# print("time :",t)

Measured memory_bytes: 9312
# 0028
array = []
while True:
    try:
        a = input()
        if a == '': break
        array.append(int(a))
    except EOFError:
        break
s = set(array)
mx = max(list(map(lambda a: array.count(a), s)))
for a in sorted(s):
    if array.count(a) == mx:
        print(a)

Measured memory_bytes: 7684
using System.Collections.Generic;
using System.Linq;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (r[0] < r[1])
            {
                for (int i = 0; i < r[1]; i++)
                {
                    Console.Write(r[0]);
                }

            }
            else
            {
                for (int i = 0; i < r[0]; i++)
                {
                    Console.Write(r[1]);
                }
            }
        }
        
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <vector>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

using namespace std;

class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){}
        DisjointSet(int size) {
            rank.resize(size, 0);
            p.resize(size, 0);
            for(int i = 0; i < size; i++) makeSet(i);
        }

        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x, int y){
            return findSet(x) == findSet(y);
        }

        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }

        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }

        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

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

    DisjointSet tree(n);

    int com, x, y;
    rep(i,q){
        cin >> com >> x >> y;
        if(com == 0){
            tree.unite(x,y);
        }else{
            if(tree.same(x,y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	char a,b;
	scanf("%c %c", &a, &b);
	
	if(a==b){
		printf("H\n");
	}else{
		printf("D\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
    string s;
    cin >> s;
    bool flg;
    for (int delta = (s.length() - 1) / 2; delta > 0; delta--)
    {
        flg = true;
        for (int i = 0; i < delta; i++)
        {
            if (s[i] != s[i + delta])
            {
                flg = false;
            }
        }
        if (flg)
        {
            cout << delta * 2 << endl;
            return 0;
        }
    }
    return 0;
}


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

using rule = tuple<int,int,int>;
vector<rule> convert;

const int limit = 600;
using BST = bitset<limit>;
BST dpa[30][30],dpb[30][30];

void preprocessing(const auto &ary,BST dp[30][30]){
	const int n = ary.size();
	rep(i,n+1)rep(j,n+1) dp[i][j].reset();

	rep(i,n) dp[i][i+1].set(ary[i]);

	for(int d = 2; d <=n; ++d){
		for(int l = 0; l + d <=n; ++l){
			const int r = l + d;
			for(int m = l + 1; m < r; ++ m){
				for(auto &elem:convert){
					int a,b,c;
					tie(a,b,c) = elem;
					if(dp[l][m][a] and dp[m][r][b]) dp[l][r][c] = true;
				}
			}
		}
	}

	for(int l = 0; l <= n;++l){
		for(int r = l + 1; r <= n; ++r){
			for(int k = 31; k < limit; ++k){
				dp[l][r].reset(k);
			}
		}
	}
}


int calc(int n,int m){
	int dp[30][30];
	rep(i,n+1)rep(j,m+1) dp[i][j]=-1;	
	dp[0][0] = 0;

	rep(ai,n)rep(bi,m){
		if(dp[ai][bi]== -1) continue;

		for(int aj = ai + 1; aj <= n; ++aj){
			for(int bj = bi + 1; bj <= m; ++bj){
				const auto tmp = dpa[ai][aj] & dpb[bi][bj];
				if(tmp.any()) dp[aj][bj] = max(dp[aj][bj],dp[ai][bi]+1);
			}
		}
	}

	return dp[n][m];
}


int main(void){
	int n,m,r;
	while(cin >> n >> m >> r,n){
		convert.clear();
		vector<int> a(n),b(m);
		rep(i,n) cin >> a[i];
		rep(i,m) cin >> b[i];

		int total = 31;

		rep(loop,r){
			int k,x[10],y;
			cin >> k;
			rep(i,k) cin >> x[i];
			cin >> y;
		
			int cur = x[0];
			for(int i = 1; i < k-1; ++i){
				convert.push_back(rule(cur,x[i],total));
				cur = total;
				total++;
			}
			convert.push_back(rule(cur,x[k-1],y));
		}

		int ans = -1;
		rep(i,n){
			rotate(begin(a),begin(a)+1,end(a));
			rep(j,m){
				rotate(begin(b),begin(b)+1,end(b));
				preprocessing(a,dpa);
				preprocessing(b,dpb);
				ans = max(ans, calc(n,m));
			}
		}

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

Measured memory_bytes: 3264
import java.util.Scanner;

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

        for (int k = 0; k <= N; k++) {
            for (int l = 0; l <= M; l++) {
                if (k * (M - l) + l * (N - k) == K) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
ll n, m;
ll mod = 1e9 + 7;
ll f[500005];
ll invf[500005];
ll adjust(ll x){
	x %= mod;
	return (x + mod)%mod;
}

ll power(ll a, ll b){
	a %= mod;
	if (b == 0) return 1;
	if (b == 1) return a;
	ll half = power(a, b/2);
	half *= half;
	half %= mod;
	if (b % 2 == 1){
		half *= a;
		half %= mod;
	}
	return half;
}

void init(){
	f[0] = 1;
	invf[0] = power(f[0], mod - 2);
	REP(i, 1, 500004){
		f[i] = f[i - 1]*i;
		f[i] %= mod;
		invf[i] = power(f[i], mod - 2);
	}
}

ll choose(ll x, ll y){
	ll ans = (((f[x]*invf[y])%mod)*invf[x - y])%mod;
	return ans;
}

ll perm(ll x, ll y){
	ll ans = (f[x]*invf[x - y])%mod;
	return ans;
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	init();
	cin >> n >> m;
	ll ans = 0;
	for (ll i = 0; i <= n; i++){
		if (i % 2 == 0){
			ll cur = perm(m - i, n - i)*choose(n, i);
			cur %= mod;
			ans += cur;
			ans %= mod;
		} else {
			ll cur = perm(m - i, n - i)*choose(n, i);
			cur %= mod;
			ans -= cur;
			ans = adjust(ans);			
		}
		
	}
	ans *= perm(m, n);
	ans %= mod;
	
	cout << ans << endl;
}

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

int main() {
    string S;
    cin >> S;
    vector<int> n(4);
    for(int i=0;i<4;i++) n[i] = S[i] - '0';
    // for(int i=0;i<4;i++) cout << S[i] << endl;

    for(int tmp=0;tmp<(1<<3);tmp++) {
        bitset<3> s(tmp);
        int ans = n[0];
        // cout << s << endl;
        for(int i=0;i<3;i++) {
            if(s.test(i)) ans += n[i+1];
            else ans -= n[i+1];
        }
        // cout << ans << endl;
        if(ans == 7) {
            cout << n[0];
            for(int i=0;i<3;i++) {
                if(s.test(i)) cout << "+" << n[i+1];
                else cout << "-" << n[i+1];
            }
            cout << "=7" << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

char s[100005];
int main() {
	scanf("%s",s+1);
	int n=strlen(s+1);
	int ans=n;
	fup(i,1,n-1,1)
	{
		if(s[i]!=s[i+1])ans=min(ans,max(i,n-i));
	}
	printf("%d",ans);
}

Measured memory_bytes: 384
#include <string>
#include <algorithm>

#include <iostream>
using namespace std;

int main(){
    string s;
    cin>>s;
    sort(s.begin(), s.end());
    string t;
    cin>>t;
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s<t) {
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
typedef long long ll;

using namespace std;

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

  int w[N];
  ll v[N];
  for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

  ll dp[N + 1][W + 1];

  for (int i = 0; i <= W; i++) dp[0][i] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      if (j >= w[i]) {
	dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      }
      else dp[i + 1][j] = dp[i][j];
    }
  }
  cout << dp[N][W] << endl;  
  
}


Measured memory_bytes: 79104
import java.util.*;
import java.io.*;
public class Main{
	
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		int k=fs.nextInt();
		int arr[]=fs.readArray(n);
		int dp[]=new int[n];
		Arrays.fill(dp,(int)1e9);
		dp[0]=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					dp[j]=Math.min(dp[j],dp[i]+Math.abs(arr[j]-arr[i]));
				}
			}
		}
		System.out.println(dp[n-1]);
	}
}
class FastScanner 
{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public double nextDouble()
		{
			return Double.parseDouble(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

Measured memory_bytes: 44176
/*
    Solution by Abil
*/

#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const long long N = (1e6 + 12);
const long long mod = (1e9 + 7);
const long long inf = (1e9 + 123);

int dp[N], w[N], v[N];
main(){
    int n, k;
    cin >> n >> k;

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

    for(int i = 1;i <= n; i++){
        for(int j = k;j - w[i] >= 0; j--){
            dp[j] = max(dp[j],dp[j - w[i]] + v[i]);
        }
    }
    cout << dp[k];
}


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

int main() {
  int N;
  cin >> N;
  vector<int> cards(N);

  for (int i = 0; i < N; i++) {
    cin >> cards.at(i);
  }

  sort(cards.begin(), cards.end(), greater<int>() );

  int alice = 0, bob = 0;
  for (int i = 0; i < N; i++) {
    if ((i % 2) == 0) {
      alice += cards.at(i);
    }
    else {
      bob += cards.at(i);
    }
  }

  cout << alice - bob << endl;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, x;
    cin >> n >> x;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    ll ans = 0;
    if (a[0] > x) {
        ll temp = a[0] - x;
        a[0] = x;
        ans += temp;
    }
    repd(i, 1, n) {
        ll temp = a[i] - (x - a[i - 1]);
        if (temp <= 0) {
            continue;
        }
        ans += temp;
        a[i] -= temp;
    }
    cout << ans << endl;
    return 0;
}



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

typedef long long ll;

int main() {
	int N, H;
	cin >> N >> H;
	vector<int> a(N), b(N);
	for(int i=0; i<N; i++) cin >> a[i] >> b[i];

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());

	int ans=0;
	for (int i = 0; i < b.size(); i++) {
		if (a[0] < b[i]) {
			H -= b[i];
			ans++;
			if(H <= 0) break;
		}
	}
	if (H <= 0) {
		cout << ans << endl;
		return 0;
	}
	if(H%a[0]==0) ans += H / a[0];
	else ans += H / a[0] + 1;

	cout << ans << endl;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	for(int i=0; i<N; i++){
		cin >> a.at(i);
	}

	sort(a.begin(), a.end(), greater<int>());

	int alice = 0, bob = 0;
	for(int i=0; i<N; i++){
		if( i%2==0 ){
			alice += a.at(i);
		}
		else{
			bob += a.at(i);
		}
	}

	cout << alice-bob << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long n = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int m = vs[1];
			int[][] war = new int[m][];
			for (int i = 0; i < m; i++) {
				war[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
			}
			int bridge = -1;
			int ans = 0;
			foreach (var item in war.OrderBy(p => p[1])) {
				//System.Diagnostics.Debug.WriteLine($"{item[0]}-{item[1]}");
				if (item[0] > bridge) {
					bridge = item[1] - 1;
					ans++;
					//System.Diagnostics.Debug.WriteLine(bridge);
				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


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

int main() {
	int n;
	string s;
	string t;
	string ans;

	cin >> n;
	cin >> s >> t;

	for(int i = 0; i < n; i++) {
		ans.push_back(s[i]);
		ans.push_back(t[i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vll;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.bigin(),v.end()
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define R(a) a=sqrt(a)
#define POW(a,b) a=pow(a,b)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    FAST;
    string s,t;
    cin>>s>>t;
    ll ans,a;
    ans=0;
    rep(i,s.length()-t.length()+1){
        a=0;
        rep(j,t.length()){
            if(s[i+j]==t[j]){
                a++;
            }
        }
        MAX(ans,a);
    }
    ans=t.length()-ans;
    cout<<ans;
    return 0;
}



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

int main(){
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for(ll a = k; a <= n+1; a++) {
    ll b = a*(a-1)/2;
    ll c = a*(2*n-a+1)/2;
    (ans += c-b+1) %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long L, R;
  cin >> L >> R;
  R = min(R, L+2019);
  long long ans = 2018;
  for (auto i = L; i <= R; i++){
    for (auto j = i+1; j <= R; j++){
      long long x = (i*j) % 2019;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 1e5+5;
int v[N_MAX];

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string S;cin >> S;
  int N = S.length();
  int n = 0;
  char pre = S[0];
  rep(i,S.length()){
    if(pre!=S[i]){
      v[n] = i;
      ++n;
    }
    pre = S[i];
  }
  int minimum = N;
  rep(i,n) minimum = min(minimum, max(v[i],N-v[i]));
  cout << minimum << endl;
  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <utility>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define fore(i, init, n) for(int i = init; i < n; i++)
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fs first
#define sc second
#define INF (1LL<<61)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MAXN = 1e5+5;
int n, h[MAXN], dp[MAXN];

int main() {
    cin >> n;
    fore(i,0,n) cin >> h[i];

    dp[n-1] = 0;
    dp[n-2] = abs(h[n-1] - h[n-2]);   

    for(int i = n-3; i >= 0; i--) {
        dp[i] = min(dp[i+1] + abs(h[i] - h[i+1]), dp[i+2] + abs(h[i] - h[i+2]));
    }
    
    cout << dp[0];
    
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#define N 100001
#define INF 100000001
using namespace std;
struct edge{
	int to,val,next;
} e[2*N];
int n,u,v,w,root,f[N],hd[N],size[N];
int cnt=0,ans1=INF,minn=INF;
long long ans=0;
 inline void build(int u,int v,int w)
 {
 	cnt++;
 	e[cnt].to=v;
 	e[cnt].val=w;
 	e[cnt].next=hd[u];
 	hd[u]=cnt;
 }
 void dfs(int x,int fat,int val)
 {
 	int maxn=0;
 	size[x]=1;
 	for(int i=hd[x];i;i=e[i].next)
 	{
 		int t=e[i].to;
 		if(t!=fat)
 		{
 			dfs(t,x,e[i].val);
 			size[x]+=size[t];
 			maxn=max(maxn,size[t]);
 		}
 	}
 	ans+=1ll*2*val*min(size[x],n-size[x]);
 	maxn=max(maxn,n-size[x]);
 	f[x]=maxn;
 	if(maxn<minn)
 	{
 		minn=maxn;
 		root=x;
 	}
 }
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d%d",&u,&v,&w);
		build(u,v,w);build(v,u,w);
	}
	dfs(1,0,0);
	for(int i=hd[root];i;i=e[i].next)
	{
		ans1=min(ans1,e[i].val);
		if(f[root]==f[e[i].to])
		{
			printf("%lld",ans-e[i].val);
			return 0;
		}
	}
	printf("%lld",ans-ans1);
	return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>

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

  
  
  
  
 return 0; 
}

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

#ifdef LOCAL
#include "bib/debug.h"
#else
#define debug
#define cerr if (false) cerr 
#endif

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

  int n, m;
  cin >> n >> m;
  vector<int> A(n);
  long long s = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    s += A[i];
  }
  sort(A.rbegin(), A.rend());
  if (m * 4LL * A[m - 1] >= s) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
M = 10 ** 9 + 7
def mod_pow(a, b, mod):
	bin_b = []
	while b:
		bin_b.append(b % 2)
		b >>= 1
	ret = 1
	for j in reversed(bin_b):
		ret = (ret * ret) % mod
		if j == 1:
			ret = (ret * a) % mod
	return ret
ans = (mod_pow(10, N, M) - 2 * mod_pow(9, N, M) + mod_pow(8, N, M)) % M
print(ans)

Measured memory_bytes: 61864