akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define sentinel 2000000000
#define nMAX 500000
int L[(nMAX/2)+2],R[(nMAX/2)+2];
int count;
void merge(int A[],int n,int left,int mid,int right){
    int n1,n2;
    int i,j,k;
    n1=mid-left;
    n2=right-mid;
    
    for(i=0;i<n1;i++) L[i]=A[left+i];
    for(i=0;i<n2;i++) R[i]=A[mid+i];
    
    L[n1]=R[n2]=sentinel;
    i=0;j=0;
    for(k=left;k<right;k++){
	count++;
	if(L[i]<=R[j]) A[k]=L[i++];
	else A[k]=R[j++];
    }
}
    
void mergeSort(int A[],int n,int left,int right){
    int mid;
    if(left+1<right){
	mid=(left+right)/2;
	mergeSort(A,n,left,mid);
	mergeSort(A,n,mid,right);
	merge(A,n,left,mid,right);
    }
}

int main(void){
    int i,n;
    int A[nMAX];
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);

    mergeSort(A,n,0,n);
    for(i=0;i<n;i++){
	if(i) printf(" ");
	printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",count);

    return 0;
}

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

typedef long long ll;
typedef long double ld;

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

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

int main(){

    char c;

    cin >> c;

    cout << (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ? "vowel" : "consonant") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*(int)1e5 + 10;
// make sure N size is correctttt!!!!!!!!!


int n, a[N];
int32_t main(){_

   cin>>n;

   bool second = true;
   for (int i = 0; i < n; ++i)
   {
      int x;
      cin>>x;
      second &= (x % 2 == 0);
   }

   puts(second ? "second" : "first");
   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
const ll MOD=100000007;
#define rep(i,a,b) for(ll i=a;i<b;i++)
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}
int main(){
    ll n;
    cin>>n;
    vector<ll> h(n);
    rep(i,0,n) cin>>h[i];
    ll cnt=1;
    rep(i,1,n){
        bool f=1;
        rep(j,0,i){
            if(h[j]>h[i]) f=0;
        }
        if(f) cnt++; 
    }    
    cout<<cnt;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a=0,cnt=0,N;
    cin >> N;
    for (int i=1;i<N+1;i=i+2){
        for(int j=1;j<i+1;j++){
            if(i%j==0){
                cnt++;
            }
        }
        if(cnt==8){
            a++;
        }
        cnt=0;
    }
    cout <<a;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main (void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    //直接話せるとき
    if(abs(a - b) <= d && abs(b - c) <= d && abs(c - a) <= d){
        cout << "Yes" << endl;
    }else if(abs(c - a) <= d){
        cout << "Yes" << endl;
    }else if(abs(a - b) <= d && abs(b - c) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3580
import sys 
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
l = read().decode().split()
c = Counter(l)

max = c.most_common()[0][1]
ans = [i[0] for i in c.items() if i[1] >= max]

print('\n'.join(sorted(ans)))

Measured memory_bytes: 50064
#include <cstdio>

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    int ans;
    if((a + b) % 2 == 0){
        ans = (a + b) / 2;
    }else{
        ans = (a + b) / 2 + 1;
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass
{
	static void Main(string[] args)
	{
		AnswerA();
	}
	public static void AnswerA()
	{
	　var N = int.Parse(Console.ReadLine());
      var A = int.Parse(Console.ReadLine());

      var surplus = N % 500;
      if (surplus <= A)
        Console.WriteLine("Yes");
      else
        Console.WriteLine("No");
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define LL long long
#define INF (1LL << 60)
#define ULL unsigned long long
using namespace std;

template<class T> inline
void read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

/*============ Header Template ============*/

const int N = 20 + 5;
const int M = (1 << 20) + 5;
const int mo = 1000000007;

int n, m;
LL a[N];
LL fac[M], inv[M];
LL f[N][M];

LL C(int n, int m) {return fac[n] * inv[m] % mo * inv[n - m] % mo;}

LL getpow(LL a, LL b) {
    LL ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % mo;
        a = a * a % mo;
        b >>= 1;
    }
    return ans;
}

int main() {
    read(n), read(m);
    for (int i = 1; i <= m; i++) read(a[i]);
    fac[0] = 1;
    for (int i = 1; i <= (1 << n); i++) fac[i] = fac[i - 1] * i % mo; inv[1 << n] = getpow(fac[1 << n], mo - 2);
    for (int i = (1 << n) - 1; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % mo;
    sort(a + 1, a + m + 1);
    f[m + 1][0] = (1 << n);
    for (int i = m; i >= 1; i--) {
        for (int s = 0; s < (1 << n); s++) {
            (f[i][s] += f[i + 1][s]) %= mo;
            int res = (1 << n) - s - a[i];
            if (res < 0) break;
            for (int p = 0; p < n; p++) {
                int c = (1 << p) - 1;
                if (c > res) break;
                if ((1 << p) & s) continue;
                (f[i][s | (1 << p)] += C(res, c) * f[i + 1][s] % mo * fac[1 << p] % mo) %= mo;
            }
        }
    }
    LL ans = fac[1 << n];
    for (int s = 1; s < (1 << n); s++) {
        // printf("%d %lld\n", s, f[1][s]);
        ans = (ans + ((__builtin_popcount(s) & 1) ? -1 : 1) * f[1][s] * fac[(1 << n) - s - 1] % mo) % mo;
    }
    printf("%lld\n", (ans + mo) % mo);
    return 0;
}

Measured memory_bytes: 39168
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m, q_ = map(int, input().split())
acc = [[0]*(n+1) for _ in range(n+1)] # 最初に[0]を足しとく

for i in range(m):
    l, r = map(int, input().split())
    acc[l][r]+=1

#ヨコに累積和
for i in range(1,n+1):
    for j in range(1,n+1):
        acc[i][j] += acc[i-1][j]
#タテに累積和
for i in range(1,n+1):
    for j in range(1,n+1):
        acc[i][j] += acc[i][j-1]

ans = [0]*q_

for i in range(q_):
    p, q = map(int, input().split())
    ans[i] = acc[q][q]+acc[p-1][p-1]-acc[p-1][q]-acc[q][p-1]

print(*ans,sep='\n')


Measured memory_bytes: 19052
#include <cassert>
#include <iostream>
#include <vector>

/* デバッグ時はコメントアウトする */
#define NDEBUG

static const int MAX_WEIGHT = 50;	/* セミ地図の最大幅 */
static const int MAX_HEIGHT = 50;	/* セミ地図の最大高さ */

int scan_input_cicada(void)
{
	char in;
	std::cin >> in;
	return in - '0';
}

void cicada(void)
{
	int  weight, height;							/* input 幅、input 高さ */
	std::vector<int> min_encount(MAX_WEIGHT, 0);	/* メモ用最小遭遇数 */

	/* -------------------- */
	/* 地図の幅、高さを取得 */
	/* -------------------- */
	std::cin >> height >> weight;
	
	/* -------------------------- */
	/* 最小セミ遭遇数の一覧を作成 */
	/* -------------------------- */
	/* 左上 */
	min_encount[0] = scan_input_cicada();
	
	/* 一番上の一列 */
	for (int w = 1; w < weight; ++w)
	{
		min_encount[w] = min_encount[w - 1] + scan_input_cicada();
	}

	/* 二列目以降 */
	for (int h = 1; h < height; ++h)
	{
		/* 一番左 */
		min_encount[0] += scan_input_cicada();

		/* 左から2番目以降 */
		for (int w = 1; w < weight; ++w)
		{
			int left = min_encount[w - 1];
			int up   = min_encount[w];

			min_encount[w] = std::min(left, up) + scan_input_cicada();
		}
	}

	/* -------------------------- */
	/* 出会う蝉の数の最小値を出力 */
	/* -------------------------- */
	std::cout << min_encount[weight - 1] << std::endl;

	return;
}

int main()
{
	cicada();
	return 0;
}



Measured memory_bytes: 3116
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

ll dp[1005][1005];
char a[1005][1005];
ll h,w;


ll dfs(ll i, ll j){
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    ll ans = 0;
    if(i+1<h && a[i+1][j]=='.') ans+=dfs(i+1, j) % mod;
    if(j+1<w && a[i][j+1]=='.') ans+=dfs(i, j+1) % mod;
    dp[i][j] = ans % mod;
    return ans %mod;
}


int main(){FIN
    cin>>h>>w;
    REP(i,h) REP(j,w) cin>>a[i][j];
    REP(i,1005) REP(j,1005) dp[i][j] = -1;
    dp[h-1][w-1] = 1;

    
    

    cout<<dfs(0,0)<<endl;
    return 0;
}

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

using ll = long long;
const ll INF = 1e13;

ll n, m, x;
ll cost[15];
ll a[15][15];
ll arr[15];
ll ans = INF;

void allPossibleSubset(ll arr[],ll n)
{
	ll count = pow(2,n);
	for (int i = 0; i < count; i++)
	{
        ll temp_ans = 0;
        vector<ll> algos(15, 0);
		for (int j = 0; j < n; j++)
		{
			if ((i & (1 << j)) > 0) {
				// cout << arr[j] << " ";
                temp_ans += cost[j];
                for (int k = 0; k < m; k++) {
                    algos[k] += a[j][k];
                }
            }
		}
        bool valid = true;
        for (int j = 0; j < m; j++) {
            if (algos[j] < x) {
                valid = false;
            }
        }
        if (valid) {
            ans = min(ans, temp_ans);
        }
    }
}

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

    for (int i = 0; i < n; i++) {
        cin >> cost[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
        arr[i] = i;
    }

	allPossibleSubset(arr,n);

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 4004
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    long A = nextLong();

    String[] in = splitString(next());

    String c = "";

    for(int i=0;i<4;i++){
      if(!in[i].equals(".")){
        c += in[i];
      }
    }

    long B = Long.parseLong(c);

    long ans = A*B/100;

    System.out.println(ans);

  }

  static int lcm(int a,int b){
    return a*b*gcd(a,b);
  }

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

  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


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

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

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;
  int l = S.length();

  int ans1 = 0;
  int ans2 = 0;

  REP(i, l) {
    if (i % 2 == 1) {
      if (S.at(i) == '0') {
        ++ans1;
      } else {
        ++ans2;
      }
    } else {
      if (S.at(i) == '1') {
        ++ans1;
      } else {
        ++ans2;
      }
    }
  }

  cout << min(ans1, ans2) << endl;

  return 0;
}


Measured memory_bytes: 512
n,m = map(int,input().split())
 
h = []
a = 1
b = 0
mod = 10 ** 9 + 7
 
for i in range(m):
    h += [int(input()),]
h += [0,]
    
cur = 0
for i in range(1,n):
    if i == h[cur]:
        a,b = 0,a
        cur += 1
    else:
        a,b = a + b,a
        a %= mod

print((a + b) % mod)

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

#define MAX 100000

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs(int current, int prev) {
    // ノード current を訪問した直後の処理
    prenum[current] = lowest[current] = timer;
    timer++;

    visited[current] = true;

    int next;

    for (int i = 0; i < G[current].size(); i++) {
        next = G[current][i];
        if (!visited[next]) {
            // ノード current からノード next へ訪問する直前の処理
            parent[next] = current;

            dfs(next, current);

            // ノード next の探索が終了した後の処理
            lowest[current] = min(lowest[current], lowest[next]);
        } else if (next != prev) {
            // エッジ current --> next が Back-edge の場合の処理
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }

    // ノード current の探索が終了した直後の処理
}

void art_points() {
    for (int i = 0;  i < N; i++) visited[i] = false;
    timer = 1;
    // lowest の計算
    dfs(0, -1); // 0 == root

    set<int> ap;
    int np = 0;
    for (int i = 1; i < N; i++) {
        int p = parent[i];
        if (p == 0) np++;
        else if (prenum[p] <= lowest[i]) ap.insert(p);
    }
    if (np > 1) ap.insert(0);
    for (set<int>::iterator it = ap.begin(); it != ap.end(); it++)
        cout << *it << endl;
}

int main() {
    int m;
    cin >> N >> m;

    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    art_points();

    return 0;
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()

typedef vector<int> vi;
typedef map<int, int> mi;
typedef pair<int, int> pi;
typedef long long ll;

int main() {
  int N;
  string S;
  string arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  cin >> N >> S;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < arr.size(); j++) {
      if (S[i] == arr[j]) {
        cout << arr[(j + N) % arr.size()];
        break;
      }
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,A,B,C,D;
  cin >> N;
  A = N / 1000;
  B = ( N / 100 ) % 10;
  C = ( N / 10 ) % 10;
  D = N % 10;
  
  if (B == C){
    if (A == B){
      cout << "Yes" << endl;
    }
    else if (D == B){
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
    
  else {
    cout << "No" << endl;
  }
}
      

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,k,n;
    scanf("%d",&n);
    char s[n+2];
    scanf("%s",s);
    int count=0;
    for(i=1;i<n;i++){
        if(s[i]!=s[i-1]){
            count++;
        }
        else
            continue;
    }
    printf("%d\n",count+1);
}


Measured memory_bytes: 256
X = int(input())
a_500 = 0
a_5 = 0

if(X >=500):
    a_500 = X//500
    X = X - 500*a_500
else:
    pass

if(X >=5):
    a_5 = X//5
    X = X - 5*a_5
else:
    pass

ans = 1000*a_500 + 5*a_5
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>

#define MAXN 100005
#define INF 10000000000000000ll

using namespace std;

struct Edge {
    int v, next;
    long long w[2];
}edge[MAXN * 2];
int e, ft[MAXN];

int n, m, S, T;
bool flag[MAXN];
long long dist[2][MAXN];
int qu[MAXN];
long long dp[MAXN];

void add_edge(int u, int v, int w1, int w2)
{
    edge[e].v = v;
    edge[e].w[0] = w1;
    edge[e].w[1] = w2;
    edge[e].next = ft[u];
    ft[u] = e++;
}

void cal(int idx, int s)
{
    memset(flag, false, sizeof(flag));
    for (int i = 1; i <= n; i++) {
        dist[idx][i] = INF;
    }
    dist[idx][s] = 0;
    int head, tail;
    head = tail = 0;
    qu[tail++] = s;
    flag[s] = true;

    while (head != tail) {
        int u = qu[head];
        head = (head + 1) % (n + 1);
        for (int i = ft[u]; i != -1; i = edge[i].next) {
            int v = edge[i].v;
            long long w = edge[i].w[idx] + dist[idx][u];
            if (w < dist[idx][v]) {
                dist[idx][v] = w;
                if (!flag[v]) {
                    qu[tail] = v;
                    tail = (tail + 1) % (n + 1);
                    flag[v] = true;
                }
            }
        }
        flag[u] = false;
    }
}

int main()
{
    while (cin >> n >> m >> S >> T) {
        e = 0;
        memset(ft, -1, sizeof(ft));
        int u, v, w1, w2;
        while (m--) {
            scanf("%d%d%d%d", &u, &v, &w1, &w2);
            add_edge(u, v, w1, w2);
            add_edge(v, u, w1, w2);
        }
        cal(0, S);
        cal(1, T);
        long long total = 1000000000000000ll;
        for (int i = 0; i <= n; i++)
            dp[i] = 0;
        long long opt = 0;
        for (int i = n; i > 0; i--) {
            long long w = dist[0][i] + dist[1][i];
            w = total - w;
            opt = max(opt, w);
            dp[i - 1] = opt;
        }
        for (int i = 0; i < n; i++)
            printf("%lld\n", dp[i]);
    }
    return 0;
}


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

int main() {
    map<string,int> A;
    int n; cin >> n;
    vector<string> blue(n);
    rep(i,n){
        cin >> blue[i];
        A[blue[i]]++;
    }
    int m;cin >> m;
    vector<string> red(m);
    rep(i,m){ 
        cin >> red[i];
        A[red[i]]--;
    }
    int ans=0;
    rep(i,n){
        ans=max(ans,A[blue[i]]);
    }
    cout << ans;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())), dtype=np.int32)
b = np.array(list(map(int, input().split())), dtype=np.int32)

ans = 0
mod = 1
for k in range(30):
    mod *= 2
    t = mod // 2
    cnt = 0
    bb = np.sort(b % mod)
    aa = a % mod
    l1, r1, l2, r2 = (np.searchsorted(bb, v - aa).sum() for v in (t, 2*t, 3*t, 4*t))
    cnt += r1 - l1
    cnt += r2 - l2

    if cnt % 2:
        ans += t

print(ans)


Measured memory_bytes: 35224
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type node struct {
	isNotRoot bool
	left      int
	right     int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	length, _ := strconv.Atoi(sc.Text())
	tree := make([]node, length)

	for sc.Scan() {
		v := strings.Split(sc.Text(), " ")
		id, _ := strconv.Atoi(v[0])

		tree[id].left, _ = strconv.Atoi(v[1])
		if tree[id].left >= 0 {
			tree[tree[id].left].isNotRoot = true
		}

		tree[id].right, _ = strconv.Atoi(v[2])
		if tree[id].right >= 0 {
			tree[tree[id].right].isNotRoot = true
		}
	}

	var root int
	for i, v := range tree {
		if !v.isNotRoot {
			root = i
			break
		}
	}

	fmt.Println("Preorder")
	preorder(tree, root)
	fmt.Println("\nInorder")
	inorder(tree, root)
	fmt.Println("\nPostorder")
	postorder(tree, root)
	fmt.Println("")
}

func preorder(tree []node, point int) {
	if point == -1 {
		return
	}
	fmt.Printf(" %d", point)
	preorder(tree, tree[point].left)
	preorder(tree, tree[point].right)
}

func inorder(tree []node, point int) {
	if point == -1 {
		return
	}
	inorder(tree, tree[point].left)
	fmt.Printf(" %d", point)
	inorder(tree, tree[point].right)
}

func postorder(tree []node, point int) {
	if point == -1 {
		return
	}
	postorder(tree, tree[point].left)
	postorder(tree, tree[point].right)
	fmt.Printf(" %d", point)
}



Measured memory_bytes: 1120
from itertools import accumulate
from bisect import bisect_right

N, K = map(int, input().split())
A = [0] + [int(input()) for i in range(N)]

diff = [a - K for a in A]
diff = list(accumulate(diff))


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)

    def reset(self):
        self.bit = [0] * (self.size + 1)


BIT = BinaryIndexedTree(N + 1)

temp = sorted(diff)
order = [bisect_right(temp, d) for d in diff]
ans = 0

for x in order:
    ans += BIT.sum(x)
    BIT.add(x, 1)

print(ans)


Measured memory_bytes: 33140
#include <iostream>

using namespace std;

char s[4];

const int D = 4;
typedef long long ll;
typedef ll M[D][D];

void MtM(M ans, M a, M b){
    M tmp = {0};
    for(int i =0;i<D;i++){
        for(int j = 0;j<D;j++){
            for(int k = 0;k<D;k++){
                tmp[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for(int i =0 ;i<D ;i++)for(int j = 0;j<D;j++)ans[i][j] = tmp[i][j];
}

void qp(M ans, M a, int q){
    M tmp ={0};
    for(int i =0;i<D;i++)tmp[i][i] = 1;
    while(q){
        if(q) MtM(a,a,a);
        q<<=1;
    }
    for(int i =0;i<D;i++){
        for(int j =0;j<D;j++){
            ans[i][j] = tmp[i][j];
        }
    }
}
const int N = 100;
ll a[N];
int main()
{
    int n ;cin>>n;
    a[0] = 2; a[1] = 1;
    for(int i =2;i<=n;i++)a[i] = a[i-1] + a[i-2];
    cout<<a[n];
     return 0;
}


Measured memory_bytes: 256
n = int(input())
L = list(map(int,input().split()))
i = 0
num = 1
cnt = 0
while i <=n-1:
    if L[i] == num:
        num +=1 
    else:
        cnt +=1
    i+= 1
if num == 1:
    print(-1)
else:
    print(cnt)

Measured memory_bytes: 24744
import math

N,K=map(int,input().split())
S=input()
L=[]
seq=0
prev='2'
for i in S:
  if i == prev:
    seq += 1
  else:
    L.append(seq)
    prev = i
    seq = 1
L.append(seq)
L.append(0)

L_cum = [0]*(len(L)+1)
for i in range(len(L)):
  L_cum[i]=L_cum[i-1]+L[i]

if S[0] == '0':
  num_0 = math.ceil((len(L)-2)/2)
  if num_0<=K:
    ans=N
  else:
    rev=[0]*(num_0-K+1)
    for i in range(num_0-K+1):
      rev[i]=L_cum[2*(K+i)]-L_cum[i*2-1]
    ans=max(rev)
else:
  num_0 = math.floor((len(L)-2)/2)
  if num_0<=K:
    ans=N
  else:
    rev=[0]*(num_0-K+1)
    for i in range(num_0-K+1):
      rev[i]=L_cum[2*(K+i)+1]-L_cum[2*i]
    ans=max(rev)
print(ans)

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

import copy
import queue

N = int(input())
a_list = list(map(int, input().split()))

gain = sum([a for a in a_list if a > 0])

# Flow network
S = 0
T = N + 1
c = [{} for i in range(N + 2)]
for i, a in enumerate(a_list):
    index = i + 1
    if a <= 0:
        c[S][index] = -a
    else:
        c[index][T] = a
    for j in range(index, N + 1, index):
        if not j == index:
            c[index][j] = 10e15

# Residual network
r = copy.deepcopy(c)

# Edmonds-Karp algorithm
max_flow = 0
while True:
    # Find path to T
    q, s, p = queue.Queue(), {S}, None
    q.put((S,))
    findPath = False
    while not q.empty() and not findPath:
        cand_path = q.get(False)
        for to, path in r[cand_path[-1]].items():
            if path == 0:
                continue
            elif to == T:
                p = cand_path + (to,)
                findPath = True
            elif not to in s:
                q.put(cand_path + (to,))
                s.add(to)

    if not findPath:
        break

    # Minimum flow
    min_flow = min([r[p[i]][p[i+1]] for i in range(len(p)-1)])
    max_flow += min_flow
    for i in range(len(p)-1):
        r[p[i]][p[i+1]] -= min_flow
        if p[i] in r[p[i+1]]:
            r[p[i+1]][p[i]] += min_flow
        else:
            r[p[i+1]][p[i]] = min_flow

print(gain - max_flow)


Measured memory_bytes: 50028
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;
    
int main() {
  string s;
  cin >> s;
  int ss = s.size(), sum = 0;
  rep(i, 0, ss) {
    sum += s[i]-'0';
  }
  if(sum % 9 == 0) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  int sum=a+b*5+c*10+d*50+e*100+f*500;
  if(sum>=1000){cout<<1<<endl;}
  else{cout<<0<<endl;}

}



Measured memory_bytes: 3052
import  numpy as np


def divisors(num):
    array = []
    limit = int(num ** 0.5) + 1
    for i in range(1, limit):
        if num % i == 0:
            div1 = i
            div2 = num//i
            array.append(div1)
            if div1 != div2:
                array.append(div2)
    array.sort(reverse=True)
    return array


n, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=int)

total = sum(A)
candidates = divisors(total)


for div in candidates:
    mods = A % div
    mods.sort()
    add = div - mods

    addcum = np.cumsum(add)
    subcum = np.cumsum(mods)
    for i in range(n):
        addcount = addcum[n-1] - addcum[i]
        subcount = subcum[i]
        if addcount == subcount and addcount <= k:
            print(div)
            exit()

Measured memory_bytes: 14432
N,M=map(int,input().split())
nums={}
for i in range(M):
    s,c=map(str,input().split())
    if s in nums.keys():
        if nums[s]!=c:
            ans=-1
            print(ans)
            exit()
    else:
        nums[s]=c
for i in range(1,N+1):
    if str(i) not in nums.keys():
        nums[str(i)]='0' if i!=1 else '1'
n=[]
for i in sorted(nums):
    n.append(nums[i])
ans=int(''.join(n))
if len(list(str(ans)))!=N:
    ans=-1
if N ==1 and M == 0:
    ans=0
print(ans)

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int n, m, min=1001, max=-1;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> m;
        if(min>m) min = m;
        if(max<m) max = m;
    }
    cout << max - min << endl;
    return 0;
}

Measured memory_bytes: 256
def nyu():
    N, M = map(int, input().split())
    S = [list(input().split()) for i in range(M)]
    return N,M,S

def kansu(N,M,S):

    S_tmp=[]
    for i in range(M):
        tmp = [int(S[i][0]),int(S[i][1]),0,i]
        S_tmp.append(tmp) 
    S_tmp.sort()
    tmp = S_tmp[0][0]
    cnt = 1

    for i in range(M):
        if tmp == int(S_tmp[i][0]):
            S_tmp[i][2] = cnt
            cnt += 1
        else :
            tmp = S_tmp[i][0]
            S_tmp[i][2] = 1
            cnt = 2
#    print(S_tmp)
    S_tmp = sorted(S_tmp, key=lambda x: x[3])
#    print(S_tmp)
    for i in range(M):
        print(str(S_tmp[i][0]).zfill(6),str(S_tmp[i][2]).zfill(6),sep='')
    



    # for m1 in range(M):
    #     cnt = 1
    #     tmp_m1 = S[m1][0]
    #     tmp_m2 = S[m1][1]
    #     for m2 in range(M):
    #         if S[m2][0] == tmp_m1 and S[m2][1] < tmp_m2:
    #             cnt = cnt + 1
    #     print(str(S[m1][0]).zfill(6),str(cnt).zfill(6),sep='')


N,M,S = nyu()
kansu(N,M,S)
#print(S)



Measured memory_bytes: 53788
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{n:usize, s:[i64;n]};
    let mut s = s;
    s.sort();
    let sum:i64 = s.iter().sum();
    if sum%10==0 {
        let v:Vec<i64> = s.iter().filter(|&x| *x%10!=0).cloned().collect();
        //debug!(v);
        if v.len() == 0 {
            println!("0");
        } else {
            println!("{}", sum - v[0]);
        }
    } else {
        println!("{}", sum);
    }
}


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

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int a[(1<<18)+18];
ii dp[(1<<18)+18][2];

void upd(int u, int v)
{
	vector<ii> V;
	V.pb(dp[u][0]);V.pb(dp[u][1]);V.pb(dp[v][0]);V.pb(dp[v][1]);
	sort(V.begin(),V.end()); V.erase(unique(V.begin(),V.end()),V.end());
	reverse(V.begin(),V.end());
	dp[u][0]=V[0]; dp[u][1]=V[1];
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<(1<<n);i++) cin>>a[i];
	for(int i=0;i<(1<<n);i++) dp[i][0]=dp[i][1]=mp(-int(1e9),-int(1e9));
	for(int i=0;i<(1<<n);i++)
	{
		dp[i][0]=mp(a[i],i);
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j)) upd(i,i^(1<<j));
		}
	}
	int ans=0;
	for(int i=1;i<(1<<n);i++)
	{
		ans=max(ans,dp[i][0].fi+dp[i][1].fi);
		cout<<ans<<'\n';
	}
}


Measured memory_bytes: 8192
import sys

S = input()

r_num = S.count("R")
if r_num == 0:
    print(0)
    sys.exit()
if r_num == 1:
    print(1)
    sys.exit()
if r_num == 2:
    if S[1] == "S":
        print(1)
    else:
        print(2)
if r_num == 3:
    print(3)

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

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; }

int h, w, k;
string field[10];

int solve() {
    int res = 1 << 29;
    for (int bit = 0; bit < (1 << (h - 1)); bit++) {
        bool safe = true;
        int n = 0;
        vector<int> ord(h, 0);
        for (int i = 0; i < h - 1; i++) {
            if (!(bit & (1 << i))) ord[i+1] = ord[i];
            else ord[i+1] = ord[i] + 1, n++;
        }
        int add = 0;
        vector<int> nums(n+1, 0);
        for (int x = 0; x < w; x++) {
            vector<int> one(n+1, 0);
            bool ok = true;
            for (int y = 0; y < h; y++) {
                one[ord[y]] += field[y][x] - '0';
                nums[ord[y]] += field[y][x] - '0';
                if (one[ord[y]] > k) safe = false;
                if (nums[ord[y]] > k) ok = false;
            }
            if (!ok) add++, nums = one;
        }
        if (safe) chmin(res, n+add);
    }
    return res;
}

int main() {
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) cin >> field[i];
    cout << solve() << endl;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
S = str(input())
S += "x"*4000
all_string = Counter(S)

after_happen = {0: all_string}
for i in range(1, N+1):
    tmp = after_happen[i-1].copy()
    after_happen[i] = tmp
    after_happen[i][S[i-1]] -= 1
ans = 0
rgb = set(["R", "G", "B"])
for i in range(N-2):
    for j in range(i+1, N-1):
        # 最後に引くのを忘れない
        # j+1以降で探す
        if S[i] == S[j]:
            continue
        target = rgb-set([S[i], S[j]])
        target = list(target)[0]
        # print(target)
        ans += after_happen[j][target]
        # 余分に数えている分を引きたい
        if S[j+(j-i)] == target:
            ans -= 1
print(ans)


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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	for (int i = 0; i < 19; i++) {
		cin >> S[i];
	}
	S[5] = ' ';
	S[13] = ' ';
	for (int i = 0; i < 19; i++) {
		cout<<S[i];
	}
}

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

