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

//-std=c++11
//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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 trace(...)
#endif

#define LL long long
#define FI ios_base::sync_with_stdio(0); cin.tie(NULL);
#define PREC cout << setprecision(10) << fixed;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
const int MX = 1e5 + 5;

int main()
{
	#define int long long
	int n,x,m;
	cin >> n >> x >> m;

	int start;

	set<int> st;
	st.insert(x);
	int last = x;
	while(1) {
		int next = (last * last)%m;
		if(st.find(next) != st.end()) {
			start = next;
			break;
		}
		st.insert(next);
		last = next;
	}

	vector<int> val;
	int sum = 0;
	val.push_back(start);
	sum += start;
	last = start;
	while(1) {
		int next = (last * last)%m;
		if(next == start) {
			break;
		}
		val.push_back(next);
		sum += next;
		last = next;
	}
	int sz = val.size();

	int ans = 0;

	int curr = x;
	while(curr != start && n > 0) {
		ans += curr;
		curr = (curr * curr)%m;
		n--;
	}

	int cyc = n/sz;
	ans += cyc * sum;

	int rem = n%sz;
	for(int i=0;i<rem;i++) {
		ans += val[i];
	}

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


Measured memory_bytes: 6160
process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});

// 解答
function main(inputs:Array<string>) : void {

    // 枚数
    let count: number = Number(inputs[0].split(' ')[0]);
    let strMap: {[key: string]: number} = {};

    // 文字列の格納&回数計算
    for (let i = 1; i <= count; i++) {

        if (inputs[i] in strMap) {

            strMap[inputs[i]] = strMap[inputs[i]] + 1;
        } else {
            strMap[inputs[i]] = 0;
        }
    }

    let max = 0;
    let strList: string[] = [];

    // 回数最大の文字列抽出
    for (let str in strMap) {

        if (strMap[str] > max) {

            strList = new Array();
            max = strMap[str];
        }

        if (strMap[str] == max) {

            strList.push(str);
        }
    }

    return console.log(strList.sort().join('\n'));
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.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; }

struct Pos{
	int x, y;
};

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	vector<Pos> p(2);
	rep(i, 2) cin >> p[i].x >> p[i].y;

	int x = p[1].x - p[0].x;
	int y = p[1].y - p[0].y;

	printf("%d %d %d %d\n", p[1].x-y, p[1].y+x, p[0].x-y, p[0].y+x);
	return 0;
}

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

