akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    static int FIELD_SIZE = 10;

    public static void main(String[] args) throws IOException {

        // フィールドの初期化
        int[] field = initField();

        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(System.in));

        String input = bufferedReader.readLine();
        while (input != null) {
            int x = Integer.parseInt(input.split(",")[0]);
            int y = Integer.parseInt(input.split(",")[1]);
            int size = Integer.parseInt(input.split(",")[2]);
            selectPaintField(field, x, y, size);

            input = bufferedReader.readLine();
        }
        System.out.println(countField(field)[0]);
        System.out.println(countField(field)[1]);
    }

    /**
     * フィールドの色の濃さを評価して、白いフィールドと、一番色の濃いフィールドの数を数える
     *
     * @param field
     *            フィールドを表す配列
     * @return 結果の配列（[0]：白いフィールド数、[1]：一番色の濃いフィールド数）
     */
    private static int[] countField(int[] field) {
        int[] result = {0, 0};
        for (int y = 0; y < FIELD_SIZE; y++) {
            for (int x = 0; x < FIELD_SIZE; x++) {
                if (field[y * 10 + x] == 0) {
                    result[0]++;
                }
                if (result[1] < field[y * 10 + x]) {
                    result[1] = field[y * 10 + x];
                }
            }
        }
        return result;
    }

    /**
     * フィールドを表す配列を初期化する
     *
     * @return 初期化されたフィールド用配列
     */
    private static int[] initField() {
        int[] field = new int[FIELD_SIZE * FIELD_SIZE];
        for (int y = 0; y < FIELD_SIZE; y++) {
            for (int x = 0; x < FIELD_SIZE; x++) {
                field[y * FIELD_SIZE + x] = 0;
            }
        }
        return field;
    }

    /**
     * フィールドに色を塗る。
     *
     * @param field
     *            フィールドを表す配列
     * @param x
     *            フィールドのx座標
     * @param y
     *            フィールドのy座標
     */
    private static void paintField(int[] field, int x, int y) {
        if (0 <= x && x < FIELD_SIZE && 0 <= y && y < FIELD_SIZE)
            field[y * FIELD_SIZE + x]++;
    }

    /**
     * インクのサイズにより、色を塗る範囲を決める
     *
     * @param field
     *            フィールドを表す配列
     * @param x
     *            フィールドのx座標
     * @param y
     *            フィールドのy座標
     * @param size
     *            インクのサイズ
     */
    private static void selectPaintField(int[] field, int x, int y, int size) {
        paintField(field, x, y);
        paintField(field, x - 1, y);
        paintField(field, x, y - 1);
        paintField(field, x + 1, y);
        paintField(field, x, y + 1);

        if (size > 1) {
            paintField(field, x - 1, y - 1);
            paintField(field, x + 1, y - 1);
            paintField(field, x - 1, y + 1);
            paintField(field, x + 1, y + 1);
        }

        if (size > 2) {
            paintField(field, x - 2, y);
            paintField(field, x, y - 2);
            paintField(field, x + 2, y);
            paintField(field, x, y + 2);
        }
    }

}

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

#define INF INT_MAX
typedef long long ll;

using namespace std;

char a[1005][1005];
int memo[1005][1005];
vector<pair<int,int>> b;

