akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec

void Main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans = max(a*c, a*d);
	ans = max(ans, b*d);
	ans = max(ans, b*c);
	cout<<ans<<_n;
}


void Test();
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3616
N = int(input())
V = list(map(int, input().split())) # 価値
C = list(map(int, input().split())) # コスト


X = 0 # 価値
Y = 0 # コスト

def dfs(index, x, y):
    buff = 0
    buff1 = 0
    if (index >= N):
        return x - y
    buff = dfs(index+1, x+V[index], y+C[index])
    buff1 = dfs(index+1, x, y)
    return max(buff, buff1)



ans = dfs(0, 0, 0)
print(ans)


Measured memory_bytes: 3064
N, X = map(int,input().split())
x = list(map(lambda y: abs(int(y)-X),input().split()))
m = min(x)

def prim(y):
    p=[]
    while y>1:
        for i in range(2,y+1):
            if y%i==0:
                y//=i
                p.append(i)
                break
    return p
   
ans=1

for i in prim(m):
    if m%i !=0:
        continue
    if set([j%i for j in x]) == {0}:
        ans *= i
        x = [j//i for j in x]
    if set([j%(m//i) for j in x]) == {0}:
        ans *= (m//i)
        x = [j//(m//i) for j in x]

print(ans)

Measured memory_bytes: 14444
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    string s;
    int ans=0;
    cin>>s;
    for(int i=1;i<s.length();i++)
    {
        if(s[i]!=s[i-1]){ans++;}
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    
    vector<int> v(n), c(n);
    rep(i, n){
        cin >> v.at(i);
    }
    rep(i, n){
        cin >> c.at(i);
    }
    
    int sum = 0;
    rep(i, n){
        sum += max(v.at(i)-c.at(i), 0);
    }
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int a[2],b[2];
    for (int i = 0; i < 2; ++i)
    {
        cin>>a[i];
    }
    for (int i = 0; i < 2; ++i)
    {
        cin>>b[i];
    }
    int flag (0);
    while(1)
    {
        if(!flag)
        {
            b[0]-=a[1];
            if(b[0]<=0)
                break;
        }
        else
        {
            a[0]-=b[1];
            if(a[0]<=0)
                break;
        }
        flag^=1;
    }
    cout<<(flag ? "No" : "Yes");

    printclock;
    return 0;
}


Measured memory_bytes: 3800
N, L = map(int, input().split())
A = list(map(int, input().split()))


X = [A[i] + A[i + 1] for i in range(N - 1)]
if any(map(lambda x: x >= L, X)):
    print('Possible')

    for i, x in enumerate(X, start=1):
        if x >= L:
            xi = i
            break

    for i in range(1, xi):
        print(i)
    for i in reversed(range(xi + 1, N)):
        print(i)
    print(xi)

else:
    print('Impossible')


Measured memory_bytes: 14052
#include<bits/stdc++.h>
using namespace std;
/// from  https://atcoder.jp/contests/abc113/submissions/3540482

int main(){
    const int mod=1000000007;
    int h,w,k;
    scanf("%d %d %d",&h,&w,&k);
    vector<vector<int>> dp(h+1,vector<int>(w,0));
    dp[0][0]=1;
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            for (int kk=0;kk<1<<(w-1);kk++) {
                bool ok=true;
                for (int l=0;l<w-2;l++) {
                    if (((kk>>l)&1) && ((kk>>(l+1))&1)) ok=false;
                }
                if (ok) {
                    if (j>=1 && ((kk>>(j-1))&1)) {
                        dp[i+1][j-1]+=dp[i][j];
                        dp[i+1][j-1]%=mod;
                    } else if (j<=w-2 && ((kk>>j)&1)) {
                        dp[i+1][j+1]+=dp[i][j];
                        dp[i+1][j+1]%=mod;
                    } else {
                        dp[i+1][j]+=dp[i][j];
                        dp[i+1][j]%=mod;
                    }
                }
            }
        }
    }
    printf("%d\n",dp[h][k-1]);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

class UnionFind {
public:
    vector<int> par;
    int N;
    UnionFind(int n) {
        par.resize(n, -1);
        N = n;
    }
    int Find(int n) {
        return par[n] < 0 ? n : par[n] = Find(par[n]);
    }
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        if (-par[x] < -par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        N--;
        return true;
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -par[Find(x)];
    }
    int size() {
        return N;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    REP(i, 0, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        uf.Union(a, b);
    }
    cout << uf.size() << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    a, b, k = map(int, input().split())
    if a >= 1:
        if k > a:
            k = k - a
            a = 0
        else:
            a = a - k
            k = 0
    if b >= 1:
        if k > b:
            b = 0
        else:
            b = b - k
    print(a, b)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int w, h, x, y, r;
    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
    if (x-r >= 0) {
        if (y-r >= 0) {
            if (w >= x+r) {
                if (h >= y+r) {
                    printf("Yes\n");
                }else{
                    printf("No\n");
                }
            }else{
                printf("No\n");
            }
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 584
#include <stdio.h>

int a[200001], ps[200001][20], n;

bool pos(int l, int r) {
	for(int i=0;i<20;i++) {
		if(ps[r][i]-ps[l-1][i]>1) return false;
	}
	return true;
}

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		for(int j=0;j<20;j++) {
			ps[i][j]=ps[i-1][j];
			if(a[i]&(1<<j)) ps[i][j]++;
		}
	}
	long long res=0;
	for(int i=1;i<=n;i++) {
		if(pos(i,n)) res+=n-i+1;
		else if(!pos(i,i+1)) res++;
		else {
			int lo=i+1, hi=n;
			while(lo+1<hi) {
				int mid=(lo+hi)/2;
				if(pos(i,mid)) lo=mid;
				else hi=mid;
			}
			res+=lo-i+1;
		}
	}
	printf("%lld\n",res);
	return 0;
}

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

int main(void){
	char s[200002];
	int D[200001][2];
	int (*d)[2]=D+1;
	scanf("%s", s);
	int i;
	d[-1][0]=d[-1][1]=0;
	d[0][0]=1; d[0][1]=INT_MIN;
	d[1][0]=s[0]==s[1]?INT_MIN:2; d[1][1]=1;
	i=2;{
		int f, g;
		f=d[i-1][1]+1;
		g=d[i-1][0]+1;
		if(s[i]!=s[i-1] && g>f) f=g;
		d[i][0] = f;
		d[i][1] = d[i-2][0]+1;
	}
	for(i=3; s[i]!=0; i++){
		int f, g;
		f=d[i-1][1]+1;
		g=d[i-1][0]+1;
		if(s[i]!=s[i-1] && g>f) f=g;
		d[i][0] = f;
		f=d[i-2][0]+1;
		g=d[i-2][1]+1;
		if((s[i]!=s[i-2] || s[i-1]!=s[i-3]) && g>f) f=g;
		d[i][1] = f;
	}
	printf("%d\n", d[i-1][0]>d[i-1][1]?d[i-1][0]:d[i-1][1]);
}



Measured memory_bytes: 1920
import sys
N=int(input())
a=list(map(int, input().split()))
s=1
# aに0がある場合を省く
if 0 in a:
    print(0)
    sys.exit()
else:
# sが10^18になったら打ち切る
    for i in a:
        if s<10**18:
            s*=i
    if s>10**18:
        print(-1)
        sys.exit()
    print(s)

Measured memory_bytes: 21700
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    vector<int>A(3);
    REP(i,3)cin>>A[i];
    sort(A.begin(),A.end());
    A[1]-=A[0];A[2]-=A[0];A[0]=0;
    int ans=0;
    A[0]+=(A[2]/2)*2;
    ans+=A[2]/2;
    int z=A[2]-A[1];
  	A[1]+=(z/2)*2;
    ans+=z/2;
    sort(A.begin(),A.end());
  	A[1]-=A[0];A[2]-=A[0];A[0]=0;
    if(A[1]==0&&A[2]==1)ans++;
    if(A[1]==1&&A[2]==1)ans+=2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 1e5 + 5;

int dp[N], isAChild[N];
vector <int> children[N];

int longestPath(int node) {
  if (dp[node])
    return dp[node];

  for (int i = 0; i < children[node].size(); i++)
    dp[node] = max(dp[node], 1 + longestPath(children[node][i]));

  return dp[node];
}

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

  int n, m, x, y;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    isAChild[y] = 1;
    children[x].push_back(y);
  }

  int answer = 0;

  for (int i = 1; i <= n; i++)
    if (!isAChild[i])
      answer = max(answer, longestPath(i));
  
  cout << answer << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

ll n, W, w0, w, v;
vector<int> vs[4];

int solve(int a, int b, int c, int d) {
    ll sum = a * w0 + b * (w0 + 1) + c * (w0 + 2) + d * (w0 + 3);
    if (sum > W) return -1;

    int res = 0;
    for (int i = 0; i < a; i++)
        res += vs[0][i];
    for (int i = 0; i < b; i++)
        res += vs[1][i];
    for (int i = 0; i < c; i++)
        res += vs[2][i];
    for (int i = 0; i < d; i++)
        res += vs[3][i];
    
    return res;
}

int main(void) {
    cin >> n >> W;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            cin >> w0 >> v;
            vs[0].push_back(v);
        } else {
            cin >> w >> v;
            vs[w - w0].push_back(v);
        }
    }

    for (int i = 0; i < 4; i++)
        sort(vs[i].begin(), vs[i].end(), greater<int>());

    int ans = -1;
    for (int i = 0; i <= vs[0].size(); i++)
        for (int j = 0; j <= vs[1].size(); j++)
            for (int k = 0; k <= vs[2].size(); k++)
                for (int l = 0; l <= vs[3].size(); l++)
                    ans = max(ans, solve(i, j, k ,l));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// 解説を見た
// http://hamayanhamayan.hatenablog.jp/entry/2017/10/28/230944
// DPわかりやすい

#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

double dp[102][102];

int main() {
    int N;
    cin >> N;
    vector<int> T(N+1);
    vector<int> V(N+1);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }

    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int cur = 0; cur < 105; cur++) {
            if (dp[i][cur] && cur <= V[i]) {
                for (int dst = 0; dst < 105; dst++) {
                    if (dst <= V[i]) {
                        int a = V[i] - cur;
                        int b = V[i] - dst;

                        if (a + b <= T[i]) {
                            double up = 1.0 * (cur + V[i]) * a / 2;
                            double mx = V[i] * (T[i] - a - b);
                            double down = 1.0 * (dst + V[i]) * b / 2;
                            dp[i+1][dst] = max(dp[i+1][dst], dp[i][cur] + up + mx + down);
                        } else if (T[i] < abs(dst - cur)) {
                            // do nothing (うごけない)
                        } else {
                            double t2acc = 1.0 * (dst - cur + T[i]) / 2;
                            double t2deacc = 1.0 * (T[i] - dst + cur) / 2;
                            double vmax = cur + t2acc;

                            double xup = 1.0 * (cur + vmax) * t2acc / 2;
                            double xdown = 1.0 * (dst + vmax) * t2deacc / 2;

                            dp[i+1][dst] = max(dp[i+1][dst], dp[i][cur] + xup + xdown);
                        }
                    }
                }
            }
        }
    }

    cout << fixed << setprecision(10) << dp[N][0] - 1 << endl;

    return 0;
}

Measured memory_bytes: 384
n, m = map(int,input().split())
arr = [1, n]
check = True
for i in range(m):
    l, r = map(int, input().split())
    if l <= arr[0] and r>= arr[1]:
        continue
    elif l > arr[1] or r < arr[0]:
        check = False
    if arr[0] <= l and l <= arr[1]:
        arr[0] = l
    if arr[1] >= r and r >= arr[0]:
        arr[1] = r
if check:
    print (arr[1] - arr[0] + 1)
else:
    print (0)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n,s) for (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define _GLIBCXX_DEBUG
// head

int main(){
    int x,y,z;
    cin >>x>>y>>z;
    cout << (x-z)/(y+z)<<endl;
}

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

int main(){
    int N;
    cin >> N;
    int H[N];
    for(int i=0;i<N;i++){ cin >> H[i]; }
    int count = 1;
    
    for(int i=1;i<N;i++){
        bool view = true;
        for(int j=0;j<i;j++){
            if(H[i] < H[j]){
                view = false;
                break;
            }
        }
        if(view){ count++; }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
<?php
$n = fgets(STDIN);
$v = fgets(STDIN);
$c = fgets(STDIN);
$rowV = explode(" ", $v);
$rowC = explode(" ", $c);
$result = 0;

for($i=0;$i<$n;$i++){
  if($rowV[$i]>$rowC[$i]){
    $result += $rowV[$i]-$rowC[$i];
  }
}

echo $result;

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

class Tree{
    public:
        int N;
        vector<int> parent;
        vector<vector<int> > child;
        vector<int> depth;
        Tree(int n){
            N = n;
            parent.resize(N, -1);
            child.resize(N);
        }

        void set(int nparent, vector<int> childs){
            child[nparent] = childs;
            REP(i, childs.size()){
                parent[childs[i]] = nparent;
            }
        }

        void setdepth(){
            depth.resize(N);
            REP(i, N){
                if(parent[i]==-1){
                    stack<PII> st;
                    st.push({i, 0});
                    while(!st.empty()){
                        PII d = st.top();
                        st.pop();
                        depth[d.first] = d.second;
                        REP(j, child[d.first].size()){
                            st.push({child[d.first][j], d.second + 1});
                        }
                    }
                }
            }
        }
};

signed  main(){
    int N;
    cin >> N;
    Tree tree(N);
    REP(i, N){
        int id;
        int k;
        cin >> id >> k;
        vector<int> line(k);
        REP(j, k)cin>>line[j];
        tree.set(id, line);
    }
    tree.setdepth();
    REP(i, N){
        cout << "node " << i << ": parent = " << tree.parent[i] << ", depth = " << tree.depth[i]
            << ", " << (tree.parent[i]==-1?"root":tree.child[i].size()==0?"leaf":"internal node");
        cout << ", [";
        REP(j, tree.child[i].size()){
            cout << tree.child[i][j] << (j+1 < tree.child[i].size() ? ", ":"");
        }
        cout << "]" << endl;
    }
    return 0;
}




Measured memory_bytes: 7104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int ans=0;
int main() {
	cin>>s;
	for(int i=0;i<s.size()/2;i++) if(s[i]!=s[s.size()-i-1]) ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int x[N], y[N], h[N];
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }
    map<int, int> m;
    vector<vector<int>> d;
    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            int H = 0;
            for (int i = 0; i < N; i++) {
                if (h[i] == 0) continue;
                ll t = abs(x[i] - cx) + abs(y[i] - cy);
                if (H == 0) {
                    H = t + h[i];
                } else if(H != t + h[i]){
                    H = 0;
                    break;
                }
            }
            if (H != 0) {
                d.push_back(vector<int>({cx, cy, H}));
                //cout << cx << " " << cy << " " << H << "\n";
                //return 0;
            }
            
        }
    }
    for (vector<int> v : d) {
        bool flag = true;
        for (int i = 0; i < N; i++) {
            if (h[i] != max(v[2] - abs(x[i] - v[0]) - abs(y[i] - v[1]), 0)) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << v[0] << " " << v[1] << " " << v[2] << "\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4048
#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;
    int 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: 3628
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int a, b;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b;
  int ans = max({a + b, a - b, a * b});

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <math.h>
#include <map>
#include <queue>

#define say(s) cout << s << endl
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define vec vector

using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vec<int> h(n);
  rep(i, n) cin >> h[i];

  ll dp[100010];
  rep(i, 100010) dp[i] = INF;

  dp[0] = 0;
  rep(i, n) {
    if (i == 0) {
      continue;
    }
    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]));
    }
  }

  say(dp[n-1]);

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
using namespace std;
//cout << << endl;
typedef long long int ll;
typedef long double ld;



