akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath> 
using namespace std;

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

    if(d == 0){
        if(n % 100 == 0){
            cout << n+1 << endl;
        }
        else {
            cout << n << endl;
        }

        return 0;
    }
    else if(d == 1){
        if(n % 100 == 0){
            cout << (n+1) * 100 << endl;
        }
        else {
            cout << n * 100 << endl;
        }
        return 0;
    }
    else {
        if(n % 100 == 0){
            cout << (n+1) * 100 * 100 << endl;
        }
        else {
            cout << n * 100 * 100 << endl;
        }
        return 0;
    }
}

Measured memory_bytes: 256
/**
 * @author Video Vocabulary
 * @date 2020-06-27 18:00:52
 */
#include <bits/stdc++.h>

using namespace std;

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

    string s, t;
    cin >> s >> t;
    int n = s.size();
    int ans = 0;
    for (int i=0; i<n; i++) {
        if (s[i] != t[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3824
#include<iostream>
#include<string>
#include<set>
#include<vector>

using namespace std;

string s;

int x, y;

vector<int> X, Y;

set<int> SX, SY, nSX,nSY;

int main(void) {

	cin >> s;
	cin >> x >> y;

	s += "Q";

	int d = 0;
	int dis = 0;
	for (int i = 0; i<int(s.size()); i++) {
		if (s.substr(i, 1) == "T"||s.substr(i,1)=="Q") {
			if (d == 0) { X.push_back(dis); }
			else { Y.push_back(dis); }
			d++; d = d % 2;
			dis = 0;
		}
		else { dis++;
		       }
	}
	
	//================
	/*for (int i = 0;i<int(X.size());i++) {
		cout << " " << X[i];
	} cout << endl;

	for (int i = 0;i<int(Y.size());i++) {
		cout << " " << Y[i];
	} cout << endl;*/
	//====================

	SX.insert(X[0]);

	for (int i = 1; i<int(X.size()); i++) {
		nSX.clear();
		for (auto it = SX.begin(); it != SX.end(); it++) {
			nSX.insert((*it) + X[i]);
			nSX.insert((*it) - X[i]);
		}
		SX = nSX;
	}

	if ((int)Y.size() > 0) { SY.insert(Y[0]); SY.insert(-Y[0]); }
	else { SY.insert(0); }

	for (int i = 1; i<int(Y.size()); i++) {
		nSY.clear();
		for (auto it = SY.begin(); it != SY.end(); it++) {
			nSY.insert((*it) + Y[i]);
			nSY.insert((*it) - Y[i]);
		}
		SY = nSY;
	}

/*	for (auto it = SX.begin(); it != SX.end(); it++) {
		cout << " " << (*it);
	}cout << endl;

	for (auto it = SY.begin(); it != SY.end(); it++) {
		cout << " " << (*it);
	}cout << endl;*/


	if (SX.count(x) > 0 && SY.count(y) > 0) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }



	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

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

        // 入力
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();

        // 処理
        long out = 0;
        if(a == 0){
            //
        } else {
            long num = a + b;
            long m = n / num;
            out = a * m;
            long check = n % num;
            if(check != 0){
                //min(check, a)
                out += check < a ? check : a;
            }

        }

        // 出力
        System.out.println(out);
    }

}

Measured memory_bytes: 23124
n,m,p = map(int,input().split())
graph = [[] for _ in range(n)]
INF = float("inf")
dist = [INF]*n
dist[0] = 0

for _ in range(m):
	f,t,c = map(int,input().split())
	graph[f-1].append((t-1,p-c))
#print(graph)

for _ in range(n):
	update = False
	for f,e in enumerate(graph):
		for t,c in e:
			if dist[f] != INF and dist[t] > dist[f] + c:
				dist[t] = dist[f] + c
				update = True
	if not update:
		break
else:
	prev = dist[-1]
	for _ in range(n):
		for f,e in enumerate(graph):
			for t,c in e:
				if dist[f] != INF and dist[t] > dist[f] + c:
					dist[t] = -INF
	if dist[-1] != prev:
		print(-1)
		exit()
#print(dist)

print(max(0,dist[-1]*(-1)))


Measured memory_bytes: 57080
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define F first
#define S second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

ll gcd (ll a, ll b)
{
  ll c;
  while(a != 0){
     c = a; a = b%a;  b = c;
  }
  return b;
}

int main(void){
    for(ll a, b, d; cin >> a >> b >> d, a;){
        ll sum = b - d;
        while(sum < 0 || sum % a != 0){
            sum += b;
        }
        pair<ll, ll> res = mp(sum / a, (sum + d) / b);

        sum = a - d;
        while(sum < 0 || sum % b != 0){
            sum += a;
        }
        if((sum + d) / a + sum / b <= res.F + res.S){
            if((sum + d) / a + sum / b != res.F + res.S ||
               (sum + d) + sum < res.F * a + res.S * b)
                res = mp((sum + d) / a, sum / b);
        }

        sum = d - a;
        while(0 <= sum && sum % b != 0){
            sum -= a;
        }
        if(0 <= sum && (d - sum) / a + sum / b <= res.F + res.S){
            if((d - sum) / a + sum / b != res.F + res.S ||
               d < res.F * a + res.S * b)
                res = mp((d - sum) / a, sum / b);
        }

        sum = d - b;
        while(0 <= sum && sum % a != 0){
            sum -= b;
        }
        if(0 <= sum && (d - sum) / b + sum / a <= res.F + res.S){
            if((d - sum) / b + sum / a != res.F + res.S ||
               d < res.F * a + res.S * b)
                res = mp(sum / a, (d - sum) / b);
        }

        cout << res.F << " " << res.S << endl;
    }

	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

string s;
int k;
vector<string> vec;

int main(){
  ios_base::sync_with_stdio(false);

  cin >> s;
  cin >> k;
  
  for(int i=0;i<s.size();i++){
    for(int j=1;j<=k;j++){
      string str = s.substr(i, j);
      vec.push_back(str);
    }
  }
  
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());

  cout << vec[k-1] << endl;

  return 0;
}



Measured memory_bytes: 1660
from collections import deque

S = input()
Q = int(input())

deque = deque([c for c in S])
flag = 0

for _ in range(Q):
  pack = input().split()

  T = int(pack[0])
  if T == 1:
    flag = flag ^ 1

  if T == 2:
    F, C = int(pack[1]), pack[2]
    if F == 1:
      if flag:
        deque.append(C)
      else:
        # 最初に追加するパターン
        deque.appendleft(C)
    if F == 2:
      if flag:
        deque.appendleft(C)
      else:
        # 最後尾に追加するパターン
        deque.append(C)

print("".join(reversed(deque) if flag else deque))

Measured memory_bytes: 8548
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	b := make([]int, n)
	for i := range b {
		fmt.Scan(&b[i])
	}
	fmt.Println(seek(n, a, b))
}