int main(void){
	int H,W;
	cin >> H >> W;
	queue<pair<int,int>> q;
	for(int j = 0;j < H;j++){
		for(int i = 0;i < W;i++){
			cin >> a[j][i];
			if(a[j][i] == '#'){
				b.push_back(make_pair(j,i));
				q.push(make_pair(j,i));
				memo[j][i] = 0;
			}else{
				memo[j][i] = INF;
			}
		}
	}
	int ans = 0;
	while(q.size() > 0){
		int y = q.front().first;
		int x = q.front().second;
		q.pop();
		for(int dirY = -1;dirY <=1;dirY++){
			for(int dirX = -1;dirX <= 1;dirX++){
				if((dirY == dirX) || (dirY == -1*dirX))continue;
				if(0 <= y + dirY && y + dirY < H
					&& 0 <= x + dirX && x + dirX < W){
					if(memo[y+dirY][x+dirX] > memo[y][x] + 1 ){
						memo[y+dirY][x+dirX] = memo[y][x] + 1;
						if(ans < memo[y+dirY][x+dirX])ans = memo[y+dirY][x+dirX];
						q.push(make_pair(y+dirY,x+dirX));
					}
				}
			}
		}
	}

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

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

using namespace std;

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

    cin >> N;
    rep(i, N) {
        int val;
        cin >> val;
        H.push_back(val);
    }
    
    int count[100000] = {0};
    REP(i, 1, N) count[i] = H[i] <= H[i - 1] ? count[i - 1] + 1 : 0;
    cout << *max_element(count, count + N) << endl;
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> e(m);
  for (auto& x : e) {
    cin >> x.first >> x.second;
    x.first--;
    x.second--;
  }
  vector<int> par(n, -1);
  auto root = [&](int t) {
    if (par[t] < 0) return t;
    for (int i = t;; i = par[i])
      if (par[i] < 0) return par[t] = i;
  };
  vector<ll> ans;
  ll a = (ll)n * (n - 1) / 2;
  for (int i = m; i--;) {
    ans.push_back(a);
    int r1 = root(e[i].first), r2 = root(e[i].second);
    if (r1 != r2) {
      a -= (ll)par[r1] * par[r2];
      if (par[r1] > par[r2]) swap(r1, r2);
      par[r1] += par[r2];
      par[r2] = r1;
    }
  }
  reverse(ans.begin(), ans.end());
  for (auto x : ans) cout << x << "\n";
}


Measured memory_bytes: 3444
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int a, b;
	scanf("%d %d", &a, &b);
	if(a < 1 || a > 9 || b < 1 || b > 9) puts("-1");
	else printf("%d\n", a * b);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

class Point {
    public:
        double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator+ (Point p) { return Point(x + p.x, y + p.y); }
    Point operator- (Point p) { return Point(x - p.x, y - p.y); }
    Point operator* (double a) { return Point(x * a, y * a); }
    Point operator/ (double a) { return Point(x / a, y / a); }

    double norm() { return x * x + y * y; }
    double abs() { return sqrt(norm()); }