int main(){
    ll a,ans,x;
    cin >> a;
    x=a/15;
    ans=a*800-x*200;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
  int m,f,r;
 
  for(int i=1;i>0;i++){
  scanf("%d %d %d",&m,&f,&r);
  if(m==-1 && f==-1 && r==-1){
    break;}
  if(m==-1 || f==-1){
    printf("F\n");}
  else{
    if(m+f>=80){
      printf("A\n");}
    else{
      if(m+f<80 && m+f>=65){
        printf("B\n");}
      else{
        if(m+f<65 && m+f>=50){
          printf("C\n");}
        else{
          if(m+f<50 && m+f>=30){
            if(r>=50){
              printf("C\n");}
            else{
              printf("D\n");}}
          else{
            if(m+f<=30){
              printf("F\n");}}}}}}}
return 0;
}


Measured memory_bytes: 2036
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,j,a[1000]={0},x[1000],y[1000],maxn=0;
	char s[1000]={0};
	scanf("%d",&n);
	scanf("%s",&s);
	for(i=0;i<n;i++)
	{
		a[i]=s[i]-'a';
	}
	for(i=0;i<n;i++)
	{
		int ans=0;
		x[a[i]]=1;
		memset(y,0,sizeof(y));
		for(j=i+1;j<n;j++)
		{
			y[a[j]]=1;
		}
		for(j=0;j<26;j++)
		{
			if(x[j]==1&&y[j]==1)
			ans++;
		}
		if(ans>maxn)
		maxn=ans;
	}
	printf("%d",maxn);
	
}

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