int main() {
    string S,T;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++)
    {
        if(S[i]!=T[i])break;
        if(i==S.size()-1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    vector<int64_t> x(n);
    vector<pair<int64_t, pair<int64_t, int64_t>>> times;
    for (auto i : irange(0L, n)) {
        int64_t s, t, xx;
        cin >> s >> t >> xx;
        x[i] = xx;
        times.emplace_back(s - xx, make_pair(-2L, i));
        times.emplace_back(t - xx, make_pair(-1L, i));
    }

    for (auto i : irange(0L, q)) {
        int64_t d;
        cin >> d;
        times.emplace_back(d, make_pair(0L, i));
    }

    sort(times.begin(), times.end());

    priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>, greater<pair<int64_t, int64_t>>> queue;
    vector<bool> active(n, false);
    vector<int64_t> ans(q, -1L);
    for (auto&& a : times) {
        auto t = a.first;
        auto type = a.second.first;
        auto idx = a.second.second;
        if (type == -2L) {
            // start
            active[idx] = true;
            queue.emplace(x[idx], idx);
        } else if (type == -1L) {
            // end
            active[idx] = false;
        } else {
            // query
            while (!queue.empty() && !active[queue.top().second]) {
                queue.pop();
            }

            if (!queue.empty()) {
                ans[idx] = queue.top().first;
            }
        }
    }

    for (auto a : ans) {
        cout << a << "\n";
    }

    cout << flush;
}

Measured memory_bytes: 28520
import java.util.*;
class Main {
    public static void main(String...args) {
       Scanner scan = new Scanner(System.in);
       String str = null;
       int total =0;
       while(true) {
           str = scan.next();
           if(str.equals("-"))break;
           int times = scan.nextInt();
           for(int i = 0 ; i < times; i++) {
               total += scan.nextInt();
           }
           for(int n = 0; n < str.length(); n++) {
               System.out.print(str.charAt((total + n )%str.length()));
           } 
           System.out.println();
           total = 0;
       }
    
    }
}




Measured memory_bytes: 26320
# -*- coding: utf-8 -*-
a, b, c, k = map(int, input().split())

if a >= k:
    print(k)
else:
    if a+b >= k:
        print(a)
    else:
        if a+b+c == k:
            print(a-c)
        else:
            print(a-(k-(a+b)))


Measured memory_bytes: 9176
package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    line1 := readLine(reader)
    arr := strings.Split(line1, " ")
    a, _ := strconv.Atoi(arr[0])
    b, _ := strconv.Atoi(arr[1])

    if a > 0 {
        fmt.Println("Positive")
    } else if b < 0 {
        if (a * -1 - b * -1) % 2 == 0 {
            fmt.Println("Negative")
        } else {
            fmt.Println("Positive")
        }
    } else {
        if a * -1 == b {
            fmt.Println("Zero")
        } else {
            if a * -1 - 0 == 1 {
                fmt.Println("Zero")
            } else if (a * -1 - 0) % 2 == 0 {
                fmt.Println("Positive")
            } else {
                fmt.Println("Negative")
            }
        }
    }
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1000000)

    for {
        l, p, e := reader.ReadLine()

        if e != nil {
            panic(e)
        }

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using BigInt = long long;
#define ALL(a)  (a).begin(),(a).end()

int main(){
    string a, b;
    cin >> a >> b;
    int n = stoi(a + b);
    if (sqrt(n) == (int)sqrt(n)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

bool cmp(pair<int, int> x, pair<int, int> y)
{
	if(x.ss == y.ss)
		return x.ff < y.ff;
	else
		return x.ss < y.ss;
}
int main()
{
	int n;
	cin >> n;
	vector <pair<int, int>> p(n);
	for (int i = 0; i < n; i++)
	{
		cin >> p[i].ff >> p[i].ss;
	}
	sort(all(p), cmp);
	int t = 0;
	for (int i = 0; i < n; i++)
	{
		if(t + p[i].ff <= p[i].ss)
		{
			t = t + p[i].ff;
		}
		else
		{
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}


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

int A, B;

int main () {
	cin >> A >> B;
	if (A==1){
		if (B==2){
			cout << "3";
		} else {
			cout << "2";
		}
	} else if (A==2){
		if (B==1){
			cout << "3";
		} else {
			cout << "1";
		}
	} else if (A==3){
		if (B==1){
			cout << "2";
		} else {
			cout << "1";
		}
	}
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

long long COM(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;
}

// gcd, lcm
ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}


int main() {
    vector<string> log;
    int n;
    cin >> n;
    string first;
    cin >> first;
    char latest = first[first.size() - 1];
    log.push_back(first);
    REP(i, n - 1) {
       string a;
       cin >> a;
       if (latest == a[0] && find( log.begin(), log.end(), a ) == log.end()) {
           latest = a[a.size() - 1];
           log.push_back(a);
       } else {
           cout << "No";
           return 0;
       }
    }
    cout << "Yes";
    return 0;
}


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

int main(){
	int data[12][10] = {0};
	int n;

	cin >> n;

	for (int i = 0; i < n; i++){
		int b, f, r, v;
		cin >> b >> f >> r >> v;

		f += (b - 1) * 3;
		f -= 1;

		r -= 1;
		data[f][r] += v;
	}

	
	for (int i = 0; i < 12;i++){
		for (int j = 0; j < 10; j++){
			if (i % 3 == 0 && i != 0 && j == 0) cout << "####################" << endl;
			cout << " ";
			cout << data[i][j];
		}
		 cout << endl;
	}
}

Measured memory_bytes: 1160
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		double tsubo = 3.305785;

		        Scanner stdin = new Scanner(System.in);

		        int a = stdin.nextInt();

		        int b = stdin.nextInt();

		        double s = (a * b) / tsubo;

		        BigDecimal land = new BigDecimal(s);
				BigDecimal land1 = land.setScale(6,BigDecimal.ROUND_HALF_UP);

				System.out.println(land1);



		    }
		}

Measured memory_bytes: 26540
<?php
fscanf(STDIN, "%d", $N);
$d = [];
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $a[$i], $b[$i]);
    $c[$i] = $a[$i] + $b[$i];
}
array_multisort($c, SORT_DESC, $a, $b);
$T = $A = 0;
for ($i = 0; $i < $N; $i++) {
    if ($i % 2 === 0) {
        $T += $a[$i];
    } else {
        $A += $b[$i];
    }
}
printf("%d", $T - $A);


Measured memory_bytes: 33396
#include <bits/stdc++.h>
#define REP(i, n, s) for (int i = (s); i < (n); i++)
using namespace std;
typedef long long LL;

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

	int N, X, A, pre;
	cin >> N >> X;
	cin >> A;
	LL res = 0;
	if (A > X) {
		res += A - X;
		A = X;
	}
	pre = A;
	while (--N) {
		cin >> A;
		if (A + pre > X) {
			res += A + pre - X;
			A -= A + pre - X;
		}
		pre = A;
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
signed main(void)
{
	string s;cin>>s;
	if(s[1]=='B')
		cout<<"ARC"<<endl;
	else
		cout<<"ABC"<<endl;
	return 0;
}




Measured memory_bytes: 3592
# 166A
# SがABCの時、今週開催予定はARCと出力される

# 標準入力
S = input()

# ABCが入力されたときARCを出力する
if S == 'ABC':
    print('ARC')

# ARCが入力されたとき（ABC以外のとき）ABCと表示される

else:
    print('ABC')

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

int main(){
  
  int N;
  std::cin >> N;
  std::vector<int> Hs(N);
  for(int i = 0; i < N; ++i) std::cin >> Hs[i];
  
  int count = 0;
  int maxH = 0;
  for(const auto &Hi : Hs){
  	 if(Hi >= maxH){
       ++count;
       maxH = Hi;
     } 
  }
  std::cout << count; 
  
  return 0;
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  int ans = 1;
  for (int i = 0; i < a; i++) {
    if (ans < b) ans *= 2;
    else ans += b;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*
 * Program compiled with natsubf by Natsu Kinmoe
 * Natsubf is a multifunctional brainfuck tool
 * https://github.com/natsukmoe/natsubf
 */
#include <cstdio>

char ram[30000];
int ptr;

int main(){
	ram[ptr]=getchar();
	ram[ptr]=getchar();
	ram[ptr]=getchar();
	ptr+=1;
	ram[ptr]=getchar();
	ptr-=1;
	while(ram[ptr]){
		ram[ptr]+=255;
		ptr+=1;
		ram[ptr]+=255;
		ptr-=1;
	}
	ptr+=2;
	ram[ptr]+=1;
	ptr-=1;
	while(ram[ptr]){
		while(ram[ptr]){
			ram[ptr]+=255;
		}
		ptr+=1;
		ram[ptr]+=255;
		ptr+=1;
		ram[ptr]+=5;
		while(ram[ptr]){
			ptr+=1;
			ram[ptr]+=15;
			ptr-=1;
			ram[ptr]+=255;
		}
		ptr+=1;
		ram[ptr]+=3;
		putchar(ram[ptr]);
		while(ram[ptr]){
			ram[ptr]+=255;
		}
		ptr-=1;
		ram[ptr]+=10;
		while(ram[ptr]){
			ptr+=1;
			ram[ptr]+=11;
			ptr-=1;
			ram[ptr]+=255;
		}
		ptr+=1;
		ram[ptr]+=1;
		putchar(ram[ptr]);
		ptr-=3;
	}
	ptr+=2;
	ram[ptr]=getchar();
	ptr+=1;
	ram[ptr]=getchar();
	ptr-=2;
	while(ram[ptr]){
		ptr+=1;
		while(ram[ptr]){
			ram[ptr]+=255;
			ptr+=1;
			ram[ptr]+=255;
			ptr-=1;
		}
		ptr+=2;
		ram[ptr]+=1;
		ptr-=1;
		while(ram[ptr]){
			while(ram[ptr]){
				ram[ptr]+=255;
			}
			ptr+=1;
			ram[ptr]+=255;
			ptr+=1;
			ram[ptr]+=5;
			while(ram[ptr]){
				ptr+=1;
				ram[ptr]+=15;
				ptr-=1;
				ram[ptr]+=255;
			}
			ptr+=1;
			ram[ptr]+=3;
			putchar(ram[ptr]);
			while(ram[ptr]){
				ram[ptr]+=255;
			}
			ptr-=1;
			ram[ptr]+=10;
			while(ram[ptr]){
				ptr+=1;
				ram[ptr]+=11;
				ptr-=1;
				ram[ptr]+=255;
			}
			ptr+=1;
			ram[ptr]+=1;
			putchar(ram[ptr]);
			ptr-=3;
		}
		ptr+=1;
		while(ram[ptr]){
			ram[ptr]+=255;
			ptr+=1;
			ram[ptr]+=8;
			while(ram[ptr]){
				ptr+=1;
				ram[ptr]+=11;
				ptr-=1;
				ram[ptr]+=255;
			}
			ptr+=1;
			ram[ptr]+=1;
			putchar(ram[ptr]);
			ptr-=1;
			ram[ptr]+=3;
			while(ram[ptr]){
				ptr+=1;
				ram[ptr]+=4;
				ptr-=1;
				ram[ptr]+=255;
			}
			ptr+=1;
			putchar(ram[ptr]);
			ram[ptr]+=14;
			putchar(ram[ptr]);
			ptr-=1;
		}
	}
	return 0;
}


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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int a, b;
    cin >> a >> b;

    int x = a + b, y = a - b, z = a * b;
    cout << max(x, max(y, z)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

main(){
	int X,Y;
	int a = 0;
	int b = 0;
	double c = 0;
	scanf("%d %d",&X,&Y);
	a = X / Y;
	b = X % Y;
	c = (double)X/Y; 
	printf("%d %d %f\n", a, b, c);
	return 0;
}

Measured memory_bytes: 636
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    s = 0
    t = 0
    for c in a:
        s += abs(t-c)
        t = c
    s += abs(t)

    r = []
    r.append(s - abs(a[0]) - abs(a[0]-a[1]) + abs(a[1]))
    for i in range(1,n-1):
        r.append(s - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1]))
    r.append(s - abs(a[-1]) - abs(a[-1]-a[-2]) + abs(a[-2]))


    return '\n'.join(map(str,r))


print(main())




Measured memory_bytes: 21372
#include <stdio.h>
#include <string.h>
int main (){
    int x;
    char c[101];
    scanf("%d " , &x);
    scanf("%s" , c);
    int len = strlen(c);
    if (len <= x) {
        printf("%s\n", c);
    }
    else {
        for (int i = 0; i < x; i++){
            printf("%c", c[i]);
        }
        printf("...\n");
    }
    return 0;
}



Measured memory_bytes: 1660
/*
 Educational Dp Contest Atcoder
 
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

const ll MOD =998244353;
const ll hell=1000000007;
const int INF=1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=405;
int dp[N][N];int a[N];int pre[N];
int cost(int i,int j)
{
    int c=pre[j];
    if(i)
        c-=pre[i-1];
    return c;
}
void solve()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {cin>>a[i];
    }
    pre[0]=a[0];
    for(int i=1;i<=n;i++)
        pre[i]=pre[i-1]+a[i];
    for(int l=1;l<=n;l++)
    {
        for(int i=0;i<=n-l;i++)
        {
            int j=i+l-1;
            if(l==1)
            {
                dp[i][j]=0;
            }
            else if(l==2)
            {
                dp[i][j]=a[i]+a[j];
            }
            else
            {
                dp[i][j]=INF;
                for(int k=j-1;k>=i;k--)
                {
                    dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+cost(i,k)+cost(k+1,j));
                }
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    
}

int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  int sum=a+b;
  int sub=a-b;
  int mul=a*b;
  if(sum>=sub&&sum>=mul)
    cout<<sum;
  else if(sub>=sum&&sub>=mul)
    cout<<sub;
  else
    cout<<mul;
  return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
const long long MODNUM = 7;

int main() {

    string s; cin >> s;
    vector<int> a(26,0);

    rep(i, s.size()) {
        a[s[i]-'a']++;
    }

    rep(i, 26) {
        if(a[i]%2!=0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


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

int main() {
    int n,l,r,sum;
    sum = 0;
    cin >> n ;
    for(int i = 0; i < n; i++) {
        cin >> l >> r;
        sum += r-l+1;
    }
    cout << sum <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) ((x).begin(), (x).end())
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

ll n, m;
V<V<int>> G;
V<V<ll>> x;
V<ll> dp;
V<int> pp;

void dfs1(int i, int p) {
    dp[i] = 1;
    for(int e : G[i]) {
        if(e != p) {
            dfs1(e, i);
            x[i].push_back((dp[e] + 1) % m);
            dp[i] *= dp[e] + 1;
            dp[i] %= m;
        } else {
            pp[i] = x[i].size();
            x[i].push_back(-1);
        }
    }
}

void dfs2(int i, int p, ll d_p = -1) {
    if(p != -1) {
        x[i][pp[i]] = d_p;
        (dp[i] *= d_p) %= m;
    }
    V<ll> s1, s2;
    s1 = s2 = x[i];
    rep(j, s1.size() - 1)(s1[j + 1] *= s1[j]) %= m;
    FORR(j, s2.size() - 1)(s2[j] *= s2[j + 1]) %= m;
    rep(j, G[i].size()) {
        if(G[i][j] == p) continue;
        ll d =
            ((j ? s1[j - 1] : 1) * (j + 1 < G[i].size() ? s2[j + 1] : 1) + 1) %
            m;
        dfs2(G[i][j], i, d);
    }
}

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

    cin >> n >> m;
    G.resize(n);
    dp.resize(n);
    x.resize(n);
    pp.assign(n, -1);
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs1(0, -1);
    dfs2(0, -1);
    rep(i, n) cout << dp[i] << endl;

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    int ans = 0;
    for (int i = n-2; i >= 0; i--) {
        if ( h[i] >= h[i+1]+2 ) {
            cout << "No" << endl;
            return 0;
        }
        if ( h[i] > h[i+1]) {
            h[i]--;
        }
    }

    for (int i = 0; i < n-1; i++) {
        if ( h[i] <= h[i+1]) {
            ans++;
        }
    }

    if ( ans == n-1 ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include<iomanip>
using namespace std;


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

    vector<int> vec;
    for(int i= 0;i<50000;i++)
    {
        vec.push_back(i*1.08);
    }
    std::vector<int>::iterator itr;
    itr = std::find(vec.begin(), vec.end(), N);
	if (itr == vec.end()) 
    {
        std::cout << ":(" << std::endl;
    }
    else
    {
        const int wanted_index = std::distance(vec.begin(), itr);
	    std::cout << wanted_index  << std::endl;
    }
    
 

}

Measured memory_bytes: 640
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <list>
#include <math.h>
#include<string.h>
#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)

//	rep(i,10)cout << i << endl;
using namespace std;

int main(void){
	int cnt=0;
	char s[1000];
	scanf("%s" ,s);
	int len=strlen(s);
	int flg=0;
	rep(i,len){
		if(s[i]=='C')	flg=1;
		else if(s[i]=='F' && flg==1)flg=2;
	//	printf("%c %d\n",s[i],flg);
	}
	if(flg==2)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define inver(a) power(a,mod-2)
using namespace std;
inline char nc()
{
    // return getchar();
    static char buf[100000],*l=buf,*r=buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x=0; int f=1,ch=nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x*=f;
}
typedef long long ll;
const int mod=998244353;
const int maxk=5e5+50;
int n,k;
int fac[maxk],inv[maxk];
inline int add(int x) {return x>=mod?x-mod:x;}
inline int sub(int x) {return x<0?x+mod:x;}
ll power(ll x,ll y)
{
    ll re=1;
    while(y)
    {
        if(y&1) re=re*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return re;
}
inline ll binom(int x,int y)
{
    if(x<y) return 0;
    return (ll)fac[x]*inv[y]%mod*inv[x-y]%mod; 
}
inline int sol(int X,int Y,int T)
{
    if(0>=T||Y-X>=T) return 0;
    return sub(binom(X+Y,X)-binom(X+Y,Y-T));
}
void init(int n)
{
    fac[0]=1;
    for(int i=1;i<=n;++i) fac[i]=(ll)fac[i-1]*i%mod;
    inv[n]=inver(fac[n]);
    for(int i=n;i>=1;--i) inv[i-1]=(ll)inv[i]*i%mod;
}
int main()
{
    read(n),read(k);
    init(k);
    int an=0;
    for(int R=k,B=0;R>B;--R,++B) 
    {
        int T=max(0,n-(R-B));
        an=add(an+sol(R,B,B-T+1));
    }
    if((~k&1))
    {
        int B=k>>1,T=B-n+1;
        if(T>0) an=add(an+sol(B,B-1,T));
    }
    printf("%d\n",an);
    return 0;
}

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

string even, odd;

int main(){
  cin >> odd >> even;
  int e, o;
  e = even.size();
  o = odd.size();
  for(int i = 0; i < e + o; i++){
    if(i % 2 == 0){
      cout << odd[i / 2];
    }
    else{
      cout << even[(i - 1) / 2];
    }
  }
  cout << endl;
}


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

bool is_prime[250000];
void set_prime(){
  for(int i = 0; i < 250000; i++) is_prime[i] = true;
  is_prime[0] = false;
  is_prime[1] = false;
  for(int i = 2; i <= 500; i++){
    if(is_prime[i]){
      for(int j = i * i; j < 250000; j += i) is_prime[j] = false;
    }
  }
}

int main(void){
  int n, ans;
  set_prime();
  while(1){
    cin >> n;
    if(n == 0) break;
    ans = 0;
    for(int i = n + 1; i < n * 2 + 1; i++){
      if(is_prime[i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}


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

int main(){
	string s;
	cin >> s;
	int count[3]={0,0,0};
	for(int i=0; i<(int)s.length(); i++){
		count[s[i]-'a']++;
	}
	int cmax=0, cmin=1e9;
	for(int i=0; i<3; i++){
		cmax=max(cmax, count[i]);
		cmin=min(cmin, count[i]);
	}
	if(cmax-cmin>1){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
	return 0;
}

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

int main()
{
  int D;
  cin >> D;
  switch (D)
  {
  case 25:
    cout << "Christmas" << endl;
    break;
  
  case 24:
    cout << "Christmas Eve" << endl;
    break;
  
  case 23:
    cout << "Christmas Eve Eve" << endl;
    break;
  
  case 22:
    cout << "Christmas Eve Eve Eve" << endl;
    break;

  default:
    break;
  }
  return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var tpr=(Arr.shift()).split(" ").map(Number);
   if(tpr[0]==0 && tpr[1]==0 &&  tpr[2]==0)break;
   var G=[];
   var Tp=[];
   for(var i=0;i<tpr[0];i++){
      G[i]=[i,0,0];
      Tp[i]=[];
      for(var j=0;j<tpr[1];j++){
         Tp[i][j]=0;
      }
   }
   for(var i=0;i<tpr[2];i++){
      var arr=(Arr.shift()).split(" ");
      var t=(arr[0]-0)-1;
      var p=(arr[1]-0)-1;
      var time=arr[2]-0;
      if(arr[3]=="WRONG")Tp[t][p]++;
      if(arr[3]=="CORRECT"){
         G[t][1]++;
         G[t][2]+=(Tp[t][p]*1200)+time;
      }
   }
   G.sort(function(a,b){
      a=((50-a[0])*0.01)+(a[1]*1000000)+(610800-a[2]);
      b=((50-b[0])*0.01)+(b[1]*1000000)+(610800-b[2]);
      return b-a;
   });
   G.forEach(function(v){
      console.log((v[0]+1)+" "+v[1]+" "+v[2]);
   });
}

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

int gcd(int a, int b) {
  if (a < b) { int tmp = a; a = b; b = tmp; }
  if (b == 0) return a;
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> a(n), l(n + 1, 0), r(n + 2, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    l[i + 1] = gcd(l[i], a[i]);
    r[n - i] = gcd(r[n - i + 1], a[n - i - 1]);
  }
  for (int i = 0; i <= n; i++) ans = max(ans, gcd(l[i], r[i + 2]));
  cout << ans << "\n";
}

Measured memory_bytes: 1408
n = int(input())
alst = list(map(int, input().split()))
mod_cnt = [0, 0, 0]
for a in alst:
  mod_cnt[a % 3] += 1
if mod_cnt[1] == 0 and mod_cnt[2] == 0:
  print(1)
elif mod_cnt[1] == mod_cnt[2]:
  print(mod_cnt[0] + mod_cnt[1] + mod_cnt[2])
elif mod_cnt[1] < mod_cnt[2]:
  print(mod_cnt[0] + mod_cnt[1] + min(mod_cnt[1] + 3, mod_cnt[2]))
elif mod_cnt[1] > mod_cnt[2]:
  print(mod_cnt[0] + min(mod_cnt[1], mod_cnt[2] + 3) + mod_cnt[2])


Measured memory_bytes: 15032
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull B = 5575777;

int h,w;
char t[20][20];
int ans=15*15;

map< ull , int > mp[20][20];

void dfs(int y,int x,int c){
  if(c>=ans)return;
  
  if(x==w+1){
    dfs(y+1,0,c);
    return;
  }
  
  if(y==h+1){
    ans=min(ans,c);
    return;
  }

  ull key=0;
  int ny=y-1,nx=x-1;
  for(int i=0;i<=2*w+1;i++){
    char ch='z';
    if(0<=ny&&ny<h&&0<=nx&&nx<w)ch=t[ny][nx];
    key=key*B+ch;
    nx++;
    if(nx==w){
      nx=0;
      ny++;
    }
  }
  
  if(mp[y][x].count(key)==0)mp[y][x][key]=15*15;
  if(mp[y][x][key]<=c)return;
  mp[y][x][key]=c;
  
  if(y&&x&&'1'<=t[y-1][x-1]&&t[y-1][x-1]<='9'){
    
  }else{
    dfs(y,x+1,c);
    
  }
  
  if(y<h && x<w && t[y][x]!='.'){
    bool flag=true;
    for(int i=-1;i<=1;i++){
      for(int j=-1;j<=1;j++){
        int py=y+i,px=x+j;
        if(0<=py && py<h && 0<=px&&px<w && '0'<=t[py][px]&&t[py][px]<='9'){
          if(t[py][px]=='0')flag=false;
          t[py][px]--;
        }
      }
    }
    bool flag2=true;
    if(y&&x&&'1'<=t[y-1][x-1]&&t[y-1][x-1]<='9')flag2=false;
    
    if(flag && flag2){
      dfs(y,x+1,c+1);
    }
    
    for(int i=-1;i<=1;i++){
      for(int j=-1;j<=1;j++){
        int py=y+i,px=x+j;
        if(0<=py && py<h && 0<=px&&px<w && '0'-1<=t[py][px]&&t[py][px]<='9'){
          t[py][px]++;
        }
      }
    }
  }
  

}

int main(){
  
  while(cin>>h>>w){
    if(h==0&&w==0)break;
    ans=15*15;
    
    for(int i=0;i<20;i++)
      for(int j=0;j<20;j++)
        mp[i][j].clear();
    
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin>>t[i][j];
      }
    }
    
    dfs(0,0,0);
    cout<<ans<<endl;
  }
  return 0;  
}



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

int main() {
    ll N, D, A;
    cin >> N >> D >> A;
    P xh[N];
    int mx = 0, X, H;
    rep(i, N) {
        cin >> X >> H;
        xh[i].first = X;
        xh[i].second = H;
        mx = max(mx, H);
    }

    
    sort(xh, xh + N);
    if (D * 2 >= xh[N-1].first) {
        //cout << ceil(mx * 1.0 / A) << endl;
        cout << (mx + A - 1) / A << endl;
        return 0;
    }

    ll ans = 0;
    rep(i, N) {
        if (xh[i].second == 0) continue;
        ll next = xh[i].first + D * 2;
        int cnt = ceil((xh[i].second * 1.0) / A);
        ans += cnt;
        ll bomb = A * cnt;
        for (int j = i; j < N; j++) {
            if (xh[j].first > next) break;
            xh[j].second = max(0ll, xh[j].second - bomb);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

N = I()
c = _S()

R = c.count('R')
ans = 0

# Rを左詰めすれば良い。左から探索してWであれば入れ替える
# for i in range(R):
#     if c[i]=='W':
#         ans += 1
ans = c[:R].count('W')
print(ans)

Measured memory_bytes: 92148
using System;

namespace ConsoleApp1
{
	class Program
	{
		enum enState { Vacant, Male, Female };
		static void Main(string[] a_asArgs)
		{
			int l_iN = int.Parse(Console.ReadLine());

			int l_iIndex1 = 0;
			int l_iIndex2 = (l_iN - 1) / 2;
			int l_iIndex3 = l_iN - 1;
			enState l_State1;
			enState l_State2;

			if ((l_State1 = GetState(l_iIndex1)) == enState.Vacant) return;
			if ((l_State2 = GetState(l_iIndex2)) == enState.Vacant) return;

			for (int l_iTurn = 0; l_iTurn < 20; l_iTurn++)
			{
				if ((l_iIndex2 - l_iIndex1) % 2 == 0 && l_State1 == l_State2 || (l_iIndex2 - l_iIndex1) % 2 != 0 && l_State1 != l_State2)
				{
					l_iIndex1 = l_iIndex2;
					l_iIndex2 = (l_iIndex2 + l_iIndex3) / 2;
					if (l_iIndex1 == l_iIndex2)
					{
						if ((l_State2 = GetState(l_iIndex3)) == enState.Vacant) return;
					}
					l_State1 = l_State2;
					if ((l_State2 = GetState(l_iIndex2)) == enState.Vacant) return;
				}
				else
				{
					l_iIndex3 = l_iIndex2;
					l_iIndex2 = (l_iIndex1 + l_iIndex2) / 2;
					if ((l_State2 = GetState(l_iIndex2)) == enState.Vacant) return;
				}
			}
		}

		static enState GetState(int a_iIndex)
		{
			Console.WriteLine(a_iIndex);
			switch (Console.ReadLine()[0])
			{
				case 'M':
					return enState.Male;

				case 'F':
					return enState.Female;

				default:
					return enState.Vacant;
			}
		}
	}
}


Measured memory_bytes: 13512
#include <bits/stdc++.h>
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
#define x first
#define y second

int main(){
    int n;
    cin >> n;
    vector<pair<ll, ll>> c(n);
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        c[i].x = a+b;
        c[i].y = a-b;
    }
    
    ll min_x=1<<30;
    ll min_y=1<<30;
    ll max_x=-(1<<30);
    ll max_y=-(1<<30);
    rep(i, n){
        if(c[i].x < min_x)min_x=c[i].x;
        if(c[i].y < min_y)min_y=c[i].y;
        if(c[i].x > max_x)max_x=c[i].x;
        if(c[i].y > max_y)max_y=c[i].y;
    }
    cout << max({max_x-min_x, max_y-min_y}) << endl;
}

Measured memory_bytes: 6396
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long sum1 = 0;
		long count1 = 0;
		long sum2 = 0;
		long count2 = 0;
		for (int i = 0; i < n; i++) {
		    int a = sc.nextInt();
		    sum1 += a;
		    sum2 += a;
		    if (i % 2 == 0) {
		        if (sum1 <= 0) {
		            count1 += 1 - sum1;
		            sum1 = 1;
		        }
		        if (sum2 >= 0) {
		            count2 += sum2 + 1;
		            sum2 = -1;
		        }
		    } else {
		        if (sum2 <= 0) {
		            count2 += 1 - sum2;
		            sum2 = 1;
		        }
		        if (sum1 >= 0) {
		            count1 += sum1 + 1;
		            sum1 = -1;
		        }
		    }
		}
		System.out.println(Math.min(count1, count2));
	}
}


Measured memory_bytes: 48340
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;


int main(int argc, char* argv[]) {

	long A, B , flg ,ans = 0;
	string wrk1,wrk2;

	cin >> A >> B;

	for (long i = A; i <= B; i++) {
		std::stringstream ss;
		ss << i;
		wrk1 = ss.str();
		wrk2 = wrk1;
		flg = 1;
		for(int j=0;j<wrk1.length();j++){
			if(wrk1[j] != wrk2[wrk1.length()-j-1]){
				flg = 0;
				break;
			}
		}

		if(flg){
			ans++;
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 384
from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
# import sys
# sys.setrecursionlimit(10**7)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
i_m=9223372036854775807
def inin():
    return int(input())
def stin():
    return input()
def spin():
    return map(int,stin().split())
def lin():                           #takes array as input
    return list(map(int,stin().split()))
def matrix(n):
    #matrix input
    return [list(map(int,input().split()))for i in range(n)]

################################################
def calculate_sum(a, N): #sum of a to N
    # Number of multiples 
    m = N / a 
    # sum of first m natural numbers 
    sum = m * (m + 1) / 2
    # sum of multiples 
    ans = a * sum
    return ans
def series(N):
    return (N*(N+1))//2

def count2Dmatrix(i,list):
    return sum(c.count(i) for c in list)

def modinv(n,p):
    return pow(n,p-2,p)

def GCD(x, y): 
    x=abs(x)
    y=abs(y)
    if(min(x,y)==0):
        return max(x,y)
    while(y): 
        x, y = y, x % y 
    return x
def LCM (x, y):
    return (x * y) // GCD(x, y)
    
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l
def isprime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
prime=[]
def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
q=[]       
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j
# d = {}
 
"""*******************************************************"""
n = inin()
a = lin()

# m = max(a)
c, d = 0, 0

for i in range(n-1):
    if a[i]>a[i+1]:
        d = a[i] - a[i+1]
        c += d
        a[i+1] = a[i]

print(c)

Measured memory_bytes: 33096
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val p = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }

  var allEven = true
  for (ai in a) {
    if (ai % 2 != 0) {
      allEven = false
      break
    }
  }
  if (allEven) {
    if (p == 0) {
      println(Math.pow(2.0, n.toDouble()).toLong())
    } else {
      println(0)
    }
    return
  }


  println(Math.pow(2.0, n.toDouble() - 1).toLong())

}

Measured memory_bytes: 37716
#include<stdio.h>
int main(void)
{
	int a,x;;
	scanf("%d",&a);
	x=0;
	if(a>=105){
		x++;
	}
	if(a>=135){
		x++;
	}
	if(a>=165){
		x++;
	}
	if(a>=189){
		x++;
	}
	if(a>=195){
		x++;
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int x; cin >> x;
  if (x >= 30) cout << "Yes" << '\n';
  else cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3548
# include <bits/stdc++.h>
using namespace std;
int main ()
{
  int n,l;
  cin>>n>>l;
  long long ans=0;
  for (int i=1;i<=n;++i)
    ans=ans+(l+i-1);
  if (l>=0)
    	ans=ans-l;
  else
      {
      	if (l<0)
      	  	if (1-l>n)
      	  	  ans=ans-(l+n-1);
	  }
	printf ("%d\n",ans);
  return 0;
} 

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< ll, ll > P;
typedef pair< int, P > PP;

//-----------------------------------------------------------------------------


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

    int a, b;
    cin >> a >> b;
    int d = b - a;
    cout << (1 + d) * d / 2 - b << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define test int t; cin >> t; while (t--)
#define fast ios::sync_with_stdio(NULL); cin.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define ll long long
typedef vector<ll> vecll;
typedef vector<int> veci;
typedef vector<char> vecc;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define time 1.0 * clock() / CLOCKS_PER_SEC

int main(){
    fast;
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    ll n,k;
    cin>>n>>k;
    if(n>=10)cout<<k;
    else{
        cout<<k+(100*(10-n));
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long a,b;
    cin >> a>>b;
    long ans=a+b;
    if(a-b>ans)
    ans=a-b;
    if(a*b>ans)
    ans=a*b;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (int)n;i++)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int N;
    cin >> N;
    int dif = 0;
    vector<int> v(N);
    for(int i = 0;i < N;i++) cin >> v[i];
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i = 0;i < N;i++)
    {
        if(i%2==0)dif+=v[i];
        else dif-=v[i];
    }
    cout << dif << '\n';
}

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

using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  int ans=0;
  rep(i,N){
    while(a[i]%2==0){
      a[i]/=2;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

var (
	BufferSize = 10*10*10*10*10*10*10 + 10
	n          = 0
	a          = 0
	b          = 0
	c          = 0
	d          = 0
	s          = ""
)

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}

	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}

	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func check() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n = scanInt(sc)
	a = scanInt(sc) - 1
	b = scanInt(sc) - 1
	c = scanInt(sc) - 1
	d = scanInt(sc) - 1
	s = scanStr(sc)

	if c > d {
		abdc()
		return
	}

	abcd()
}

func abdc() {
	canMove := false
	for i := b; ; {
		if s[i-1] != '#' && s[i] != '#' && s[i+1] != '#' {
			canMove = true
		}

		if i == d {
			break
		}

		if i+1 < len(s) && s[i+1] == '.' {
			i += 1
			continue
		}

		if i+2 < len(s) && s[i+2] == '.' {
			i += 2
			continue
		}

		fmt.Printf("No\n")
		return
	}

	if !canMove {
		fmt.Printf("No\n")
		return
	}

	if !move(a, c) {
		fmt.Printf("No\n")
		return
	}

	fmt.Printf("Yes\n")
}

func abcd() {
	if !move(b, d) {
		fmt.Printf("No\n")
		return
	}

	if !move(a, c) {
		fmt.Printf("No\n")
		return
	}

	fmt.Printf("Yes\n")
}

func move(start int, target int) bool {
	for i := start; ; {
		if i == target {
			break
		}

		if i+2 < len(s) && s[i+2] == '.' {
			i += 2
			continue
		}

		if i+1 < len(s) && s[i+1] == '.' {
			i += 1
			continue
		}

		return false
	}

	return true
}

func main() {
	check()
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> next(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> next[i]; next[i]--;
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    long long ans = -1e17;
    for (int i = 0; i < n; ++i) {
        int now = i;
        long long cycle_sum = 0;
        int cycle_len = 0;
        while (true) {
            cycle_sum += c[now];
            cycle_len++;
            now = next[now];
            if (now == i) break;
        }
        long long path_sum = 0;
        int path_len = 0;
        while (true) {
            path_sum += c[now];
            path_len++;
            if (path_len > k) break;
            int laps = (k - path_len) / cycle_len;
            long long score = path_sum + max(cycle_sum, 0ll) * laps;
            ans = max(ans, score);
            now = next[now];
            if (now == i) break;
        }
    }
    cout << ans << endl;
}

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

int main(){
  string s;
  cin >> s;
  int sum = 700;
  if(s[0] == 'o') sum += 100;
  if(s[1] == 'o') sum += 100;
  if(s[2] == 'o') sum += 100;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())
coordinates = []
for i in range(n):
    coordinates.append(list(map(int, input().split(' '))))

sum_length = 0
for i, j in itertools.product(coordinates, coordinates):
    sum_length += pow((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2, 1/2)

average_length = sum_length / n
print(average_length)

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

int main(){
  string s;
  cin >> s;

  if(s=="zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
    return 0;
  }

  int alphabet[26];
  for(int i=0;i<26;i++){
    alphabet[i]=0;
  }

  if(s.length()<26){
    for(int i=0;i<s.length();i++){
      alphabet[s[i]-'a']=1;
    }
    for(int i=0;i<26;i++){
      if(alphabet[i]==0){
        s.push_back(i+'a');
        break;
      }
    }
    cout << s << endl;
    return 0;
  }
  bool flag = true;
  for(int i=24;flag;i--){
    alphabet[s[i+1]-'a']=1;
    for(int j=s[i]-'a';j<26;j++){
      if(alphabet[j]){
        s.erase(s.begin()+i,s.begin()+s.length());
        s.push_back('a'+j);
        cout << s << endl;
        flag = false;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    map<int,vector<int> >A;
    for (int i = 2;i<n+1;i++){
        int x;
        cin>>x;
        A[x].push_back(i);
    }
    for (int i = 1;i<n+1;i++){
        cout<<A[i].size()<<endl;
    }
    return 0;
}

Measured memory_bytes: 25476