    bool operator< (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator== (const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};
struct Segment {
    Point p1, p2;
    Segment(Point p1, Point p2): p1(p1), p2(p2) {}
};
typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;

class Circle {
    public:
        Point c;
        double r;
        Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

double dot(Vector v1, Vector v2) {
    return v1.x * v2.x + v1.y * v2.y;
}

double cross(Vector v1, Vector v2) {
    return v1.x * v2.y - v1.y * v2.x;
}

Point project(Segment s, Point p) {
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / base.norm();
    return s.p1 + base * r;
}

Point reflect(Segment s, Point p) {
    Point x = project(s, p);
    return p + (x - p) * 2;
}

#define equals(a,b) fabs(a-b)<EPS
bool isParallel(Vector a, Vector b) {
    return equals(cross(a, b), 0.0);
}
bool isOrthogonal(Vector a, Vector b) {
    return equals(dot(a, b), 0.0);
}

int check(Vector a, Vector b) {
    if (isParallel(a, b)) return 2;
    if (isOrthogonal(a, b)) return 1;
    return 0;
}


int main() {
    int q; cin >> q;
    rep(_, q) {
        double x[4], y[4];
        rep(i, 4) cin >> x[i] >> y[i];
        Vector v1(Point(x[0], y[0]) - Point(x[1], y[1]));
        Vector v2(Point(x[2], y[2]) - Point(x[3], y[3]));
        cout << check(v1, v2) << endl;
    }
}



Measured memory_bytes: 3240
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int n,m;
int ans;
int b[10][10];
int f[300][10];
int cty(int x,int y){
    if(f[x][y]!=-1) return f[x][y];
    if(!(x&(1<<(y-1)))) return f[x][y]=0;
    f[x][y]=0;        
    int X=x;
    x^=(1<<(y-1));
    for(int i=1;i<=n;i++){
            if(!b[i][y]) continue;
            if(!(x&(1<<(i-1)))) continue;
            f[X][y]+=cty(x,i);
    }
    return f[X][y];
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
            int q,w;
            scanf("%d%d",&q,&w);
            b[q][w]=b[w][q]=1;
    }
    memset(f,-1,sizeof(f));
    f[1][1]=1;
    for(int i=2;i<=n;i++)f[1<<(i-1)][i]=0;
    for(int i=1;i<=n;i++){
            ans+=cty((1<<n)-1,i);
    }
    printf("%d\n",ans);
	//system("pause");
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gya[200010];
ll kai[200010];
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    gya[n]=gyaku(kai[n]);
    for(int i=n-1;i>=1;i--){
        gya[i]=gya[i+1]*(i+1);
        gya[i]%=mod;
    }
    gya[0]=1;
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    ret*=gya[k];
    ret%=mod;
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){
    ll n,x;cin>>n>>x;
    vector<pll> v;
    ll s=0;
    ll b[n],l[n],u[n];
    ll ma=0;
    rep(i,0,n){
        cin>>b[i]>>l[i]>>u[i];
        v.push_back(make_pair(u[i]*(x-b[i])+l[i]*b[i],i));
        s+=l[i]*b[i];
        ma=max(ma,l[i]);
    }
    sort(v.begin(),v.end(),greater<pll>());
    ll ans=0;
    ll t=0;
    bool used[n];
    fill(used,used+n,false);
    rep(i,0,n){
        t+=v[i].first;
        if(t<s){
            ans+=x;
            used[v[i].second]=true;
        }
        else{
            t-=v[i].first;
            ll mi=inf;
            rep(j,0,n){
                if(used[j]==false){
                
                ll e=ceil((double)(s-t)/l[j]);
                mi=min(mi,e);
                ll k=t+l[j]*b[j]-u[j]*b[j];
                ll f=ceil((double)(s-k)/u[j]);
                mi=min(mi,f);
                }
              else{
                ll k=t+v[i].first-(u[j]*(x-b[j])+l[j]*b[j]);
                ll e=ceil((double)(s-k)/l[j]);
                mi=min(mi,e);
                ll kk=k+l[j]*b[j]-u[j]*b[j];
                ll f=ceil((double)(s-kk)/u[j]);
                mi=min(mi,f);
              }
            }
            cout<<ans+mi<<endl;
            return 0;
        }
        //cout<<ans<<" "<<s<<endl;
    }
}


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

using std::cout;
using std::cin;
using std::endl;

/*  テンプレここから */
typedef long long ll;

#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int n;
    cin >> n;

    int a = 0;
    for(int i = 1; i <= n; ++ i){
        if(i % 2 == 1) ++ a;
    }

    printf("%.10f\n", a/(double)n);
}

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

A.sort()

R = A[0]

while True:
    C = A.copy()
    B = [A[0]] + [a for a in [A[i+1] % A[i] for i in range(len(A)-1)] if a > 0]
    B = list(set(B))
    B.sort()
    R = min(R, B[0])
    if C == B:
        break
    elif R == 1:
        break
    else:
        A = B

print(R)


Measured memory_bytes: 14608
#include <bits/stdc++.h>
using namespace std;
 
//#define READ_NUMBER(i) scanf("%d",i)
 
int main(){
	int A, B;
	cin >> A >> B;
	if(B % A == 0){
		cout << A + B << endl;
	}else{
		cout << abs(A - B) << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  int N;
  scanf("%d", &N);
  int A[N];
  int seCnt = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    if (A[i] % 2 == 0) {
      seCnt++;
      if ((A[i] % 3 == 0 || A[i] % 5 == 0)) {
        cnt++;
      }
    }
  }
  if (seCnt == cnt) {
    printf("APPROVED\n");
  } else {
    printf("DENIED\n");
  }
  return 0;
}

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

int main() {
    int n, m, tmp;
    cin >> n >> m;
    int v[m], u[m-1];
    for (int i=0; i<m; i++) {
        cin >> tmp;
        v[i] = tmp;
    }
    if (n>=m) {
        cout << 0 << endl;
        return 0;
    }
    sort(v, v+m); // ascending
    for (int i=0; i<m-1; i++) {
        u[i] = v[i+1] - v[i];
    }
    sort(u, u+m-1); // ascending
    int sum=0;
    for (int i=0; i<m-n; i++) {
        sum += u[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
//#define f first
#define s second
#define int long long
#define vi vector<int>
#define pi pair<int,int>
const int mod = (int)1e9+7;
const int N = (int)1e5+7;

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
   // cin >> t;
    int c = 1;
    while(t--)
    {
      int n,k;
      cin >> n >> k;
      int ans =  0;
      for(int i=0;i<n;i++)
      {
          int a;cin >> a;
           ans+=k<=a;
      }
      cout<<ans<<"\n";
     
    }  
 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    string a, b;
    cin >> a >> b;
    int num1, num2;
    istringstream ss;
    ss = istringstream(a);
    ss >> num1;
    ss = istringstream(b);
    ss >> num2;
    string bb, aa;
    rep(i, num1){bb += b;}
    rep(i, num2){aa += a;}
    if(aa > bb){cout << bb << endl;}
    else{cout << aa << endl;}
}

Measured memory_bytes: 3556
#include<iostream>
#include<string>
using namespace std;
string a;
bool ab[200005];
int main(){
	int i,j,k;
	int x,y;
	int s=0;
	cin>>a;
	for(i=0;i<a.size();i++){
		if(ab[i])continue;
		x=i; y=i+1;
		while(a[x]=='S' && a[y]=='T'){
			ab[x]=true; ab[y]=true;
			x--; y++;
			while(x>=0 && ab[x]){
				x--;
			}
			while(y<a.size() && ab[y]){
				y++;
			}
			if(x<0 || y>=a.size())break;
		}
	}
	for(i=0;i<a.size();i++){
		if(!ab[i])s++;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 772
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int num = 1;
    while(1) {
        int n;
        cin >> n;
        if(n == 0) break;

        vector<double> x(n), y(n);
        for(int i = 0; i < n; i++) {
            cin >> x[i] >> y[i];
        }

        double rectangle = 0.0;

        for(int i = 1; i < n; i++) {
            double X = x[i] - x[i-1];
            double Y = y[i] + y[i-1];
            rectangle += X * Y;
        }
        double X = x[0] - x[n-1];
        double Y = y[0] + y[n-1];
        rectangle += X * Y;

        printf("%d %.1f\n", num, rectangle/2);
        num++;
    }

    return 0;
}


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

/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/* MACROS */ 
typedef unsigned long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */ 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

// #define cerr if(false)cerr
/* CODE STARTS HERE */

void solve(){
    int n; cin >> n;
    vi v(n),ans(n);
    
    ll sum = 0;
    rep(i,0,n) cin >> v[i], sum += v[i];
    
    for(int i=0;i<n-1;i+=2){
    	sum -= (2*v[i]);
    }
    
    ans[n-1] = sum;
    repr(i,n-2,0){
    	ans[i] = 2*v[i] - ans[i+1];
    }
    for(auto x:ans) cout << x << ' ';
}

int main(){
    IOS;
    solve();
}

Measured memory_bytes: 4008
#include <iostream>
#include <algorithm>
using namespace std;
struct Student{
    int n,time;

    bool operator<(Student student) const{
        return time < student.time;
    }
}student[100000];

int main() {
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        int time;
        cin >> time;
        student[i-1] = {i,time};
    }
    sort(student,student+N);

    for(int i = 0; i < N; i++) {
        cout << student[i].n << ' ';
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 1536
/*
phu lki ...
*/

#include<bits/stdc++.h>
#define mod 1000000007
#define pp pair<long long,long long>
#define ll long long
#define ff first
#define ss second
#define horse_power ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
ll n,k;

void solve(){
   cin>>n>>k;
   vector<ll> h(n+1),dp(n+1,0);
   for(int i=1;i<=n;i++)
      cin>>h[i];
   dp[1]=0;
   // cout<<dp[1]<<" "<<dp[2]<<" ";
   for(int i=2;i<=n;i++)
   {   dp[i]=INT_MAX;
       for(int j=max(1LL,i-k);j<i;j++){
         dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
       }
  // cout<<dp[i]<<" ";
   }
   cout<<dp[n]<<"\n";


}

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


}


Measured memory_bytes: 1792
#include<stdio.h>
#define N 36
int main (){
  char T1[N],T2[N];
  int F1[N],F2[N];
  int n,i,j,f,minj,flag=0;
  char t,k;
  scanf("%d%c",&n,&k);
  for(i=0;i<n;i++){
    if(i!=n-1) scanf("%c%d ",&T1[i],&F1[i]);
    else scanf("%c%d",&T1[i],&F1[i]);
    T2[i]=T1[i];
    F2[i]=F1[i];
  }
  
  

  for(i=0;i<n;i++){
    for(j=n-1;j>0;j--){
      if(F1[j]<F1[j-1]){
	f=F1[j-1];
	F1[j-1]=F1[j];
	F1[j]=f;
	t=T1[j-1];
	T1[j-1]=T1[j];
	T1[j]=t;
      }
	}
  }
 for(i=0;i<n-1;i++) printf("%c%d ",T1[i],F1[i]);
  printf("%c%d\n",T1[n-1],F1[n-1]);
  printf("Stable\n");

  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(F2[j]<F2[minj]) minj = j;
    }
    f=F2[i];
    F2[i]=F2[minj];
    F2[minj]=f;
    t=T2[i];
    T2[i]=T2[minj];
    T2[minj]=t;
  }
  for(i=0;i<n-1;i++) {
    printf("%c%d ",T2[i],F2[i]);
    if(T2[i]!=T1[i]) flag=1;
  }
  printf("%c%d\n",T2[n-1],F2[n-1]);
  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");
  
  
  return 0;
}



Measured memory_bytes: 2124
aryAlphabetCount = Array.new(26,0);
strAlphabet = "abcdefghijklmnopqrstuvwxyz";

while true do
 
	inputLines = gets;
 
	if inputLines == nil || inputLines.length == 0 then
		break;
	end
 
	checkStr = inputLines.downcase;
	
	for checkStrIndex in 0..checkStr.length-1 do
		for alphabetIndex in 0..strAlphabet.length-1 do
			
			if checkStr[checkStrIndex] == strAlphabet[alphabetIndex] then
				
				aryAlphabetCount[alphabetIndex] += 1;
		end
			
		end
	end
end

for index in 0..aryAlphabetCount.length-1 do
	
	puts strAlphabet[index] + " : " + aryAlphabetCount[index].to_s
end

Measured memory_bytes: 8836
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;

int n, a[mxn];
ll cs[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a+n, greater<int>());
    for (int i = 0; i < n; i++) {
        cs[i] += a[i], cs[i+1] += cs[i];
    }
    auto can = [&](int x)->bool {
        ll siz = cs[n]-(x ? cs[x-1] : 0);
        for (int i = x-1; i >= 0; i--) {
            if (a[i] > siz*2) return 0;
            siz += a[i];
        }
        return 1;
    };
    int lo = 0, hi = n-1, ans;
    while (lo<=hi) {
        auto mid = (lo+hi)>>1;
        if (can(mid)) ans = mid, lo = mid+1;
        else hi = mid-1;
    }
    cout << ans+1 << '\n';
}

Measured memory_bytes: 1408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 3e5+10;

//head

int h, w, m;
P hw[N];
int cnth[N], cntw[N];
vi mh, mw;
int maxh, maxw;


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w >> m;
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    cnth[l]++;
    cntw[r]++;
    hw[i] = P(l, r);
  }
  sort(hw, hw+m);
  maxh = *max_element(cnth, cnth+h);
  maxw = *max_element(cntw, cntw+w);
  rep(i, h) if(maxh == cnth[i]) {
    mh.emplace_back(i);
  }
  rep(i, w) if(maxw == cntw[i]) {
    mw.emplace_back(i);
  }
  rep(i, mh.size()) rep(j, mw.size()) {
    auto itr = lower_bound(hw, hw+m, P(mh[i], mw[j]));
    if(*itr == P(mh[i], mw[j])) continue;
    else {
      cout << maxh + maxw << endl;
      return 0;
    }
  }

  cout << maxh + maxw - 1 << endl;
}