using namespace std;

#define x first
#define y second
#define all(v) v.begin(),v.end()

typedef unsigned long long ull;
typedef pair<long,long> ll;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector <ll> v(n);
	for (auto &c : v){
		cin >> c.x >> c.y;
	}
	sort(all(v),[](auto a, auto b){return a.y < b.y;});
	long ans = 0;
	for (auto c : v){
		if (ans + c.x <= c.y){
			ans+=c.x;
		}
		else{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}
                    
	

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793238;
int main(){
  double A, B, H, M; cin >> A >> B >> H >> M;
  double a=pi*(30*H+(M/2))/180;
  double b=pi*6*M/180;
  double c=abs(a-b);
  double x=(A-B*cos(c));
  double y=B*sin(c);
  cout << fixed << setprecision(12);
  cout << sqrt(x*x+y*y) << endl;
  return 0;
}

Measured memory_bytes: 4100
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  cin>>n;
  while(n--){
    Int r,c;
    cin>>r>>c;
    vector<string> s(r);
    for(Int i=0;i<r;i++) cin>>s[i];
    Int h,w;
    cin>>h>>w;
    vector<string> t(h);
    for(Int i=0;i<h;i++) cin>>t[i];
    Int ans=-1;
    auto in=[&](Int y,Int x){
      return 0<=y&&y<h&&0<=x&&x<w;
    };
    auto check=[&](Int y,Int x){
      vector<string> u=t;
      for(Int i=0;i<r;i++){
	for(Int j=0;j<c;j++){
	  if(s[i][j]=='.') continue;
	  if(!in(y+i,x+j)) return;
	  if(u[y+i][x+j]=='#') return;
	  u[y+i][x+j]='#';
	}
      }
      Int res=0;
      for(Int i=0;i<h;i++){
	Int tmp=0;
	for(Int j=0;j<w;j++){
	  if(u[i][j]=='#') tmp++;
	}
	res+=(tmp==w);
      }
      ans=max(ans,res);
    };
    for(Int k=0;k<4;k++){
      for(Int i=-r+1;i<h;i++)
	for(Int j=-c+1;j<w;j++)
	  check(i,j);
      vector<string> v(c);
      for(Int i=r-1;i>=0;i--)
	for(Int j=0;j<c;j++)
	  v[j].push_back(s[i][j]);
      swap(r,c);
      s=v;
      //for(Int i=0;i<r;i++) cout<<s[i]<<endl;cout<<endl;
    }
    cout<<ans<<endl;
  }
  
  return 0;
}

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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