func seek(n int, a, b []int) int {
	sum := make([]int, n)
	for i := 0; i < n; i++ {
		for _, v := range a[:i+1] {
			sum[i] += v
		}
		for _, v := range b[i:] {
			sum[i] += v
		}
	}
	sort.Ints(sum)
	return sum[len(sum)-1]
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <bitset>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}



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

	ll a[1001] = {}, b[1001] = {}, c[1001] = {};


	REP(i, n) {
		scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
	}

	ll ans = 0;

	REP(ca, 2) {
		REP(cb, 2) {
			REP(cc, 2) {
				vector<ll> buf(n);
				REP(i, n) {
					buf[i] = a[i] + b[i] + c[i];
				}

				sort(ALL(buf),  greater<ll>());
				ll ba = 0;
				REP(i, m) {
					ba += buf[i];
				}

				ans = max(ans, ba);

				REP(i, n) {
					c[i] *= -1;
				}
			}

			REP(i, n) {
				b[i] *= -1;
			}

		}

		REP(i, n) {
			a[i] *= -1;
		}

	}


	cout << ans << endl;

	return 0;
}


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

int main(){
    string S; cin >> S;
    vector<ll> in(4);
    rep(i, 0, 4) in[i] = S[i] - '0';
    for(int bit = 0; bit < 8; bit++){
        ll tmp = in[0];
        string ans[3];
        for(int i = 0; i < 3; i++){
            if(bit & (1<<i)){
                tmp += in[i+1];
                ans[i] = '+';
            }else{
                tmp -= in[i+1];
                ans[i] = '-';
            }
        }
        if(tmp == 7){
            cout << in[0];
            rep(i, 0, 3) cout << ans[i] << in[i+1];
            cout << "=" << tmp << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

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

    int ans = 0, k = 0, prevh = -1;
    rep(i, n){
        if(prevh >= h[i]){
            k++;
            if(i == n - 1){
                ans = max(ans,k);
            }
        } else {
            ans = max(ans, k);
            k = 0;
        }
        prevh = h[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String args[]){
		ArrayList[] a;
		a=new ArrayList[10];
		///a[1]=new ArrayList<Integer>();
		//a[1].add(3);
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				System.out.printf("%dx%d=%d\n",i,j,i*j);
			}
		}
		
	}
}

Measured memory_bytes: 18120
# 公式解説を見てからやった
# 複数サイクルでき、1-K回移動可能
# N < 5000?多分、O(N * 2N)くらいで行けそうに見えるが。。。

if __name__ == "__main__":

	N,K = map(int,input().split())
	P = [ int(p)-1 for p in input().split() ]
	C = list(map(int,input().split()))

	# 一度計算したサイクル情報を一応キャッシュしておく。。。
	# あんまり意味なさそう
	cycleIDs = [ -1 for _ in range(N) ]
	cycleInfs = []


	# print(P)

	ans = -1e19
	cycleID = 0

	for n in range(N):

		v = n
		currentCycleItemCnt = 0
		currentCycleTotal = 0

		if cycleIDs[v] != -1:
			currentCycleItemCnt, currentCycleTotal = cycleInfs[ cycleIDs[v] ]
			# print(currentCycleItemCnt, currentCycleTotal)
		else:
			while True:
				# 全頂点について、属するサイクルを計算する
				currentCycleItemCnt += 1
				currentCycleTotal += C[v]

				v = P[v]
				if v == n:
					# サイクル発見
					cycleInfs.append( (currentCycleItemCnt, currentCycleTotal) )
					cycleID += 1
					break

				# 一応、一度サイクルを計算した頂点については、
				# その頂点の属するサイクルの情報をメモっておく。。。
				cycleIDs[v] = cycleID

		procCnt = 0
		currentCycleSumTmp = 0

		for k in range(min(K,currentCycleItemCnt)):
			# 頂点vにコマが置かれた時の最高スコアを計算し、
			# これまでの最高スコアを上回ったら、これまでの最高スコアを更新する
			procCnt = k+1
			currentCycleSumTmp += C[v]

			cycleLoopCnt = 0
			if 0 < currentCycleTotal:
				cycleLoopCnt = int(( K - procCnt ) // currentCycleItemCnt)

			# print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, "procCnt, cycleLoopCnt, currentCycleTotal=", procCnt, cycleLoopCnt, currentCycleTotal)
			ans = max( ans, currentCycleSumTmp + cycleLoopCnt * currentCycleTotal )
			v = P[v]


	print(ans)


Measured memory_bytes: 74340
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		/*
		 * 計算式は 距離= sqrt( (x1-x2)^2 + (y1-y2)^2 )
		 */

		double distance = DistanceCalculation(sc.nextDouble(), sc.nextDouble(), sc.nextDouble(), sc.nextDouble());

		System.out.println(distance);

	}

	static double DistanceCalculation(double x1, double y1, double x2, double y2) {
		double distance = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
		return distance;
	}

}