Measured memory_bytes: 12032
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX_TIME = 24*60*60 + 1;

int calcTime(string s){
    int ret = (s[0] - '0') * 60 * 60 * 10;
    ret += (s[1] - '0') * 60 * 60;
    ret += (s[3] - '0') * 60 * 10;
    ret += (s[4] - '0') * 60;
    ret += (s[6] - '0') * 10;
    ret += (s[7] - '0');
    return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> ims(MAX_TIME, 0);
        rep(i,n){
            string s;
            cin >> s;
            ims[calcTime(s)]++;
            cin >> s;
            ims[calcTime(s)]--;
        }
        int ans = 0;
        rep(i,MAX_TIME-1){
            ims[i+1] += ims[i];
            chmax(ans, ims[i]);
        }
        cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 3524
#include <stdio.h>
int main(void){
  int n,x;
  scanf("%d%d",&n,&x);
  int l[n],warp=0,ans=1;
  for(int i=0; i<n; i++){
    scanf("%d", &l[i]);
    warp+=l[i];
    if(warp<=x)ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
int main(){
  long long a,b,p,wr=2,ans=1;
  cin>>a>>b;
  while (a!=b){
    if(a>b)a=a-b;
    else b=b-a;
  }
  p=a;
  while(wr*wr<p&&a!=1){
    if(a%wr==0){
      while(a%wr==0)a=a/wr;
      ans++;
    }
    wr++;
  }
  if(a!=1)ans++;
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
L, A, B, M = map(int, raw_input().split())

# first i such that A + i*B has d digits.
# A + i*B >= 10^d
# i*B >= 10^d - A
# i >= 
# i = (10^d - A + (B-1))/B

def get_indices(d):
	i_start = (10**d - A + (B-1)) / B
	i_end = (10**(d+1) - A + (B-1)) / B
	i_start = max(0, i_start)
	i_end = max(0, i_end)
	i_start = min(L, i_start)
	i_end = min(L, i_end)
	return (d+1, i_start, i_end)
	
index_pairs = [get_indices(n) for n in xrange(0, 19)]

def get_chunk_value(num_digs, i_start, i_end):
	if i_start == i_end:
		return (0, 0)
	
	a = A + B*(i_end - 1)
	d = -B
	n = i_end - i_start
	r = 10 ** num_digs
	
	Mt = M*((1-r)**2)
	
	numerator = (1-r)*(a - (a + n*d)*pow(r, n, Mt)) + d*r*(1 - pow(r, n, Mt))
	numerator %= Mt
	assert numerator % (1-r)**2 == 0
	return (num_digs*(i_end-i_start), numerator/(1-r)**2)
	
	

# print index_pairs
chunk_values = [get_chunk_value(n, i_start, i_end) for n, i_start, i_end 
													in index_pairs]
# print chunk_values

ans = 0
digits_offset = 0
for num_digs, value in reversed(chunk_values):
	ans += value * pow(10, digits_offset, M)
	digits_offset += num_digs
	
ans %= M
print ans
	





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

using namespace std;

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

    int ans = 0;
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k<N; k++){
                if(L[i] != L[j] && L[j] != L[k] && L[k] != L[i]){
                    int maxL = max(L[i], max(L[j], L[k]));
                    if(maxL < L[i] + L[j] + L[k] - maxL){
                        ans++;
                    }
                }
            }
        }
    }

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

Measured memory_bytes: 3636
#include<stdio.h>
#include <string.h>

int main(){
	char bun[100];
	char right[100] = {'y','u','i','o','p','h','j','k','l','n','m'};
	int i,j;
	int flag = 2;
	int beforeflag = 2;
	int count = 0;
	for(;;){
		scanf("%s",bun);

		if(strcmp(bun,"#") == 0)break;

		
		for(j = 0;j < strlen(right);j++){
			if(bun[0] == right[j]){
				beforeflag = 1;
				break;
			}
		}
			
			
		

		for(i = 1;i < strlen(bun);i++){
			flag = 2;
			for(j = 0;j < strlen(right);j++){
				if(bun[i] == right[j]){
					flag = 1;
					break;
				}
			}
			if(beforeflag != flag){
				beforeflag = flag;
				count++;
			}
		}
		printf("%d\n",count);
		beforeflag = 2;
		count = 0;

	}
	return 0;
}

Measured memory_bytes: 540
function Main(input) {
  input = input.split("\n");
  var A = input[1].split(" ").map(Number);
  var sum = 0;
  for(var i=0;i<A.length;i++){
    sum += A[i];
  }
  var half = 0;
  var jout = 0;
  for(var j=0;sum/2>half;j++){
    half += A[j];
    jout = j;
  }
  if(half-sum/2 > sum/2-half+A[jout]){
  half -= A[jout];
  }
	console.log(Math.abs(half-sum/2)*2);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 36288
#シェルソート
#挿入ソートは、飛び飛びで値を整列すつもの
#それの飛ぶ範囲をどんどん狭めていって正解を出す
import math

def insertionsort(list, length, g, count):
    for i in range(g, length):
        v = list[i]
        j = i - g
        while j >= 0 and list[j] > v:
            list[j+g] = list[j]
            j = j - g
            count += 1
        list[j+g] = v

    return list, count

def shellsort(list, length):
    count = 0
    g_list = [1]
    g_cell = 4
    while g_cell < length:
        g_list.append(g_cell)
        g_cell = g_cell * 3 + 1

    g_list.reverse()
    print(len(g_list))
    result = ''
    for g in g_list:
        result += str(g) + ' '
    print(result[:-1])

    for g in g_list:
        list, count = insertionsort(list, length, g, count)

    return list, count

l = int(input())
target = []
for i in range(l):
    target.append(int(input()))

result, count = shellsort(target, l)
print(count)
for r in result:
    print(r)



Measured memory_bytes: 45580
while 1:
	arr = list(map(str, input().split()))
	a = int(arr[0])
	b = int(arr[2])
	op = arr[1]
	
	if op == '+':
		print(a + b)
	elif op == '-':
		print(a - b)
	elif op == '*':
		print(a * b)
	elif op == '/':
		print(int(a / b))
	else:
		break



Measured memory_bytes: 5596
def solve(N, M, C, Bs, As):
    ans = 0
    for adata in As:
        if sum(a * b for a, b in zip(adata, Bs)) + C > 0:
            ans += 1
    return ans


if __name__ == "__main__":
    N, M, C = tuple(map(int, input().split(" ")))
    Bs = list(tuple(map(int, input().split(" "))))
    As = list(list(tuple(map(int, input().split(" ")))) for __ in range(N))
    print(solve(N, M, C, Bs, As))


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

struct Edge {
  int index;
  int dst;
};

ll use[20];

ll DFS(int curr, int dst, int prev, ll used, const vector<vector<Edge>>& edges) {
  // DBG(curr, dst, prev, used);
  if (curr == dst) {
    return used;
  }
  for (const Edge& e : edges[curr]) {
    if (e.dst == prev) continue;
    ll res = DFS(e.dst, dst, curr, used | (1LL << e.index), edges);
    if (res > 0) {
      return res;
    }
  }
  return 0;
}

int popcount(ll x) {
  int ret = 0;
  REP(i, 50) if (x & (1LL << i)) ++ret;
  return ret;
}

int main() {
  CIN(int, N);
  vector<vector<Edge>> edges(N);
  REP(i, N - 1) {
    CIN(int, a, b);
    --a, --b;
    edges[a].push_back({i, b});
    edges[b].push_back({i, a});
  }
  CIN(int, M);
  REP(i, M) {
    CIN(int, u, v);
    --u, --v;
    use[i] = DFS(u, v, -1, 0, edges);
    DBG(use[i]);
  }
  ll ans = 1LL << (N - 1);
  for (int s = 1; s < (1 << M); ++s) {
    int cnt = 0;
    ll u = 0;
    for (int i = 0; i < M; ++i) {
      if (s & (1 << i)) {
        ++cnt;
        u |= use[i];
      }
    }
    ans -= (cnt % 2 ? 1 : -1) * (1LL << (N - 1 - popcount(u)));
  }
  COUT(ans);
}


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

#define o(output) cout << output << endl

using namespace std;

string s,t,u;
int a,b,c,d;
int l[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
char A,B;
priority_queue<int,vector<int>,greater<int> >small;

int main(){
  cin >> s >> t >>u;
  if(s.back()==t.front()&&t.back()==u.front())o("YES");
  else o("NO");
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = S.length() - 1;
        long ans = 0;

        for (int i = 0; i < Math.pow(2, n); i++) {

            StringBuilder sb = new StringBuilder(S);
            for(int j = n - 1; j >= 0; j--) {
                if( (1 & i >> j) == 1) {
                    sb.insert(j + 1, "+"); 
                }
            }

            String[] str = sb.toString().split("\\+", 0);
            for(int j = 0; j < str.length; j++) {
                ans += Long.parseLong(str[j]);
            }

        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define fi(n) for(int i=0;i<n;i++)
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int n,k;
	cin>>n>>k;
	int d;
	map<int,bool>m;int x;
	for(int i=0;i<k;i++){
		cin>>d;
		for(int j=0;j<d;j++)
		{
			cin>>x;
			m[x]=true;
		}
	}
	int count=0;
	for(int i=1;i<=n;i++){
		if(m.find(i)==m.end())
		count++;
	}
	cout<<count;
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000002



int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N);
	for(int i=0;i<N;i++)scanf("%d",&A[i]);
	
	for(int i=1;i<N;i++)A[i] ^= A[i-1];
	
	vector<vector<int>> ind(1<<20,vector<int>());
	
	for(int i=0;i<N;i++){
		ind[A[i]].push_back(i);
	}
	
	int ans = 0;
	if(A.back()==0){
		int t = 1;
		for(int i=0;i<ind[0].size()-1;i++){
			t = mod(t * 2);
		}
		ans = mod(ans + t);
	}
	
	for(int i=1;i<(1<<20);i++){
		if(A.back()!=0&&A.back()!=i)continue;

		int sum = 0;
		int dp_sum = 0;
		for(int j=0;j<ind[i].size();j++){
			if(j==0){
				//sum += 1;
				dp_sum += 1;
			}
			else{
				int t = distance(lower_bound(ind[0].begin(),ind[0].end(),ind[i][j-1]),lower_bound(ind[0].begin(),ind[0].end(),ind[i][j]));
				int dp = mod(sum + mod(dp_sum * t));
				sum = dp;
				dp = mod(dp + 1);
				
				dp_sum = mod(dp_sum + dp);
			}
		}
		
		if(A.back()==0){
			ans = mod(ans + dp_sum);
		}
		else{
			ans = mod(ans + sum + 1);
		}
		
	}
	
	cout<<ans<<endl;
		

	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);

    REP(i, N){
        cin >> A[i];
    }

    ll ans = 0;
    ll now = A[0];
    for(ll i=1; i<N; i++){
        if(now > A[i]){
            ans += now - A[i];
        }
        else{
            now = A[i];
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define rep(i,n) for(int i = 0;i < (n);i++)

using namespace std;
using ll = long long;
using P = pair<int,int>;



int main(){
	
	int N;
	cin >> N;
	
	vector<int> L(N);
	for(int i = 0;i < N;i++){
		cin >> L[i];
	}
	
	int count = 0;
	
	for(int i = 0;i < N;i++){
		for(int j = i + 1;j < N;j++){
			for(int k = j + 1;k < N;k++){
				if( ( L[i] != L[j] ) && ( L[j] != L[k] ) && ( L[i] != L[k] ) && ( i < j ) && ( j < k ) ){
					if( ( ( L[i] + L[j] ) > L[k] )
					 && ( ( L[i] + L[k] ) > L[j] )
					 && ( ( L[j] + L[k] ) > L[i] ) ){
						count++;
					}
				}
			}
		}
	}
	
	cout << count;
	
	
	return 0;
	
}


Measured memory_bytes: 3624
# AOJ 1007: JPEG Compression
# Python3 2018.7.5 bal4u

import sys
from sys import stdin
input = stdin.readline

cno = 0
while True:
	n = int(input())
	if n == 0: break
	cno += 1
	a = [[0 for j in range(12)] for i in range(12)]
	m = k = f = 1;
	while True:
		if f:
			for r in range(k-1, -1, -1):
				a[r][k-1-r] = m
				m += 1
		else:
			for c in range(k-1, -1, -1):
				a[k-1-c][c] = m
				m += 1
		f = 1-f
		k += 1
		if k > n: break
	k = n-1
	while True:
		if f:
			for c in range(n-k, n):
				a[2*n-1-k-c][c] = m
				m += 1
		else:
			for r in range(n-k, n):
				a[r][2*n-1-k-r] = m
				m += 1
		f = 1-f
		k -= 1
		if k < 1: break
	print("Case ", cno, ":", sep='')
	for r in range(n):
		for c in range(n): print(format(a[r][c], "3d"), end='')
		print()


Measured memory_bytes: 5660
from numpy import*;n,_=map(int,input().split());a=0;M=[array(list(map(int,input().split()))) for i in range(n)]
for i in range(n):
	for j in range(i+1,n):
		if linalg.norm(M[i]-M[j]).is_integer():a+=1
print(a)

Measured memory_bytes: 12484
/*input
12 18
*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n, m;
  cin >> n >> m;
  vector <ll> vec;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (m % i == 0) vec.pb(i);
      if (n / i != i && (m % (n / i)) == 0) vec.pb(n / i);
    }
  }
  sort(all(vec));
  n = vec.size();
  int ans = 0;
  map <ll, ll> mp;
  for (auto v : vec) {
    bool ok = true;
    for (auto it : mp) {
      if (__gcd(v, it.F) > 1) {
        ok = false;
      }
    }
    if (ok) {
      mp[v] = 1;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }
};

int main()
{
    input in;
    output out;

    int N = in.read<int>();
    std::vector<int> A(N);
    in.read(A.begin(), N);

    auto m = std::max_element(A.begin(), A.end());

    for (auto it = A.begin(); it != A.end(); ++it) {
        if (it != m) {
            out << *m;
            continue;
        }

        auto a = std::max_element(A.begin(), m);
        auto b = std::max_element(m + 1, A.end());
        if (a == m)
            out << *b;
        else if (b == A.end())
            out << *a;
        else
            out << std::max(*a, *b);
    }

    return 0;
}


Measured memory_bytes: 2432