void solve() {
    int n;
    cin >> n;

    vecl v(n);
    vecl cum(n+1,0);
    for (int i=0; i<n; ++i) {
        cin >> v[i];
        cum[i+1] = cum[i] + v[i];
    }

    ll half = cum[n] / 2;
    int l = 0, r = n;
    while (l<r) {
        int mid = l + (r - l) / 2;

        if (cum[mid]<half) {
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    int hidx = l;

    if (cum[n]%2==0 && cum[hidx]==half) {
        cout << 0 << endl;
        return;
    }

    ll ans = abs(cum[n] - cum[hidx] - cum[hidx]);
    hidx -= 1;
    ans = min(ans, abs(cum[n]-cum[hidx]-cum[hidx]));
    cout << ans << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
        solve();
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10005
#define int long long
#define T int t;cin>>t;while(t--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define debug(x) cout<<x = <<x<<n;
#define set_dp(dp) memset(dp,-1,sizeof(dp))
using namespace std;

signed main(){
	ios_base::sync_with_stdio(false);	
	cin.tie(0);
	cout.tie(0);
	
 	int n;
 	cin>>n;
 	vector<int> arr(n);
 	f(i,0,n) cin>>arr[i];
 	sort(arr.begin(), arr.end());
 	float ans = arr[0];
 	f(i,1,n){
 		ans = (ans+arr[i])/2;
 	}
 	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    char c;
    scan(c);
    writeln((c + 1).to!char);
}
















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val array = readLine()!!.split(" ").map {it.toLong()}
    val map = mutableMapOf<Long,Long>()
    var sum = 0L
    for(i in 1..n){
        val l = i-array[i-1]
        val r = i+array[i-1]
        map.put(r,map.getOrDefault(r,0)+1)
        sum+=map.getOrDefault(l,0)
    }
    println(sum)
}

Measured memory_bytes: 82252
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
int N, a[MAX];

int main(int argc, char ** argv) {
	scanf("%d", &N);
	REP(i, 1, N) scanf("%d", a+i);
	PER(i, N-1, 1) {
		if(a[i] > a[i+1]) a[i]--;
		if(a[i] > a[i+1]) puts("No"), exit(0);
	}
	puts("Yes");
	return 0;
}



Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////
vector< string > F;
int H, W, K;
int cal(vector<int> color) {
	int ans = 0;

	int A = color[H - 1];
	A++;
	vector<int> sumA(A, 0);
	vector<int> sumB(A, 0);
	for (int w = 0; w < W; ++w) {
		for (int i = 0; i < A; ++i) {
			sumB[i] = 0;
		}
		for (int h = 0; h < H; ++h) {
			sumB[color[h]] += (F[h][w] - '0');
		}
		for (int i = 0; i < A; ++i) {
			if (sumB[i] > K) {//分割できない。
				return -1;
			}
		}
		bool test = true;
		for (int i = 0; i < A; ++i) {
			if (sumA[i] + sumB[i] > K) {
				test = false;
				break;
			}
		}
		if (test == false) {//分割する。
			++ans;
			sumA = sumB;
		}
		else {
			for (int i = 0; i < A; ++i) {
				sumA[i] += sumB[i];
			}
		}
	}
	return ans;
}
void solve() {
	cin >> H >> W >> K;
	F.resize(H);
	for (int h = 0; h < H; ++h) {
		cin >> F[h];
	}
	int ans = INF;
	for (int s = 0; s < (1 << H); ++s) {
		int res1 = 0;
		int No = 0;
		vector<int> color(H,0);
		for (int i =0; i <H; ++i) {
			color[i] = No;
			if (s & (1 << i)) {
				++No;
				++res1;
			}
		}
		int res2 = cal(color);
		if(res2 < 0) {
			continue;
		}
		if (ans > res1+res2) {
			ans = res1 + res2;
		}
	}
	cout << ans << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
  cin>>n>>k;
  int o;
  if(n%2 == 1) o = (n/2)+1;
  else o = n/2;
  if(o >= k) cout<<"YES"<<"\n";
  else cout<<"NO"<<"\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  static int n, p;
  static int[] a;

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

    n = sc.nextInt();
    p = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    long[][] dp = new long[n + 1][2];
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
      if(a[i - 1] % 2 == 0){
        dp[i][0] = dp[i - 1][0] * 2;
        dp[i][1] = dp[i - 1][1] * 2;
      }
      else{
        dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
        dp[i][1] = dp[i - 1][1] + dp[i - 1][0];
      }
    }

    System.out.println(dp[n][p]);
  }
}