Measured memory_bytes: 27884
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()

if N % 2 == 0:
    ans = 0
    for i in range(N // 2):
        ans -= 2 * A[i]
    for i in range(N // 2, N):
        ans += 2 * A[i]
    ans += A[N // 2 - 1]
    ans -= A[N // 2]
    print(ans)
else:
    ans1 = 0
    for i in range(N // 2):
        ans1 -= 2 * A[i]
    for i in range(N // 2, N):
        ans1 += 2 * A[i]
    ans1 -= A[N // 2]
    ans1 -= A[N // 2 + 1]

    ans2 = 0
    for i in range(N // 2 + 1):
        ans2 -= 2 * A[i]
    for i in range(N // 2 + 1, N):
        ans2 += 2 * A[i]
    ans2 += A[N // 2]
    ans2 += A[N // 2 - 1]
    print(max(ans1, ans2))


Measured memory_bytes: 7512
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
e=0
for x in b.values():
    e+=x*(x-1)
for x in a:
    t=b[x]
    p=e-t*(t-1)+(t-1)*(t-2)
    print(p//2)

Measured memory_bytes: 26780
def bubble_sort(array, n)
  count = 0
  flag = true
  head = 0

  while flag
    flag = false
    (n-1).downto(head+1) do |i|
      if array[i] < array[i-1]
        flag = true
        array[i], array[i-1] = array[i-1], array[i]
        count += 1
      end
    end
    head += 1
  end
  count
end

def trace(array)
  puts array.join(' ')
end

n = $stdin.gets.chomp.to_i
array = $stdin.gets.chomp.split(' ').map(&:to_i)

count = bubble_sort(array, n)
trace(array)
puts count

Measured memory_bytes: 8688
#include <bits/stdc++.h>
#define INF 100000000000000000ll
#define MAX_V 1000
#define MAX_E 2000
using namespace std;

int V, E;
long long d[MAX_V][MAX_V];

bool Warshall_Floyd() {
	for (int k = 0; k < V; k++) {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
				if (d[i][k] != INF && d[k][j] != INF && d[i][j] > d[i][k] + d[k][j]) {
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}
	for (int i = 0; i < V; i++)
		if (d[i][i] < 0) return true;
	return false;
}

int main()
{
	cin >> V >> E;
	for (int i = 0; i < V; i++) {
		for (int j = 0; j < V; j++) {
			if (i == j)
				d[i][j] = 0;
			else
				d[i][j] = INF;
		}
	}
	for (int i = 0, s, t, c; i < E; i++) {
		cin >> s >> t >> c;
		d[s][t] = c;
	}

	if (!Warshall_Floyd()) {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
				if (d[i][j] == INF)
					cout << "INF";
				else
					cout << d[i][j];
				if (j != V - 1)
					cout << ' ';
			}
			cout << endl;
		}
	}
	else {
		cout << "NEGATIVE CYCLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 3588
package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)
	as := make([]int, k)
	for i := 0; i < k; i++ {
		fmt.Scan(&as[i])
	}

	mn, mx := 2, 2
	for i := k - 1; i >= 0; i-- {
		a := as[i]
		mn = (mn + a - 1) / a * a
		mx = (mx/a)*a + a - 1

		if mn > mx {
			fmt.Println(-1)
			return
		}
	}

	if check(mn, as) && check(mx, as) {
		fmt.Println(mn, mx)
	} else {
		fmt.Println(-1)
	}
}

func check(n int, as []int) bool {
	for i := 0; i < len(as); i++ {
		n -= n % as[i]
	}
	return n == 2
}


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

typedef long long ll;
typedef pair< int, int > PII;
typedef pair< ll, ll > PLL;

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define PI 3.14159265358979323846
#define INF 1000000006
#define LINF 1000000000000000006
#define DINF 1e300
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair

const int N = 1e5 + 10;

string s, a[ 4 ];

void init() {
  cin >> s;
  a[ 0 ] = "dream";
  a[ 1 ] = "dreamer";
  a[ 2 ] = "erase";
  a[ 3 ] = "eraser";
}
void GG() {
  cout << "NO" << endl;
}
void solve() {
  for ( int i = s.size() - 1 ; i >= 0 ; --i ) {
    if ( s[ i ] == 'r' ) {
      string tmp; 
      if ( i - 5 >= 0 )
        tmp = s.substr( i - 5, 6 );
      string tmp2;
      if ( i - 6 >= 0 )
        tmp2 = s.substr( i - 6, 7 );
      if ( tmp2 == "dreamer" )
        i -= 6;
      else if ( tmp == "eraser" )
        i -= 5;
      else
        return GG();
    }
    else if ( s[ i ] == 'e' ) {
      string tmp = s.substr( i - 4, 5 ); 
      if ( tmp == "erase" )
        i -= 4;
      else 
        return GG();
    }
    else if ( s[ i ] == 'm' ) {
      string tmp = s.substr( i - 4, 5 );
      if ( tmp == "dream" )
        i -= 4;
      else 
        return GG();
    }
    else 
      return GG();
  }
  cout << "YES" << endl;
}
int main() {
  IOS;
  int __ = 1;
  //cin >> __;
  while ( __-- ) {
    init();
    solve();
  }
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
main(){
	for (int m,f,r,s;std::cin>>m>>f>>r,s=m+f,m+1||f+1||r+1;std::cout<<((m+1&&f+1)?(s>=80?"A":(s>=65?"B":(s>=50?"C":(s>=30?(r>=50?"C":"D"):"F")))):"F")<<std::endl);
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdlib>
#include<string>

using namespace std;

struct Node{
	int key;
	Node *parent,*left,*right;
};

Node *root,*NIL;//????????????NULL??§????????????????????????

void insert(int k);
void inorder(Node *u);
void preorder(Node *u);
Node* find(Node *x,int key);

int main(){
	int m; cin>>m;
	int key;
	string command;
	for(int i=0;i<m;i++){
		cin>>command;
		if(command=="insert"){
			cin>>key;
			insert(key);
		}else if(command=="print"){
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;
		}else if(command=="find"){
			Node *x;
			cin>>key;
			x = find(root,key);
			if(x==NULL){
				cout<<"no"<<endl;
			}else if(x->key==key){
				cout<<"yes"<<endl;
			}
		}
	}
}

void insert(int k){
	Node *x,*y,*z;
	x = root,y = NIL;
	z = (Node *)malloc(sizeof(Node));
	z->key = k; z->left = z->right = NIL;

	while(x!=NIL){
		y = x;
		if(z->key<x->key)
			x = x->left;
		else
			x = x->right;
	}

	z->parent = y;

	if(y==NIL) root = z;
	else
		if(y->key>z->key)
			y->left = z;
		else
			y->right = z;
}

Node* find(Node *x,int key){
	while(x!=NIL&&x->key!=key){
		if(key<x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}
	return x;
}

void inorder(Node *u){
	if(u==NIL) return ;
	inorder(u->left);
	cout<<" "<<u->key;
	inorder(u->right);
}

void preorder(Node *u){
	if(u==NIL) return ;
	cout<<" "<<u->key;
	preorder(u->left);
	preorder(u->right);
}

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

long long sb, sumA, sumB;
int a, b, n, t, q;
multiset<int> A, B;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> q;
	while(q){
		cin >> t;
		if(t == 1){
			cin >> a >> b;
			sb += b;
			n++;
			
			if(A.empty())
				A.insert(a), sumA += a;
			else if(B.empty()){
				int t = (*A.begin());
				if(a >= t){
					B.insert(a);
					sumB += a;
				}else{
					A.erase(A.find(t));
					B.insert(t);
					sumA -= t;
					sumB += t;
					A.insert(a);
					sumA += a;
				}
			}
			else{
				int bb = (*B.begin()),
					aa = (*A.rbegin());
					
				if(a >= bb){
					B.insert(a);
					sumB += a;
					bb = (*B.begin());
					if(B.size() > (n / 2)){
						B.erase(B.find(bb));
						A.insert(bb);
						sumB -= bb;
						sumA += bb;
					}	
				}else{
					A.insert(a);
					sumA += a;
					aa = (*A.rbegin());
					if(A.size() > (n - (n / 2))){
						A.erase(A.find(aa));
						B.insert(aa);
						sumB += aa;
						sumA -= aa;
					}
				}
			}
			
		}
		else{
			int r = (*A.rbegin());
			long long j = (sumB - (1LL * B.size() * r)) + ((1LL * A.size() * r) - sumA);
			cout << r << ' ' << j + sb << '\n';
 		}
		
		
		q--;
	}
}

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

int main(void){
    int a, b, c;
    ll ma = 0;

    cin >> a >> b >> c;
    ma = max(max(a, b), c);

    ll ans = a + b + c + ma * 10 - ma;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def ss(s):
    n=len(s)
    if n%2==1:
        return False
    else:
        m=n//2
        s1=s[:m]
        s2=s[m:]        
        for i in range(m):
            if s1[i]!=s2[i]:
                return False
        return True

S=input()
for i in range(1,len(S)):
    if ss(S[:-i]):
        print(len(S)-i)
        break

Measured memory_bytes: 38256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


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

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	cin >> a >> b;

	if (a % b == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
	/*int N;
	cin >> N;
	string ans = "";
	while (N != 0) {
		if (N % 2 != 0) {
			N--;
			ans = "1" + ans;
		}
		else ans = "0" + ans;
		N /= -2;
	}
	if (ans == "")ans = "0";
	cout << ans << endl;*/

}
	

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <ctime>
#include <cstdlib>
#include <bitset>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 1010;
char s[N];
int has[300];

int main(){
    scanf("%s",s);
    for(int i=0;s[i];++i) has[(int)s[i]] = true;
    bool ok = true;
    ok &= (has['S'] == has['N']);
    ok &= (has['E'] == has['W']);
    puts(ok?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  double r;
  cin >> r;
  cout << fixed << setprecision(10) << r * r * M_PI << " " << 2 * r * M_PI;
}



Measured memory_bytes: 3284
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string n;
    int k;
    cin >> n >> k;
    int odp = 0;
    for (int d = 1; d <= (int) n.size() - 1; ++d)
    {
        if (d < k)
            continue;
        if (k == 1)
            odp += 9;
        if (k == 2)
            odp += (d - 1) * 9 * 9;
        if (k == 3)
            odp += (d - 1) * (d - 2) / 2 * 9 * 9 * 9;
    }
    int nz = 0;
    for (int i = 0; i < n.size(); ++i)
    {
        for (int c = (i == 0) ? 1 : 0; c < n[i] - '0'; ++c)
        {
            int r = (int) n.size() - i - 1;
            if (nz + (c != 0) > k)
                continue;
            int moge = k - (nz + (c != 0));
            if (r < moge)
                continue;
            if (moge == 0)
                ++odp;
            if (moge == 1)
                odp += r * 9;
            if (moge == 2)
                odp += r * (r - 1) / 2 * 9 * 9;
        }
        if (n[i] != '0')
            ++nz;
    }
    nz = 0;
    for (int i = 0; i < n.size(); ++i)
        nz += (n[i] != '0');
    if (nz == k)
        ++odp;
    cout << odp;
    return 0;
}


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

// Macros
#define F  first
#define S  second
#define PB push_back

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <


// CODE STARTS HERE

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

	vector<ll> A(n);
	for(auto& i: A) cin >> i;

	for(int i = k; i < n; ++i)
		cout << (A[i - k] < A[i] ? "Yes\n" : "No\n");
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Measured memory_bytes: 4764
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n), b(n);
	REP(i, n)cin >> a[i];
	REP(i, n)cin >> b[i];
	queue<int> q;
	REP(i, n) {
		if (b[i] > b[(i + 1) % n] + b[(i + n - 1) % n]) {
			q.push(i);
		}
	}
	auto calc = [&](int p) {
		int c = (b[p] - a[p]) / (b[(p + 1) % n] + b[(p + n - 1) % n]);
		return c;
	};
	ll ans = 0;
	while (!q.empty()) {
		int p = q.front(); q.pop();
		int res = calc(p);
		b[p] -= res * (b[(p + 1) % n] + b[(p + n - 1) % n]);
		ans += res;
		if (calc((p + 1) % n) > 0)q.push((p + 1) % n);
		if (calc((p + n - 1) % n) > 0)q.push((p + n - 1) % n);

	}
	bool ok = true;
	REP(i, n)if (a[i] != b[i])ok = false;
	if (ok)cout << ans << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 2304
package main

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

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	//	var jpy, btc float64
	var ans float64
	for i := 0; i < n; i++ {
		var a float64
		var b string
		fmt.Scan(&a, &b)
		if b == "JPY" {
			ans += a
		} else {
			ans += a * 380000
		}
	}
	fmt.Println(ans) // output for debug
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let mut s = get!(String).chars().collect::<Vec<_>>();
    let k = get!(usize);

    if s.iter().all(|&e| e == s[0]) {
        println!("{}", s.len()*k/2);
        return;
    }
    let n = s.len();
    let mut pcount = 0;
    let mut c = 0;
    let mut before = ' ';
    for i in 0..n {
        if before != s[i] {
            before = s[i];
            pcount += c/2;
            c = 1;
        } else {
            c += 1;
        }
    }
    pcount += c/2;
    let last = s[n-1];
    let mut i = 0;
    while s[i] == last && i<n {
        s.push(last);
        i += 1;
    }
    let mut count = 0;
    let mut c = 0;
    let mut before = ' ';
    for i in s.len()-n..s.len() {
        if before != s[i] {
            before = s[i];
            count += c/2;
            c = 1;
        } else {
            c += 1;
        }
    }
    count += c/2;
    println!("{}", count*(k-1) + pcount);
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
int main(){
  
    long int n,i;
    cin>>n;
    vector<long int>arr(n),temp(n);
    
    for(i=0;i<n;i++) cin>>arr[i],temp[i]=arr[i];
    sort(temp.begin(),temp.end());
    
    int count=0;
    for(i=0;i<n;i++){
     
        if(temp[i]!=arr[i]){
            count++;
        }
        
        if(count>2){
         cout<<"NO";return 0;   
        }
            
    }
    
    cout<<"YES";
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vvll vector<ll>
#define vll(a) vector<ll> a(MAXN)
#define pb push_back
#define fo(a) for(auto&a1:(a))
#define fd(a,b) for(int i=(a);i>=(b);i--)
#define fk(a,b) for(int k=(a);k<(b);k++)
#define fj(a,b) for(int j=(a);j<(b);j++)
#define f(a,b) for(ll i=(a);i<(b);i++)
#define forni(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define fdk(a,b) for(int k=(a);k>=(b);k--)
#define fdj(a,b) for(int j=(a);j>=(b);j--)
#define ri(n) scanf("%d",&(n));
#define rll(n) scanf("%lld",&(n));
#define T(t) int t;scanf("%d",&(t));while((t)--)
#define MAXN2 10000005
#define pll pair<ll,ll>
#define PI 3.14159265
#define mset(a) memset((a),0,sizeof((a)))
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sortv(a) sort(a.begin(),a.end())
#define v2d vector<vvll>
#define v3d vector<v2d>
#define max_value(a,b) a=max(a,b)
#define min_value(a,b) a=min(a,b)
using namespace std;
const ll MAXN=205;
const ll mod=1e9+7;
vector<ll> tr[MAXN];
bool vis[MAXN];
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	f(0,n)
	cin>>a[i];
	ll h=a[0],ans=0;
	f(1,n)
	{
		h=max(h,a[i]);
		ans+=h-a[i];
	}
	cout<<ans<<"\n";
	
    return 0;
}


Measured memory_bytes: 5200
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

def get_str
  gets.chomp
end

N = get_int
S = []
N.times do |i|
  S[i] = get_str
end

set = Set.new

S.each do |s|
  set.add(s)
end

puts set.length


Measured memory_bytes: 46364
//////// Step 
// https://atcoder.jp/contests/abc176/tasks/abc176_c
// date: 2020-08-22T21:00:10.587211
// memo: 
    
//<editor-fold desc="my macro">

#include<bits/stdc++.h>
#ifdef LOCAL
    #include<my/dump.h>
#else
    #define dump(...) 42 
    #define dumpi(x) 42 
#endif

typedef long long ll;
using namespace std;

#define foe(x, a) for(auto& (x) : (a))
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rep3(i, a, b) for(ll i=a, i##_len=(b);i<i##_len;i++)
#define _rep2(i, n) _rep3(i,0,n)
#define repd(...) _overload3(__VA_ARGS__,_repd3,_repd2,)(__VA_ARGS__)
#define _repd3(i, a, b) for(ll i=b-1, i##_len=(a);i>=i##_len;i--)
#define _repd2(i, n) _repd3(i,0,n)
#define loop(...) _overload3(__VA_ARGS__,,_loop2,_loop1)(__VA_ARGS__)
#define _loop2(i, a) for(ll i=a;; i++)
#define _loop1(i) _loop2(i,0)

#define all(x) x.begin(),x.end()
#define SIZE(x) ((ll)(x).size())

#define pb(a) push_back(a)
#define mp make_pair
#define F first
#define S second
#define vec vector
#define umap unordered_map
#define uset unordered_set

ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

template<typename T, typename ...Args>
void ci(T& first, Args&... args) {
    ((cin >> first), ..., (cin >> args)); //C++17
}

template<char Sep, typename T, typename ...Args>
void print_seq(const T& first, const Args&... args) {
    ((cout << first), ..., (cout << Sep << args)); //C++17
}

void co(){ cout << endl; }
template<typename... Words>
void co(Words... words) {
    print_seq<' '>(words...);
    cout << endl;
}
#define coi(x) cout<<(x)<<" "

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define sankou(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define asrt(expr...) assert((expr))
//</editor-fold>

#define INF 1e19
#define MOD 1e9+7
#define MAXR 1e5

int solve() {
    ll N;
    ci(N);

    ll buf_max= 0;
    ll sum=0;
    rep(i,N) {
        ll a;
        ci(a);
        if ( i == 0) {
            buf_max = a;
            continue;
        }
        if (buf_max > a) {
            sum += (buf_max - a);
        } else {
            buf_max = a;
        }
    }
    co(sum);
    return 0;
}

int main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    
    solve();
    return 0;
}


Measured memory_bytes: 3592
import java.util.*;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] A = new int[N+1];
		int[] a = new int[N+1];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			a[A[i]]++;
		}
		long ans = 0L;
		for (int i = 0; i <= N; i++) {
			long x = a[i];
			ans += x*(x-1)/2;
		}

		for (int i = 0; i < N; i++) {
			long temp = ans;
			long x = a[A[i]];
			if (x >= 2) {
				temp -= x*(x-1)/2;
				temp += (x-1)*(x-2)/2;
			}
			System.out.println(temp);
		}
	}

}

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

int main() {
    int N;
    std::cin >> N;

    std::vector<char> S(N);
    for (char& s : S) {
        std::cin >> s;
    }

    if (std::find(S.begin(), S.end(), 'Y') != S.end()) {
        std::cout << "Four" << std::endl;
    } else {
        std::cout << "Three" << std::endl;
    }
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

void tsort(int pos);
int dfs(int pos);

vector< int > graph[SIZE];
vector< int > graph_sort;

int dp[SIZE];
bool visited[SIZE];


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

    int n, m;
    cin >> n >> m;
    for( int i = 0; i < m; ++i ) {
        int x, y;
        cin >> x >> y;
        graph[x].pb(y);

    }

    // Topological Sort
    for( int i = 1; i <= n; ++i ) {
        tsort(i);

    }

    for( int i = 1; i <= n; ++i ) {
        visited[i] = false;

    }

    int res = 0;
    for( int i = 1; i <= n; ++i ) {
        res = max(res, dfs(graph_sort[i]));

    }
    cout << res << endl;

    return 0;
}

void tsort(int pos) {
    if( visited[pos] ) return;
    visited[pos] = true;

    for( int i = 0; i < graph[pos].size(); ++i ) {
        tsort(graph[pos][i]);

    }

    graph_sort.pb(pos);
    return;
}

int dfs(int pos) {
    if( visited[pos] ) return dp[pos];
    visited[pos] = true;

    int tmp = 0;
    for( int i = 0; i < graph[pos].size(); ++i ) {
        tmp = max(tmp, dfs(graph[pos][i]) + 1);

    }
    dp[pos] = tmp;

    return dp[pos];
}


Measured memory_bytes: 10872
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans=0;
	int i=0,j=0;
	int n=s.length();
	while(i<=j&&j<n)
	{
		if(s[i]==s[j]&&s[i]=='R')
		{
			j++;
		}
		if(s[i]==s[j]&&s[j]=='S')
		{
			i++;
			j++;
		}
		if(s[i]!=s[j])
		{
			ans=max(ans,j-i);
			i=j;
		}
	}
	if(i<j)
	{
		ans=max(ans,j-i);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3624
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
	static void Main(string[] args)
	{

        int n = int.Parse(Console.ReadLine());
        int[,,] room = new int[4, 3, 10];


        for (int i = 0; i < n;i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            room[int.Parse(s[0]) - 1, int.Parse(s[1]) - 1,int.Parse(s[2]) - 1] += int.Parse(s[3]);

        }


        for (int i = 0; i < 4;i++)
        {
            for (int j = 0; j < 3;j++)
            {
                for (int k = 0; k < 10;k++)
                {
                    Console.Write(" {0}",room[i,j,k]);
                }
                Console.WriteLine();
            }
            if(i<3) Console.WriteLine("####################");

        }
		
		//Console.WriteLine("");

	}
}

Measured memory_bytes: 9212
#include<stdio.h>
int main() {
  int a, b, i, j;
  int result = 0;
  int num = 1;
  scanf("%d", &a);
  scanf("%d", &b);
  
  for (i=0; i<a; i++) {
      num *= 100;
  }
  for (j=0; j<b; j++) {
      result += num;
      if (result % (num * 100) == 0) {
          result += num;
      }
  }
  printf("%d\n", result);
  return 0;
}

Measured memory_bytes: 128
n=int(input())
s=input()
ans=[]
minscore=0
score=0
for i in range(n):
  if s[i]=='(':
    score+=1
  else:
    score-=1
  minscore=min(minscore,score)
finalscore=score
for i in range(-minscore):
  ans.append('(')
for i in range(n):
  ans.append(s[i])
for i in range(-minscore+finalscore):
  ans.append(')')
print(''.join(ans))

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a*b%2==0){
    cout<<"Even"<<endl;
  }else{
    cout<<"Odd"<<endl;
  }
}



Measured memory_bytes: 3616
#include <iostream>
#include <complex>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

void rotate(int a[], string str)
{
    for(auto itr = str.begin(); itr != str.end(); ++itr)
    {
        int tmp;
        switch (*itr) {
            case 'N':
                tmp = a[0];
                a[0] = a[1];
                a[1] = a[5];
                a[5] = a[4];
                a[4] = tmp;
                break;
            case 'S':
                tmp = a[0];
                a[0] = a[4];
                a[4] = a[5];
                a[5] = a[1];
                a[1] = tmp;
                break;
            case 'W':
                tmp = a[3];
                a[3] = a[0];
                a[0] = a[2];
                a[2] = a[5];
                a[5] = tmp;
                break;
            case 'E':
                tmp = a[2];
                a[2] = a[0];
                a[0] = a[3];
                a[3] = a[5];
                a[5] = tmp;
                break;
        }
    }
}

int main(void)
{
    int a[6], q;
    string str;
    for (int i = 0; i < 6; ++i)
        cin >> a[i];
    cin >> q;

    int t, f;
    for (int i = 0; i < q; ++i) {
        cin >> t >> f;

        if (t == a[5])
                rotate(a, "NN");
        else if (t == a[1])
                rotate(a, "N");
        else if (t == a[3])
                rotate(a, "E");
        else if (t == a[2])
                rotate(a, "W");
        else if (t == a[4])
                rotate(a, "S");

        if (f == a[1])
                cout << a[2] << endl;
        else if (f == a[2])
                cout << a[4] << endl;
        else if (f == a[4])
                cout << a[3] << endl;
        else if (f == a[3])
                cout << a[1] << endl;
    }

    return 0;
}







Measured memory_bytes: 3192