using namespace std;

typedef long long ll;

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

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

	int n;
	cin >> n;

	vector<int> f(n+1, 0);

	for(int x = 1; x <= n; x++){
		for(int y = 1; y <= n; y++){
			for(int z = 1; x * x + y * y + z * z + x * y + y * z + z * x <= n; z++){
				int r =  x * x + y * y + z * z + x * y + y * z + z * x;
				f[r]++;
			}
		}
	}

	rep(i, n) cout << f[i+1] << "\n";
}


Measured memory_bytes: 3616
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll h1,m1,h2,m2,k;
    std::cin >> h1>>m1>>h2>>m2>>k;
    ll rem = h2*60+m2-h1*60-m1;
    std::cout << rem-k << std::endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]==s[1]&&s[0]!=s[2]||s[1]==s[2]&&s[0]!=s[1]||s[0]==s[2]&&s[0]!=s[1]){cout<<"Yes"<<endl;return 0;}
    else{cout<<"No"<<endl;return 0;}
    }

Measured memory_bytes: 3628
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
p.sort(key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        x0, y0, h0 = p[0]
        h = abs(x0 - cx) + abs(y0 - cy) + h0
        if all(max(h - abs(xi - cx) - abs(yi - cy), 0) == hi for xi, yi, hi in p):
            print(cx, cy, h)
            exit()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPN(i,n) for(int i=1;i<=(n);i++)
using namespace std;
int n,fa[100050],num[100050];
vector<int>c[100050];
int dfs(int n,int f)
{
	fa[n]=f;
	int t=1;
	for(int i=0;i<c[n].size();i++)
	{
		if(c[n][i]!=f)
		{
			t+=dfs(c[n][i],n);
		}
	}	
	return num[n]=t;
}
int main()
{
	cin>>n;
	int a,b;
	REPN(i,n-1)
	{
		cin>>a>>b;
		c[a].push_back(b);
		c[b].push_back(a);
	}
	num[1]=dfs(1,1);
	int z=n,sum=0;
	while(fa[z]!=z)
	{
		sum++;
		z=fa[z];
	}
	z=n;
	REPN(i,(sum-1)/2)
	{
		z=fa[z];
	}
	if(num[z]>=n-num[z])
	{
		cout<<"Snuke"<<endl;
	}
	else 
	{
		cout<<"Fennec"<<endl;
	}
	return 0;
} 

Measured memory_bytes: 14336
/**
 *	@file: A.cpp
 *	@author: Huy Le
 *	@created: 2020-08-22 19:01
**/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define sz(x) (int)(x).size()
const char newl = '\n';

void DEBUGLOCAL() { cerr << ")" << newl; }
template<class A, class... B> 
void DEBUGLOCAL(A argc, B... argv) {
	cerr << argc;
	if(sizeof...(argv))
		cerr << ", ";
	DEBUGLOCAL(argv...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") [" << __FUNCTION__ << "] -> (" << #__VA_ARGS__ << "): (",DEBUGLOCAL(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int ts;
int n;
vector<ll> a;

void solve() {
	cin >> n;
	a = vector<ll>(n);
	for(int i=0; i<n; ++i)
		cin >> a[i];
	ll ans = 0, cur = -1;
	for(int i=0; i<n-1; ++i) {
		cur = max(cur, a[i]);
		ll tmp = cur - a[i+1];
		ans += (tmp >0?tmp:0);
	}
	cout << ans;
}

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

	//cin >> ts;
	//while(ts--)
		solve();
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  vector<int> v(n + 1, 0);
  int now = 1;
  v[now] += 1;
  int ans = 1;
  while (true) {
    if (a[now] == 2) {
      cout << ans << endl;
      break;
    }
    if (v[now] > 1) {
      cout << -1 << endl;
      break;
    }
    ans++;
    now = a[now];
    v[now] += 1;
  }

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define ld long double
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=10005,mod=998244353;
ll fac[N],ni[N];
int f[N][N],n,m,ans;
char a[N],b[N];
inline int ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
ll c(int a,int b){
	return fac[a]*ni[a-b]%mod*ni[b]%mod;
}
signed main(){
	scanf("%s%s",a,b);
	for(int i=0;i<10000;i++)if(a[i]=='1'){
		if(b[i]=='1')n++; else m++;
	}
	for(int i=fac[0]=1;i<N;i++)fac[i]=fac[i-1]*i%mod; ni[N-1]=ksm(fac[N-1],mod-2); for(int i=N-1;i;i--)ni[i-1]=ni[i]*i%mod;
	f[0][0]=1;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i)f[i][j]=(ll)f[i-1][j]*i*j%mod;
			if(j)f[i][j]=(f[i][j]+(ll)f[i][j-1]*j*j)%mod;
		}
		ans=(ans+c(n,i)*fac[n-i]%mod*c(n+m,i+m)%mod*fac[n-i]%mod*f[i][m])%mod;
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 389632
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  ll N;cin>>N;
  ll K;cin>>K;
  ll Q; cin>>Q;
  ll A[Q+10];
  rep1(i,Q){
    cin>>A[i];
  }
  ll B[N+10];
  rep1(i,N){
    B[i]=0;
  }
  
  rep1(i,Q){
    B[A[i]]++;
  }
  
  ll j=Q-K+1;
  rep1(i,N){
    if(B[i]<j) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}




Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};


int r[4005],g[4005],b[4005];


int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=n-1;i>=0;--i){
        if(s[i]=='R'){
            r[i]=1;
        }
        if(s[i]=='G'){
            g[i]=1;
        }
        else if(s[i]=='B'){
            b[i]=1;
        }
    }
    for(int i=n-2;i>=0;--i){
        r[i]+=r[i+1];
        g[i]+=g[i+1];
        b[i]+=b[i+1];
    }
    ll ans=0;
    for(int i=0;i<n-2;++i){
        for(int j=i+1;j<n-1;++j){
            int diff=j-i;
            if(s[i]!=s[j]){
                if(s[i]!='G' and s[j]!='G'){
                    ans+=g[j+1];
                    if(s[j+diff]=='G')
                        ans-=1;
                }
                if(s[i]!='R' and s[j]!='R'){
                    ans+=r[j+1];
                    if(s[j+diff]=='R')
                        ans-=1;
                }
                if(s[i]!='B' and s[j]!='B'){
                    ans+=b[j+1];
                    if(s[j+diff]=='B')
                        ans-=1;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3676
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
	public static void main (String[] args) throws java.lang.Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
	    HashMap<String,ArrayList<Integer>> ansMap = new HashMap<String,ArrayList<Integer>>();
	    ArrayList<String> keySet = new ArrayList<String>();
	    while(line!=null){
	        String[] lines = line.split(" ");
	        ArrayList<Integer> list;
	        if(ansMap.containsKey(lines[0])){
	            list = ansMap.get(lines[0]);
	        }else{
	            list = new ArrayList<Integer>();
	            keySet.add(lines[0]);
	            ansMap.put(lines[0],list);
	        }
	        list.add(Integer.parseInt(lines[1]));
	        line = br.readLine();
	    }
	    Collections.sort(keySet);
	    for(String key:keySet){
	        System.out.println(key);
	        ArrayList<Integer> list = ansMap.get(key);
	        Collections.sort(list);
	        int i=0;
	        for(int j:list){
	            if(i!=0){
    	            System.out.print(" ");
	            }
	            i++;
	            System.out.print(j);
	        }
	        System.out.println("");
	    }
	}

}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<vector<int>> c(n, vector<int>(3));
  REP(i, n) {
    cin >> c[i][0] >> c[i][1] >> c[i][2];
  }

  vector<vector<int>> dp(n, vector<int>(3));
  dp[0][0] = c[0][0];
  dp[0][1] = c[0][1];
  dp[0][2] = c[0][2];

  for(int i=1;i<n;++i) {
    for(int j=0;j<3;++j) {
      dp[i][j] = max(dp[i][j], max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + c[i][j]);
    }
  }
  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
}


Measured memory_bytes: 11136