Measured memory_bytes: 21844
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::cmp::Ordering;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

struct UnionFind {
  par: Vec<usize>,
  rank: Vec<usize>,
}

impl UnionFind {
  fn new(n: usize) -> Self {
    let mut uf = UnionFind {par: vec![0; n], rank: vec![0; n]};
    for (i, item) in uf.par.iter_mut().enumerate() {
      *item = i;
    }
    uf
  }
  fn find(&mut self, x: usize) -> usize {
    if self.par[x] == x {
      x
    } else {
      let px = self.par[x];
      self.par[x] = self.find(px);
      self.par[x]
    }
  }
  fn unite(&mut self, x: usize, y: usize) {
    let x = self.find(x);
    let y = self.find(y);
    match self.rank[x].cmp(&self.rank[y]) {
      Ordering::Less => self.par[x] = y,
      Ordering::Greater => self.par[y] = x,
      Ordering::Equal => {
        self.par[y] = x;
        self.rank[x] += 1;
      }
    }
  }
  fn same(&mut self, x: usize, y: usize) -> bool {
    self.find(x) == self.find(y)
  }
}

fn main() {
  input!{
    n: usize,
    m: usize,
    p: [usize1; n],
    xy: [(usize1, usize1); m]
  }
  let mut uf = UnionFind::new(n);
  for (x, y) in xy {
    uf.unite(x, y);
  }
  let ans = p.iter().enumerate()
    .filter(|&(i, &x)| uf.same(i, x))
    .count();
  println!("{}", ans);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define fst first
#define snd second
#define fore(i,a,n) for(ll i=a;i<n;i++)
#define rfore(i, a, b) for(ll i = b - 1; i >= (ll)a; i--)
#define pb push_back
#define mp make_pair
#define bs binary_search
#define mm(a,b) memset(a,b,sizeof(a));
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int) (n).size())
#define INFI ((ll)1e9)
#define MINI ((ll)-1e15)
#define EPS 1e-9
#define endl "\n"
using namespace std;
typedef long long ll;  
typedef long double ld;
const ll MOD = 1e9+7;     
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const ll MAXN =1000005;

struct STree { // example: range sum with range addition
	vector<int> st,lazy;int n;
	STree(int n): st(4*n+5,0), lazy(4*n+5,0), n(n) {}
	void init(int k, int s, int e, int *a){
		lazy[k]=0;  // lazy neutral element
		if(s+1==e){st[k]=a[s];return;}
		int m=(s+e)/2;
		init(2*k,s,m,a);init(2*k+1,m,e,a);
		st[k]=st[2*k]+st[2*k+1]; // operation
	}
	void push(int k, int s, int e){
		if(!lazy[k])return; // if neutral, nothing to do
		st[k]+=(e-s)*lazy[k]; // update st according to lazy
		if(s+1<e){ // propagate to children
			lazy[2*k]+=lazy[k];
			lazy[2*k+1]+=lazy[k];
		}
		lazy[k]=0; // clear node lazy
	}
	void upd(int k, int s, int e, int a, int b, int v){
		push(k,s,e);
		if(s>=b||e<=a)return;
		if(s>=a&&e<=b){
			lazy[k]+=v; // accumulate lazy
			push(k,s,e);return;
		}
		int m=(s+e)/2;
		upd(2*k,s,m,a,b,v);upd(2*k+1,m,e,a,b,v);
		st[k]=st[2*k]+st[2*k+1]; // operation
	}
	int query(int k, int s, int e, int a, int b){
		if(s>=b||e<=a)return 0; // operation neutral
		push(k,s,e);
		if(s>=a&&e<=b)return st[k];
		int m=(s+e)/2;
		return query(2*k,s,m,a,b)+query(2*k+1,m,e,a,b); // operation
	}
	void init(int *a){init(1,0,n,a);}
	void upd(int a, int b, int v){upd(1,0,n,a,b,v);}
	int query(int a, int b){return query(1,0,n,a,b);}
}; // usage: STree rmq(n);rmq.init(x);rmq.upd(s,e,v);rmq.query(s,e);

ll n,t,q,x,k,d,a;
map<ll,ll> m,m2;
set< ll > s;
int main(){
    cin >> n >> d >> a;
    STree st(MAXN);
    fore(i,0,n){
        ll x,y;
        cin >> x >> y;
        s.insert(x); s.insert(x+2*d);
        m2[x]=y;
    }
    for(auto x : s){
        m[x]=q;
        if(m2[x])st.upd(q,q+1,m2[x]);
        q++;
    }
    ll res = 0;
    for(auto x : s){
        if(!m2[x])continue;
        ll l = st.query(m[x],m[x]+1);
        if(l <= 0)continue;
        ll t = x+(2*d);
        res+=(l+a-1)/a;
        st.upd(m[x],m[t]+1,-(((l+a-1)/a)*a));
    }
    cout << res;
}   


Measured memory_bytes: 100224
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;

int main()
{
  int X,i=1,tmp=0;
  cin>>X;
  while(tmp<X){
    tmp+=i;
    i++;
  }
  cout<< i-1  <<endl;
}

Measured memory_bytes: 256
// Problem: C - Step
// Contest: AtCoder - AtCoder Beginner Contest 176
// URL: https://atcoder.jp/contests/abc176/tasks/abc176_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define ll long long
const int N = 2e5+5;
const int mod = 1e9;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 10000000;
 
void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(9);
}
 
//3. Structure or classes
//3. Ends here
 
//1. Data structures declaration here
//1. Ends here
 
//2. Extra Functions here
//2. Ends here
 
 
void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}
 
 
 
void solve()
{
	int n;cin>>n;
	int a[n];
	
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	int maxh=-1;
	int sum=0;
	
	for(int i=0;i<n;i++){
		maxh=max(maxh,a[i]);
		sum+=maxh-a[i];
	}
	
	cout<<sum<<"\n";
    return;
}
// how r u bro

Measured memory_bytes: 5148
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJDPL_1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = ReadInt();
            int n = nm[0];
            int m = nm[1];

            var c = ReadInt().OrderBy(x => x).ToArray();

            int[,] dp = new int[m + 1, n + 1];
            for (int i = 0; i < m + 1; i++)
            {
                for (int j = 0; j < n + 1; j++)
                {
                    dp[i, j] = int.MaxValue / 2;
                }
            }
            dp[0, 0] = 0;

            for (int i = 1; i <= m; i++)
            {
                for (int j = 0; j < n + 1; j++)
                {
                    if (j < c[i - 1])
                    {
                        dp[i, j] = Math.Min(dp[i, j], dp[i - 1, j]);
                    }
                    else dp[i, j] = Math.Min(dp[i, j - c[i - 1]] + 1, dp[i - 1, j]);
                }
            }

            Console.WriteLine(dp[m, n]);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}



Measured memory_bytes: 20124
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

pair<int, int> dfs(const vector<vector<int>>& graph, int v, int p) {
    int diam = 0;

    int top1 = 0, top2 = 0;

    for (int u: graph[v])
        if (u != p) {
            auto sub = dfs(graph, u, v);

            diam = max(diam, sub.first);
            sub.second += 1;
            
            if (sub.second > top1)
                top2 = top1, top1 = sub.second;
            else if (sub.second > top2)
                top2 = sub.second;
        }

    diam = max(diam, top1 + top2);
    return {diam, top1};
}

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n = input<int>();
    vector<vector<int>> graph(n);

    for (int i = 0; i != n - 1; ++i) {
        int a, b;
        cin >> a >> b;

        --a, --b;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int rs = dfs(graph, 0, -1).first;

    string win = "First";
    string lose = "Second";
    
    if (rs == 0)
        cout << win << "\n";
    else if (rs == 1)
        cout << lose << "\n";
    else {
        rs -= 2;

        if (rs % 3 == 2)
            cout << lose << "\n";
        else
            cout << win << "\n";
    }
    return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  int a;
  unordered_map<int, int> mp;
  LL now = 0;
  mp[0] = 1;
  REP (i, n) {
    cin >> a;
    now = (now + a) % m;
    mp[now] += 1;
  }

  LL ans = 0;
  for (auto x : mp) {
    if (x.second > 1) {
      ans += (LL)x.second * (LL)(x.second - 1) / 2;
    }
  }
  cout << ans << endl;
}


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

int n;
int m;

int l[200055], r[200055], a[200055];

vector<int> in[200055];
vector<int> out[200055];

long long dp[200055];

long long dat[800055];
long long lazy[800055];

void push(int from, int to) {
	dat[to] += lazy[from];
	lazy[to] += lazy[from];
}
void update(int id, int x, int y, int l, int r, long long val) {
	if (l > y || r < x) return;
	
	if (l <= x && y <= r) {
		dat[id] += val;
		lazy[id] += val;
		return;
	}
	
	int mid = (x + y) >> 1;
	
	if (lazy[id] != 0) {
		push(id, id + id);
		push(id, id + id + 1);
		
		lazy[id] = 0;
	}
	
	update(id + id, x, mid, l, r, val);
	update(id + id + 1, mid + 1, y, l, r, val);
	
	dat[id] = max(dat[id + id], dat[id + id + 1]);
}
long long query(int id, int x, int y, int l, int r) {
	if (l > y || r < x) return -LLONG_MAX;
	
	if (l <= x && y <= r) {
		return dat[id];
	}
	
	int mid = (x + y) >> 1;
	
	if (lazy[id] != 0) {
		push(id, id + id);
		push(id, id + id + 1);
		
		lazy[id] = 0;
	}
	
	return max(query(id + id, x, mid, l, r), query(id + id + 1, mid + 1, y, l, r));
}
int main() {
	cin >> n >> m;
	
	for (int i = 0; i < m; i++) {
		scanf("%d %d %d", &l[i], &r[i], &a[i]);
		
		in[l[i]].push_back(i);
		out[r[i]].push_back(i);
	}
	
	for (int i = 1; i <= n; i++) {
		for (auto v : in[i]) {
			update(1, 0, n, 0, i - 1, a[v]);
		}
		
		long long val = query(1, 0, n, 0, i - 1);
		
		dp[i] = val;
		
		update(1, 0, n, i, i, dp[i]);
		
		for (auto v : out[i]) {
			update(1, 0, n, 0, l[v] - 1, -a[v]);
		}
	}
	
	cout << *max_element(dp, dp + n + 1);
}


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

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':


N = int(input().rstrip())
xyh = []
itr = 0
for i in range(N):
	a, b, c = map(int, input().rstrip().split())
	itr = max(itr, c)
	xyh.append([a, b, c])

def solve(x, y, h):
	for xyh_in in xyh:
		if xyh_in[2] != max((h - abs(x - xyh_in[0]) - abs(y - xyh_in[1])), 0):
			return False
	return True

for i in range(101):
	for j in range(101):
		for k in range(itr, itr+101):
			if solve(i, j, k):
				print(str(i) + " " + str(j) + " " + str(k))



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

int main(){
  int n;
  cin >> n;
  vector<char>s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  int count=0;
  for(int i=0;i<n-2;i++){
    if(s.at(i)=='A'){
      if(s.at(i+1)=='B'){
        if(s.at(i+2)=='C'){
          count++;
        }
        else{
          continue;
        }
      }
      else{
        continue;
      }
    }
    else{
      continue;
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	string A, B, C; cin >> A >> B >> C;
	if (A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0)) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int T;
    cin>>T;
    if(T>=30)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3632